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.
62 lines
1.7 KiB
62 lines
1.7 KiB
#pragma once
|
|
|
|
#ifdef _WIN32
|
|
#ifdef WIREROUTINGDLL_EXPORTS // VisualStudio DLL 项目模板会将 <PROJECTNAME>_EXPORTS 添加到定义预处理器宏。
|
|
#define INTERSECTION_API __declspec(dllexport) // _WIN32
|
|
#else
|
|
#define INTERSECTION_API __declspec(dllimport)
|
|
#endif
|
|
#else
|
|
#define INTERSECTION_API
|
|
#endif
|
|
|
|
#include "Geometry.h"
|
|
#include <numeric>
|
|
#include <algorithm>
|
|
#include <vector>
|
|
#include <cstddef>
|
|
#include <iostream> // std::cerr
|
|
#include <stdexcept> // std::length_error
|
|
#include <exception> // 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<Vec3f> faceCenters;
|
|
std::vector<BVHNode> nodes;
|
|
|
|
|
|
BVH_intersection(const Mesh &mesh_);
|
|
size_t dfsBuild(std::vector<size_t> &indicesList, AABB aabb, size_t &nowIdx) ;
|
|
bool intersectWithLineSegment(const LineSegment &lineSegment) const;
|
|
|
|
private:
|
|
AABB computeAABB(const std::vector<size_t> &indices);
|
|
bool recursiveLineSegIntersection(const LineSegment &lineSegment, size_t nodeIdx) const;
|
|
void nth(std::vector<size_t> &indicesList, size_t kth, int longAxis);
|
|
void recursiveChoose(std::vector<size_t> &indicesList, size_t begin, size_t end, size_t kth, int longAxis);
|
|
};
|