1 // Created on: 2013-12-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BVH_Triangulation_Header
17 #define _BVH_Triangulation_Header
19 #include <BVH_PrimitiveSet.hxx>
21 //! Triangulation as an example of BVH primitive set.
22 //! \tparam T Numeric data type
23 //! \tparam N Vector dimension
24 template<class T, int N>
25 class BVH_Triangulation : public BVH_PrimitiveSet<T, N>
29 typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
33 //! Creates empty triangulation.
34 BVH_Triangulation() {}
36 //! Creates empty triangulation.
37 BVH_Triangulation (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
38 : BVH_PrimitiveSet<T, N> (theBuilder)
43 //! Releases resources of triangulation.
44 virtual ~BVH_Triangulation() {}
48 //! Array of vertex coordinates.
49 typename BVH::ArrayType<T, N>::Type Vertices;
51 //! Array of indices of triangle vertices.
56 //! Returns total number of triangles.
57 virtual Standard_Integer Size() const Standard_OVERRIDE
59 return BVH::Array<Standard_Integer, 4>::Size (Elements);
62 //! Returns AABB of entire set of objects.
63 using BVH_PrimitiveSet<T, N>::Box;
65 //! Returns AABB of the given triangle.
66 virtual BVH_Box<T, N> Box (const Standard_Integer theIndex) const Standard_OVERRIDE
68 const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
70 const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value (Vertices, anIndex.x());
71 const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value (Vertices, anIndex.y());
72 const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value (Vertices, anIndex.z());
74 BVH_VecNt aMinPoint (aPoint0), aMaxPoint (aPoint0);
76 BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint1);
77 BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint2);
78 BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint1);
79 BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint2);
80 return BVH_Box<T, N> (aMinPoint, aMaxPoint);
83 //! Returns centroid position along the given axis.
84 virtual T Center (const Standard_Integer theIndex,
85 const Standard_Integer theAxis) const Standard_OVERRIDE
87 const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
89 const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value (Vertices, anIndex.x());
90 const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value (Vertices, anIndex.y());
91 const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value (Vertices, anIndex.z());
92 return (BVH::VecComp<T, N>::Get (aPoint0, theAxis) +
93 BVH::VecComp<T, N>::Get (aPoint1, theAxis) +
94 BVH::VecComp<T, N>::Get (aPoint2, theAxis)) * static_cast<T> (1.0 / 3.0);
97 //! Performs transposing the two given triangles in the set.
98 virtual void Swap (const Standard_Integer theIndex1,
99 const Standard_Integer theIndex2) Standard_OVERRIDE
101 BVH_Vec4i& anIndices1 = BVH::Array<Standard_Integer, 4>::ChangeValue (Elements, theIndex1);
102 BVH_Vec4i& anIndices2 = BVH::Array<Standard_Integer, 4>::ChangeValue (Elements, theIndex2);
103 std::swap (anIndices1, anIndices2);
108 #endif // _BVH_Triangulation_Header