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

Revision 1996, 5.1 KB checked in by mattausch, 17 years ago (diff)
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        InitRayCast(externKdTree);
20}
21
22
23IntelRayCaster::~IntelRayCaster()
24{
25}
26
27
28bool IntelRayCaster::InitRayCast(const string externKdTree)
29{
30  cout<<"Ray Cast file: " << externKdTree << endl;
31  return mlrtaLoadAS(externKdTree.c_str());
32}
33
34
35int 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          cerr<<"HERE"<<endl;
76          Vector3 dir = -simpleRay.mDirection;
77                hittriangle = mlrtaIntersectAS(
78                                                                                &simpleRay.mOrigin.x,
79                                                                                &dir.x,
80                                                                                normal,
81                                                                                dist);
82
83                Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
84               
85                if (intersect)
86                {
87                        hitB.mObject = intersect;
88                        hitB.mNormal = Vector3(normal[0], normal[1], normal[2]);
89                        // Get the normal of that face
90                        //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh();
91                        //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
92                        //-rays[index+i].mDirection; // $$ temporary
93                        hitB.mPoint = simpleRay.Extrap(dist);
94                }
95        }
96
97        return ProcessRay(
98                                          simpleRay,
99                                          hitA,
100                                          hitB,
101                                          vssRays,
102                                          box,
103                                          castDoubleRay,
104                                          pruneInvalidRays
105                                          );
106}
107
108
109void IntelRayCaster::CastRays16(
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        static int counter=0;
122        Debug<<counter++<<endl;
123#endif
124
125        static int forward_hit_triangles[16];
126        static float forward_dist[16];
127
128        static int backward_hit_triangles[16];
129        static float backward_dist[16];
130
131       
132        Vector3 min = mPreprocessor.mSceneGraph->GetBox().Min();
133        Vector3 max = mPreprocessor.mSceneGraph->GetBox().Max();
134
135        for (i=0; i < num; i++) {
136#if DEBUG_RAYCAST
137          if (counter == 43964) {
138                Debug<<rays[i].mOrigin<<" "<<rays[i].mDirection<<endl;
139          }
140#endif
141          mlrtaStoreRayAS16(&rays[i].mOrigin.x,
142                                                &rays[i].mDirection.x,
143                                                i);
144        }
145
146#if DEBUG_RAYCAST
147        Debug<<"TA\n"<<flush;
148#endif
149
150        mlrtaTraverseGroupAS16(&min.x,
151                                                   &max.x,
152                                                   forward_hit_triangles,
153                                                   forward_dist);
154
155#if DEBUG_RAYCAST
156        Debug<<"TAB\n"<<flush;
157#endif
158
159        if (castDoubleRay) {
160          for (i=0; i < num; i++)  {
161                Vector3 dir = -rays[i].mDirection;
162                mlrtaStoreRayAS16(&rays[i].mOrigin.x,
163                                                  &dir.x,
164                                                  i);
165          }
166         
167#if DEBUG_RAYCAST
168          Debug<<"TB\n"<<flush;
169#endif
170         
171          mlrtaTraverseGroupAS16(&min.x,
172                                                         &max.x,
173                                                         backward_hit_triangles,
174                                                         backward_dist);
175        }
176       
177#if DEBUG_RAYCAST
178        Debug<<"BBB\n"<<flush;
179#endif
180
181        for (i=0; i < num; i++)
182        {
183                Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
184
185#if DEBUG_RAYCAST
186                Debug<<"FH\n"<<flush;
187#endif
188
189                Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]);
190
191                if (intersect)
192                {
193                        hitA.mObject = intersect;
194                        // Get the normal of that face
195                        hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]);
196
197                        //-rays[index+i].mDirection; // $$ temporary
198                        hitA.mPoint = rays[i].Extrap(forward_dist[i]);
199                }
200       
201#if DEBUG_RAYCAST
202                Debug<<"BH\n"<<flush;
203#endif
204
205                if (castDoubleRay)
206                {
207                        Intersectable *intersect = mPreprocessor.GetParentObject(backward_hit_triangles[i]);
208
209                        if (intersect)
210                        {
211                                hitB.mObject = intersect;
212                                hitB.mNormal = mPreprocessor.GetParentNormal(backward_hit_triangles[i]);
213
214                                // normalB = rays[i].mDirection; // $$ temporary
215                                hitB.mPoint = rays[i].Extrap(-backward_dist[i]);
216                        }
217                }
218
219#if DEBUG_RAYCAST
220                Debug<<"PR\n"<<flush;
221#endif
222
223                ProcessRay(rays[i],
224                                   hitA,
225                                   hitB,
226                                   vssRays,
227                                   sbox,
228                                   castDoubleRay,
229                                   pruneInvalidRays
230                                   );
231        }
232
233#if DEBUG_RAYCAST
234        Debug<<"C16F\n"<<flush;
235#endif
236}
237
238}
239
240#endif
Note: See TracBrowser for help on using the repository browser.