Browse Source

modify some files

main
forty-twoo 3 years ago
parent
commit
9f0869094f
  1. 40
      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

40
3rdparty/tinynurbs/core/basis.h

@ -15,15 +15,16 @@
namespace tinynurbs
{
/**
/**
* Find the span of the given parameter in the knot vector.
* @param[in] degree Degree of the curve.
* @param[in] knots Knot vector of the curve.
* @param[in] u Parameter value.
* @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
int n = static_cast<int>(knots.size()) - degree - 2;
assert(n >= 0);
@ -61,9 +62,9 @@ template <typename T> int findSpan(unsigned int degree, const std::vector<T> &kn
mid = (int)std::floor((low + high) / 2.0);
}
return mid;
}
}
/**
/**
* Compute a single B-spline basis function
* @param[in] i The ith basis function to compute.
* @param[in] deg Degree of the basis function.
@ -71,8 +72,9 @@ template <typename T> int findSpan(unsigned int degree, const std::vector<T> &kn
* @param[in] u Parameter to evaluate the basis functions at.
* @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;
// Special case
if ((i == 0 && close(u, U[0])) || (i == m - deg - 1 && close(u, U[m])))
@ -113,9 +115,9 @@ template <typename T> T bsplineOneBasis(int i, unsigned int deg, const std::vect
}
}
return N[0];
}
}
/**
/**
* Compute all non-zero B-spline basis functions
* @param[in] deg Degree of the basis function.
* @param[in] span Index obtained from findSpan() corresponding the u and knots.
@ -123,9 +125,9 @@ template <typename T> T bsplineOneBasis(int i, unsigned int deg, const std::vect
* @param[in] u Parameter to evaluate the basis functions at.
* @return N Values of (deg+1) non-zero basis functions.
*/
template <typename T>
std::vector<T> bsplineBasis(unsigned int deg, int span, const std::vector<T> &knots, T u)
{
template <typename T>
std::vector<T> bsplineBasis(unsigned int deg, int span, const std::vector<T> &knots, T u)
{
std::vector<T> N;
N.resize(deg + 1, T(0));
std::vector<T> left, right;
@ -149,9 +151,9 @@ std::vector<T> bsplineBasis(unsigned int deg, int span, const std::vector<T> &kn
N[j] = saved;
}
return N;
}
}
/**
/**
* Compute all non-zero derivatives of B-spline basis functions
* @param[in] deg Degree of the basis function.
* @param[in] span Index obtained from findSpan() corresponding the u and knots.
@ -160,10 +162,10 @@ std::vector<T> bsplineBasis(unsigned int deg, int span, const std::vector<T> &kn
* @param[in] num_ders Number of derivatives to compute (num_ders <= deg)
* @return ders Values of non-zero derivatives of basis functions.
*/
template <typename T>
array2<T> bsplineDerBasis(unsigned int deg, int span, const std::vector<T> &knots, T u,
template <typename T>
array2<T> bsplineDerBasis(unsigned int deg, int span, const std::vector<T> &knots, T u,
int num_ders)
{
{
std::vector<T> left, right;
left.resize(deg + 1, 0.0);
right.resize(deg + 1, 0.0);
@ -269,7 +271,7 @@ array2<T> bsplineDerBasis(unsigned int deg, int span, const std::vector<T> &knot
}
return ders;
}
}
} // namespace tinynurbs

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.
## Platform
The project could run both on Linux and Windows.
## Compile
```
mkdir build
cd build
cmake ..
make
make #if you are using visual studio, find the .sln project and build it.
```
## Run

19
examples/example3_curve_curve_intersection/main.cpp

@ -28,6 +28,25 @@ int main(int argc, char *argv[])
crv1.degree = 2;
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);
BVH_AABB bvh_curve1(11, 2, 100, crv1);
// 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_
#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

3
include/show_libigl.hpp

@ -21,7 +21,8 @@ extern igl::opengl::glfw::Viewer viewer;
#define YELLOW Eigen ::RowVector3d(1, 1, 0)
#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 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 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_)
{
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 <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