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

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

put #triangles into new format. warning! problems with power plant

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