Ignore:
Timestamp:
09/12/06 17:39:08 (18 years ago)
Author:
mattausch
Message:

worked on triangle processing. logical units will be created by grouping objects
using their visibility definitions.

File:
1 edited

Legend:

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

    r1328 r1344  
    162162        Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl; 
    163163        Debug << "load polygons as meshes: " << mLoadPolygonsAsMeshes << endl; 
     164 
     165        if (mRayCastMethod == 0) 
     166                cout << "ray cast method: internal" << endl; 
     167        else 
     168                cout << "ray cast method: intel" << endl; 
    164169} 
    165170 
     
    231236        cout << "number of input files: " << files << endl; 
    232237        bool result = false; 
     238 
     239        // root for different files 
     240        mSceneGraph->SetRoot(new SceneGraphNode()); 
     241 
    233242        if (files == 1) { 
    234243                 
     
    245254                cout << filename << endl; 
    246255 
    247                 SceneGraphNode *sroot = mSceneGraph->GetRoot(); 
    248  
    249256                if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 
    250                 { cout << "here5800" << endl; 
     257                {  
    251258                        result = parser->ParseFile( 
    252259                                filename,  
    253                                 &sroot, 
     260                                mSceneGraph->GetRoot(), 
    254261                                mLoadPolygonsAsMeshes, 
    255262                                &mFaceParents); 
    256263                } 
    257264                else 
    258                 { cout << "here776645" << endl; 
    259                         result = parser->ParseFile(filename, &sroot, mLoadPolygonsAsMeshes); 
     265                {  
     266                        result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadPolygonsAsMeshes); 
    260267                } 
    261                  cout << "here98809845" << endl; 
     268                 
    262269                delete parser; 
    263270 
    264271        } else { 
    265                 // root for different files 
    266                 mSceneGraph->SetRoot(new SceneGraphNode()); 
     272                 
    267273                for (int i= 0; i < filenames.size(); i++) { 
    268274                  if (strstr(filenames[i].c_str(), ".x3d")) 
     
    271277                        parser = new UnigraphicsParser; 
    272278                   
    273                   SceneGraphNode *node; 
     279                  SceneGraphNode *node = new SceneGraphNode(); 
    274280                  bool success; 
    275281                   
    276282                  if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 
    277                   { cout << "here4500" << endl; 
     283                  {  
    278284                          success = parser->ParseFile( 
    279285                                  filename,  
    280                                   &node, 
     286                                  node, 
    281287                                  mLoadPolygonsAsMeshes, 
    282288                                  &mFaceParents); 
     
    284290                  else 
    285291                  { 
    286                           cout << "here45" << endl; 
    287                           success = parser->ParseFile(filename, &node, mLoadPolygonsAsMeshes); 
     292                          success = parser->ParseFile(filename, node, mLoadPolygonsAsMeshes); 
    288293                  } 
    289294 
    290295                  if (success)  
    291                   { cout << "here4509999" << endl; 
     296                  {  
    292297                          mSceneGraph->GetRoot()->mChildren.push_back(node); 
    293                           // at least one file parsed 
    294                           result = true; 
     298                          result = true; // at least one file parsed 
    295299                  } 
    296300                   
     
    298302                } 
    299303        } 
    300          cout << "here8888" << endl; 
    301  
     304         
    302305        if (result)  
    303         { cout << "here199" << endl; 
     306        {  
    304307                // HACK  
    305308                if (ADDITIONAL_GEOMETRY_HACK) 
     
    307310 
    308311                mSceneGraph->AssignObjectIds(); 
    309  cout << "here99" << endl; 
     312  
    310313                int intersectables, faces; 
    311314                mSceneGraph->GetStatistics(intersectables, faces); 
    312  cout << "here999" << endl; 
     315  
    313316                cout<<filename<<" parsed successfully."<<endl; 
    314317                cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 
     
    316319                mSceneGraph->CollectObjects(&mObjects); 
    317320                mSceneGraph->GetRoot()->UpdateBox(); 
    318  cout << "here9999" << endl; 
     321  
    319322                if (0) 
    320323                { 
     
    369372{ 
    370373  mKdTree = new KdTree; 
     374 
    371375  // add mesh instances of the scene graph to the root of the tree 
    372376  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot(); 
    373         cout << "here3.95" << endl; 
     377         
    374378  mSceneGraph->CollectObjects(&root->mObjects); 
    375         cout << "here3.97" << endl; 
     379   
    376380  long startTime = GetTime(); 
    377  
    378381  cout << "building kd tree ... " << endl; 
     382 
    379383  mKdTree->Construct(); 
     384 
    380385  cout << "construction finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs " << endl; 
     386 
    381387  return true; 
    382388} 
     
    847853        case INTEL_RAYCASTER: 
    848854#ifdef GTP_INTERNAL 
    849           cout<<"Ray Cast file: "<<externKdTree<<endl; 
     855          cout<<"Ray Cast file: " << externKdTree << endl; 
    850856          return mlrtaLoadAS(externKdTree.c_str()); 
    851857#endif 
     
    868874{ 
    869875#ifdef GTP_INTERNAL 
     876        //cout << "intel ray" << endl; 
    870877        VssRay *vssRay  = NULL; 
    871878        int hits = 0; 
     
    875882        Intersectable *objectA = NULL, *objectB = NULL; 
    876883        float dist; 
    877          
    878884        double normal[3]; 
    879885 
    880886        hittriangle = mlrtaIntersectAS(&viewPoint.x, 
    881                                                                    &direction.x, 
    882                                                                    normal, 
    883                                                                    dist); 
    884  
    885         if (hittriangle !=-1 ) { 
    886           if (hittriangle >= mFaceParents.size()) 
    887                 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    888           else { 
    889                 objectA = mFaceParents[hittriangle].mObject; 
    890                 normalA = Vector3(normal[0], normal[1], normal[2]); 
    891                 // Get the normal of that face 
    892                 //              Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
    893                 //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
    894                 //-rays[index+i].mDirection; // $$ temporary 
    895                 pointA = viewPoint + direction*dist; 
    896           } 
    897         } 
    898  
    899          
     887                &direction.x, 
     888                normal, 
     889                dist); 
     890 
     891        if (hittriangle != -1 ) { 
     892                if (hittriangle >= mFaceParents.size()) 
     893                        cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
     894                else { 
     895                        objectA = mFaceParents[hittriangle].mObject; 
     896                        normalA = Vector3(normal[0], normal[1], normal[2]); 
     897                        // Get the normal of that face 
     898                        //              Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
     899                        //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     900                        //-rays[index+i].mDirection; // $$ temporary 
     901                        pointA = viewPoint + direction*dist; 
     902                } 
     903        } 
     904 
     905 
    900906        Vector3 dir = -direction; 
    901907        hittriangle = mlrtaIntersectAS(&viewPoint.x, 
    902                                                                    &dir.x, 
    903                                                                    normal, 
    904                                                                    dist); 
    905  
    906         if (hittriangle !=-1 ) { 
    907           if (hittriangle >= mFaceParents.size()) 
    908                 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
    909           else { 
    910                 objectB = mFaceParents[hittriangle].mObject; 
    911                 normalB = Vector3(normal[0], normal[1], normal[2]); 
    912                 // Get the normal of that face 
    913                 //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
    914                 //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
    915                 //-rays[index+i].mDirection; // $$ temporary 
    916                 pointB = viewPoint + dir*dist; 
    917         } 
     908                &dir.x, 
     909                normal, 
     910                dist); 
     911 
     912        if (hittriangle != -1 ) { 
     913                if (hittriangle >= mFaceParents.size()) 
     914                        cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
     915                else { 
     916                        objectB = mFaceParents[hittriangle].mObject; 
     917                        normalB = Vector3(normal[0], normal[1], normal[2]); 
     918                        // Get the normal of that face 
     919                        //              Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
     920                        //              normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     921                        //-rays[index+i].mDirection; // $$ temporary 
     922                        pointB = viewPoint + dir * dist; 
     923                } 
    918924        } 
    919925 
    920926        return ProcessRay(viewPoint, 
    921                                           direction, 
    922                                           objectA, pointA, normalA, 
    923                                           objectB, pointB, normalB, 
    924                                           probability, 
    925                                           vssRays, 
    926                                           box 
    927                                           ); 
     927                direction, 
     928                objectA, pointA, normalA, 
     929                objectB, pointB, normalB, 
     930                probability, 
     931                vssRays, 
     932                box 
     933                ); 
    928934#else 
    929935        return -1; 
     
    971977        else { 
    972978          if (hittriangle >= mFaceParents.size()) { 
    973                 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
     979                cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    974980                return NULL; 
    975981          } 
     
    989995#endif 
    990996 
    991          
    992          
    993997} 
    994998 
     
    10021006                                                                  ) 
    10031007{ 
    1004  
     1008  cout << "internal ray" << endl; 
    10051009  int hits = 0; 
    10061010  static Ray ray; 
     
    10091013 
    10101014  //  AxisAlignedBox3 box = Union(mKdTree->GetBox(), mViewCellsManager->GetViewSpaceBox()); 
    1011    
    1012  
    10131015  AxisAlignedBox3 sbox = box; 
    10141016  sbox.Enlarge(Vector3(-Limits::Small)); 
     
    10421044  } 
    10431045 
    1044    
    10451046  SetupRay(ray, viewPoint, -direction); 
    10461047  ray.mFlags &= ~Ray::CULL_BACKFACES; 
     
    10761077                                                  ); 
    10771078          vssRays.push_back(vssRay); 
     1079          //cout << "ray: " << *vssRay << endl; 
    10781080          hits ++; 
    10791081        } 
     
    10881090                                                  ); 
    10891091          vssRays.push_back(vssRay); 
     1092          //cout << "ray: " << *vssRay << endl; 
    10901093          hits ++; 
    10911094        } 
     
    11721175                                                  ); 
    11731176          vssRays.push_back(vssRay); 
     1177          //cout << "ray: " << *vssRay << endl; 
    11741178          hits ++; 
    11751179        } 
     
    11841188                                                  ); 
    11851189          vssRays.push_back(vssRay); 
     1190          //cout << "ray: " << *vssRay << endl; 
    11861191          hits ++; 
    11871192        } 
     
    11991204{ 
    12001205  int i; 
    1201   int num = 16; 
     1206  const int num = 16; 
    12021207 
    12031208#if DEBUG_RAYCAST 
     
    12141219 
    12151220 
    1216    
    1217  
    12181221  Vector3 min = sbox.Min(); 
    12191222  Vector3 max = sbox.Max(); 
     1223   
    12201224  for (i=0; i < num; i++) { 
    12211225        mlrtaStoreRayAS16(&rays[index + i].mOrigin.x, 
     
    12231227                                          i); 
    12241228  } 
    1225    
    12261229   
    12271230  mlrtaTraverseGroupAS16(&min.x, 
     
    12371240  } 
    12381241   
    1239    
    12401242  mlrtaTraverseGroupAS16(&min.x, 
    12411243                                                 &max.x, 
     
    12441246   
    12451247 
    1246  
    12471248  for (i=0; i < num; i++) { 
    12481249        Intersectable *objectA = NULL, *objectB = NULL; 
     
    12501251        Vector3 normalA, normalB; 
    12511252 
    1252  
    1253    
    1254         if (forward_hit_triangles[i] !=-1 ) { 
     1253        if (forward_hit_triangles[i] != -1 ) { 
    12551254          if (forward_hit_triangles[i] >= mFaceParents.size()) 
    1256                 cerr<<"Warning: traingle index out of range! "<<forward_hit_triangles[i]<<endl; 
    1257           else { 
     1255                cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl; 
     1256          else {  
    12581257                objectA = mFaceParents[forward_hit_triangles[i]].mObject; 
    12591258                // Get the normal of that face 
    1260                 Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 
    1261                 normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 
     1259                normalA = objectA->GetNormal(mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
    12621260                //-rays[index+i].mDirection; // $$ temporary 
    12631261                pointA = rays[index+i].Extrap(forward_dist[i]); 
    12641262          } 
    12651263        } 
    1266          
     1264          
    12671265        if (backward_hit_triangles[i]!=-1) { 
    12681266          if (backward_hit_triangles[i] >= mFaceParents.size()) 
    1269                 cerr<<"Warning: traingle index out of range! "<<backward_hit_triangles[i]<<endl; 
    1270           else { 
     1267                cerr<<"Warning: triangle index out of range! "<<backward_hit_triangles[i]<<endl; 
     1268          else {  
    12711269                objectB = mFaceParents[backward_hit_triangles[i]].mObject; 
    1272                 Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 
    1273                  
    1274                 normalB = mesh->GetFacePlane(mFaceParents[backward_hit_triangles[i]].mFaceIndex).mNormal; 
    1275                  
    1276                 //        normalB = rays[index+i].mDirection; // $$ temporary 
     1270                normalB = objectB->GetNormal(mFaceParents[forward_hit_triangles[i]].mFaceIndex); 
     1271                 
     1272                // normalB = rays[index+i].mDirection; // $$ temporary 
    12771273                pointB = rays[index+i].Extrap(-backward_dist[i]); 
    12781274          } 
    12791275        } 
    1280  
     1276  
    12811277        ProcessRay(rays[index+i].mOrigin, 
    12821278                           rays[index+i].mDirection, 
     
    12881284                           ); 
    12891285  } 
     1286   
    12901287#endif 
    12911288   
     
    13121309{ 
    13131310  long t1 = GetTime(); 
    1314   for (int i=0; i < rays.size(); ) { 
    1315         if (i + 16 < rays.size()) { 
     1311   
     1312  for (int i = 0; i < (int)rays.size(); ) { 
     1313          // method only available for intel raycaster yet 
     1314        if (i + 16 < (int)rays.size()) { 
     1315 
    13161316          CastRays16( 
    13171317                                 i, 
     
    13211321          i += 16; 
    13221322        } else { 
    1323  
    13241323          CastRay(rays[i].mOrigin, 
    13251324                          rays[i].mDirection, 
     
    13271326                          vssRays, 
    13281327                          mViewCellsManager->GetViewSpaceBox()); 
    1329  
    13301328          i++; 
    13311329        } 
     
    13351333 
    13361334  long t2 = GetTime(); 
    1337    
    13381335  cout<<2*rays.size()/(1e3*TimeDiff(t1, t2))<<"M rays/s"<<endl; 
    13391336} 
     
    13541351          
    13551352          int hittriangle; 
    1356            
    13571353 
    13581354#ifdef GTP_INTERNAL 
     
    13671363           if (hittriangle !=-1 ) { 
    13681364                if (hittriangle >= mFaceParents.size()) 
    1369                   cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 
     1365                  cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 
    13701366                else { 
    13711367                  result = mFaceParents[hittriangle].mObject; 
     
    13751371          } 
    13761372#else 
    1377         hittriangle = -1; 
     1373          hittriangle = -1; 
    13781374#endif 
    13791375 
    1380           
    13811376          break; 
    13821377        } 
Note: See TracChangeset for help on using the changeset viewer.