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