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