0024739: TKOpenGl - port ray-tracing from OpenCL to GLSL for better integration and...
[occt.git] / src / BVH / BVH_Types.lxx
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
16namespace BVHTools
17{
18 template<class T, int N> struct VecComp
19 {
20 // Not implemented
21 };
22
23 template<class T> struct VecComp<T, 2>
24 {
25 typedef typename BVHTools::VectorType<T, 2>::Type BVH_Vec2t;
26
27 static T Get (const BVH_Vec2t& theVec,
28 const Standard_Integer theAxis)
29 {
30 return theAxis == 0 ? theVec.x() : theVec.y();
31 }
32 };
33
34 template<class T> struct VecComp<T, 3>
35 {
36 typedef typename BVHTools::VectorType<T, 3>::Type BVH_Vec3t;
37
38 static T Get (const BVH_Vec3t& theVec,
39 const Standard_Integer theAxis)
40 {
41 return theAxis == 0 ? theVec.x() : ( theAxis == 1 ? theVec.y() : theVec.z() );
42 }
43 };
44
45 template<class T> struct VecComp<T, 4>
46 {
47 typedef typename BVHTools::VectorType<T, 4>::Type BVH_Vec4t;
48
49 static T Get (const BVH_Vec4t& theVec,
50 const Standard_Integer theAxis)
51 {
52 return theAxis == 0
53 ? theVec.x()
54 : (theAxis == 1 ? theVec.y() : ( theAxis == 2 ? theVec.z() : theVec.w() ));
55 }
56 };
57
58 template<class T, int N = 1> struct ArrayOp
59 {
60 typedef typename BVHTools::ArrayType<T, N>::Type BVH_ArrayNt;
61
62 static inline
63 const typename BVHTools::VectorType<T, N>::Type& Value (const BVH_ArrayNt& theArray,
64 const Standard_Integer theIndex)
65 {
66 #ifdef _BVH_USE_STD_VECTOR_
67 return theArray.at (theIndex);
68 #else
69 return theArray.Value (theIndex);
70 #endif
71 }
72
73 static inline
74 typename BVHTools::VectorType<T, N>::Type& ChangeValue (BVH_ArrayNt& theArray,
75 const Standard_Integer theIndex)
76 {
77 #ifdef _BVH_USE_STD_VECTOR_
78 return theArray.at (theIndex);
79 #else
80 return theArray.ChangeValue (theIndex);
81 #endif
82 }
83
84 static inline void Append (BVH_ArrayNt& theArray,
85 const typename BVHTools::VectorType<T, N>::Type& theElement)
86 {
87 #ifdef _BVH_USE_STD_VECTOR_
88 theArray.push_back (theElement);
89 #else
90 theArray.Append (theElement);
91 #endif
92 }
93
94 static inline Standard_Integer Size (const BVH_ArrayNt& theArray)
95 {
96 #ifdef _BVH_USE_STD_VECTOR_
97 return static_cast<Standard_Integer> (theArray.size());
98 #else
99 return static_cast<Standard_Integer> (theArray.Size());
100 #endif
101 }
102
103 static inline void Clear (BVH_ArrayNt& theArray)
104 {
105 #ifdef _BVH_USE_STD_VECTOR_
106 theArray.clear();
107 #else
108 theArray.Clear();
109 #endif
110 }
111 };
112}