1 | #ifndef _HavranRayCaster_H__
|
---|
2 | #define _HavranRayCaster_H__
|
---|
3 |
|
---|
4 |
|
---|
5 | #include "RayCaster.h"
|
---|
6 | #include "Containers.h"
|
---|
7 | #include <string>
|
---|
8 |
|
---|
9 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
10 |
|
---|
11 | #include "ktbconf.h"
|
---|
12 | #include "raypack.h"
|
---|
13 |
|
---|
14 | #endif // USE_HAVRAN_RAYCASTER
|
---|
15 |
|
---|
16 | namespace GtpVisibilityPreprocessor {
|
---|
17 |
|
---|
18 |
|
---|
19 | class Intersectable;
|
---|
20 | class VssRay;
|
---|
21 | class KdTree;
|
---|
22 | class Ray;
|
---|
23 | class SimpleRayContainer;
|
---|
24 | class AxisAlignedBox3;
|
---|
25 | class Vector3;
|
---|
26 | struct VssRayContainer;
|
---|
27 | class Preprocessor;
|
---|
28 | struct SimpleRay;
|
---|
29 | class CKTB;
|
---|
30 |
|
---|
31 | // This macro should be undefined when testing ray tracing
|
---|
32 | // by casting rays from file or using camera
|
---|
33 | #define _PROCESS_RAY
|
---|
34 |
|
---|
35 | /** This class provides an interface for ray casting.
|
---|
36 | */
|
---|
37 | class HavranRayCaster: public RayCaster
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | /** Default constructor initialising e.g., KD tree
|
---|
41 | */
|
---|
42 | HavranRayCaster(const Preprocessor &preprocessor);
|
---|
43 | virtual ~HavranRayCaster();
|
---|
44 |
|
---|
45 | void Build(ObjectContainer &objlist);
|
---|
46 |
|
---|
47 | int Type() const { return HAVRAN_RAYCASTER; }
|
---|
48 |
|
---|
49 | virtual int CastRay(
|
---|
50 | const SimpleRay &simpleRay,
|
---|
51 | VssRayContainer &vssRays,
|
---|
52 | const AxisAlignedBox3 &box,
|
---|
53 | const bool castDoubleRay,
|
---|
54 | const bool pruneInvalidRays = true
|
---|
55 | );
|
---|
56 |
|
---|
57 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
58 | VssRayContainer &vssRays,
|
---|
59 | const AxisAlignedBox3 &sbox,
|
---|
60 | const bool castDoubleRay,
|
---|
61 | const bool pruneInvalidRays = true
|
---|
62 | );
|
---|
63 |
|
---|
64 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
65 | int offset,
|
---|
66 | VssRayContainer &vssRays,
|
---|
67 | const AxisAlignedBox3 &sbox,
|
---|
68 | const bool castDoubleRay,
|
---|
69 | const bool pruneInvalidRays = true
|
---|
70 | );
|
---|
71 | void
|
---|
72 | CastSimpleForwardRays(SimpleRayContainer &rays,
|
---|
73 | const AxisAlignedBox3 &sbox
|
---|
74 | );
|
---|
75 |
|
---|
76 | virtual void CastRays(
|
---|
77 | SimpleRayContainer &rays,
|
---|
78 | VssRayContainer &vssRays,
|
---|
79 | const AxisAlignedBox3 &sbox,
|
---|
80 | const bool castDoubleRay,
|
---|
81 | const bool pruneInvalidRays = true);
|
---|
82 |
|
---|
83 | // Using packet of 4 rays supposing that these are coherent
|
---|
84 | // We give a box to which each ray is clipped to before the
|
---|
85 | // ray shooting is computed !
|
---|
86 | virtual void CastRaysPacket4(const Vector3 &minBox,
|
---|
87 | const Vector3 &maxBox,
|
---|
88 | const Vector3 origin4[],
|
---|
89 | const Vector3 direction4[],
|
---|
90 | int result4[],
|
---|
91 | float dist4[]);
|
---|
92 |
|
---|
93 | #ifdef _USE_HAVRAN_SSE
|
---|
94 | // Just for testing concept
|
---|
95 | virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
|
---|
96 | bool castDoubleRay,
|
---|
97 | const bool pruneInvalidRays = true);
|
---|
98 | #endif
|
---|
99 |
|
---|
100 | bool ExportBinTree(const string &filename);
|
---|
101 | bool ImportBinTree(const string &filename, ObjectContainer &objects);
|
---|
102 |
|
---|
103 | protected:
|
---|
104 | CKTB *mKtbtree;
|
---|
105 | #ifdef _USE_HAVRAN_SSE
|
---|
106 | static GALIGN16 RayPacket2x2 raypack;
|
---|
107 | #endif
|
---|
108 | };
|
---|
109 |
|
---|
110 |
|
---|
111 | // --------------------------------------------------------------------
|
---|
112 | // The implementation of ray caster with dynamic objects
|
---|
113 |
|
---|
114 | class HavranDynRayCaster: public HavranRayCaster
|
---|
115 | {
|
---|
116 | public:
|
---|
117 | /** Default constructor initialising e.g., KD tree
|
---|
118 | */
|
---|
119 | HavranDynRayCaster(const Preprocessor &preprocessor);
|
---|
120 | virtual ~HavranDynRayCaster();
|
---|
121 |
|
---|
122 | int Type() const { return HAVRAN_DYN_RAYCASTER; }
|
---|
123 |
|
---|
124 | virtual int CastRay(const SimpleRay &simpleRay,
|
---|
125 | VssRayContainer &vssRays,
|
---|
126 | const AxisAlignedBox3 &box,
|
---|
127 | const bool castDoubleRay,
|
---|
128 | const bool pruneInvalidRays = true
|
---|
129 | );
|
---|
130 |
|
---|
131 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
132 | VssRayContainer &vssRays,
|
---|
133 | const AxisAlignedBox3 &sbox,
|
---|
134 | const bool castDoubleRay,
|
---|
135 | const bool pruneInvalidRays = true
|
---|
136 | );
|
---|
137 |
|
---|
138 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
139 | int offset,
|
---|
140 | VssRayContainer &vssRays,
|
---|
141 | const AxisAlignedBox3 &sbox,
|
---|
142 | const bool castDoubleRay,
|
---|
143 | const bool pruneInvalidRays = true
|
---|
144 | );
|
---|
145 | virtual void
|
---|
146 | CastSimpleForwardRays(SimpleRayContainer &rays,
|
---|
147 | const AxisAlignedBox3 &sbox);
|
---|
148 |
|
---|
149 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
150 | VssRayContainer &vssRays,
|
---|
151 | const AxisAlignedBox3 &sbox,
|
---|
152 | const bool castDoubleRay,
|
---|
153 | const bool pruneInvalidRays = true);
|
---|
154 |
|
---|
155 | // Using packet of 4 rays supposing that these are coherent
|
---|
156 | // We give a box to which each ray is clipped to before the
|
---|
157 | // ray shooting is computed !
|
---|
158 | virtual void CastRaysPacket4(const Vector3 &minBox,
|
---|
159 | const Vector3 &maxBox,
|
---|
160 | const Vector3 origin4[],
|
---|
161 | const Vector3 direction4[],
|
---|
162 | int result4[],
|
---|
163 | float dist4[]);
|
---|
164 |
|
---|
165 | #ifdef _USE_HAVRAN_SSE
|
---|
166 | // Just for testing concept
|
---|
167 | virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
|
---|
168 | bool castDoubleRay,
|
---|
169 | const bool pruneInvalidRays = true);
|
---|
170 | #endif
|
---|
171 |
|
---|
172 | virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m);
|
---|
173 |
|
---|
174 | virtual void UpdateDynamicObjects(const Matrix4x4 &m);
|
---|
175 |
|
---|
176 | virtual void DeleteDynamicObjects();
|
---|
177 |
|
---|
178 | protected:
|
---|
179 |
|
---|
180 | // The kd-tree for dynamic objects
|
---|
181 | CKTB *mDynKtbtree;
|
---|
182 |
|
---|
183 | #ifdef _USE_HAVRAN_SSE
|
---|
184 | // This has to be aligned by 16 Bytes boundary - if HavranDynRayCaster
|
---|
185 | // is aligned, then also this data entity below !!!
|
---|
186 | static GALIGN16 RayPacket2x2 raypack_t;
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | ObjectContainer *dynobjects;
|
---|
190 | bool dynamicFlag;
|
---|
191 |
|
---|
192 | Matrix4x4 matTr, matTr_inv;
|
---|
193 |
|
---|
194 | int result4_t[4];
|
---|
195 | float dist4_t[4];
|
---|
196 | SimpleRay sray_t;
|
---|
197 |
|
---|
198 | Vector3 orig[16];
|
---|
199 | Vector3 dirs[16];
|
---|
200 | float tdist[32];
|
---|
201 | Intersectable* objI[32];
|
---|
202 | Vector3 normal[32];
|
---|
203 |
|
---|
204 | // This transforms the ray
|
---|
205 | void ApplyTransform(SimpleRay &sray) {
|
---|
206 | sray.mOrigin = matTr_inv * sray.mOrigin;
|
---|
207 | sray.mDirection = RotateOnly(matTr_inv, sray.mDirection);
|
---|
208 | // note that normalization to the unit size of the direction
|
---|
209 | // is NOT computed -- this is what we want.
|
---|
210 | }
|
---|
211 | };
|
---|
212 |
|
---|
213 |
|
---|
214 | } // namespace
|
---|
215 |
|
---|
216 | #endif
|
---|
217 |
|
---|
218 | //#endif // _HavranRayCaster_H__
|
---|