Changeset 490


Ignore:
Timestamp:
01/03/06 02:06:09 (18 years ago)
Author:
mattausch
Message:

added loading and storing rays capability

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
18 edited

Legend:

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

    r489 r490  
    1919 
    2020Preprocessor { 
     21        # stored sample rays 
     22        samplesFilename rays.out 
    2123#       type sampling 
    2224        type vss 
     
    2628VssPreprocessor { 
    2729        samplesPerPass  100000 
    28         initialSamples 500000 
     30        initialSamples 5000000 
    2931        vssSamples 200000 
    3032        vssSamplesPerPass 100000 
    3133        useImportanceSampling true 
     34        loadInitialSamples  false 
     35        storeInitialSamples true 
    3236} 
    3337 
     
    6872        vssSamplesPerPass 100000 
    6973        useImportanceSampling true 
     74        loadInitialSamples true 
     75        storeInitialSamples false 
    7076} 
    7177 
     
    143149} 
    144150 
    145  
    146151ViewCells { 
    147152        loadFromFile false 
     
    155160        height 5.0 
    156161        maxViewCells 100 
    157         maxPvs 130 
     162        maxPvs 90 
    158163         
    159164         
     
    167172 
    168173        Visualization { 
    169                 # how much samples are be used for visualization 
    170                 samples 1000 
     174                # how much samples we use for visualization 
     175                samples 5000 
    171176                #colorCode PVS 
    172177                #colorCode MergedLeaves 
     
    233238                samples 300000 
    234239                epsilon 0.005 
    235                 randomize true 
     240                randomize false 
    236241        } 
    237242 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r489 r490  
    11761176          "true"); 
    11771177 
     1178   RegisterOption("VssPreprocessor.loadInitialSamples", 
     1179          optBool, 
     1180          "-vss_load_loadInitialSamples=", 
     1181          "false"); 
     1182 
     1183   RegisterOption("VssPreprocessor.storeInitialSamples", 
     1184          optBool, 
     1185          "-vss_store_storedInitialSamples=", 
     1186          "false"); 
     1187    
    11781188 
    11791189  /************************************************************************************/ 
     
    14111421                                 "sampling"); 
    14121422 
     1423   RegisterOption("Preprocessor.samplesFilename", 
     1424                                  optString, 
     1425                                  "-preprocessor_samples_filename=", 
     1426                                  "rays.out"); 
    14131427 
    14141428   /**************************************************************************************/ 
     
    16281642        RegisterOption("RssPreprocessor.updateSubdivision", optBool, "rss_update_subdivision", "false"); 
    16291643 
     1644        RegisterOption("RssPreprocessor.loadInitialSamples", 
     1645          optBool, 
     1646          "-vss_load_loadInitialSamples=", 
     1647          "false"); 
     1648 
     1649        RegisterOption("RssPreprocessor.storeInitialSamples", 
     1650          optBool, 
     1651          "-vss_store_storeInitialSamples=", 
     1652          "false"); 
    16301653 
    16311654        /************************************************************************************/ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r486 r490  
    134134 
    135135  virtual void ExportViewpoint(const Vector3 &point, const Vector3 &direction) = 0; 
    136  
    137136}; 
    138137  
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r480 r490  
    238238        mViewCellsManager->SetRenderer(mRenderSimulator); 
    239239 
    240         //Debug << "Visualization samples: " << mViewCellsManager->GetVisualizationSamples() << endl; 
    241  
    242240        //-- parse view cells construction method 
    243  
    244241        bool loadViewCells = false; 
    245242        environment->GetBoolValue("ViewCells.loadFromFile", loadViewCells); 
     
    256253        return true; 
    257254} 
     255 
     256 
     257inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
     258{ 
     259        return obj1->mId < obj2->mId; 
     260} 
     261 
     262 
     263bool Preprocessor::LoadSamples(VssRayContainer &samples,  
     264                                                           ObjectContainer &objects) const 
     265{ 
     266        std::stable_sort(objects.begin(), objects.end(), ilt); 
     267        char fileName[100]; 
     268        environment->GetStringValue("Preprocessor.samplesFilename", fileName); 
     269         
     270        Vector3 origin, termination; 
     271        // HACK: needed only for lower_bound algorithm 
     272        MeshInstance object(NULL); 
     273        ifstream samplesIn(fileName); 
     274 
     275        if (!samplesIn.is_open()) 
     276                return false; 
     277 
     278        string buf; 
     279         
     280        while (!(getline(samplesIn, buf)).eof()) 
     281        { 
     282                sscanf(buf.c_str(), "%f %f %f %f %f %f %d",  
     283                           &origin.x, &origin.y, &origin.z, 
     284                           &termination.x, &termination.y, &termination.z, &(object.mId)); 
     285                 
     286                if (1) 
     287                { 
     288                        ObjectContainer::iterator oit = 
     289                                lower_bound(objects.begin(), objects.end(), &object, ilt); 
     290 
     291                        samples.push_back(new VssRay(origin, termination, NULL, *oit)); 
     292                } 
     293                else 
     294                { 
     295                        samples.push_back(new VssRay(origin, termination, NULL, objects[object.mId])); 
     296                } 
     297        } 
     298         
     299        samplesIn.close(); 
     300 
     301        return true; 
     302} 
     303 
     304bool Preprocessor::WriteSamples(const VssRayContainer &samples) const 
     305{ 
     306        char buf[100]; 
     307        environment->GetStringValue("Preprocessor.samplesFilename", buf); 
     308        ofstream samplesOut(buf); 
     309 
     310        VssRayContainer::const_iterator it, it_end = samples.end(); 
     311         
     312        if (!samplesOut.is_open()) 
     313                return false; 
     314 
     315        for (it = samples.begin(); it != it_end; ++ it) 
     316        { 
     317                VssRay *ray = *it; 
     318         
     319                samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " "  
     320                                   << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " "  
     321                                   << ray->mTerminationObject->mId << "\n"; 
     322        } 
     323        samplesOut.close(); 
     324 
     325        return true; 
     326} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r468 r490  
    1616class VspBspTree; 
    1717class RenderSimulator; 
     18struct VssRayContainer; 
     19 
    1820 
    1921/** Namespace for the external visibility preprocessor 
     
    7880  virtual void BspTreeStatistics(ostream &s); 
    7981 
     82  /** Loads samples from file. 
     83          @param samples returns the stored sample rays 
     84          @param objects needed to associate the objects ids 
     85          @returns true if samples were loaded successfully 
     86  */ 
     87  bool LoadSamples(VssRayContainer &samples, 
     88                                   ObjectContainer &objects) const; 
     89 
     90  /** Exports samples to file. 
     91          @returns true if samples were written successfully 
     92  */ 
     93  bool WriteSamples(const VssRayContainer &samples) const; 
    8094  /// scene graph loaded from file 
    8195  SceneGraph *mSceneGraph; 
     
    104118  */ 
    105119  RenderSimulator *mRenderSimulator; 
    106  
    107 protected: 
    108  
    109   ///////////////////////// 
    110  
    111   /// samples used for construction of the BSP view cells tree. 
    112   int mBspConstructionSamples; 
    113    /// samples used for construction of the VSP KD tree. 
    114   int mVspKdConstructionSamples; 
    115120}; 
    116121 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp

    r487 r490  
    2727  environment->GetIntValue("RssPreprocessor.vssSamplesPerPass", mRssSamplesPerPass); 
    2828  environment->GetBoolValue("RssPreprocessor.useImportanceSampling", mUseImportanceSampling); 
    29   environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples); 
    3029 
    3130  environment->GetBoolValue("RssPreprocessor.Export.pvs", mExportPvs); 
     
    3433  environment->GetIntValue("RssPreprocessor.Export.numRays", mExportNumRays); 
    3534  environment->GetBoolValue("RssPreprocessor.useViewcells", mUseViewcells); 
    36  
    37   environment->GetBoolValue("RssPreprocessor.updateSubdivision", mUpdateSubdivision); 
     35  environment->GetBoolValue("RssPreprocessor.useViewcells", mUseViewcells); 
     36 
     37  environment->GetBoolValue("RssPreprocessor.loadInitialSamples", mLoadInitialSamples); 
     38  environment->GetBoolValue("RssPreprocessor.storeInitialSamples", mStoreInitialSamples); 
    3839   
    3940  mStats.open("stats.log"); 
     
    443444  RssTree *rssTree = NULL; 
    444445 
    445   while (totalSamples < mInitialSamples) { 
    446         int passContributingSamples = 0; 
    447         int passSampleContributions = 0; 
    448         int passSamples = 0; 
    449         int index = 0; 
    450                  
    451         int sampleContributions; 
    452                  
    453         int s = Min(mSamplesPerPass, mInitialSamples); 
    454         for (int k=0; k < s; k++) { 
     446  if (mLoadInitialSamples) 
     447  { 
     448          cout << "Loading samples from file ... "; 
     449          LoadSamples(mVssRays, mObjects); 
     450          cout << "finished\n" << endl; 
     451  } 
     452  else 
     453  { 
     454        while (totalSamples < mInitialSamples) { 
     455                int passContributingSamples = 0; 
     456                int passSampleContributions = 0; 
     457                int passSamples = 0; 
     458                int index = 0; 
    455459                         
    456           //Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 
    457           Vector3 viewpoint;  
    458           mViewCellsManager->GetViewPoint(viewpoint); 
    459           Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 
     460                int sampleContributions; 
    460461                         
    461           sampleContributions = CastRay(viewpoint, direction, mVssRays); 
     462                int s = Min(mSamplesPerPass, mInitialSamples); 
     463                for (int k=0; k < s; k++) { 
     464                                 
     465                //Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 
     466                Vector3 viewpoint;  
     467                mViewCellsManager->GetViewPoint(viewpoint); 
     468                Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 
     469                                 
     470                sampleContributions = CastRay(viewpoint, direction, mVssRays); 
     471                                 
     472                                 
     473                //-- CORR matt: put block inside loop 
     474                if (sampleContributions) { 
     475                        passContributingSamples ++; 
     476                        passSampleContributions += sampleContributions; 
     477                } 
     478                passSamples++; 
     479                totalSamples++; 
     480                } 
     481             
    462482                         
     483                float avgRayContrib = (passContributingSamples > 0) ?  
     484                passSampleContributions/(float)passContributingSamples : 0; 
    463485                         
    464           //-- CORR matt: put block inside loop 
    465           if (sampleContributions) { 
    466                 passContributingSamples ++; 
    467                 passSampleContributions += sampleContributions; 
    468           } 
    469           passSamples++; 
    470           totalSamples++; 
    471         } 
    472      
    473                  
    474         float avgRayContrib = (passContributingSamples > 0) ?  
    475           passSampleContributions/(float)passContributingSamples : 0; 
    476                  
    477         cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    478         cout << "#TotalSamples=" << totalSamples/1000  
    479                  << "k   #SampleContributions=" << passSampleContributions << " ("  
    480                  << 100*passContributingSamples/(float)passSamples<<"%)"  
    481                  << "avgcontrib=" << avgRayContrib << endl; 
    482                  
    483         mStats << 
    484           "#Pass\n" <<mPass<<endl<< 
    485           "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 
    486           "#TotalSamples\n" << totalSamples<< endl<< 
    487           "#SampleContributions\n" << passSampleContributions << endl <<  
    488           "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    489           "#AvgRayContrib\n" << avgRayContrib << endl; 
    490          
    491         mPass++; 
    492  
    493   } 
    494    
    495   cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
     486                cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     487                cout << "#TotalSamples=" << totalSamples/1000  
     488                        << "k   #SampleContributions=" << passSampleContributions << " ("  
     489                        << 100*passContributingSamples/(float)passSamples<<"%)"  
     490                        << "avgcontrib=" << avgRayContrib << endl; 
     491                         
     492                mStats << 
     493                "#Pass\n" <<mPass<<endl<< 
     494                "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 
     495                "#TotalSamples\n" << totalSamples<< endl<< 
     496                "#SampleContributions\n" << passSampleContributions << endl <<  
     497                "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
     498                "#AvgRayContrib\n" << avgRayContrib << endl; 
     499                 
     500                mPass++; 
     501 
     502        } 
     503   
     504        cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
     505  } 
     506 
    496507  cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl <<flush; 
    497508   
     
    503514  } 
    504515   
     516  if (mStoreInitialSamples) 
     517  { 
     518          cout << "Writing samples to file ... "; 
     519          WriteSamples(mVssRays); 
     520          cout << "finished\n" << endl; 
     521  } 
     522 
    505523  if (mUseViewcells) { 
    506524        // construct view cells 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h

    r487 r490  
    3939  VssRayContainer mVssRays; 
    4040         
     41   /// if initial samples should be loaded from file 
     42  bool mLoadInitialSamples; 
     43  /// if initial samples should be stored in file 
     44  bool mStoreInitialSamples; 
     45 
    4146  RssPreprocessor(); 
    4247  ~RssPreprocessor(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp

    r387 r490  
    2929SceneGraph::CollectObjects(ObjectContainer *instances) 
    3030{ 
     31        instances->clear(); 
    3132  int number = 0; 
    3233  stack<SceneGraphNode *> nodeStack; 
     
    4041    ObjectContainer::const_iterator mi = node->mGeometry.begin(); 
    4142    for (; mi != node->mGeometry.end(); mi++) 
    42       instances->push_back(*mi); 
    43      
     43          instances->push_back(*mi); 
     44         
    4445    SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 
    4546    for (; ni != node->mChildren.end(); ni++) { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r489 r490  
    413413        app << "#AVGDEPTH ( average depth )\n" << AvgDepth() << endl; 
    414414 
    415         app << "#N_INPUT_POLYGONS (number of input polygons )\n" <<     polys << endl; 
     415        app << "#N_INPUTPOLYGONS (number of input polygons )\n" << polys << endl; 
     416 
     417        app << "#N_INVALIDLEAVES (number of invalid leaves )\n" << invalidLeaves << endl; 
    416418 
    417419        //app << "#N_PVS: " << pvs << endl; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r487 r490  
    127127        /// largest pvs 
    128128        int maxPvs; 
     129        /// number of invalid leaves 
     130        int invalidLeaves; 
    129131 
    130132        // Constructor 
     
    162164 
    163165                maxPvs = 0; 
     166                invalidLeaves = 0; 
    164167        } 
    165168 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r489 r490  
    4545        environment->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry); 
    4646 
    47         //Debug << "export rays: " << mExportRays << endl; 
    48         //Debug << "export geometry: " << mExportGeometry << endl; 
    4947        char buf[50]; 
    5048         
     
    9290} 
    9391 
     92 
     93bool ViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 
     94{ 
     95        return mSceneBox.IsInside(viewPoint); 
     96} 
    9497 
    9598void ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays) 
     
    17171720 
    17181721        mVspBspTree->Construct(constructionRays, &mSceneBox); 
    1719  
     1722         
    17201723        Debug << mVspBspTree->GetStatistics() << endl; 
     1724        // collapse invalid regions 
     1725        mVspBspTree->CollapseTree(mVspBspTree->GetRoot());  
    17211726        ResetViewCells(); 
    1722  
     1727         
    17231728        Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 
    17241729         
     
    18121817                        ExportViewCells(exporter); 
    18131818 
     1819                        if (mExportRays) 
     1820                        { 
     1821                                exporter->ExportRays(postProcessRays, RgbColor(1, 1, 0)); 
     1822                        } 
     1823 
    18141824                        if (mExportGeometry) 
    18151825                        { 
     
    19001910} 
    19011911 
     1912 
    19021913int VspBspViewCellsManager::GetType() const 
    19031914{ 
    19041915        return VSP_BSP; 
     1916} 
     1917 
     1918 
     1919bool VspBspViewCellsManager::GetViewPoint(Vector3 &viewPoint) const 
     1920{ 
     1921        if (!ViewCellsConstructed()) 
     1922                return ViewCellsManager::GetViewPoint(viewPoint); 
     1923 
     1924        // TODO: set reasonable limit 
     1925        const int limit = 20; 
     1926 
     1927        for (int i = 0; i < limit; ++ i) 
     1928        { 
     1929                viewPoint = mSceneBox.GetRandomPoint(); 
     1930                if (mVspBspTree->ViewPointValid(viewPoint)) 
     1931                { 
     1932                        return true; 
     1933                } 
     1934        } 
     1935        Debug << "failed to find valid view point, taking " << viewPoint << endl; 
     1936        return false; 
     1937} 
     1938 
     1939 
     1940bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 
     1941{ 
     1942        return mSceneBox.IsInside(viewPoint) &&  
     1943                   mVspBspTree->ViewPointValid(viewPoint); 
    19051944} 
    19061945 
     
    19131952 
    19141953        VssRayContainer visRays; 
    1915          
    19161954        GetRaySets(sampleRays, mVisualizationSamples, visRays); 
    19171955 
     
    19271965 
    19281966                        // export rays 
    1929                         /*if (mExportRays) 
     1967                        if (mExportRays) 
    19301968                        { 
    1931                                 exporter->SetWireframe(); 
    1932                                 exporter->ExportRays(visRays, RgbColor(1, 1, 0)); 
    1933                                 exporter->SetFilled(); 
    1934                         }*/ 
     1969                                exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
     1970                        } 
     1971 
    19351972                        ExportViewCells(exporter); 
    19361973                        delete exporter; 
     
    19431980        bool exportSplits = false; 
    19441981        environment->GetBoolValue("VspBspTree.Visualization.exportSplits", exportSplits); 
    1945         Debug << "export splits: " << exportSplits << endl; 
    1946  
     1982         
    19471983        if (exportSplits) 
    19481984        { 
     
    19561992} 
    19571993         
    1958  
    1959 bool VspBspViewCellsManager::GetViewPoint(Vector3 &viewPoint) const 
    1960 { 
    1961         if (!ViewCellsConstructed()) 
    1962                 return ViewCellsManager::GetViewPoint(viewPoint); 
    1963  
    1964         // TODO: set reasonable limit 
    1965         const int limit = 10; 
    1966 cout << "===" << endl; 
    1967         for (int i = 0; i < limit; ++ i) 
    1968         { 
    1969                 cout << i << " " << endl; 
    1970                 viewPoint = mSceneBox.GetRandomPoint(); 
    1971                 if (mVspBspTree->ViewPointValid(viewPoint)) 
    1972                         return true; 
    1973         } 
    1974  
    1975         return false; 
    1976 } 
    19771994 
    19781995void VspBspViewCellsManager::ExportSplits(const ObjectContainer &objects, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r489 r490  
    221221        virtual bool GetViewPoint(Vector3 &viewPoint) const; 
    222222 
     223        /** Returns true if this view point is in the valid view space. 
     224        */ 
     225        virtual bool ViewPointValid(const Vector3 &viewPoint) const; 
     226 
    223227        /** Sets a view space boundary. 
    224228        */ 
     
    517521        bool GetViewPoint(Vector3 &viewPoint) const; 
    518522 
     523        bool ViewPointValid(const Vector3 &viewPoint) const; 
     524 
    519525protected: 
    520526        /** DEPRECATED 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r489 r490  
    420420                        // view cell for invalid view space 
    421421                        viewCell = GetOrCreateOutOfBoundsCell(); 
     422                        ++ mStat.invalidLeaves; 
    422423                } 
    423424                else 
     
    12251226                nodeStack.pop(); 
    12261227                 
    1227                 // this subtree is not valid view space 
    1228                 if (!node->TreeValid()) 
    1229                         continue; 
    1230  
    12311228                if (node->IsLeaf()) 
    12321229                { 
    1233                         BspLeaf *leaf = (BspLeaf *)node; 
    1234                         leaves.push_back(leaf); 
     1230                        // test if this leaf is in valid view space 
     1231                        if (node->TreeValid()) 
     1232                        { 
     1233                                BspLeaf *leaf = (BspLeaf *)node; 
     1234                                leaves.push_back(leaf); 
     1235                        } 
    12351236                } 
    12361237                else 
     
    14281429                BspNode *node = nodeStack.top(); 
    14291430                nodeStack.pop(); 
    1430                 // this subtree is not valid view space 
    1431                 if (!node->TreeValid()) 
    1432                         continue; 
    14331431 
    14341432                if (node->IsLeaf()) 
    14351433                { 
    14361434                        ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    1437  
    1438                         if (!viewCell->Mailed()) 
     1435                        if (node->TreeValid() && !viewCell->Mailed()) 
    14391436                        { 
    14401437                                viewCell->Mail(); 
     
    16671664                nodeStack.pop(); 
    16681665 
    1669                 // view space not valid 
    1670                 if (!node->TreeValid()) 
    1671                         continue; 
    1672  
    16731666                if (node->IsLeaf()) 
    1674                 { 
    1675             if (node != n && (!onlyUnmailed || !node->Mailed())) 
     1667                {       // test if this leaf is in valid view space 
     1668            if (node->TreeValid() && 
     1669                                node != n &&  
     1670                                (!onlyUnmailed || !node->Mailed())) 
    16761671                        { 
    16771672                                // test all planes of current node if candidate really 
     
    23442339        startTime = GetTime(); 
    23452340 
    2346         int nViewCells = /*mergeStats.nodes*/ mStat.Leaves(); 
    2347  
    2348          
     2341        int nViewCells = /*mergeStats.nodes*/ mStat.Leaves() - mStat.invalidLeaves; 
     2342 
    23492343        //-- use priority queue to merge leaf pairs 
    23502344        while (!mMergeQueue.empty() && (nViewCells > mMergeMinViewCells) && 
     
    25692563                         
    25702564                BspInterior *in = dynamic_cast<BspInterior *>(node); 
    2571                 Plane3 splitPlane = in->GetPlane(); 
    2572                          
    2573                 if (splitPlane.Side(viewPoint) <= 0)  
     2565                                         
     2566                if (in->GetPlane().Side(viewPoint) <= 0)  
    25742567                { 
    25752568                        node = in->GetBack(); 
     
    25942587void VspBspTree::PropagateUpValidity(BspNode *node) 
    25952588{ 
    2596         while (!node->IsRoot() && node->TreeValid()) 
     2589        while (!node->IsRoot() && node->GetParent()->TreeValid()) 
    25972590        { 
    25982591                node = node->GetParent(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r489 r490  
    2626  environment->GetIntValue("VssPreprocessor.vssSamplesPerPass", mVssSamplesPerPass); 
    2727  environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling); 
    28   environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples); 
     28 
     29  environment->GetBoolValue("VssPreprocessor.loadInitialSamples", mLoadInitialSamples); 
     30  environment->GetBoolValue("VssPreprocessor.storeInitialSamples", mStoreInitialSamples); 
    2931 
    3032  mStats.open("stats.log"); 
     
    9193        SetupRay(ray, viewPoint, -direction); 
    9294 
    93  
    9495  if (mKdTree->CastRay(ray)) { 
    9596 
     
    389390  VssTree *vssTree = NULL; 
    390391 
    391   while (totalSamples < mInitialSamples) { 
    392         int passContributingSamples = 0; 
    393         int passSampleContributions = 0; 
    394         int passSamples = 0; 
    395         int index = 0; 
    396  
    397         int sampleContributions; 
    398  
    399         int s = Min(mSamplesPerPass, mInitialSamples); 
    400         for (int k=0; k < s; k++) { 
    401       // changed by matt 
    402           //Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 
    403           Vector3 viewpoint;  
    404           mViewCellsManager->GetViewPoint(viewpoint); 
    405           Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 
    406  
    407           sampleContributions = CastRay(viewpoint, direction, mVssRays); 
    408  
    409  
    410           //-- CORR matt: put block inside loop 
    411           if (sampleContributions) { 
    412                 passContributingSamples ++; 
    413                 passSampleContributions += sampleContributions; 
     392  mSceneGraph->CollectObjects(&mObjects); 
     393 
     394  long initialTime = GetTime(); 
     395 
     396  if (mLoadInitialSamples) 
     397  { 
     398          cout << "Loading samples from file ... "; 
     399          LoadSamples(mVssRays, mObjects); 
     400          cout << "finished\n" << endl; 
     401          totalSamples = (int)mVssRays.size(); 
     402  } 
     403  else 
     404  { 
     405          while (totalSamples < mInitialSamples) { 
     406                int passContributingSamples = 0; 
     407                int passSampleContributions = 0; 
     408                int passSamples = 0; 
     409 
     410                int index = 0; 
     411 
     412                int sampleContributions; 
     413 
     414                int s = Min(mSamplesPerPass, mInitialSamples); 
     415                for (int k=0; k < s; k++) { 
     416                        // changed by matt 
     417                        //Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 
     418                        Vector3 viewpoint;  
     419                        mViewCellsManager->GetViewPoint(viewpoint); 
     420                        Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 
     421                 
     422                        sampleContributions = CastRay(viewpoint, direction, mVssRays); 
     423 
     424                        if (sampleContributions) { 
     425                                passContributingSamples ++; 
     426                                passSampleContributions += sampleContributions; 
     427                        } 
     428                        passSamples++; 
     429                        totalSamples++; 
     430                } 
     431 
     432                mPass++; 
     433                int pvsSize = 0; 
     434                float avgRayContrib = (passContributingSamples > 0) ? 
     435                        passSampleContributions/(float)passContributingSamples : 0; 
     436 
     437                cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
     438                cout << "#TotalSamples=" << totalSamples/1000 
     439                        << "k   #SampleContributions=" << passSampleContributions << " (" 
     440                        << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
     441                        << pvsSize/(float)mObjects.size() << endl 
     442                        << "avg ray contrib=" << avgRayContrib << endl; 
     443 
     444                mStats << 
     445                        "#Pass\n" <<mPass<<endl<< 
     446                        "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 
     447                        "#TotalSamples\n" << totalSamples<< endl<< 
     448                        "#SampleContributions\n" << passSampleContributions << endl << 
     449                        "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
     450                        "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 
     451                        "#AvgRayContrib\n" << avgRayContrib << endl; 
    414452          } 
    415           passSamples++; 
    416           totalSamples++; 
    417         } 
    418  
    419         mPass++; 
    420  
    421         int pvsSize = 0; 
    422         float avgRayContrib = (passContributingSamples > 0) ? 
    423           passSampleContributions/(float)passContributingSamples : 0; 
    424  
    425         cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    426         cout << "#TotalSamples=" << totalSamples/1000 
    427                  << "k   #SampleContributions=" << passSampleContributions << " (" 
    428                  << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 
    429                  << pvsSize/(float)mObjects.size() << endl 
    430                  << "avg ray contrib=" << avgRayContrib << endl; 
    431  
    432         mStats << 
    433           "#Pass\n" <<mPass<<endl<< 
    434           "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 
    435           "#TotalSamples\n" << totalSamples<< endl<< 
    436           "#SampleContributions\n" << passSampleContributions << endl << 
    437           "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 
    438           "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 
    439           "#AvgRayContrib\n" << avgRayContrib << endl; 
    440  
    441  
    442  
    443  
    444   } 
    445  
    446   cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
    447   cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl <<flush; 
     453  
     454          cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
     455  } 
     456   
     457  cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl << flush; 
     458  Debug << (int)mVssRays.size() << " rays generated in "  
     459            << TimeDiff(initialTime, GetTime()) * 1e-3 << " seconds" << endl; 
     460 
     461  if (mStoreInitialSamples) 
     462  { 
     463          cout << "Writing " << (int)mVssRays.size() << " samples to file ... "; 
     464          WriteSamples(mVssRays); 
     465          cout << "finished\n" << endl; 
     466  } 
     467 
     468  //VssRayContainer dummyRays; 
     469  //LoadSamples(dummyRays, mObjects); 
     470  //Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 
    448471 
    449472  //int numExportRays = 10000; 
     
    455478        ExportRays(filename, mVssRays, numExportRays); 
    456479  } 
    457  
    458   mSceneGraph->CollectObjects(&mObjects); 
    459480 
    460481  // construct view cells 
     
    563584                                                                                 mViewCellsManager->GetVisualizationSamples())); 
    564585 
    565         //-- post process view cells 
     586    //-- post process view cells 
    566587        mViewCellsManager->PostProcess(mObjects, storedRays); 
    567588 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h

    r487 r490  
    2727         
    2828  ObjectContainer mObjects; 
     29 
     30  /// if initial samples should be loaded from file 
     31  bool mLoadInitialSamples; 
     32  /// if initial samples should be stored in file 
     33  bool mStoreInitialSamples; 
    2934 
    3035  // rays cast during the processing 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r469 r490  
    6666  , mCharacterCount(0) 
    6767  , mSpaceCount(0) 
     68 // , mCurrentObjectId(0) 
    6869{ 
    6970  mCurrentNode = root; 
     
    9495    MeshInstance *mi = new MeshInstance(mCurrentMesh); 
    9596    mCurrentNode->mGeometry.push_back(mi); 
     97        // set the object id to a unique value 
     98        //mi->SetId(mCurrentObjectId ++); 
    9699  } else { 
    97100    cout<<"X"; 
     
    386389// --------------------------------------------------------------------------- 
    387390X3dViewCellsParseHandlers::X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager,  
    388                                                                                                          float viewCellHeight) : 
    389   mElementCount(0) 
    390   , mAttrCount(0) 
    391   , mCharacterCount(0) 
    392   , mSpaceCount(0) 
    393   , mViewCellsManager(viewCellsManager) 
    394   , mViewCellHeight(viewCellHeight) 
     391                                                                                                         float viewCellHeight): 
     392mElementCount(0),  
     393mAttrCount(0),  
     394mCharacterCount(0),  
     395mSpaceCount(0),  
     396mViewCellsManager(viewCellsManager),  
     397mViewCellHeight(viewCellHeight) 
    395398{ 
    396399} 
     
    512515 
    513516                // create view cell from base triangle 
    514                 mViewCellsManager->AddViewCell(mViewCellsManager->ExtrudeViewCell(baseTri, mViewCellHeight)); 
     517                mViewCellsManager->AddViewCell( 
     518                        mViewCellsManager->ExtrudeViewCell(baseTri,  
     519                        mViewCellHeight)); 
    515520        } 
    516521} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.h

    r439 r490  
    1414  bool ParseFile(const string filename, SceneGraphNode **root); 
    1515  bool ParseFile(const string filename, ViewCellsManager &viewCells); 
    16  
     16   
     17  /// height of a loaded view cell 
    1718  float mViewCellHeight; 
    1819}; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h

    r439 r490  
    6464  Mesh *mCurrentMesh; 
    6565  Material *mCurrentMaterial; 
    66    
     66  //int mCurrentObjectId; 
     67 
    6768  // Handlers for X3D 
    6869  void 
Note: See TracChangeset for help on using the changeset viewer.