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 // =======================================================================
17 // function : BVH_Triangulation
19 // =======================================================================
20 template<class T, int N>
21 BVH_Triangulation<T, N>::BVH_Triangulation()
26 // =======================================================================
27 // function : ~BVH_Triangulation
29 // =======================================================================
30 template<class T, int N>
31 BVH_Triangulation<T, N>::~BVH_Triangulation()
36 // =======================================================================
39 // =======================================================================
40 template<class T, int N>
41 Standard_Integer BVH_Triangulation<T, N>::Size() const
43 return BVH::Array<Standard_Integer, 4>::Size (Elements);
46 // =======================================================================
49 // =======================================================================
50 template<class T, int N>
51 BVH_Box<T, N> BVH_Triangulation<T, N>::Box (const Standard_Integer theIndex) const
53 const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
55 const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value (Vertices, anIndex.x());
56 const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value (Vertices, anIndex.y());
57 const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value (Vertices, anIndex.z());
59 BVH_VecNt aMinPoint = aPoint0;
60 BVH_VecNt aMaxPoint = aPoint0;
62 BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint1);
63 BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint2);
64 BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint1);
65 BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint2);
67 return BVH_Box<T, N> (aMinPoint, aMaxPoint);
70 // =======================================================================
73 // =======================================================================
74 template<class T, int N>
75 T BVH_Triangulation<T, N>::Center (const Standard_Integer theIndex,
76 const Standard_Integer theAxis) const
78 const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
80 const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value (Vertices, anIndex.x());
81 const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value (Vertices, anIndex.y());
82 const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value (Vertices, anIndex.z());
84 return ( BVH::VecComp<T, N>::Get (aPoint0, theAxis) +
85 BVH::VecComp<T, N>::Get (aPoint1, theAxis) +
86 BVH::VecComp<T, N>::Get (aPoint2, theAxis) ) * static_cast<T> (1.0 / 3.0);
89 // =======================================================================
92 // =======================================================================
93 template<class T, int N>
94 void BVH_Triangulation<T, N>::Swap (const Standard_Integer theIndex1,
95 const Standard_Integer theIndex2)
97 BVH_Vec4i& anIndices1 = BVH::Array<Standard_Integer, 4>::ChangeValue (Elements, theIndex1);
98 BVH_Vec4i& anIndices2 = BVH::Array<Standard_Integer, 4>::ChangeValue (Elements, theIndex2);
100 std::swap (anIndices1, anIndices2);