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

Revision 1757, 5.3 KB checked in by bittner, 18 years ago (diff)

pvs updates

Line 
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
11namespace GtpVisibilityPreprocessor {
12
13
14IntelRayCaster::IntelRayCaster(const Preprocessor &preprocessor, const string externKdTree):
15RayCaster(preprocessor)
16{
17        InitRayCast(externKdTree);
18}
19
20
21IntelRayCaster::~IntelRayCaster()
22{
23}
24
25
26bool IntelRayCaster::InitRayCast(const string externKdTree)
27{
28        cout<<"Ray Cast file: " << externKdTree << endl;
29        return mlrtaLoadAS(externKdTree.c_str());
30}
31
32
33int 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
107void 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#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               
179                if (forward_hit_triangles[i] != -1 ) {
180                  if (forward_hit_triangles[i] >= mPreprocessor.mFaceParents.size())
181                        cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl;
182                  else {
183                        hitA.mObject = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject;
184                        // Get the normal of that face
185                        hitA.mNormal = hitA.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);
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 && (backward_hit_triangles[i] != -1)) {
195                if (backward_hit_triangles[i] >= mPreprocessor.mFaceParents.size())
196                  cerr<<"Warning: triangle  index out of range! "<<backward_hit_triangles[i]<<endl;
197                else {
198                  hitB.mObject = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject;
199                  hitB.mNormal = hitB.mObject->GetNormal(mPreprocessor.mFaceParents[backward_hit_triangles[i]].mFaceIndex);
200                 
201                  // normalB = rays[index+i].mDirection; // $$ temporary
202                  hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]);
203                }
204          }
205         
206#if DEBUG_RAYCAST
207          Debug<<"PR\n"<<flush;
208#endif
209         
210          ProcessRay(
211                                 rays[index + i],
212                                 hitA,
213                                 hitB,
214                                 vssRays,
215                                 sbox,
216                                 castDoubleRay,
217                                 pruneInvalidRays
218                                 );
219        }
220       
221#if DEBUG_RAYCAST
222        Debug<<"C16F\n"<<flush;
223#endif
224}
225
226}
227
228#endif
Note: See TracBrowser for help on using the repository browser.