Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:14:06

0001 // Created on: 2013-12-20
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef BVH_Triangulation_HeaderFile
0017 #define BVH_Triangulation_HeaderFile
0018 
0019 #include <BVH_PrimitiveSet.hxx>
0020 
0021 //! Triangulation as an example of BVH primitive set.
0022 //! \tparam T Numeric data type
0023 //! \tparam N Vector dimension
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   //! Creates empty triangulation.
0032   BVH_Triangulation() = default;
0033 
0034   //! Creates empty triangulation.
0035   BVH_Triangulation(const opencascade::handle<BVH_Builder<T, N>>& theBuilder)
0036       : BVH_PrimitiveSet<T, N>(theBuilder)
0037   {
0038     //
0039   }
0040 
0041   //! Releases resources of triangulation.
0042   ~BVH_Triangulation() override = default;
0043 
0044 public:
0045   //! Array of vertex coordinates.
0046   typename BVH::ArrayType<T, N>::Type Vertices;
0047 
0048   //! Array of indices of triangle vertices.
0049   BVH_Array4i Elements;
0050 
0051 public:
0052   //! Returns total number of triangles.
0053   int Size() const override { return BVH::Array<int, 4>::Size(Elements); }
0054 
0055   //! Returns AABB of entire set of objects.
0056   using BVH_PrimitiveSet<T, N>::Box;
0057 
0058   //! Returns AABB of the given triangle.
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   //! Returns centroid position along the given axis.
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   //! Performs transposing the two given triangles in the set.
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 // _BVH_Triangulation_Header