/* * @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 #include #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 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}; double param = 0.6; tinynurbs::array2 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 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); // ShowBVHNode(viewer, bvh_curve.bvh_aabb_node); tinynurbs::RationalCurve 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> 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 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(); }