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

Revision 1867, 4.8 KB checked in by bittner, 18 years ago (diff)

merge, global lines, rss sampling 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                Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
58               
59                if (intersect)
60                {
61                        hitA.mObject = intersect;
62                        hitA.mNormal = Vector3(normal[0], normal[1], normal[2]);
63                        // Get the normal of that face
64                        //              Mesh *mesh = ((MeshInstance *)objectA)->GetMesh();
65                        //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
66                        //-rays[index+i].mDirection; // $$ temporary
67                        hitA.mPoint = simpleRay.Extrap(dist);
68                }
69        }
70
71        if (castDoubleRay)
72        {
73                Vector3 dir = -simpleRay.mDirection;
74                hittriangle = mlrtaIntersectAS(
75                        &simpleRay.mOrigin.x,
76                        &dir.x,
77                        normal,
78                        dist);
79
80                Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
81               
82                if (intersect)
83                {
84                        hitB.mObject = intersect;
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        return ProcessRay(
95                                          simpleRay,
96                                          hitA,
97                                          hitB,
98                                          vssRays,
99                                          box,
100                                          castDoubleRay,
101                                          pruneInvalidRays
102                                          );
103}
104
105
106void IntelRayCaster::CastRays16(
107                                                                const int index,
108                                                                SimpleRayContainer &rays,
109                                                                VssRayContainer &vssRays,
110                                                                const AxisAlignedBox3 &sbox,
111                                                                const bool castDoubleRay,
112                                                                const bool pruneInvalidRays)
113{
114        int i;
115        const int num = 16;
116
117#if DEBUG_RAYCAST
118        Debug<<"C16 "<<flush;
119#endif
120
121        int forward_hit_triangles[16];
122        float forward_dist[16];
123
124        int backward_hit_triangles[16];
125        float backward_dist[16];
126
127
128        Vector3 min = sbox.Min();
129        Vector3 max = sbox.Max();
130
131        for (i=0; i < num; i++) {
132          mlrtaStoreRayAS16(&rays[index + i].mOrigin.x,
133                                                &rays[index + i].mDirection.x,
134                                                i);
135        }
136
137#if DEBUG_RAYCAST
138                Debug<<"TA\n"<<flush;
139#endif
140
141        mlrtaTraverseGroupAS16(&min.x,
142                                                   &max.x,
143                                                   forward_hit_triangles,
144                                                   forward_dist);
145       
146        if (castDoubleRay)
147          {
148                for (i=0; i < num; i++)
149                  {
150                        Vector3 dir = -rays[index + i].mDirection;
151                        mlrtaStoreRayAS16(&rays[index+i].mOrigin.x,
152                                                          &dir.x,
153                                                          i);
154                  }
155
156#if DEBUG_RAYCAST
157                Debug<<"TB\n"<<flush;
158#endif
159
160                mlrtaTraverseGroupAS16(&min.x,
161                                                           &max.x,
162                                                           backward_hit_triangles,
163                                                           backward_dist);
164          }
165
166#if DEBUG_RAYCAST
167        Debug<<"BBB\n"<<flush;
168#endif
169
170        for (i=0; i < num; i++)
171        {
172                Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
173
174#if DEBUG_RAYCAST
175                Debug<<"FH\n"<<flush;
176#endif
177                Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]);
178
179                if (intersect)
180                {
181                        hitA.mObject = intersect;
182                        // Get the normal of that face
183                        hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]);
184
185                        //-rays[index+i].mDirection; // $$ temporary
186                        hitA.mPoint = rays[index+i].Extrap(forward_dist[i]);
187                }
188       
189#if DEBUG_RAYCAST
190                Debug<<"BH\n"<<flush;
191#endif
192
193                if (castDoubleRay)
194                {
195                        Intersectable *intersect = mPreprocessor.GetParentObject(backward_hit_triangles[i]);
196
197                        if (intersect)
198                        {
199                                hitB.mObject = intersect;
200                                hitB.mNormal = mPreprocessor.GetParentNormal(backward_hit_triangles[i]);
201
202                                // normalB = rays[index+i].mDirection; // $$ temporary
203                                hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]);
204                        }
205                }
206
207#if DEBUG_RAYCAST
208                Debug<<"PR\n"<<flush;
209#endif
210
211                ProcessRay(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.