#pragma once #ifdef _WIN32 #ifdef WIREROUTINGDLL_EXPORTS // VisualStudio DLL 项目模板会将 _EXPORTS 添加到定义预处理器宏。 #define INTERSECTION_API __declspec(dllexport) // _WIN32 #else #define INTERSECTION_API __declspec(dllimport) #endif #else #define INTERSECTION_API #endif #include "Geometry.h" #include #include #include #include #include // std::cerr #include // std::length_error #include // std::exception struct INTERSECTION_API TriangleSegmentIntersectRes { bool hit; float t; TriangleSegmentIntersectRes(bool h, float tt); }; extern TriangleSegmentIntersectRes INTERSECTION_API triangleSegmentIntersection(const LineSegment &segment, const Vec3f &a, const Vec3f &b, const Vec3f &c); class INTERSECTION_API BVHNode { public: size_t left; size_t right; size_t parent; AABB boundingBox; BVHNode(size_t l, size_t r, size_t p, const AABB &aabb); BVHNode(); }; class INTERSECTION_API BVH_intersection { public: const Mesh &mesh; std::vector faceCenters; std::vector nodes; BVH_intersection(const Mesh &mesh_); size_t dfsBuild(std::vector &indicesList, AABB aabb, size_t &nowIdx); bool intersectWithLineSegment(const LineSegment &lineSegment) const; private: AABB computeAABB(const std::vector &indices); bool recursiveLineSegIntersection(const LineSegment &lineSegment, size_t nodeIdx) const; void nth(std::vector &indicesList, size_t kth, int longAxis); void recursiveChoose(std::vector &indicesList, size_t begin, size_t end, size_t kth, int longAxis); };