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

Revision 2003, 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{
[2003]19        if (!InitRayCast(externKdTree))
20                cout << "warning: intel ray tracer could not be initialized!" << endl;
[1520]21}
22
23
24IntelRayCaster::~IntelRayCaster()
25{
26}
27
28
29bool IntelRayCaster::InitRayCast(const string externKdTree)
30{
[2003]31        cout<<"Intel ray cast file: " << externKdTree << endl;
32       
33        return mlrtaLoadAS(externKdTree.c_str());
[1520]34}
35
36
37int IntelRayCaster::CastRay(
[1528]38                                                        const SimpleRay &simpleRay,
[1520]39                                                        VssRayContainer &vssRays,
40                                                        const AxisAlignedBox3 &box,
[1528]41                                                        const bool castDoubleRay,
[1996]42                                                        const bool pruneInvalidRays
[1520]43                                                        )
44{
[2003]45        cout << "intel ray" << endl;
[1520]46        VssRay *vssRay  = NULL;
47        int hits = 0;
48        int hittriangle;
[1533]49        Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
[1528]50
[1520]51        float dist;
52        double normal[3];
53
54        hittriangle = mlrtaIntersectAS(
[1984]55                                                                   &simpleRay.mOrigin.x,
56                                                                   &simpleRay.mDirection.x,
57                                                                   normal,
58                                                                   dist);
59       
[1520]60        if (hittriangle != -1 ) {
[1786]61                Intersectable *intersect = mPreprocessor.GetParentObject(hittriangle);
62               
63                if (intersect)
64                {
65                        hitA.mObject = intersect;
[1528]66                        hitA.mNormal = Vector3(normal[0], normal[1], normal[2]);
[1520]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
[1528]71                        hitA.mPoint = simpleRay.Extrap(dist);
[1520]72                }
73        }
74
75        if (castDoubleRay)
76        {
[2003]77                //cerr<<"HERE"<<endl;
78                Vector3 dir = -simpleRay.mDirection;
[1520]79                hittriangle = mlrtaIntersectAS(
[1960]80                                                                                &simpleRay.mOrigin.x,
81                                                                                &dir.x,
82                                                                                normal,
83                                                                                dist);
[1520]84
[1786]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);
[1520]96                }
97        }
98
99        return ProcessRay(
[1867]100                                          simpleRay,
101                                          hitA,
102                                          hitB,
103                                          vssRays,
104                                          box,
105                                          castDoubleRay,
[1996]106                                          pruneInvalidRays
[1867]107                                          );
[1520]108}
109
110
111void IntelRayCaster::CastRays16(
112                                                                SimpleRayContainer &rays,
113                                                                VssRayContainer &vssRays,
114                                                                const AxisAlignedBox3 &sbox,
[1528]115                                                                const bool castDoubleRay,
[1996]116                                                                const bool pruneInvalidRays)
[1520]117{
118        int i;
119        const int num = 16;
[1972]120       
[1520]121#if DEBUG_RAYCAST
122        Debug<<"C16 "<<flush;
[1983]123        static int counter=0;
124        Debug<<counter++<<endl;
[1520]125#endif
126
[1984]127        static int forward_hit_triangles[16];
128        static float forward_dist[16];
[1520]129
[1984]130        static int backward_hit_triangles[16];
131        static float backward_dist[16];
[1520]132
[1942]133       
134        Vector3 min = mPreprocessor.mSceneGraph->GetBox().Min();
135        Vector3 max = mPreprocessor.mSceneGraph->GetBox().Max();
[1520]136
137        for (i=0; i < num; i++) {
[1983]138#if DEBUG_RAYCAST
139          if (counter == 43964) {
140                Debug<<rays[i].mOrigin<<" "<<rays[i].mDirection<<endl;
141          }
142#endif
[1972]143          mlrtaStoreRayAS16(&rays[i].mOrigin.x,
144                                                &rays[i].mDirection.x,
[1757]145                                                i);
[1520]146        }
147
[1757]148#if DEBUG_RAYCAST
[1983]149        Debug<<"TA\n"<<flush;
[1757]150#endif
151
[1520]152        mlrtaTraverseGroupAS16(&min.x,
[1757]153                                                   &max.x,
154                                                   forward_hit_triangles,
155                                                   forward_dist);
[1520]156
[1757]157#if DEBUG_RAYCAST
[1983]158        Debug<<"TAB\n"<<flush;
[1757]159#endif
160
[1983]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);
[1757]167          }
[1983]168         
[1757]169#if DEBUG_RAYCAST
[1983]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
[1757]180        Debug<<"BBB\n"<<flush;
181#endif
182
[1520]183        for (i=0; i < num; i++)
[1786]184        {
[1533]185                Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
[1757]186
187#if DEBUG_RAYCAST
[1786]188                Debug<<"FH\n"<<flush;
[1757]189#endif
[1984]190
[1786]191                Intersectable *intersect = mPreprocessor.GetParentObject(forward_hit_triangles[i]);
192
193                if (intersect)
194                {
195                        hitA.mObject = intersect;
[1757]196                        // Get the normal of that face
[1786]197                        hitA.mNormal = mPreprocessor.GetParentNormal(forward_hit_triangles[i]);
198
[1757]199                        //-rays[index+i].mDirection; // $$ temporary
[1972]200                        hitA.mPoint = rays[i].Extrap(forward_dist[i]);
[1786]201                }
202       
[1757]203#if DEBUG_RAYCAST
[1786]204                Debug<<"BH\n"<<flush;
[1757]205#endif
[1786]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
[1972]216                                // normalB = rays[i].mDirection; // $$ temporary
217                                hitB.mPoint = rays[i].Extrap(-backward_dist[i]);
[1786]218                        }
[1520]219                }
[1786]220
[1757]221#if DEBUG_RAYCAST
[1786]222                Debug<<"PR\n"<<flush;
[1757]223#endif
[1786]224
[1972]225                ProcessRay(rays[i],
[1786]226                                   hitA,
227                                   hitB,
228                                   vssRays,
229                                   sbox,
230                                   castDoubleRay,
[1996]231                                   pruneInvalidRays
[1786]232                                   );
[1520]233        }
[1786]234
[1520]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.