Browse Source

add some files

main
forty-twoo 2 years ago
parent
commit
f8ac9b7fed
  1. 2
      README.md
  2. 4
      include/bvh.hpp
  3. 5
      include/show_in_libigl.hpp
  4. 93
      src/bvh.cpp
  5. 12
      src/main.cpp
  6. 25
      src/show_in_libigl.cpp

2
README.md

@ -1 +1 @@
test Nurbs curve surface intersection calculation

4
include/bvh.hpp

@ -25,7 +25,6 @@ typedef struct BVH_AABB_Node
std::vector<struct BVH_AABB_Node *> childPtr; //把每个孩子结点指针存储到容器里 std::vector<struct BVH_AABB_Node *> childPtr; //把每个孩子结点指针存储到容器里
} BVH_AABB_Node, *BVH_AABB_NodePtr; } BVH_AABB_Node, *BVH_AABB_NodePtr;
class BVH_AABB class BVH_AABB
{ {
public: public:
@ -48,9 +47,6 @@ public:
BVH_AABB_NodePtr Build_NurbsSurface(tinynurbs::RationalSurface<double> &surface, BVH_AABB_NodePtr &curNode, int curLevel, double u, double v, double ustep, double vstep); BVH_AABB_NodePtr Build_NurbsSurface(tinynurbs::RationalSurface<double> &surface, BVH_AABB_NodePtr &curNode, int curLevel, double u, double v, double ustep, double vstep);
AABB &UnionBound(const AABB &a, const AABB &b); AABB &UnionBound(const AABB &a, const AABB &b);
AABB &UpdateBound(const AABB &bound, const glm::vec3 &p); AABB &UpdateBound(const AABB &bound, const glm::vec3 &p);
}; };
#endif // !BVH_H_ #endif // !BVH_H_

5
include/show_in_libigl.hpp

@ -0,0 +1,5 @@
#include "bvh.hpp"
#include <igl/opengl/glfw/Viewer.h>
void ShowCurve_Igl(igl::opengl::glfw::Viewer viewer, tinynurbs::RationalCurve<double> &curve, double sampleNum);
void ShowSurface_Igl(igl::opengl::glfw::Viewer viewer, tinynurbs::RationalSurface<double> &surface, double sampleNumU, double sampleNumV);

93
src/bvh.cpp

@ -0,0 +1,93 @@
#include "bvh.hpp"
AABB &BVH_AABB::UnionBound(const AABB &a, const AABB &b)
{
AABB ret;
ret.Bmin = glm::vec3(fmin(a.Bmin.x, b.Bmin.x),
fmin(a.Bmin.y, b.Bmin.y),
fmin(a.Bmin.z, b.Bmin.z));
ret.Bmax = glm::vec3(fmax(a.Bmax.x, b.Bmax.x),
fmax(a.Bmax.y, b.Bmax.y),
fmax(a.Bmax.z, b.Bmax.z));
return ret;
}
AABB &BVH_AABB::UpdateBound(const AABB &bound, const glm::vec3 &p)
{
AABB ret;
ret.Bmin = glm::vec3(fmin(bound.Bmin.x, p.x),
fmin(bound.Bmin.y, p.y),
fmin(bound.Bmin.z, p.z));
ret.Bmax = glm::vec3(fmax(bound.Bmax.x, p.x),
fmax(bound.Bmax.y, p.y),
fmax(bound.Bmax.z, p.z));
return ret;
}
BVH_AABB_NodePtr BVH_AABB::Build_NurbsCurve(tinynurbs::RationalCurve<double> &curve, BVH_AABB_NodePtr &curNode, int curLevel, double t, double tstep)
{
if (curLevel == Hlevel)
{
for (double i = t; i < t + tstep; i += tstep / sampleNum)
{
curNode->bound = UpdateBound(curNode->bound, tinynurbs::curvePoint(curve, i));
}
curNode->childPtr.clear();
curNode->param.push_back(std::make_pair(t, t + tstep));
return curNode;
}
BVH_AABB_NodePtr childNode1 = new BVH_AABB_Node;
BVH_AABB_NodePtr childNode2 = new BVH_AABB_Node;
double tstep_ = tstep / (double)BranchNum;
Build_NurbsCurve(curve, childNode1, curLevel + 1, t, tstep_);
Build_NurbsCurve(curve, childNode2, curLevel + 1, t + tstep_, tstep_);
curNode->bound = UnionBound(curNode->bound, childNode1->bound);
curNode->bound = UnionBound(curNode->bound, childNode2->bound);
curNode->childPtr.push_back(childNode1);
curNode->childPtr.push_back(childNode2);
curNode->param.push_back(std::make_pair(t, t + tstep));
return curNode;
}
BVH_AABB_NodePtr BVH_AABB::Build_NurbsSurface(tinynurbs::RationalSurface<double> &surface, BVH_AABB_NodePtr &curNode, int curLevel, double u, double v, double ustep, double vstep)
{
if (curLevel == Hlevel)
{
for (double i = u; i < u + ustep; i++)
{
for (double j = v; j < v + vstep; j++)
{
curNode->bound = UpdateBound(curNode->bound, tinynurbs::surfacePoint(surface, i, j));
}
}
curNode->childPtr.clear();
curNode->param.push_back(std::make_pair(u, u + ustep));
curNode->param.push_back(std::make_pair(v, v + vstep));
return curNode;
}
BVH_AABB_NodePtr childNode1 = new BVH_AABB_Node;
BVH_AABB_NodePtr childNode2 = new BVH_AABB_Node;
BVH_AABB_NodePtr childNode3 = new BVH_AABB_Node;
BVH_AABB_NodePtr childNode4 = new BVH_AABB_Node;
double ustep_ = ustep / (double)BranchNum;
double vstep_ = vstep / (double)BranchNum;
Build_NurbsSurface(surface, childNode1, curLevel + 1, u, v, ustep_, vstep_);
Build_NurbsSurface(surface, childNode2, curLevel + 1, u + ustep_, v, ustep_, vstep_);
Build_NurbsSurface(surface, childNode3, curLevel + 1, u, v + vstep_, ustep_, vstep_);
Build_NurbsSurface(surface, childNode4, curLevel + 1, u + ustep_, v + vstep_, ustep_, vstep_);
curNode->param.push_back(std::make_pair(u, u + ustep));
curNode->param.push_back(std::make_pair(v, v + vstep));
return curNode;
}

