1 | #include "IntelRayCaster.h"
|
---|
2 | #include "VssRay.h"
|
---|
3 | #include "Preprocessor.h"
|
---|
4 |
|
---|
5 | #ifdef GTP_INTERNAL
|
---|
6 | #include "ArchModeler2MLRT.hxx"
|
---|
7 |
|
---|
8 | #define DEBUG_RAYCAST 0
|
---|
9 |
|
---|
10 |
|
---|
11 | namespace GtpVisibilityPreprocessor {
|
---|
12 |
|
---|
13 |
|
---|
14 | IntelRayCaster::IntelRayCaster(const Preprocessor &preprocessor, const string externKdTree):
|
---|
15 | RayCaster(preprocessor)
|
---|
16 | {
|
---|
17 | InitRayCast(externKdTree);
|
---|
18 | }
|
---|
19 |
|
---|
20 |
|
---|
21 | IntelRayCaster::~IntelRayCaster()
|
---|
22 | {
|
---|
23 | }
|
---|
24 |
|
---|
25 |
|
---|
26 | bool IntelRayCaster::InitRayCast(const string externKdTree)
|
---|
27 | {
|
---|
28 | cout<<"Ray Cast file: " << externKdTree << endl;
|
---|
29 | return mlrtaLoadAS(externKdTree.c_str());
|
---|
30 | }
|
---|
31 |
|
---|
32 |
|
---|
33 | int IntelRayCaster::CastRay(
|
---|
34 | const SimpleRay &simpleRay,
|
---|
35 | VssRayContainer &vssRays,
|
---|
36 | const AxisAlignedBox3 &box,
|
---|
37 | const bool castDoubleRay,
|
---|
38 | const bool pruneInvalidRays
|
---|
39 | )
|
---|
40 | {
|
---|
41 | //cout << "intel ray" << endl;
|
---|
42 | VssRay *vssRay = NULL;
|
---|
43 | int hits = 0;
|
---|
44 | int hittriangle;
|
---|
45 | Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
|
---|
46 |
|
---|
47 | float dist;
|
---|
48 | double normal[3];
|
---|
49 |
|
---|
50 | hittriangle = mlrtaIntersectAS(
|
---|
51 | &simpleRay.mOrigin.x,
|
---|
52 | &simpleRay.mDirection.x,
|
---|
53 | normal,
|
---|
54 | dist);
|
---|
55 |
|
---|
56 | if (hittriangle != -1 ) {
|
---|
57 | if (hittriangle >= mPreprocessor.mFaceParents.size())
|
---|
58 | cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
|
---|
59 | else {
|
---|
60 | hitA.mObject = mPreprocessor.mFaceParents[hittriangle].mObject;
|
---|
61 | hitA.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
62 | // Get the normal of that face
|
---|
63 | // Mesh *mesh = ((MeshInstance *)objectA)->GetMesh();
|
---|
64 | // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
|
---|
65 | //-rays[index+i].mDirection; // $$ temporary
|
---|
66 | hitA.mPoint = simpleRay.Extrap(dist);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (castDoubleRay)
|
---|
71 | {
|
---|
72 | Vector3 dir = -simpleRay.mDirection;
|
---|
73 | hittriangle = mlrtaIntersectAS(
|
---|
74 | &simpleRay.mOrigin.x,
|
---|
75 | &dir.x,
|
---|
76 | normal,
|
---|
77 | dist);
|
---|
78 |
|
---|
79 | if (hittriangle != -1 ) {
|
---|
80 | if (hittriangle >= mPreprocessor.mFaceParents.size())
|
---|
81 | cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
|
---|
82 | else
|
---|
83 | {
|
---|
84 | hitB.mObject = mPreprocessor.mFaceParents[hittriangle].mObject;
|
---|
85 | hitB.mNormal = Vector3(normal[0], normal[1], normal[2]);
|
---|
86 | // Get the normal of that face
|
---|
87 | // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh();
|
---|
88 | // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
|
---|
89 | //-rays[index+i].mDirection; // $$ temporary
|
---|
90 | hitB.mPoint = simpleRay.Extrap(dist);
|
---|
91 | }
|
---|
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 = sbox.Min();
|
---|
130 | Vector3 max = sbox.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 | mlrtaTraverseGroupAS16(&min.x,
|
---|
139 | &max.x,
|
---|
140 | forward_hit_triangles,
|
---|
141 | forward_dist);
|
---|
142 |
|
---|
143 | if (castDoubleRay)
|
---|
144 | {
|
---|
145 | for (i=0; i < num; i++)
|
---|
146 | {
|
---|
147 | Vector3 dir = -rays[index + i].mDirection;
|
---|
148 | mlrtaStoreRayAS16(&rays[index+i].mOrigin.x,
|
---|
149 | &dir.x,
|
---|
150 | i);
|
---|
151 | }
|
---|
152 |
|
---|
153 | mlrtaTraverseGroupAS16(&min.x,
|
---|
154 | &max.x,
|
---|
155 | backward_hit_triangles,
|
---|
156 | backward_dist);
|
---|
157 | }
|
---|
158 |
|
---|
159 | for (i=0; i < num; i++)
|
---|
160 | {
|
---|
161 | Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
|
---|
162 |
|
---|
163 | if (forward_hit_triangles[i] != -1 ) {
|
---|
164 | if (forward_hit_triangles[i] >= mPreprocessor.mFaceParents.size())
|
---|
165 | cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl;
|
---|
166 | else {
|
---|
167 | hitA.mObject = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject;
|
---|
168 | // Get the normal of that face
|
---|
169 | hitA.mNormal = hitA.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);
|
---|
170 | //-rays[index+i].mDirection; // $$ temporary
|
---|
171 | hitA.mPoint = rays[index+i].Extrap(forward_dist[i]);
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (castDoubleRay && (backward_hit_triangles[i] != -1)) {
|
---|
176 | if (backward_hit_triangles[i] >= mPreprocessor.mFaceParents.size())
|
---|
177 | cerr<<"Warning: triangle index out of range! "<<backward_hit_triangles[i]<<endl;
|
---|
178 | else {
|
---|
179 | hitB.mObject = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject;
|
---|
180 | hitB.mNormal = hitB.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);
|
---|
181 |
|
---|
182 | // normalB = rays[index+i].mDirection; // $$ temporary
|
---|
183 | hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]);
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | ProcessRay(
|
---|
188 | rays[index + i],
|
---|
189 | hitA,
|
---|
190 | hitB,
|
---|
191 | vssRays,
|
---|
192 | sbox,
|
---|
193 | castDoubleRay,
|
---|
194 | pruneInvalidRays
|
---|
195 | );
|
---|
196 | }
|
---|
197 |
|
---|
198 | #if DEBUG_RAYCAST
|
---|
199 | Debug<<"C16F\n"<<flush;
|
---|
200 | #endif
|
---|
201 | }
|
---|
202 |
|
---|
203 | }
|
---|
204 |
|
---|
205 | #endif
|
---|