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