0025234: Implementing LBVH builder
[occt.git] / src / BVH / BVH_Types.hxx
1 // Created on: 2013-12-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BVH_Types_Header
17 #define _BVH_Types_Header
18
19 // Use this macro to switch between STL and OCCT vector types
20 #define _BVH_USE_STD_VECTOR_
21
22 #include <NCollection_Vec2.hxx>
23 #include <NCollection_Vec3.hxx>
24 #include <NCollection_Vec4.hxx>
25 #include <NCollection_Vector.hxx>
26 #include <NCollection_Mat4.hxx>
27 #include <Standard_Type.hxx>
28
29 #include <vector>
30
31 namespace BVH
32 {
33   //! Allows for fast switching between Eigen and NCollection vectors.
34   template<class T, int N> struct VectorType
35   {
36     // Not implemented
37   };
38
39   template<class T> struct VectorType<T, 1>
40   {
41     typedef T Type;
42   };
43
44   template<class T> struct VectorType<T, 2>
45   {
46     typedef NCollection_Vec2<T> Type;
47   };
48
49   template<class T> struct VectorType<T, 3>
50   {
51     typedef NCollection_Vec3<T> Type;
52   };
53
54   template<class T> struct VectorType<T, 4>
55   {
56     typedef NCollection_Vec4<T> Type;
57   };
58
59   template<class T, int N = 1> struct ArrayType
60   {
61   #ifndef _BVH_USE_STD_VECTOR_
62     typedef NCollection_Vector<typename VectorType<T, N>::Type> Type;
63   #else
64     typedef std::vector<typename VectorType<T, N>::Type> Type;
65   #endif
66   };
67
68   //! Allows to fast switching between Eigen and NCollection matrices.
69   template<class T, int N> struct MatrixType
70   {
71     // Not implemented
72   };
73
74   template<class T> struct MatrixType<T, 4>
75   {
76     typedef NCollection_Mat4<T> Type;
77   };
78
79   template<class T>
80   static inline Standard_Integer IntFloor (const T theValue)
81   {
82     const Standard_Integer aRes = static_cast<Standard_Integer> (theValue);
83     
84     return aRes - static_cast<Standard_Integer> (aRes > theValue);
85   }
86 }
87
88 //! 2D vector of integers.
89 typedef BVH::VectorType<Standard_Integer, 2>::Type BVH_Vec2i;
90 //! 3D vector of integers.
91 typedef BVH::VectorType<Standard_Integer, 3>::Type BVH_Vec3i;
92 //! 4D vector of integers.
93 typedef BVH::VectorType<Standard_Integer, 4>::Type BVH_Vec4i;
94
95 //! Array of 2D vectors of integers.
96 typedef BVH::ArrayType<Standard_Integer, 2>::Type BVH_Array2i;
97 //! Array of 3D vectors of integers.
98 typedef BVH::ArrayType<Standard_Integer, 3>::Type BVH_Array3i;
99 //! Array of 4D vectors of integers.
100 typedef BVH::ArrayType<Standard_Integer, 4>::Type BVH_Array4i;
101
102 //! 2D vector of single precision reals.
103 typedef BVH::VectorType<Standard_ShortReal, 2>::Type BVH_Vec2f;
104 //! 3D vector of single precision reals.
105 typedef BVH::VectorType<Standard_ShortReal, 3>::Type BVH_Vec3f;
106 //! 4D vector of single precision reals.
107 typedef BVH::VectorType<Standard_ShortReal, 4>::Type BVH_Vec4f;
108
109 //! Array of 2D vectors of single precision reals.
110 typedef BVH::ArrayType<Standard_ShortReal, 2>::Type BVH_Array2f;
111 //! Array of 3D vectors of single precision reals.
112 typedef BVH::ArrayType<Standard_ShortReal, 3>::Type BVH_Array3f;
113 //! Array of 4D vectors of single precision reals.
114 typedef BVH::ArrayType<Standard_ShortReal, 4>::Type BVH_Array4f;
115
116 //! 2D vector of double precision reals.
117 typedef BVH::VectorType<Standard_Real, 2>::Type BVH_Vec2d;
118 //! 3D vector of double precision reals.
119 typedef BVH::VectorType<Standard_Real, 3>::Type BVH_Vec3d;
120 //! 4D vector of double precision reals.
121 typedef BVH::VectorType<Standard_Real, 4>::Type BVH_Vec4d;
122
123 //! Array of 2D vectors of double precision reals.
124 typedef BVH::ArrayType<Standard_Real, 2>::Type BVH_Array2d;
125 //! Array of 3D vectors of double precision reals.
126 typedef BVH::ArrayType<Standard_Real, 3>::Type BVH_Array3d;
127 //! Array of 4D vectors of double precision reals.
128 typedef BVH::ArrayType<Standard_Real, 4>::Type BVH_Array4d;
129
130 //! 4x4 matrix of single precision reals.
131 typedef BVH::MatrixType<Standard_ShortReal, 4>::Type BVH_Mat4f;
132
133 //! 4x4 matrix of double precision reals.
134 typedef BVH::MatrixType<Standard_Real, 4>::Type BVH_Mat4d;
135
136 #include <BVH_Types.lxx>
137
138 #endif // _BVH_Types_Header