Changeset 331


Ignore:
Timestamp:
10/17/05 02:57:13 (19 years ago)
Author:
mattausch
Message:

fixed box error at from ray construction of bsp view cells

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r330 r331  
    99#       filename vienna.x3d 
    1010#       filename ../data/vienna/vienna-simple.x3d 
    11         filename ../data/vienna/vienna-buildings.x3d 
     11#       filename ../data/vienna/vienna-buildings.x3d 
    1212#       filename ../data/vienna/viewcells-25-sel.x3d 
    13 #       filename ../data/atlanta/atlanta2.x3d 
     13        filename ../data/atlanta/atlanta2.x3d 
    1414#       filename ../data/soda/soda.dat 
    1515#       filename ../data/soda/soda5.dat 
     
    5656 
    5757Sampling { 
    58         totalSamples    5000 
     58        totalSamples    1000000 
    5959        samplesPerPass  20 
    6060} 
     
    7676BspTree { 
    7777        Construction { 
    78                 input fromRays 
     78                input fromRays 
    7979        #       input fromViewCells 
    8080        #       input fromSceneGeometry 
    81                 samples 3000 
     81                samples 200000 
    8282                sideTolerance 0.002 
    8383        } 
     
    114114        Termination { 
    115115                maxPolysForAxisAligned 100 
    116                 maxPolygons 20 
     116                maxPolygons 2 
    117117                maxDepth 100 
    118118        } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r329 r331  
    5353   
    5454        if (strcmp(viewCellsStr, "bspTree") == 0) 
    55         { 
    56                 Debug << "here bsp" << endl; 
    57         mViewCellsType = BSP_VIEW_CELLS; 
    58         } 
     55                mViewCellsType = BSP_VIEW_CELLS; 
    5956        else if (strcmp(viewCellsStr, "kdTree") == 0) 
    60                 { 
    61                 Debug << "here kd" << endl; 
    62         mViewCellsType = KD_VIEW_CELLS; 
    63         } 
     57                mViewCellsType = KD_VIEW_CELLS; 
    6458        else if (strcmp(viewCellsStr, "sceneDependent") == 0) 
    6559        { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r330 r331  
    88#include "ViewCell.h" 
    99 
    10 SamplingPreprocessor::SamplingPreprocessor(): mPass(0) 
     10SamplingPreprocessor::SamplingPreprocessor(): mPass(0), mSampleRays(NULL) 
    1111{ 
    1212  // this should increase coherence of the samples 
     
    2222SamplingPreprocessor::~SamplingPreprocessor() 
    2323{ 
    24         // clean up 
    25         if (mSampleRays) 
    26         { 
    27                 CLEAR_CONTAINER (*mSampleRays); 
    28                 DEL_PTR (mSampleRays); 
    29         } 
     24        CLEAR_CONTAINER(mSampleRays); 
    3025} 
    3126 
     
    6661                break; 
    6762        case BspTree::FROM_SCENE_GEOMETRY: 
    68                  
    6963                DeleteViewCells(); // we generate new view cells 
    7064                mSceneGraph->CollectObjects(&objects); 
    71                 mBspTree->Construct(objects, &mViewCells); 
    72                  
     65                mBspTree->Construct(objects, &mViewCells);       
    7366                break; 
    7467        case BspTree::FROM_RAYS: 
    7568                DeleteViewCells(); // we generate new view cells 
    76                 mSceneGraph->CollectObjects(&objects); 
    7769                mBspTree->Construct(mSampleRays, &mViewCells); 
    7870                break; 
     
    8173                break; 
    8274        } 
     75         
    8376         
    8477        return true; 
     
    278271 
    279272  int pvsOut = Min((int)objects.size(), 10); 
    280   int vcPvsOut = Min((int)mViewCells.size(), 5); 
    281  
     273 
     274  vector<Ray> rays[10]; 
     275 
     276  vector<Ray> vcRays[5]; 
    282277  ViewCellContainer pvsViewCells; 
    283  
    284   // some random view cells for output 
    285   for (int j = 0; j < vcPvsOut; ++ j) 
    286   { 
    287           int idx = Random((int)mViewCells.size()); 
    288           Debug << "output view cell=" << idx << endl; 
    289           pvsViewCells.push_back(mViewCells[Random((int)mViewCells.size())]); 
    290   } 
    291  
    292   vector<Ray> rays[10]; 
    293   vector<Ray> vcRays[5]; 
    294  
    295278  vector<Ray> viewCellRays; // used for BSP tree construction 
    296   
    297   mSampleRays = new RayContainer(); 
    298   //mSampleRays->reserve(mBspConstructionSamples); 
    299279 
    300280  while (totalSamples < mTotalSamples) { 
     
    303283                int passSamples = 0; 
    304284                int index = 0; 
    305                          
    306                 cout << "totalSamples: "  << totalSamples; 
     285                Real maxTime = 0; 
     286                int maxTimeIdx = 0; 
     287 
     288                cout << "totalSamples: "  << totalSamples << endl; 
     289 
    307290                for (i = 0; i < objects.size(); i++) { 
    308                          
    309                         Debug << "\nsampling object " << i << " of " << (int)objects.size() << " sample " << passSamples << endl; 
    310  
     291                                                 
    311292                        KdNode *nodeToSample = NULL; 
    312293                        Intersectable *object = objects[i]; 
     
    369350                         
    370351                        object->GetRandomSurfacePoint(point, normal); 
     352                         
     353                        long samplesPerObjStart = GetTime(); 
     354 
    371355                        bool viewcellSample = true; 
    372356                        int sampleContributions; 
    373                          
    374                         long startTime = GetTime(); 
    375357 
    376358                        if (viewcellSample) { 
     
    400382                                        sampleContributions = CastRay(object, ray); 
    401383 
    402                                         // CORR matt: put inside loop 
     384                                        //-- CORR matt: put block inside loop 
     385                                        if (sampleContributions) { 
     386                                                passContributingSamples++; 
     387                                                passSampleContributions += sampleContributions; 
     388                                        } 
     389 
    403390                                        if ( i < pvsOut ) 
    404391                                                rays[i].push_back(ray); 
     
    412399                                                } 
    413400                                        } 
     401                                        //------------------- 
    414402 
    415403                                        if (mViewCellsType == BSP_VIEW_CELLS)  
    416404                                        { 
    417                                                 // save rays for bsp tree construction 
     405                        // save rays for bsp tree construction 
    418406                                                if ((BspTree::sConstructionMethod = BspTree::FROM_RAYS) && 
    419407                                                        (totalSamples < mBspConstructionSamples)) 
    420408                                                { 
    421                                                         //cout << "pushing back sampling ray << " << mSampleRays->size() << endl; 
    422                                                         mSampleRays->push_back(new Ray(ray)); 
     409                                                        //cout << "pushing back sampling ray << " << mSampleRays.size() << endl; 
     410                                                        mSampleRays.push_back(new Ray(ray)); 
    423411                                                } 
    424412                                                else 
    425413                                                { 
    426                                                         // construct BSP tree using the samples 
     414                            // construct BSP tree using the samples 
    427415                                                        if (!mBspTree) 
    428416                                                        { 
    429                                                                 Debug << "Building bsp tree" << endl; 
    430417                                                                BuildBspTree(); 
    431418 
    432                                                                 CLEAR_CONTAINER (*mSampleRays); 
    433                                                                 DEL_PTR (mSampleRays); 
     419                                                                BspTreeStatistics(Debug);        
     420                                                                Export("vc_bsptree.x3d", false, false, true); 
    434421                                                        } 
    435422                                                        // check whether we can add this to the rays 
     
    440427                                                                                vcRays[j].push_back(ray); 
    441428                                                                        } 
     429                                                        // some random view cells for output 
     430                                                        if (pvsViewCells.empty()) 
     431                                                        { 
     432                                                                int vcPvsOut = Min((int)mViewCells.size(), 5); 
     433                                                         
     434                                                                for (int j = 0; j < vcPvsOut; ++ j) 
     435                                                                { 
     436                                                                        int idx = Random((int)mViewCells.size()); 
     437                                                                        Debug << "output view cell=" << idx << endl; 
     438                                                                        pvsViewCells.push_back(mViewCells[Random((int)mViewCells.size())]); 
     439                                                                } 
     440                                                        } 
    442441                                                }                                
    443442                                        } 
     
    449448                                //                              object->GetRandomVisibleMesh(Plane3(normal, point)); 
    450449                        } 
    451                         long t = TimeDiff(startTime, GetTime()); 
    452                         Debug << "pass time: " << t << endl; 
    453                  
     450                                 
     451                        // measure maximal time for samples per object 
     452                        Real t = TimeDiff(samplesPerObjStart, GetTime()); 
     453 
     454                        if (t > maxTime) 
     455                        { 
     456                                maxTime = t; 
     457                                maxTimeIdx = i; 
     458                        } 
     459         
     460                        // CORR matt: must add all samples 
    454461                        passSamples += mSamplesPerPass; 
    455                  
    456                         if (sampleContributions) { 
    457                                 passContributingSamples++; 
    458                                 passSampleContributions += sampleContributions; 
    459                         } 
    460462                } 
    461463         
    462                 // CORR matt: must add pass samples 
    463                 totalSamples += passSamples; // totalSamples ++; 
     464                totalSamples += passSamples;  
    464465                 
    465466                //    if (pass>10) 
    466467                //      HoleSamplingPass(); 
    467468     
    468                  
    469469                mPass++; 
    470470 
     
    483483                } 
    484484 
    485                 cout << "#Pass " << mPass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     485                Debug << "maximal time needed for pass: " << maxTime << " (object " << maxTimeIdx << ")" << endl; 
     486 
     487                float avgRayContrib = (passContributingSamples > 0) ?  
     488                        passSampleContributions/(float)passContributingSamples : 0; 
     489 
     490                cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    486491                cout << "#TotalSamples=" << totalSamples/1000  
    487492                                 << "k   #SampleContributions=" << passSampleContributions << " ("  
    488493                                 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    489494                                 << pvsSize/(float)objects.size() << endl  
    490                                  << "avg ray contrib=" <<  
    491                                  ((passContributingSamples > 0) ? passSampleContributions/(float)passContributingSamples : 0) 
    492                                  << endl; 
    493                  
     495                                 << "avg ray contrib=" << avgRayContrib << endl; 
    494496                 
    495497                mStats << 
     
    500502                        "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    501503                        "#AvgPVS\n"<< pvsSize/(float)objects.size() << endl << 
    502                         "#AvgRayContrib\n" <<  
    503                         ((passContributingSamples > 0) ? passSampleContributions/(float)passContributingSamples : 0) 
    504                         << endl; 
     504                        "#AvgRayContrib\n" << avgRayContrib << endl; 
    505505        } 
    506506 
     
    509509   
    510510  //  HoleSamplingPass(); 
    511   if (1) { 
     511  if (0) { 
    512512    Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 
    513513    exporter->SetExportRayDensity(true); 
     
    534534    delete exporter; 
    535535  } 
     536   
    536537  if (1) { 
    537538  if (mViewCellsType == BSP_VIEW_CELLS) 
    538539  { 
     540          bool exportSplits = false; 
     541          environment->GetBoolValue("BspTree.exportSplits", exportSplits); 
     542 
     543          // export the bsp splits 
     544          if (exportSplits) 
     545          { 
     546                  Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
     547 
     548                  if (exporter)  
     549                  {      
     550                          Material m;  
     551                          m.mDiffuseColor = RgbColor(1, 0, 0); 
     552                          exporter->SetForcedMaterial(m); 
     553                          exporter->SetWireframe(); 
     554                          exporter->ExportBspSplits(*mBspTree); 
     555 
     556                          // take forced material, else big scenes cannot be viewed 
     557                          m.mDiffuseColor = RgbColor(0, 1, 0); 
     558                          exporter->SetForcedMaterial(m); 
     559                          exporter->SetFilled(); 
     560 
     561                          exporter->ResetForcedMaterial(); 
     562 
     563                          if (1) 
     564                          { 
     565                                  Material m;//= RandomMaterial(); 
     566                                  m.mDiffuseColor = RgbColor(0, 0, 1); 
     567                                  exporter->SetForcedMaterial(m); 
     568                  
     569                                  for (int j = 0; j < objects.size(); ++ j) 
     570                                           exporter->ExportIntersectable(objects[j]); 
     571                         
     572                                  delete exporter; 
     573                          } 
     574                  } 
     575          } 
     576 
    539577          for (int j = 0; j < pvsViewCells.size(); ++ j) 
    540                 { 
    541                         ViewCell *vc = pvsViewCells[j]; 
    542  
    543                         Intersectable::NewMail(); 
    544  
    545                         char s[64]; sprintf(s, "bsp-pvs%04d.x3d", j); 
    546                         Exporter *exporter = Exporter::GetExporter(s); 
    547                         exporter->SetFilled(); 
    548  
    549                         ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 
    550  
    551                         Material m;//= RandomMaterial(); 
    552                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    553                         exporter->SetForcedMaterial(m); 
    554  
    555                         exporter->ExportViewCell(vc); 
    556  
    557                         Debug << "pvs size: " << (int)vc->GetPvs().GetSize() << " of " << (int)objects.size(); 
    558                         Debug << " exporting rays: " << (int)vcRays[j].size() << endl; 
    559  
    560                         exporter->SetWireframe(); 
    561  
    562                         // export view cells 
    563                         m.mDiffuseColor = RgbColor(1, 0, 1); 
    564                         exporter->SetForcedMaterial(m); 
    565                         exporter->ExportViewCells(mViewCells); 
     578          { 
     579                  ViewCell *vc = pvsViewCells[j]; 
     580 
     581                  Intersectable::NewMail(); 
     582                  char s[64]; sprintf(s, "bsp-pvs%04d.x3d", j); 
     583 
     584                  Exporter *exporter = Exporter::GetExporter(s); 
     585                  exporter->SetFilled(); 
     586 
     587                  ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 
     588 
     589                  Material m;//= RandomMaterial(); 
     590                  m.mDiffuseColor = RgbColor(0, 1, 0); 
     591                  exporter->SetForcedMaterial(m); 
     592 
     593                  exporter->ExportViewCell(vc); 
     594 
     595                  Debug << j << ": pvs size=" << (int)vc->GetPvs().GetSize()  
     596                            << ", piercing rays=" << (int)vcRays[j].size() << endl; 
     597 
     598                  exporter->SetWireframe(); 
     599 
     600                  // export view cells 
     601                  m.mDiffuseColor = RgbColor(1, 0, 1); 
     602                  exporter->SetForcedMaterial(m); 
     603                  exporter->ExportViewCells(mViewCells); 
    566604                         
    567                         // export rays piercing this view cell 
    568                         exporter->ExportRays(vcRays[j], 1000, RgbColor(0, 1, 0)); 
    569  
    570                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    571                         exporter->SetForcedMaterial(m); 
    572  
    573                         // output pvs of view cell 
    574                         for (; it != vc->GetPvs().mEntries.end(); ++ it)  
    575                         { 
    576                                 Intersectable *intersect = (*it).first; 
    577                                 if (!intersect->Mailed()) 
    578                                 { 
    579                                         exporter->ExportIntersectable(intersect); 
    580                                         intersect->Mail(); 
    581                                 }                        
    582                         } 
    583  
    584                         // output rest of the objects 
    585                         if (1) 
    586                         { 
    587                                 Material m;//= RandomMaterial(); 
    588                                 m.mDiffuseColor = RgbColor(0, 0, 1); 
    589                                 exporter->SetForcedMaterial(m); 
    590                  
    591                                 for (int j = 0; j < objects.size(); ++ j) 
    592                                         if (!objects[j]->Mailed()) 
    593                                         { 
    594                                                 //if (j == 2198)m.mDiffuseColor = RgbColor(1, 0, 1); 
    595                                                 //else m.mDiffuseColor = RgbColor(1, 1, 0); 
    596                                                 exporter->SetForcedMaterial(m); 
    597                                                 exporter->ExportIntersectable(objects[j]); 
    598                                                 objects[j]->Mail(); 
    599                                         } 
    600                         } 
    601                         DEL_PTR(exporter); 
     605                  // export rays piercing this view cell 
     606                  exporter->ExportRays(vcRays[j], 1000, RgbColor(0, 1, 0)); 
     607 
     608                  m.mDiffuseColor = RgbColor(1, 0, 0); 
     609                  exporter->SetForcedMaterial(m); 
     610 
     611                  // output pvs of view cell 
     612                  for (; it != vc->GetPvs().mEntries.end(); ++ it)  
     613                  { 
     614                          Intersectable *intersect = (*it).first; 
     615                          if (!intersect->Mailed()) 
     616                          { 
     617                                  exporter->ExportIntersectable(intersect); 
     618                                  intersect->Mail(); 
     619                          }                      
     620                  } 
     621                 
     622                  // output rest of the objects 
     623                  if (1) 
     624                  { 
     625                          Material m;//= RandomMaterial(); 
     626                          m.mDiffuseColor = RgbColor(0, 0, 1); 
     627                          exporter->SetForcedMaterial(m); 
     628 
     629                          for (int j = 0; j < objects.size(); ++ j) 
     630                                  if (!objects[j]->Mailed()) 
     631                                  { 
     632                                          //if (j == 2198)m.mDiffuseColor = RgbColor(1, 0, 1); 
     633                                          //else m.mDiffuseColor = RgbColor(1, 1, 0); 
     634                                          exporter->SetForcedMaterial(m); 
     635                                          exporter->ExportIntersectable(objects[j]); 
     636                                          objects[j]->Mail(); 
     637                                  } 
     638                  } 
     639                  DEL_PTR(exporter); 
    602640                } 
    603641  }   
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r329 r331  
    2323  ofstream mStats; 
    2424  ObjectContainer mObjects; 
    25   RayContainer *mSampleRays; 
     25  RayContainer mSampleRays; 
    2626  int mBspConstructionSamples; 
    2727 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r330 r331  
    174174                // bound ray 
    175175                if ((ray->GetType() == Ray::LOCAL_RAY) &&  
    176                         (ray->intersections.empty())      && 
     176                        (!ray->intersections.empty())      && 
    177177                        (ray->intersections[0].mT <= maxT)) 
    178178                { 
     
    327327{ 
    328328} 
     329 
    329330ViewCell *BspLeaf::GetViewCell() 
    330331{ 
     
    341342        return true;  
    342343} 
     344 
     345int BspLeaf::GenerateViewCell(const RayContainer &rays,  
     346                                                           ViewCellContainer &viewCells) 
     347{ 
     348        int sampleContri = 0; 
     349        ViewCell *viewCell = new ViewCell(); 
     350        viewCells.push_back(viewCell); 
     351                                 
     352    mViewCell = viewCell; 
     353 
     354    RayContainer::const_iterator it, it_end = rays.end(); 
     355 
     356        // add contributions from samples to the PVS 
     357        for (it = rays.begin(); it != it_end; ++ it) 
     358        { 
     359                for (int i = 0; i < (int)(*it)->intersections.size(); ++ i) 
     360                        sampleContri = viewCell->GetPvs().AddSample((*it)->intersections[i].mObject); 
     361        } 
     362        return sampleContri; 
     363} 
     364 
    343365 
    344366/****************************************************************/ 
     
    501523                        BspNode *subRoot = Subdivide(tStack, tData);             
    502524 
     525                        int sampleContri = 0; 
     526 
    503527                        // generate new view cell for each leaf 
    504528                        if (viewCells && subRoot->IsLeaf()) 
    505                                 GenerateViewCell(dynamic_cast<BspLeaf *>(subRoot), *viewCells); 
    506                 } 
    507         } 
    508 } 
    509  
    510 void BspTree::GenerateViewCell(BspLeaf *leaf, ViewCellContainer &viewCells) const 
    511 { 
    512         ViewCell *viewCell = new ViewCell(); 
    513         viewCells.push_back(viewCell); 
    514                                  
    515         leaf->SetViewCell(viewCell); 
     529                                sampleContri += dynamic_cast<BspLeaf *>(subRoot)-> 
     530                                        GenerateViewCell(*tData.mRays, *viewCells); 
     531 
     532                        DEL_PTR(tData.mRays); 
     533                } 
     534        } 
    516535} 
    517536 
     
    585604} 
    586605 
    587 void BspTree::Construct(const ViewCellContainer &viewCells) 
     606int BspTree::Construct(const ViewCellContainer &viewCells) 
    588607{ 
    589608        mStat.nodes = 1; 
     
    595614 
    596615        // construct tree from the view cell polygons 
    597         Construct(polys, new RayContainer()); 
    598 } 
    599  
    600  
    601 void BspTree::Construct(const ObjectContainer &objects, ViewCellContainer *viewCells) 
     616        return Construct(polys, new RayContainer()); 
     617} 
     618 
     619 
     620int BspTree::Construct(const ObjectContainer &objects, ViewCellContainer *viewCells) 
    602621{ 
    603622        mStat.nodes = 1; 
     
    610629 
    611630        // construct tree from polygon soup 
    612         Construct(polys, new RayContainer(), viewCells); 
    613 } 
    614  
    615 void BspTree::Construct(RayContainer *rays,  
     631        return Construct(polys, new RayContainer(), viewCells); 
     632} 
     633 
     634int BspTree::Construct(const RayContainer &sampleRays,  
    616635                                                ViewCellContainer *viewCells) 
    617636{ 
     637        mStat.nodes = 1; 
     638        mBox.Initialize();      // initialise bsp tree bounding box 
     639         
    618640        PolygonContainer *polys = new PolygonContainer(); 
    619          
    620         RayContainer::const_iterator rit, rit_end = rays->end(); 
     641        RayContainer *rays = new RayContainer(); 
     642 
     643        RayContainer::const_iterator rit, rit_end = sampleRays.end(); 
    621644 
    622645        long startTime = GetTime(); 
     
    626649 
    627650        //-- extract polygons from faces stored in the rays 
    628         for (rit = rays->begin(); rit != rit_end; ++ rit) 
     651        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
    629652        { 
    630653                Ray *ray = *rit; 
    631          
    632654                ray->SetId(-1); // reset id 
     655                rays->push_back(ray); 
    633656 
    634657                for (int i = 0; i < (int)ray->intersections.size(); ++ i) 
    635658                { 
    636659                        MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->intersections[i].mObject); 
    637                         Face *face = obj->GetMesh()->mFaces[i]; 
    638                          
    639                          std::map<Face *, Polygon3 *>::iterator it= facePolyMap.find(face); 
    640  
    641                          if (it != facePolyMap.end())  
    642                          { 
    643                                  (*it).second->AddPiercingRay(ray); 
    644                          }  
    645                          else 
    646                          { 
    647                                  Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 
    648                                  polys->push_back(poly); 
    649                                  poly->AddPiercingRay(ray); 
    650  
    651                                  facePolyMap[face] = poly; 
    652                          } 
    653                 } 
    654         } 
    655  
    656          
     660                        Face *face = obj->GetMesh()->mFaces[ray->intersections[i].mFace]; 
     661 
     662                        // store rays piercing a face with the polygon representing the face 
     663                        std::map<Face *, Polygon3 *>::iterator it= facePolyMap.find(face); 
     664 
     665                        if (it != facePolyMap.end())  
     666                        { 
     667                                (*it).second->AddPiercingRay(ray); 
     668                        }  
     669                        else 
     670                        { 
     671                                Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 
     672                                polys->push_back(poly); 
     673                                Debug << "poly: " << *poly << endl; 
     674                                poly->AddPiercingRay(ray); 
     675 
     676                                facePolyMap[face] = poly; 
     677                        } 
     678                } 
     679        } 
     680         
     681        Polygon3::IncludeInBox(*polys, mBox); 
    657682        mStat.polys = (int)polys->size(); 
    658683 
    659         Debug << "**** Finished polygon extraction ****\n"; 
    660         Debug << "ray casting time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    661  
    662         Construct(polys, rays, viewCells); 
    663 } 
    664  
    665 void BspTree::Construct(PolygonContainer *polys, RayContainer *rays, ViewCellContainer *viewCells) 
     684        Debug << "**** Finished polygon extraction ****" << endl; 
     685        Debug << polys->size() << " polys extracted from " << rays->size() << " rays" << endl; 
     686        Debug << "extraction time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     687 
     688        return Construct(polys, rays, viewCells); 
     689} 
     690 
     691int BspTree::Construct(PolygonContainer *polys,  
     692                                           RayContainer *rays,  
     693                                           ViewCellContainer *viewCells) 
    666694{ 
    667695        std::stack<BspTraversalData> tStack; 
    668696 
    669697        BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell, rays); 
    670  
    671698        tStack.push(tData); 
    672699 
     
    674701        cout << "**** Contructing bsp tree ****\n"; 
    675702 
     703        int sampleContri = 0; 
     704 
    676705        while (!tStack.empty())  
    677706        { 
     
    683712 
    684713                if (viewCells && subRoot->IsLeaf()) 
    685                         GenerateViewCell(dynamic_cast<BspLeaf *>(subRoot), *viewCells); 
     714                        sampleContri += dynamic_cast<BspLeaf *>(subRoot)-> 
     715                                        GenerateViewCell(*tData.mRays, *viewCells); 
     716                DEL_PTR(tData.mRays); 
    686717        } 
    687718 
    688719        cout << "**** Finished tree construction ****\n"; 
    689720        Debug << "BSP tree contruction time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     721        return sampleContri; 
    690722} 
    691723 
     
    696728        if ((tData.mPolygons->size() <= sTermMaxPolygons) || (tData.mDepth >= sTermMaxDepth)) 
    697729        { 
    698 #ifdef _DEBUG 
     730//#ifdef _DEBUG 
    699731                Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: "  
    700732                          << (int)tData.mPolygons->size() << endl; 
    701 #endif 
     733//#endif 
    702734                EvaluateLeafStats(tData); 
    703735                BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 
     
    711743                leaf->ProcessPolygons(tData.mPolygons, sStoreSplitPolys); 
    712744                DEL_PTR(tData.mPolygons); 
    713                 DEL_PTR(tData.mRays); 
    714  
     745         
    715746                return leaf; 
    716747        } 
     
    726757        RayContainer *backRays = new RayContainer(); 
    727758         
    728  
    729759        // create new interior node and two leaf nodes 
    730760        BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode),  
     
    736766                                                                                   *frontRays, 
    737767                                                                                   *backRays); 
    738  
    739768        ViewCell *frontViewCell = mRootCell; 
    740769        ViewCell *backViewCell = mRootCell; 
     
    775804        DEL_PTR(tData.mNode); 
    776805        DEL_PTR(tData.mPolygons); 
    777         DEL_PTR(tData.mRays); 
    778  
     806         
    779807        return interior; 
    780808} 
     
    820848{ 
    821849        mStat.nodes += 2; 
    822  
     850         
    823851        // select subdivision plane 
    824852        BspInterior *interior =  
     
    838866                                                                       coincident,  
    839867                                                                       sStoreSplitPolys); 
     868 
    840869        BspInterior *parent = leaf->GetParent(); 
    841870 
     
    10631092{ 
    10641093        float val = 0; 
    1065          
     1094 
    10661095        if (sSplitPlaneStrategy & VERTICAL_AXIS) 
    10671096        { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r329 r331  
    229229        void SetViewCell(ViewCell *viewCell); 
    230230 
     231        /** Generates new view cell and stores it back in the container. 
     232                @returns the number of sample contributions from the rays 
     233        */ 
     234        int GenerateViewCell(const RayContainer &rays, ViewCellContainer &viewCells); 
     235 
    231236protected: 
    232237 
     
    295300                Many leafs can point to the same viewcell. 
    296301        */ 
    297         void Construct(const ViewCellContainer &viewCells); 
     302        int Construct(const ViewCellContainer &viewCells); 
    298303 
    299304        /** Constructs tree using the given list of objects.  
     
    304309                @returns list of view cells. 
    305310        */ 
    306         void Construct(const ObjectContainer &objects, ViewCellContainer *viewCells); 
    307  
    308         /** Constructs the tree from  a given bundle of rays. 
    309                 @param rays the bundle of sample rays 
     311        int Construct(const ObjectContainer &objects, ViewCellContainer *viewCells); 
     312 
     313        /** Constructs the tree from a given set of rays. 
     314                @param sampleRays the set of sample rays the construction is based on 
    310315                @param viewCells if not NULL, new view cells are  
    311316                created in the leafs and stored in the conatainer 
    312317        */ 
    313         void Construct(RayContainer *rays,  
    314                                    ViewCellContainer *viewCells = NULL); 
     318        int Construct(const RayContainer &sampleRays,  
     319                              ViewCellContainer *viewCells = NULL); 
    315320 
    316321        /** Returns list of BSP leaves. 
     
    380385                created in the leafs and stored in the conatainer 
    381386        */ 
    382         void Construct(PolygonContainer *polys, RayContainer *rays, ViewCellContainer *viewCells = NULL); 
     387        int Construct(PolygonContainer *polys,  
     388                          RayContainer *rays,  
     389                                  ViewCellContainer *viewCells = NULL); 
    383390 
    384391        /** Selects the best possible splitting plane.  
     
    526533                                                         vector<SortableEntry> &splitCandidates) const; 
    527534 
    528  
    529         /** Generates new view cell for a leaf and stores it back in the container. 
    530         */ 
    531         void BspTree::GenerateViewCell(BspLeaf *leaf, ViewCellContainer &viewCells) const; 
    532  
    533535        /// Pointer to the root of the tree 
    534536        BspNode *mRoot; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r330 r331  
    3939  p->ParseViewCellsOptions(); 
    4040 
     41  // construct tree immediately for "from view cells" or "from scene geometry" 
     42  // construction method. For "from rays" construction, wait until there is 
     43  // a certain number of rays collected 
    4144  if (p->mViewCellsType == Preprocessor::BSP_VIEW_CELLS && 
    42           !(BspTree::sConstructionMethod == BspTree::FROM_RAYS)) // construct tree later 
     45          !(BspTree::sConstructionMethod == BspTree::FROM_RAYS))  
    4346  { 
    44           Debug << "do1" << endl; 
    4547          if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS) 
    4648          { 
     
    6163          p->BspTreeStatistics(Debug); 
    6264 
    63           bool exportSplits = false; 
    64           environment->GetBoolValue("BspTree.exportSplits", exportSplits); 
    65  
    66           // export the bsp splits 
    67           if (exportSplits) 
    68           { 
    69                   Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
    70  
    71                   if (exporter)  
    72                   {      
    73                           Material m;  
    74                           m.mDiffuseColor = RgbColor(1, 0, 0); 
    75                           exporter->SetForcedMaterial(m); 
    76                           exporter->SetWireframe(); 
    77                           exporter->ExportBspSplits(*p->mBspTree); 
    78  
    79                           // take forced material because does not load for big scenes otherwise 
    80                           m.mDiffuseColor = RgbColor(0, 1, 0); 
    81                           exporter->SetForcedMaterial(m); 
    82                           exporter->SetFilled(); 
    83  
    84                           exporter->ResetForcedMaterial(); 
    85  
    86                           if (1) 
    87                           { 
    88                                   ObjectContainer objects; 
    89                                   p->mSceneGraph->CollectObjects(&objects); 
    90                   Material m;//= RandomMaterial(); 
    91                                   m.mDiffuseColor = RgbColor(0, 0, 1); 
    92                                   exporter->SetForcedMaterial(m); 
    93                   
    94                                   for (int j = 0; j < objects.size(); ++ j) 
    95                                            exporter->ExportIntersectable(objects[j]); 
    96                          
    97                                   delete exporter; 
    98                           } 
    99                   } 
    100           } 
    10165#if 0 
    10266          //-- export the complementary view cells 
Note: See TracChangeset for help on using the changeset viewer.