6 changed files with 184 additions and 65 deletions
			
			
		@ -1 +1 @@ | 
				
			|||||
test | 
					Nurbs curve surface intersection calculation | 
				
			||||
@ -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); | 
				
			||||
@ -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; | 
				
			||||
 | 
					} | 
				
			||||
@ -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…
					
					
				
		Reference in new issue