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

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