12
src/main.cpp

@ -3,17 +3,16 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// Inline mesh of a cube // Inline mesh of a cube
const Eigen::MatrixXd V= (Eigen::MatrixXd(8,3)<< const Eigen::MatrixXd V = (Eigen::MatrixXd(8, 3) << 0.0, 0.0, 0.0,
0.0,0.0,0.0,
0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
0.0, 1.0, 1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
1.0,1.0,1.0).finished(); 1.0, 1.0, 1.0)
const Eigen::MatrixXi F = (Eigen::MatrixXi(12,3)<< .finished();
0,6,4, const Eigen::MatrixXi F = (Eigen::MatrixXi(12, 3) << 0, 6, 4,
0, 2, 6, 0, 2, 6,
0, 3, 2, 0, 3, 2,
0, 1, 3, 0, 1, 3,
@ -24,7 +23,8 @@ int main(int argc, char *argv[])
0, 4, 5, 0, 4, 5,
0, 5, 1, 0, 5, 1,
1, 5, 7, 1, 5, 7,
1,7,3).finished(); 1, 7, 3)
.finished();
// Plot the mesh // Plot the mesh
igl::opengl::glfw::Viewer viewer; igl::opengl::glfw::Viewer viewer;

25
src/show_in_libigl.cpp

@ -0,0 +1,25 @@
#include "show_in_libigl.hpp"
void ShowCurve_Igl(igl::opengl::glfw::Viewer viewer, tinynurbs::RationalCurve<double> &curve, double sampleNum)
{
double T = *(curve.knots.end() - 1);
for (double i = 0; i < T; i += T / sampleNum)
{
auto point = tinynurbs::curvePoint(curve, i);
pt << point.x, point.y, point.z;
viewer.data().add_points(pt, Eigen::RowVector3d(0, 1, 0));
}
}
void ShowSurface_Igl(igl::opengl::glfw::Viewer viewer, tinynurbs::RationalCurve<double> &curve, double sampleNumU, double sampleNumV)
{
double T = *(curve.knots.end() - 1);
for (double i = 0; i < T; i += T / sampleNum)
{
auto point = tinynurbs::curvePoint(curve, i);
pt << point.x, point.y, point.z;
viewer.data().add_points(pt, Eigen::RowVector3d(0, 1, 0));
}
}
Loading…
Cancel
Save