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 | const int index,
|
---|
110 | SimpleRayContainer &rays,
|
---|
111 | VssRayContainer &vssRays,
|
---|
112 | const AxisAlignedBox3 &sbox,
|
---|
113 | const bool castDoubleRay,
|
---|
114 | const bool pruneInvalidRays)
|
---|
115 | {
|
---|
116 | int i;
|
---|
117 | const int num = 16;
|
---|
118 |
|
---|
119 | #if DEBUG_RAYCAST
|
---|
120 | Debug<<"C16 "<<flush;
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | int forward_hit_triangles[16];
|
---|
124 | float forward_dist[16];
|
---|
125 |
|
---|
126 | int backward_hit_triangles[16];
|
---|
127 | float backward_dist[16];
|
---|
128 |
|
---|
129 |
|
---|
130 | Vector3 min = mPreprocessor.mSceneGraph->GetBox().Min();
|
---|
131 | Vector3 max = mPreprocessor.mSceneGraph->GetBox().Max();
|
---|
132 |
|
---|
133 | for (i=0; i < num; i++) {
|
---|
134 | mlrtaStoreRayAS16(&rays[index + i].mOrigin.x,
|
---|
135 | &rays[index + i].mDirection.x,
|
---|
136 | i);
|
---|
137 | }
|
---|
138 |
|
---|
139 | #if DEBUG_RAYCAST
|
---|
140 | Debug<<"TA\n"<<flush;
|
---|
141 | #endif
|
---|
142 |
|
---|
143 | mlrtaTraverseGroupAS16(&min.x,
|
---|
144 | &max.x,
|
---|
145 | forward_hit_triangles,
|
---|
146 | forward_dist);
|
---|
147 |
|
---|
148 | if (castDoubleRay)
|
---|
149 | {
|
---|
150 | for (i=0; i < num; i++)
|
---|
151 | {
|
---|
152 | Vector3 dir = -rays[index + i].mDirection;
|
---|
153 | mlrtaStoreRayAS16(&rays[index+i].mOrigin.x,
|
---|
154 | &dir.x,
|
---|
155 | i);
|
---|
156 | }
|
---|
157 |
|
---|
158 | #if DEBUG_RAYCAST
|
---|
159 | Debug<<"TB\n"<<flush;
|
---|
160 | #endif
|
---|
161 |
|
---|
162 | mlrtaTraverseGroupAS16(&min.x,
|
---|
163 | &max.x,
|
---|
164 | backward_hit_triangles,
|
---|
165 | backward_dist);
|
---|
166 | }
|
---|
167 |
|
---|
168 | #if DEBUG_RAYCAST
|
---|
169 | Debug<<"BBB\n"<<flush;
|
---|
170 | #endif
|
---|
171 |
|
---|
172 | for (i=0; i < num; i++)
|
---|
173 | {
|
---|
174 | Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
|
---|
175 |
|
---|
176 | #if DEBUG_RAYCAST
|
---|
177 | Debug<<"FH\n"<<flush;
|
---|
178 | #endif
|
---|
179 | Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]);
|
---|
180 |
|
---|
181 | if (intersect)
|
---|
182 | {
|
---|
183 | hitA.mObject = intersect;
|
---|
184 | // Get the normal of that face
|
---|
185 | hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]);
|
---|
186 |
|
---|
187 | //-rays[index+i].mDirection; // $$ temporary
|
---|
188 | hitA.mPoint = rays[index+i].Extrap(forward_dist[i]);
|
---|
189 | }
|
---|
190 |
|
---|
191 | #if DEBUG_RAYCAST
|
---|
192 | Debug<<"BH\n"<<flush;
|
---|
193 | #endif
|
---|
194 |
|
---|
195 | if (castDoubleRay)
|
---|
196 | {
|
---|
197 | Intersectable *intersect = mPreprocessor.GetParentObject(backward_hit_triangles[i]);
|
---|
198 |
|
---|
199 | if (intersect)
|
---|
200 | {
|
---|
201 | hitB.mObject = intersect;
|
---|
202 | hitB.mNormal = mPreprocessor.GetParentNormal(backward_hit_triangles[i]);
|
---|
203 |
|
---|
204 | // normalB = rays[index+i].mDirection; // $$ temporary
|
---|
205 | hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | #if DEBUG_RAYCAST
|
---|
210 | Debug<<"PR\n"<<flush;
|
---|
211 | #endif
|
---|
212 |
|
---|
213 | ProcessRay(rays[index + i],
|
---|
214 | hitA,
|
---|
215 | hitB,
|
---|
216 | vssRays,
|
---|
217 | sbox,
|
---|
218 | castDoubleRay,
|
---|
219 | pruneInvalidRays
|
---|
220 | );
|
---|
221 | }
|
---|
222 |
|
---|
223 | #if DEBUG_RAYCAST
|
---|
224 | Debug<<"C16F\n"<<flush;
|
---|
225 | #endif
|
---|
226 | }
|
---|
227 |
|
---|
228 | }
|
---|
229 |
|
---|
230 | #endif
|
---|