Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:19

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 
0029   typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
0030 
0031 public:
0032 
0033   //! Creates empty triangulation.
0034   BVH_Triangulation() {}
0035 
0036   //! Creates empty triangulation.
0037   BVH_Triangulation (const opencascade::handle<BVH_Builder<T, N> >& theBuilder)
0038   : BVH_PrimitiveSet<T, N> (theBuilder)
0039   {
0040     //
0041   }
0042 
0043   //! Releases resources of triangulation.
0044   virtual ~BVH_Triangulation() {}
0045 
0046 public:
0047 
0048   //! Array of vertex coordinates.
0049   typename BVH::ArrayType<T, N>::Type Vertices;
0050 
0051   //! Array of indices of triangle vertices.
0052   BVH_Array4i Elements;
0053 
0054 public:
0055 
0056   //! Returns total number of triangles.
0057   virtual Standard_Integer Size() const Standard_OVERRIDE
0058   {
0059     return BVH::Array<Standard_Integer, 4>::Size (Elements);
0060   }
0061 
0062   //! Returns AABB of entire set of objects.
0063   using BVH_PrimitiveSet<T, N>::Box;
0064 
0065   //! Returns AABB of the given triangle.
0066   virtual BVH_Box<T, N> Box (const Standard_Integer theIndex) const Standard_OVERRIDE
0067   {
0068     const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
0069 
0070     const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value (Vertices, anIndex.x());
0071     const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value (Vertices, anIndex.y());
0072     const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value (Vertices, anIndex.z());
0073 
0074     BVH_VecNt aMinPoint (aPoint0), aMaxPoint (aPoint0);
0075 
0076     BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint1);
0077     BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint2);
0078     BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint1);
0079     BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint2);
0080     return BVH_Box<T, N> (aMinPoint, aMaxPoint);
0081   }
0082 
0083   //! Returns centroid position along the given axis.
0084   virtual T Center (const Standard_Integer theIndex,
0085                     const Standard_Integer theAxis) const Standard_OVERRIDE
0086   {
0087     const BVH_Vec4i& anIndex = BVH::Array<Standard_Integer, 4>::Value (Elements, theIndex);
0088 
0089     const BVH_VecNt& aPoint0 = BVH::Array<T, N>::Value (Vertices, anIndex.x());
0090     const BVH_VecNt& aPoint1 = BVH::Array<T, N>::Value (Vertices, anIndex.y());
0091     const BVH_VecNt& aPoint2 = BVH::Array<T, N>::Value (Vertices, anIndex.z());
0092     return (BVH::VecComp<T, N>::Get (aPoint0, theAxis) +
0093             BVH::VecComp<T, N>::Get (aPoint1, theAxis) +
0094             BVH::VecComp<T, N>::Get (aPoint2, theAxis)) * static_cast<T> (1.0 / 3.0);
0095   }
0096 
0097   //! Performs transposing the two given triangles in the set.
0098   virtual void Swap (const Standard_Integer theIndex1,
0099                      const Standard_Integer theIndex2) Standard_OVERRIDE
0100   {
0101     BVH_Vec4i& anIndices1 = BVH::Array<Standard_Integer, 4>::ChangeValue (Elements, theIndex1);
0102     BVH_Vec4i& anIndices2 = BVH::Array<Standard_Integer, 4>::ChangeValue (Elements, theIndex2);
0103     std::swap (anIndices1, anIndices2);
0104   }
0105 
0106 };
0107 
0108 #endif // _BVH_Triangulation_Header