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 //! Releases resources of triangulation.
37 virtual ~BVH_Triangulation() {}
41 //! Array of vertex coordinates.
42 typename BVH::ArrayType<T, N>::Type Vertices;
44 //! Array of indices of triangle vertices.
49 //! Returns total number of triangles.
50 virtual Standard_Integer Size() const Standard_OVERRIDE
52 return BVH::Array<Standard_Integer, 4>::Size (Elements);
55 //! Returns AABB of entire set of objects.
56 using BVH_PrimitiveSet<T, N>::Box;
58 //! Returns AABB of the given triangle.
59 virtual BVH_Box<T, N> Box (const Standard_Integer theIndex) const Standard_OVERRIDE
61 const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
63 const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value (Vertices, anIndex.x());
64 const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value (Vertices, anIndex.y());
65 const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value (Vertices, anIndex.z());
67 BVH_VecNt aMinPoint (aPoint0), aMaxPoint (aPoint0);
69 BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint1);
70 BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint2);
71 BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint1);
72 BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint2);
73 return BVH_Box<T, N> (aMinPoint, aMaxPoint);
76 //! Returns centroid position along the given axis.
77 virtual T Center (const Standard_Integer theIndex,
78 const Standard_Integer theAxis) const Standard_OVERRIDE
80 const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
82 const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value (Vertices, anIndex.x());
83 const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value (Vertices, anIndex.y());
84 const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value (Vertices, anIndex.z());
85 return (BVH::VecComp<T, N>::Get (aPoint0, theAxis) +
86 BVH::VecComp<T, N>::Get (aPoint1, theAxis) +
87 BVH::VecComp<T, N>::Get (aPoint2, theAxis)) * static_cast<T> (1.0 / 3.0);
90 //! Performs transposing the two given triangles in the set.
91 virtual void Swap (const Standard_Integer theIndex1,
92 const Standard_Integer theIndex2) Standard_OVERRIDE
94 BVH_Vec4i& anIndices1 = BVH::Array<Standard_Integer, 4>::ChangeValue (Elements, theIndex1);
95 BVH_Vec4i& anIndices2 = BVH::Array<Standard_Integer, 4>::ChangeValue (Elements, theIndex2);
96 std::swap (anIndices1, anIndices2);
101 #endif // _BVH_Triangulation_Header