source: GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp @ 2017

Revision 2017, 5.2 KB checked in by mattausch, 17 years ago (diff)

changed to static cast

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