1 | #include "IntelRayCaster.h"
|
---|
2 | #include "VssRay.h"
|
---|
3 | #include "Preprocessor.h"
|
---|
4 | #include "SceneGraph.h"
|
---|
5 |
|
---|
6 | #ifdef GTP_INTERNAL
|
---|
7 | #include "ArchModeler2MLRT.hxx"
|
---|
8 |
|
---|
9 | #define DEBUG_RAYCAST 0
|
---|
10 |
|
---|
11 |
|
---|
12 | namespace GtpVisibilityPreprocessor {
|
---|
13 |
|
---|
14 |
|
---|
15 | IntelRayCaster::IntelRayCaster(const Preprocessor &preprocessor,
|
---|
16 | const string externKdTree):
|
---|
17 | RayCaster(preprocessor)
|
---|
18 | {
|
---|
19 | InitRayCast(externKdTree);
|
---|
20 | }
|
---|
21 |
|
---|
22 |
|
---|
23 | IntelRayCaster::~IntelRayCaster()
|
---|
24 | {
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | bool IntelRayCaster::InitRayCast(const string externKdTree)
|
---|
29 | {
|
---|
30 | cout<<"Ray Cast file: " << externKdTree << endl;
|
---|
31 | return mlrtaLoadAS(externKdTree.c_str());
|
---|
32 | }
|
---|
33 |
|
---|
34 |
|
---|
35 | int IntelRayCaster::CastRay(
|
---|
36 | const SimpleRay &simpleRay,
|
---|
37 | VssRayContainer &vssRays,
|
---|
38 | const AxisAlignedBox3 &box,
|
---|
39 | const bool castDoubleRay,
|
---|
40 | const bool pruneInvalidRays,
|
---|
41 | const bool keepOrigin
|
---|
42 | )
|
---|
43 | {
|
---|
44 | //cout << "intel ray" << endl;
|
---|
45 | VssRay *vssRay = NULL;
|
---|
46 | int hits = 0;
|
---|
47 | int hittriangle;
|
---|
48 | Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
|
---|
49 |
|
---|
50 | float dist;
|
---|
51 | double normal[3];
|
---|
52 |
|
---|
53 | hittriangle = mlrtaIntersectAS(
|
---|
54 | &simpleRay.mOrigin.x,
|
---|
55 | &simpleRay.mDirection.x,
|
---|
56 | normal,
|
---|
57 | dist);
|
---|
58 |
|
---|
59 | if (hittriangle != -1 ) {
|
---|
60 | Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
|
---|
61 |
|
---|
62 | if (intersect)
|
---|
63 | {
|
---|
64 | hitA.mObject = intersect;
|
---|
65 | hitA.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
66 | // Get the normal of that face
|
---|
67 | // Mesh *mesh = ((MeshInstance *)objectA)->GetMesh();
|
---|
68 | // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
|
---|
69 | //-rays[index+i].mDirection; // $$ temporary
|
---|
70 | hitA.mPoint = simpleRay.Extrap(dist);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | if (castDoubleRay)
|
---|
75 | {
|
---|
76 | cerr<<"HERE"<<endl;
|
---|
77 | Vector3 dir = -simpleRay.mDirection;
|
---|
78 | hittriangle = mlrtaIntersectAS(
|
---|
79 | &simpleRay.mOrigin.x,
|
---|
80 | &dir.x,
|
---|
81 | normal,
|
---|
82 | dist);
|
---|
83 |
|
---|
84 | Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
|
---|
85 |
|
---|
86 | if (intersect)
|
---|
87 | {
|
---|
88 | hitB.mObject = intersect;
|
---|
89 | hitB.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
90 | // Get the normal of that face
|
---|
91 | // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh();
|
---|
92 | // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
|
---|
93 | //-rays[index+i].mDirection; // $$ temporary
|
---|
94 | hitB.mPoint = simpleRay.Extrap(dist);
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | return ProcessRay(
|
---|
99 | simpleRay,
|
---|
100 | hitA,
|
---|
101 | hitB,
|
---|
102 | vssRays,
|
---|
103 | box,
|
---|
104 | castDoubleRay,
|
---|
105 | pruneInvalidRays,
|
---|
106 | keepOrigin
|
---|
107 | );
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | void IntelRayCaster::CastRays16(
|
---|
112 | SimpleRayContainer &rays,
|
---|
113 | VssRayContainer &vssRays,
|
---|
114 | const AxisAlignedBox3 &sbox,
|
---|
115 | const bool castDoubleRay,
|
---|
116 | const bool pruneInvalidRays,
|
---|
117 | const bool keepOrigin)
|
---|
118 | {
|
---|
119 | int i;
|
---|
120 | const int num = 16;
|
---|
121 |
|
---|
122 | #if DEBUG_RAYCAST
|
---|
123 | Debug<<"C16 "<<flush;
|
---|
124 | static int counter=0;
|
---|
125 | Debug<<counter++<<endl;
|
---|
126 | #endif
|
---|
127 |
|
---|
128 | static int forward_hit_triangles[16];
|
---|
129 | static float forward_dist[16];
|
---|
130 |
|
---|
131 | static int backward_hit_triangles[16];
|
---|
132 | static float backward_dist[16];
|
---|
133 |
|
---|
134 |
|
---|
135 | Vector3 min = mPreprocessor.mSceneGraph->GetBox().Min();
|
---|
136 | Vector3 max = mPreprocessor.mSceneGraph->GetBox().Max();
|
---|
137 |
|
---|
138 | for (i=0; i < num; i++) {
|
---|
139 | #if DEBUG_RAYCAST
|
---|
140 | if (counter == 43964) {
|
---|
141 | Debug<<rays[i].mOrigin<<" "<<rays[i].mDirection<<endl;
|
---|
142 | }
|
---|
143 | #endif
|
---|
144 | mlrtaStoreRayAS16(&rays[i].mOrigin.x,
|
---|
145 | &rays[i].mDirection.x,
|
---|
146 | i);
|
---|
147 | }
|
---|
148 |
|
---|
149 | #if DEBUG_RAYCAST
|
---|
150 | Debug<<"TA\n"<<flush;
|
---|
151 | #endif
|
---|
152 |
|
---|
153 | mlrtaTraverseGroupAS16(&min.x,
|
---|
154 | &max.x,
|
---|
155 | forward_hit_triangles,
|
---|
156 | forward_dist);
|
---|
157 |
|
---|
158 | #if DEBUG_RAYCAST
|
---|
159 | Debug<<"TAB\n"<<flush;
|
---|
160 | #endif
|
---|
161 |
|
---|
162 | if (castDoubleRay) {
|
---|
163 | for (i=0; i < num; i++) {
|
---|
164 | Vector3 dir = -rays[i].mDirection;
|
---|
165 | mlrtaStoreRayAS16(&rays[i].mOrigin.x,
|
---|
166 | &dir.x,
|
---|
167 | i);
|
---|
168 | }
|
---|
169 |
|
---|
170 | #if DEBUG_RAYCAST
|
---|
171 | Debug<<"TB\n"<<flush;
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | mlrtaTraverseGroupAS16(&min.x,
|
---|
175 | &max.x,
|
---|
176 | backward_hit_triangles,
|
---|
177 | backward_dist);
|
---|
178 | }
|
---|
179 |
|
---|
180 | #if DEBUG_RAYCAST
|
---|
181 | Debug<<"BBB\n"<<flush;
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | for (i=0; i < num; i++)
|
---|
185 | {
|
---|
186 | Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
|
---|
187 |
|
---|
188 | #if DEBUG_RAYCAST
|
---|
189 | Debug<<"FH\n"<<flush;
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]);
|
---|
193 |
|
---|
194 | if (intersect)
|
---|
195 | {
|
---|
196 | hitA.mObject = intersect;
|
---|
197 | // Get the normal of that face
|
---|
198 | hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]);
|
---|
199 |
|
---|
200 | //-rays[index+i].mDirection; // $$ temporary
|
---|
201 | hitA.mPoint = rays[i].Extrap(forward_dist[i]);
|
---|
202 | }
|
---|
203 |
|
---|
204 | #if DEBUG_RAYCAST
|
---|
205 | Debug<<"BH\n"<<flush;
|
---|
206 | #endif
|
---|
207 |
|
---|
208 | if (castDoubleRay)
|
---|
209 | {
|
---|
210 | Intersectable *intersect = mPreprocessor.GetParentObject(backward_hit_triangles[i]);
|
---|
211 |
|
---|
212 | if (intersect)
|
---|
213 | {
|
---|
214 | hitB.mObject = intersect;
|
---|
215 | hitB.mNormal = mPreprocessor.GetParentNormal(backward_hit_triangles[i]);
|
---|
216 |
|
---|
217 | // normalB = rays[i].mDirection; // $$ temporary
|
---|
218 | hitB.mPoint = rays[i].Extrap(-backward_dist[i]);
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | #if DEBUG_RAYCAST
|
---|
223 | Debug<<"PR\n"<<flush;
|
---|
224 | #endif
|
---|
225 |
|
---|
226 | ProcessRay(rays[i],
|
---|
227 | hitA,
|
---|
228 | hitB,
|
---|
229 | vssRays,
|
---|
230 | sbox,
|
---|
231 | castDoubleRay,
|
---|
232 | pruneInvalidRays,
|
---|
233 | keepOrigin
|
---|
234 | );
|
---|
235 | }
|
---|
236 |
|
---|
237 | #if DEBUG_RAYCAST
|
---|
238 | Debug<<"C16F\n"<<flush;
|
---|
239 | #endif
|
---|
240 | }
|
---|
241 |
|
---|
242 | }
|
---|
243 |
|
---|
244 | #endif
|
---|