Ignore:
Timestamp:
08/28/06 21:13:40 (18 years ago)
Author:
bittner
Message:

intel ray caster updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1291 r1292  
    2424#include "ArchModeler2MLRT.hxx" 
    2525#endif 
     26 
     27#define DEBUG_RAYCAST 0 
     28 
    2629 
    2730namespace GtpVisibilityPreprocessor { 
     
    454457} 
    455458 
     459   
     460bool 
     461Preprocessor::ConstructViewCells() 
     462{ 
     463  // if not already loaded, construct view cells from file 
     464  if (!mLoadViewCells) { 
     465        mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 
     466         
     467        // construct view cells using it's own set of samples 
     468        mViewCellsManager->Construct(this); 
     469         
     470        //-- several visualizations and statistics 
     471        Debug << "view cells construction finished: " << endl; 
     472        mViewCellsManager->PrintStatistics(Debug); 
     473  } 
     474  return true; 
     475} 
    456476 
    457477HierarchyManager *Preprocessor::CreateHierarchyManager(const char *name) 
     
    834854 
    835855        Vector3 pointA, pointB; 
    836          
    837         Intersectable *objectA =  
    838                 CastIntelSingleRay(viewPoint, direction, pointA, box); 
    839          
    840         // cast ray into other direction 
    841         Intersectable *objectB =  
    842                 CastIntelSingleRay(viewPoint, -direction, pointB, box); 
    843  
    844         const bool validSample = (objectA != objectB); 
    845          
    846         if (validSample)  
    847         {        
    848                 if (objectA)  
    849                 { 
    850                         vssRay = new VssRay(pointB, 
    851                                                                 pointA, 
    852                                                                 objectB, 
    853                                                                 objectA, 
    854                                                                 mPass, 
    855                                                                 probability 
    856                                                                 ); 
    857  
    858                         vssRays.push_back(vssRay); 
    859                         hits ++; 
    860                 } 
    861  
    862                 if (objectB)  
    863                 { 
    864                         vssRay = new VssRay(pointA, 
    865                                                                 pointB, 
    866                                                                 objectA, 
    867                                                                 objectB, 
    868                                                                 mPass, 
    869                                                                 probability 
    870                                                                 ); 
    871  
    872                         vssRays.push_back(vssRay); 
    873                         hits ++; 
    874                 } 
    875                 //Debug << "intel ray: " << *vssRay << endl; 
    876         } 
    877  
    878         //cout << "a"; 
    879         return hits; 
     856        Vector3 normalA, normalB; 
     857        Intersectable *objectA = NULL, *objectB = NULL; 
     858        float dist; 
     859         
     860        int hittriangle; 
     861        double normal[3]; 
     862        hittriangle = mlrtaIntersectAS(&viewPoint.x, 
     863                                                                   &direction.x, 
     864                                                                   normal, 
     865                                                                   dist); 
     866        if (hittriangle !=-1 ) { 
     867          if (hittriangle >= mFaceParents.size()) 
     868                cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
     869          else { 
     870                objectA = mFaceParents[hittriangle].mObject; 
     871                normalA = Vector3(normal[0], normal[1], normal[2]); 
     872                // Get the normal of that face 
     873                //              Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
     874                //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     875                //-rays[index+i].mDirection; // $$ temporary 
     876                pointA = viewPoint + direction*dist; 
     877          } 
     878        } 
     879 
     880        Vector3 dir = -direction; 
     881        hittriangle = mlrtaIntersectAS(&viewPoint.x, 
     882                                                                   &dir.x, 
     883                                                                   normal, 
     884                                                                   dist); 
     885        if (hittriangle !=-1 ) { 
     886          if (hittriangle >= mFaceParents.size()) 
     887                cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
     888          else { 
     889                objectB = mFaceParents[hittriangle].mObject; 
     890                normalB = Vector3(normal[0], normal[1], normal[2]); 
     891                // Get the normal of that face 
     892                //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
     893                //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     894                //-rays[index+i].mDirection; // $$ temporary 
     895                pointB = viewPoint + dir*dist; 
     896        } 
     897        } 
     898 
     899        return ProcessRay(viewPoint, 
     900                                          direction, 
     901                                          objectA, pointA, normalA, 
     902                                          objectB, pointB, normalB, 
     903                                          probability, 
     904                                          vssRays, 
     905                                          box 
     906                                          ); 
    880907} 
    881908 
     
    909936 
    910937        if (hittriangle == -1) 
    911         { 
     938          { 
    912939                static Ray ray; 
    913940                SetupRay(ray, viewPoint, direction); 
    914  
     941                 
    915942                float tmin = 0, tmax; 
    916943                if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 
    917                 { 
     944                  { 
    918945                        tPoint = ray.Extrap(tmax); 
    919                 } 
    920  
     946                  } 
     947                 
    921948                return NULL; 
    922         } 
    923         else 
    924         { 
     949          } 
     950        else { 
     951          if (hittriangle >= mFaceParents.size()) { 
     952                cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
     953                return NULL; 
     954          } 
     955          else { 
     956                 
    925957                tPoint[0] = pforg[0] + pfdir[0] * dist; 
    926958                tPoint[1] = pforg[1] + pfdir[1] * dist; 
    927959                tPoint[2] = pforg[2] + pfdir[2] * dist; 
    928  
     960                 
    929961                return mFaceParents[hittriangle].mObject; 
    930         } 
     962          } 
     963        } 
     964         
    931965} 
    932966 
     
    10501084{ 
    10511085  int hits=0; 
    1052  
     1086#if DEBUG_RAYCAST 
     1087  Debug<<"PR "; 
     1088#endif 
    10531089  if (objectA == NULL && objectB == NULL) 
    10541090        return 0; 
    1055  
     1091   
    10561092  AxisAlignedBox3 sbox = box; 
    10571093  sbox.Enlarge(Vector3(-Limits::Small)); 
     
    11231159        } 
    11241160  } 
    1125    
     1161 
     1162 
    11261163  return hits; 
    11271164} 
     
    11351172  int i; 
    11361173  int num = 16; 
    1137    
     1174 
     1175#if DEBUG_RAYCAST 
     1176  Debug<<"C16 "<<flush; 
     1177#endif 
    11381178  if (mRayCastMethod == INTEL_RAYCASTER) { 
    11391179#ifdef GTP_INTERNAL 
     
    11441184  int backward_hit_triangles[16]; 
    11451185  float backward_dist[16]; 
    1146    
     1186 
     1187 
    11471188  Vector3 min = sbox.Min(); 
    11481189  Vector3 max = sbox.Max(); 
    1149    
    11501190  for (i=0; i < num; i++) { 
    11511191        mlrtaStoreRayAS16(&rays[index + i].mOrigin.x, 
     
    11611201 
    11621202  for (i=0; i < num; i++) { 
    1163         Vector3 dir = -rays[index+i].mDirection; 
     1203        Vector3 dir = -rays[index + i].mDirection; 
    11641204        mlrtaStoreRayAS16(&rays[index+i].mOrigin.x, 
    11651205                                          &dir.x, 
     
    11741214   
    11751215 
     1216 
    11761217  for (i=0; i < num; i++) { 
    11771218        Intersectable *objectA = NULL, *objectB = NULL; 
    11781219        Vector3 pointA, pointB; 
    11791220        Vector3 normalA, normalB; 
     1221 
     1222 
     1223   
    11801224        if (forward_hit_triangles[i] !=-1 ) { 
    1181           objectA = mFaceParents[forward_hit_triangles[i]].mObject; 
    1182           // Get the normal of that face 
    1183           Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
    1184           normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
    1185           //-rays[index+i].mDirection; // $$ temporary 
    1186           pointA = rays[index+i].Extrap(forward_dist[i]); 
     1225          if (forward_hit_triangles[i] >= mFaceParents.size()) 
     1226                cerr<<"Warning: traingle index out of range! "<<forward_hit_triangles[i]<<endl; 
     1227          else { 
     1228                objectA = mFaceParents[forward_hit_triangles[i]].mObject; 
     1229                // Get the normal of that face 
     1230                Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
     1231                normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     1232                //-rays[index+i].mDirection; // $$ temporary 
     1233                pointA = rays[index+i].Extrap(forward_dist[i]); 
     1234          } 
    11871235        } 
    11881236         
    11891237        if (backward_hit_triangles[i]!=-1) { 
    1190           objectB = mFaceParents[backward_hit_triangles[i]].mObject; 
    1191           Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
    1192  
    1193           normalB = mesh->GetFacePlane(mFaceParents[backward_hit_triangles[i]].mFaceIndex).mNormal; 
    1194            
    1195           //      normalB = rays[index+i].mDirection; // $$ temporary 
    1196           pointB = rays[index+i].Extrap(-backward_dist[i]); 
    1197         } 
    1198          
     1238          if (backward_hit_triangles[i] >= mFaceParents.size()) 
     1239                cerr<<"Warning: traingle index out of range! "<<backward_hit_triangles[i]<<endl; 
     1240          else { 
     1241                objectB = mFaceParents[backward_hit_triangles[i]].mObject; 
     1242                Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
     1243                 
     1244                normalB = mesh->GetFacePlane(mFaceParents[backward_hit_triangles[i]].mFaceIndex).mNormal; 
     1245                 
     1246                //        normalB = rays[index+i].mDirection; // $$ temporary 
     1247                pointB = rays[index+i].Extrap(-backward_dist[i]); 
     1248          } 
     1249        } 
     1250 
    11991251        ProcessRay(rays[index+i].mOrigin, 
    12001252                           rays[index+i].mDirection, 
     
    12071259  } 
    12081260#endif 
     1261   
    12091262  } else { 
    12101263 
     
    12171270        } 
    12181271  } 
    1219    
     1272#if DEBUG_RAYCAST 
     1273  Debug<<"C16F\n"<<flush; 
     1274#endif 
    12201275} 
    12211276 
     
    12361291          i += 16; 
    12371292        } else { 
     1293 
    12381294          CastRay(rays[i].mOrigin, 
    12391295                          rays[i].mDirection, 
     
    12411297                          vssRays, 
    12421298                          mViewCellsManager->GetViewSpaceBox()); 
     1299 
    12431300          i++; 
    12441301        } 
     
    12521309} 
    12531310 
    1254  
    1255 int Preprocessor::CastRay( 
    1256                                                   const Vector3 &viewPoint, 
    1257                                                   const Vector3 &direction, 
    1258                                                   const float probability, 
    1259                                                   VssRayContainer &vssRays, 
    1260                                                   const AxisAlignedBox3 &box 
    1261                                                   ) 
    1262 { 
    1263         switch (mRayCastMethod) 
     1311Intersectable * 
     1312Preprocessor::CastSimpleRay( 
     1313                                                        const Vector3 &viewPoint, 
     1314                                                        const Vector3 &direction, 
     1315                                                        const AxisAlignedBox3 &box, 
     1316                                                        Vector3 &point, 
     1317                                                        Vector3 &normal 
     1318                                                        ) 
     1319{ 
     1320  Intersectable *result = NULL; 
     1321  switch (mRayCastMethod) 
     1322        { 
     1323        case INTEL_RAYCASTER: { 
     1324          float dist; 
     1325          int hittriangle; 
     1326          double n[3]; 
     1327          hittriangle = mlrtaIntersectAS(&viewPoint.x, 
     1328                                                                         &direction.x, 
     1329                                                                         n, 
     1330                                                                         dist); 
     1331          if (hittriangle !=-1 ) { 
     1332                if (hittriangle >= mFaceParents.size()) 
     1333                  cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
     1334                else { 
     1335                  result = mFaceParents[hittriangle].mObject; 
     1336                  normal = Vector3(n[0], n[1], n[2]); 
     1337                  point = viewPoint + direction*dist; 
     1338                } 
     1339          } 
     1340          break; 
     1341        } 
     1342        case INTERNAL_RAYCASTER: 
     1343        default: { 
     1344          static Ray ray; 
     1345           
     1346          ray.intersections.clear(); 
     1347          // do not store anything else then intersections at the ray 
     1348          ray.Init(viewPoint, direction, Ray::LOCAL_RAY); 
     1349           
     1350          ray.mFlags &= ~Ray::CULL_BACKFACES; 
     1351           
     1352          if (mKdTree->CastRay(ray)) { 
     1353                result = ray.intersections[0].mObject; 
     1354                point = ray.Extrap(ray.intersections[0].mT); 
     1355                normal = ray.intersections[0].mNormal; 
     1356          } 
     1357          break; 
     1358        } 
     1359        } 
     1360  return result; 
     1361} 
     1362 
     1363int 
     1364Preprocessor::CastRay( 
     1365                                          const Vector3 &viewPoint, 
     1366                                          const Vector3 &direction, 
     1367                                          const float probability, 
     1368                                          VssRayContainer &vssRays, 
     1369                                          const AxisAlignedBox3 &box 
     1370                                          ) 
     1371{ 
     1372#if DEBUG_RAYCAST 
     1373  Debug<<"CR "<<flush; 
     1374#endif 
     1375  switch (mRayCastMethod) 
    12641376        { 
    12651377        case INTEL_RAYCASTER: 
     
    12691381                return CastInternalRay(viewPoint, direction, probability, vssRays, box); 
    12701382        } 
     1383#if DEBUG_RAYCAST 
     1384  Debug<<"CRF "<<flush; 
     1385#endif   
    12711386} 
    12721387 
Note: See TracChangeset for help on using the changeset viewer.