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_Properties_HeaderFile
0017 #define BVH_Properties_HeaderFile
0018 
0019 #include <BVH_Box.hxx>
0020 
0021 #include <Standard_Macro.hxx>
0022 
0023 //! Abstract properties of geometric object.
0024 class BVH_Properties : public Standard_Transient
0025 {
0026   DEFINE_STANDARD_RTTIEXT(BVH_Properties, Standard_Transient)
0027 public:
0028 
0029   //! Releases resources of object properties.
0030   Standard_EXPORT virtual ~BVH_Properties() = 0;
0031 
0032 };
0033 
0034 //! Stores transform properties of geometric object.
0035 template<class T, int N>
0036 class BVH_Transform : public BVH_Properties
0037 {
0038 public:
0039 
0040   //! Type of transformation matrix.
0041   typedef typename BVH::MatrixType<T, N>::Type BVH_MatNt;
0042 
0043 public:
0044 
0045   //! Creates new identity transformation.
0046   BVH_Transform() {}
0047 
0048   //! Creates new transformation with specified matrix.
0049   BVH_Transform (const BVH_MatNt& theTransform) : myTransform (theTransform) {}
0050 
0051   //! Releases resources of transformation properties.
0052   virtual ~BVH_Transform() {}
0053 
0054   //! Returns transformation matrix.
0055   const BVH_MatNt& Transform() const { return myTransform; }
0056 
0057   //! Sets new transformation matrix.
0058   void SetTransform (const BVH_MatNt& theTransform);
0059 
0060   //! Returns inversed transformation matrix.
0061   const BVH_MatNt& Inversed() const { return myTransformInversed; }
0062 
0063   //! Applies transformation matrix to bounding box.
0064   BVH_Box<T, N> Apply (const BVH_Box<T, N>& theBox) const;
0065 
0066 protected:
0067 
0068   BVH_MatNt myTransform;         //!< Transformation matrix
0069   BVH_MatNt myTransformInversed; //!< Inversed transformation matrix
0070 
0071 };
0072 
0073 namespace BVH
0074 {
0075   template<class T, int N> struct MatrixOp
0076   {
0077     // Not implemented
0078   };
0079 
0080   template<class T> struct MatrixOp<T, 4>
0081   {
0082     typedef typename BVH::MatrixType<T, 4>::Type BVH_Mat4t;
0083 
0084     static void Inverse (const BVH_Mat4t& theIn,
0085                          BVH_Mat4t&       theOut)
0086     {
0087       theIn.Inverted (theOut);
0088     }
0089 
0090     typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
0091 
0092     static BVH_Vec4t Multiply (const BVH_Mat4t& theMat,
0093                                const BVH_Vec4t& theVec)
0094     {
0095       BVH_Vec4t aOut = theMat * theVec;
0096       return aOut * static_cast<T> (1.0 / aOut.w());
0097     }
0098   };
0099 
0100   template<class T, int N>
0101   struct UnitVector
0102   {
0103     // Not implemented
0104   };
0105 
0106   template<class T>
0107   struct UnitVector<T, 2>
0108   {
0109     typedef typename BVH::VectorType<T, 2>::Type BVH_Vec2t;
0110     static BVH_Vec2t DX() { return BVH_Vec2t (static_cast<T> (1.0), static_cast<T> (0.0)); }
0111     static BVH_Vec2t DY() { return BVH_Vec2t (static_cast<T> (0.0), static_cast<T> (1.0)); }
0112     static BVH_Vec2t DZ() { return BVH_Vec2t (static_cast<T> (0.0), static_cast<T> (0.0)); }
0113   };
0114 
0115   template<class T>
0116   struct UnitVector<T, 3>
0117   {
0118     typedef typename BVH::VectorType<T, 3>::Type BVH_Vec3t;
0119     static BVH_Vec3t DX() { return BVH_Vec3t (static_cast<T> (1.0), static_cast<T> (0.0), static_cast<T> (0.0)); }
0120     static BVH_Vec3t DY() { return BVH_Vec3t (static_cast<T> (0.0), static_cast<T> (1.0), static_cast<T> (0.0)); }
0121     static BVH_Vec3t DZ() { return BVH_Vec3t (static_cast<T> (0.0), static_cast<T> (0.0), static_cast<T> (1.0)); }
0122   };
0123 
0124   template<class T>
0125   struct UnitVector<T, 4>
0126   {
0127     typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
0128     static BVH_Vec4t DX() { return BVH_Vec4t (static_cast<T> (1.0), static_cast<T> (0.0), static_cast<T> (0.0), static_cast<T> (0.0)); }
0129     static BVH_Vec4t DY() { return BVH_Vec4t (static_cast<T> (0.0), static_cast<T> (1.0), static_cast<T> (0.0), static_cast<T> (0.0)); }
0130     static BVH_Vec4t DZ() { return BVH_Vec4t (static_cast<T> (0.0), static_cast<T> (0.0), static_cast<T> (1.0), static_cast<T> (0.0)); }
0131   };
0132 }
0133 
0134 // =======================================================================
0135 // function : SetTransform
0136 // purpose  :
0137 // =======================================================================
0138 template<class T, int N>
0139 void BVH_Transform<T, N>::SetTransform (const BVH_MatNt& theTransform)
0140 {
0141   myTransform = theTransform;
0142   BVH::MatrixOp<T, N>::Inverse (myTransform, myTransformInversed);
0143 }
0144 
0145 // =======================================================================
0146 // function : Apply
0147 // purpose  :
0148 // =======================================================================
0149 template<class T, int N>
0150 BVH_Box<T, N> BVH_Transform<T, N>::Apply (const BVH_Box<T, N>& theBox) const
0151 {
0152   typename BVH_Box<T, N>::BVH_VecNt aSize = theBox.Size();
0153 
0154   BVH_Box<T, N> aBox;
0155   for (Standard_Integer aX = 0; aX <= 1; ++aX)
0156   {
0157     for (Standard_Integer aY = 0; aY <= 1; ++aY)
0158     {
0159       for (Standard_Integer aZ = 0; aZ <= 1; ++aZ)
0160       {
0161         typename BVH_Box<T, N>::BVH_VecNt aCorner = theBox.CornerMin() +
0162           BVH::UnitVector<T, N>::DX() * aSize * static_cast<T> (aX) +
0163           BVH::UnitVector<T, N>::DY() * aSize * static_cast<T> (aY) +
0164           BVH::UnitVector<T, N>::DZ() * aSize * static_cast<T> (aZ);
0165 
0166         aBox.Add (BVH::MatrixOp<T, N>::Multiply (myTransform, aCorner));
0167       }
0168     }
0169   }
0170 
0171   return aBox;
0172 }
0173 
0174 #endif // _BVH_Properties_Header