0028824: Possibility to build OCCT 7.1.0 and above using Visual Studio 2008
[occt.git] / src / BVH / BVH_Triangulation.hxx
CommitLineData
3c4e78f2 1// Created on: 2013-12-20
2// Created by: Denis BOGOLEPOV
d5f74e42 3// Copyright (c) 2013-2014 OPEN CASCADE SAS
3c4e78f2 4//
5// This file is part of Open CASCADE Technology software library.
6//
d5f74e42 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
3c4e78f2 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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _BVH_Triangulation_Header
17#define _BVH_Triangulation_Header
18
19#include <BVH_PrimitiveSet.hxx>
20
679d3878 21//! Triangulation as an example of BVH primitive set.
22//! \tparam T Numeric data type
23//! \tparam N Vector dimension
3c4e78f2 24template<class T, int N>
25class BVH_Triangulation : public BVH_PrimitiveSet<T, N>
26{
27public:
28
3a7a7013 29 typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
3c4e78f2 30
31public:
32
679d3878 33 //! Creates empty triangulation.
e28f12b3 34 BVH_Triangulation() {}
3c4e78f2 35
f5b72419 36 //! Creates empty triangulation.
37 BVH_Triangulation (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
38 : BVH_PrimitiveSet<T, N> (theBuilder)
39 {
40 //
41 }
42
679d3878 43 //! Releases resources of triangulation.
e28f12b3 44 virtual ~BVH_Triangulation() {}
3c4e78f2 45
46public:
47
48 //! Array of vertex coordinates.
3a7a7013 49 typename BVH::ArrayType<T, N>::Type Vertices;
3c4e78f2 50
679d3878 51 //! Array of indices of triangle vertices.
3c4e78f2 52 BVH_Array4i Elements;
53
54public:
55
679d3878 56 //! Returns total number of triangles.
e28f12b3 57 virtual Standard_Integer Size() const Standard_OVERRIDE
58 {
59 return BVH::Array<Standard_Integer, 4>::Size (Elements);
60 }
3c4e78f2 61
7c58a2ab 62 //! Returns AABB of entire set of objects.
63 using BVH_PrimitiveSet<T, N>::Box;
64
679d3878 65 //! Returns AABB of the given triangle.
e28f12b3 66 virtual BVH_Box<T, N> Box (const Standard_Integer theIndex) const Standard_OVERRIDE
67 {
68 const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
69
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());
73
74 BVH_VecNt aMinPoint (aPoint0), aMaxPoint (aPoint0);
75
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);
81 }
3c4e78f2 82
679d3878 83 //! Returns centroid position along the given axis.
3c4e78f2 84 virtual T Center (const Standard_Integer theIndex,
e28f12b3 85 const Standard_Integer theAxis) const Standard_OVERRIDE
86 {
87 const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
88
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);
95 }
3c4e78f2 96
679d3878 97 //! Performs transposing the two given triangles in the set.
3c4e78f2 98 virtual void Swap (const Standard_Integer theIndex1,
e28f12b3 99 const Standard_Integer theIndex2) Standard_OVERRIDE
100 {
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);
104 }
3c4e78f2 105
106};
107
3c4e78f2 108#endif // _BVH_Triangulation_Header