Browse Source

modify some files

main
forty-twoo 3 years ago
parent
commit
9f0869094f
  1. 6
      3rdparty/tinynurbs/core/basis.h
  2. 8
      README.md
  3. 19
      examples/example3_curve_curve_intersection/main.cpp
  4. 11
      include/newton.hpp
  5. 3
      include/show_libigl.hpp
  6. 9
      src/intersection.cpp
  7. 30
      src/newton.cpp

6
3rdparty/tinynurbs/core/basis.h

@ -22,7 +22,8 @@ namespace tinynurbs
* @param[in] u Parameter value. * @param[in] u Parameter value.
* @return Span index into the knot vector such that (span - 1) < u <= span * @return Span index into the knot vector such that (span - 1) < u <= span
*/ */
template <typename T> int findSpan(unsigned int degree, const std::vector<T> &knots, T u) template <typename T>
int findSpan(unsigned int degree, const std::vector<T> &knots, T u)
{ {
// index of last control point // index of last control point
int n = static_cast<int>(knots.size()) - degree - 2; int n = static_cast<int>(knots.size()) - degree - 2;
@ -71,7 +72,8 @@ template <typename T> int findSpan(unsigned int degree, const std::vector<T> &kn
* @param[in] u Parameter to evaluate the basis functions at. * @param[in] u Parameter to evaluate the basis functions at.
* @return The value of the ith basis function at u. * @return The value of the ith basis function at u.
*/ */
template <typename T> T bsplineOneBasis(int i, unsigned int deg, const std::vector<T> &U, T u) template <typename T>
T bsplineOneBasis(int i, unsigned int deg, const std::vector<T> &U, T u)
{ {
int m = static_cast<int>(U.size()) - 1; int m = static_cast<int>(U.size()) - 1;
// Special case // Special case

8
README.md

@ -4,12 +4,18 @@
**STL**, **Libigl**, **Eigen** and the dependencies of the **igl::opengl::glfw::Viewer (OpenGL, glad and GLFW)**. The CMake build system will automatically download libigl and its dependencies using CMake FetchContent, thus requiring no setup on your part. **STL**, **Libigl**, **Eigen** and the dependencies of the **igl::opengl::glfw::Viewer (OpenGL, glad and GLFW)**. The CMake build system will automatically download libigl and its dependencies using CMake FetchContent, thus requiring no setup on your part.
## Platform
The project could run both on Linux and Windows.
## Compile ## Compile
``` ```
mkdir build mkdir build
cd build cd build
cmake .. cmake ..
make make #if you are using visual studio, find the .sln project and build it.
``` ```
## Run ## Run

19
examples/example3_curve_curve_intersection/main.cpp

@ -28,6 +28,25 @@ int main(int argc, char *argv[])
crv1.degree = 2; crv1.degree = 2;
crv1.weights = {1, 1, 1, 1, 1}; crv1.weights = {1, 1, 1, 1, 1};
double param = 0.6;
tinynurbs::array2<double> ders = tinynurbs::bsplineDerBasis(crv1.degree, tinynurbs::findSpan(crv1.degree, crv1.knots, param), crv1.knots, param, 1);
std::cout << "row:" << ders.rows() << " col:" << ders.cols() << std::endl;
for (int i = 0; i < ders.rows(); i++)
{
for (int j = 0; j < ders.cols(); j++)
{
std::cout << ders(i, j) << " ";
}
std::cout << std::endl;
}
std::vector<double> basis = tinynurbs::bsplineBasis(crv1.degree, tinynurbs::findSpan(crv1.degree, crv1.knots, param), crv1.knots, param);
for (auto it : basis)
{
std::cout << it << std::endl;
}
/***
ShowCurve_Igl(crv1, 5000, YELLOW); ShowCurve_Igl(crv1, 5000, YELLOW);
BVH_AABB bvh_curve1(11, 2, 100, crv1); BVH_AABB bvh_curve1(11, 2, 100, crv1);
// bvh_curve.Build_NurbsCurve(crv, bvh_curve.bvh_aabb_node, 0, 0, tstep); // bvh_curve.Build_NurbsCurve(crv, bvh_curve.bvh_aabb_node, 0, 0, tstep);

11
include/newton.hpp

@ -1,4 +1,15 @@
/*
* @File Created: 2022-11-26, 17:43:27
* @Last Modified: 2022-11-26, 18:50:24
* @Author: forty-twoo
* @Copyright (c) 2022, Caiyue Li(li_caiyue@zju.edu.cn), All rights reserved.
*/
#ifndef NEWTON_H_ #ifndef NEWTON_H_
#define NEWTON_H_ #define NEWTON_H_
#include "bvh.hpp"
std::vector<double> newton_curve_curve(BVH_AABB_NodePtr boxPtr1, BVH_AABB_NodePtr boxPtr2, const double &eps, bool &isConvergence);
#endif #endif

3
include/show_libigl.hpp

@ -21,7 +21,8 @@ extern igl::opengl::glfw::Viewer viewer;
#define YELLOW Eigen ::RowVector3d(1, 1, 0) #define YELLOW Eigen ::RowVector3d(1, 1, 0)
#define PINK Eigen ::RowVector3d(0.8, 0.2, 0.6) #define PINK Eigen ::RowVector3d(0.8, 0.2, 0.6)
void ShowCurve_Igl(tinynurbs::RationalCurve<double> &curve, double sampleNum, Eigen::RowVector3d color) void ShowSurface_Igl(tinynurbs::RationalSurface<double> &surface, double sampleNumU, double sampleNumV, Eigen::RowVector3d color); void ShowCurve_Igl(tinynurbs::RationalCurve<double> &curve, double sampleNum, Eigen::RowVector3d color);
void ShowSurface_Igl(tinynurbs::RationalSurface<double> &surface, double sampleNumU, double sampleNumV, Eigen::RowVector3d color);
void ShowBVHNode_Igl(BVH_AABB_NodePtr bvhNode, Eigen::RowVector3d color); void ShowBVHNode_Igl(BVH_AABB_NodePtr bvhNode, Eigen::RowVector3d color);
void ShowAABB_Igl(AABB bound, Eigen::RowVector3d color); void ShowAABB_Igl(AABB bound, Eigen::RowVector3d color);

9
src/intersection.cpp

@ -13,15 +13,6 @@ bool CurveCurveBVHIntersect(BVH_AABB_NodePtr &BoxPtr1, BVH_AABB_NodePtr &BoxPtr2
AABB box1 = BoxPtr1->bound; AABB box1 = BoxPtr1->bound;
AABB box2 = BoxPtr2->bound; AABB box2 = BoxPtr2->bound;
/*
std::cout << "Box1 : ";
box1.ShowAABB();
ShowAABB_Igl(box1, Eigen::RowVector3d(1, 0, 0));
std::cout << "Box2 : ";
box2.ShowAABB();
ShowAABB_Igl(box2, Eigen::RowVector3d(0, 0, 1));
*/
auto LineIntersect = [](double x1, double x2, double x1_, double x2_) auto LineIntersect = [](double x1, double x2, double x1_, double x2_)
{ {
bool LIntersect = true; bool LIntersect = true;

30
src/newton.cpp

@ -1 +1,31 @@
/*
* @File Created: 2022-11-26, 17:43:34
* @Last Modified: 2022-11-26, 18:50:31
* @Author: forty-twoo
* @Copyright (c) 2022, Caiyue Li(li_caiyue@zju.edu.cn), All rights reserved.
*/
#include "newton.hpp" #include "newton.hpp"
#include <Eigen/Core>
std::vector<double> newton_curve_curve(BVH_AABB_NodePtr boxPtr1, BVH_AABB_NodePtr boxPtr2, const double &eps, bool &isConvergence)
{
double param1_st = boxPtr1->param[0].first;
double param1_ed = boxPtr1->param[0].second;
double param2_st = boxPtr2->param[0].first;
double param2_ed = boxPtr2->param[0].second;
double t1 = (param1_st + param1_ed) / 2.0;
double t2 = (param2_st + param2_st) / 2.0;
Eigen::MatrixXd F(2, 2);
tinynurbs::RationalCurve<double> *crvPtr1 = boxPtr1->myBVH->NurbsCurvePtr;
tinynurbs::array2<double> der_Fx = tinynurbs::bsplineDerBasis(crvPtr1->degree, tinynurbs::findSpan(crvPtr1->degree, crvPtr1->knots, t1), crvPtr1->knots, t1, 1);
Eigen::Vector2d t(t1, t2);
Eigen::MatrixXd JacobinF(2, 2);
bool iterFlag = true;
}
Loading…
Cancel
Save