File indexing completed on 2026-09-14 09:14:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BVH_Triangulation_HeaderFile
0017 #define BVH_Triangulation_HeaderFile
0018
0019 #include <BVH_PrimitiveSet.hxx>
0020
0021
0022
0023
0024 template <class T, int N>
0025 class BVH_Triangulation : public BVH_PrimitiveSet<T, N>
0026 {
0027 public:
0028 typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
0029
0030 public:
0031
0032 BVH_Triangulation() = default;
0033
0034
0035 BVH_Triangulation(const opencascade::handle<BVH_Builder<T, N>>& theBuilder)
0036 : BVH_PrimitiveSet<T, N>(theBuilder)
0037 {
0038
0039 }
0040
0041
0042 ~BVH_Triangulation() override = default;
0043
0044 public:
0045
0046 typename BVH::ArrayType<T, N>::Type Vertices;
0047
0048
0049 BVH_Array4i Elements;
0050
0051 public:
0052
0053 int Size() const override { return BVH::Array<int, 4>::Size(Elements); }
0054
0055
0056 using BVH_PrimitiveSet<T, N>::Box;
0057
0058
0059 BVH_Box<T, N> Box(const int theIndex) const override
0060 {
0061 const BVH_Vec4i& anIndex = BVH::Array<int, 4>::Value(Elements, theIndex);
0062
0063 const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value(Vertices, anIndex.x());
0064 const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value(Vertices, anIndex.y());
0065 const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value(Vertices, anIndex.z());
0066
0067 BVH_VecNt aMinPoint(aPoint0), aMaxPoint(aPoint0);
0068
0069 BVH::BoxMinMax<T, N>::CwiseMin(aMinPoint, aPoint1);
0070 BVH::BoxMinMax<T, N>::CwiseMin(aMinPoint, aPoint2);
0071 BVH::BoxMinMax<T, N>::CwiseMax(aMaxPoint, aPoint1);
0072 BVH::BoxMinMax<T, N>::CwiseMax(aMaxPoint, aPoint2);
0073 return BVH_Box<T, N>(aMinPoint, aMaxPoint);
0074 }
0075
0076
0077 T Center(const int theIndex, const int theAxis) const override
0078 {
0079 const BVH_Vec4i& anIndex = BVH::Array<int, 4>::Value(Elements, theIndex);
0080
0081 const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value(Vertices, anIndex.x());
0082 const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value(Vertices, anIndex.y());
0083 const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value(Vertices, anIndex.z());
0084 return (BVH::VecComp<T, N>::Get(aPoint0, theAxis) + BVH::VecComp<T, N>::Get(aPoint1, theAxis)
0085 + BVH::VecComp<T, N>::Get(aPoint2, theAxis))
0086 * static_cast<T>(1.0 / 3.0);
0087 }
0088
0089
0090 void Swap(const int theIndex1, const int theIndex2) override
0091 {
0092 BVH_Vec4i& anIndices1 = BVH::Array<int, 4>::ChangeValue(Elements, theIndex1);
0093 BVH_Vec4i& anIndices2 = BVH::Array<int, 4>::ChangeValue(Elements, theIndex2);
0094 std::swap(anIndices1, anIndices2);
0095 }
0096 };
0097
0098 #endif