You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.6 KiB
93 lines
3.6 KiB
/*
|
|
* @File Created: 2022-11-26, 16:52:29
|
|
* @Last Modified: 2022-11-26, 18:51:06
|
|
* @Author: forty-twoo
|
|
* @Copyright (c) 2022, Caiyue Li(li_caiyue@zju.edu.cn), All rights reserved.
|
|
*/
|
|
|
|
#include <igl/opengl/glfw/Viewer.h>
|
|
#include <tinynurbs/tinynurbs.h>
|
|
#include "bvh.hpp"
|
|
#include "show_libigl.hpp"
|
|
#include "intersection.hpp"
|
|
|
|
igl::opengl::glfw::Viewer viewer;
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
|
|
viewer.data().point_size = 5;
|
|
|
|
tinynurbs::RationalCurve<double> crv1; // Planar curve using float32
|
|
crv1.control_points = {glm::vec3(-3, 0, 0), // std::vector of 3D points
|
|
glm::vec3(-1, 4, 0),
|
|
glm::vec3(1, -5, 0),
|
|
glm::vec3(2, 1, 0),
|
|
glm::vec3(4, -1, 0)};
|
|
crv1.knots = {0, 0, 0, 1, 2, 3, 3, 3}; // std::vector of floats
|
|
crv1.degree = 2;
|
|
crv1.weights = {1, 1, 1, 1, 1};
|
|
|
|
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);
|
|
// ShowBVHNode(viewer, bvh_curve.bvh_aabb_node);
|
|
|
|
tinynurbs::RationalCurve<double> crv2; // Planar curve using float32
|
|
crv2.control_points = {glm::vec3(-4, 4, 0), // std::vector of 3D points
|
|
glm::vec3(-2, 2, 0),
|
|
glm::vec3(1, -1, 0),
|
|
glm::vec3(3, -3, 0),
|
|
glm::vec3(4, -4, 0)};
|
|
crv2.knots = {0, 0, 0, 1, 2, 3, 3, 3}; // std::vector of floats
|
|
crv2.degree = 2;
|
|
crv2.weights = {1, 1, 1, 1, 1};
|
|
|
|
ShowCurve_Igl(crv2, 5000, YELLOW);
|
|
BVH_AABB bvh_curve2(11, 2, 100, crv2);
|
|
|
|
double tstep1 = *(crv1.knots.end() - 1);
|
|
double tstep2 = *(crv2.knots.end() - 1);
|
|
bvh_curve1.Build_NurbsCurve(crv1, bvh_curve1.bvh_aabb_node, 0, 0, tstep1);
|
|
bvh_curve2.Build_NurbsCurve(crv2, bvh_curve2.bvh_aabb_node, 0, 0, tstep2);
|
|
|
|
std::vector<std::pair<BVH_AABB_NodePtr, BVH_AABB_NodePtr>> IstNodePtr;
|
|
if (CurveCurveBVHIntersect(bvh_curve1.bvh_aabb_node, bvh_curve2.bvh_aabb_node, IstNodePtr))
|
|
{
|
|
if (IstNodePtr.size() != 0)
|
|
std::cout << "Curve1 and Curve2 intersect!\n";
|
|
else
|
|
std::cout << "Curve1 and Curve2 not intersect!\n";
|
|
int idx = 0;
|
|
for (auto it : IstNodePtr)
|
|
{
|
|
ShowAABB_Igl(it.first->bound, RED);
|
|
ShowAABB_Igl(it.second->bound, GREEN);
|
|
|
|
std::cout << "The " << idx++ << "th boxes pair lie on\n"
|
|
<< " min_point ("
|
|
<< it.first->bound.Bmin.x << ", " << it.first->bound.Bmin.y << ", " << it.first->bound.Bmin.z << ") , max_point (" << it.first->bound.Bmax.x << ", " << it.first->bound.Bmax.y << ", " << it.first->bound.Bmax.z << ")\n";
|
|
std::cout << " min_point ("
|
|
<< it.second->bound.Bmin.x << ", " << it.second->bound.Bmin.y << ", " << it.second->bound.Bmin.z << ") , max_point (" << it.second->bound.Bmax.x << ", " << it.second->bound.Bmax.y << ", " << it.second->bound.Bmax.z << ")\n";
|
|
}
|
|
}
|
|
|
|
/*
|
|
ShowCurve_Igl(viewer, crv, 100);
|
|
BVH_AABB bvh_curve(5, 2, 100);
|
|
double tstep = *(crv.knots.end() - 1);
|
|
bvh_curve.Build_NurbsCurve(crv, bvh_curve.bvh_aabb_node, 0, 0, tstep);
|
|
ShowBVHNode(viewer, bvh_curve.bvh_aabb_node);
|
|
*/
|
|
|
|
/*
|
|
double u = 0.5;
|
|
std::vector<double> basis = tinynurbs::bsplineBasis(crv.degree, tinynurbs::findSpan(crv.degree, crv.knots, u), crv.knots, u);
|
|
for (auto it : basis)
|
|
{
|
|
std::cout << it << std::endl;
|
|
}
|
|
*/
|
|
|
|
viewer.launch();
|
|
}
|
|
|