Ignore:
Timestamp:
01/15/08 15:37:02 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
2 added
10 edited

Legend:

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

    r2582 r2598  
    6868   
    6969  // pickup random object from the filtered pvs 
    70   int id = RandomValue(0, mFilteredPvs.GetSize()-1); 
     70  int id = (int)RandomValue(0, (Real)((float)mFilteredPvs.GetSize() - 0.5f)); 
    7171   
    7272  ObjectPvsIterator pit = mFilteredPvs.GetIterator(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r2593 r2598  
    103103        mUseGlLists = false; 
    104104 
    105         if (mViewCellsManager->GetViewCellPoints()->size()) 
    106                 mPvsStatFrames = (int)mViewCellsManager->GetViewCellPoints()->size(); 
     105        if (mViewCellsManager->GetViewCellPointsList()->size()) 
     106                mPvsStatFrames = (int)mViewCellsManager->GetViewCellPointsList()->size(); 
    107107        else 
    108108                Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h

    r2593 r2598  
    198198  } 
    199199 
     200  void SetViewPoint(const Vector3 &vp) { mViewPoint = vp; } 
     201  void SetViewDirection(const Vector3 &vd) { mViewDirection = vd; } 
     202 
    200203public: 
    201204 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r2597 r2598  
    794794void GvsPreprocessor::CompileViewCellsList() 
    795795{ 
    796         vector<ViewCellPoints *> *vcPoints = mViewCellsManager->GetViewCellPoints(); 
     796        ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList(); 
    797797 
    798798         
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2593 r2598  
    14831483        //      mutex.unlock(); 
    14841484 
    1485         if (mViewCellsManager->GetViewCellPoints()->size()) { 
     1485        if (mViewCellsManager->GetViewCellPointsList()->size()) { 
    14861486           
    1487           vector<ViewCellPoints *> *vcPoints = mViewCellsManager->GetViewCellPoints(); 
     1487          ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList(); 
    14881488           
    1489           vector<ViewCellPoints *>::const_iterator 
     1489          ViewCellPointsList::const_iterator 
    14901490                vit = vcPoints->begin(), 
    14911491                vit_end = vcPoints->end(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj

    r2594 r2598  
    126126                                OptimizeForWindowsApplication="TRUE" 
    127127                                AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(CG_INC_PATH)&quot;;Timer;..\src\sparsehash\src\google\sparsehash;..\src\sparsehash\src\windows;..\src\sparsehash\src\google;..\src\sparsehash\src;..\src\ootl\;..\src\ootl\src\;..\src\ootl\src\cpp;..\src\ootl\src\cpp\include\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;..\src\ootl\src\cpp\include\ootl\mswin;..\src\havran" 
    128                                 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;USE_QT;USE_VERBOSE_PVS;USE_CG;TRV000" 
     128                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;USE_QT;USE_VERBOSE_PVS;USE_CG" 
    129129                                StringPooling="TRUE" 
    130130                                MinimalRebuild="TRUE" 
     
    684684                        </File> 
    685685                        <File 
     686                                RelativePath=".\RandomViewCellsHandler.cpp"> 
     687                        </File> 
     688                        <File 
     689                                RelativePath=".\RandomViewCellsHandler.h"> 
     690                        </File> 
     691                        <File 
    686692                                RelativePath="..\src\Ray.cpp"> 
    687693                        </File> 
     
    11291135                        </File> 
    11301136                        <File 
     1137                                RelativePath=".\havran\ktbf2trv.cpp"> 
     1138                        </File> 
     1139                        <File 
    11311140                                RelativePath=".\havran\ktbftrav.cpp"> 
    11321141                        </File> 
     
    11481157                        <File 
    11491158                                RelativePath=".\havran\subdivm.h"> 
     1159                        </File> 
     1160                        <File 
     1161                                RelativePath=".\havran\testrt.h"> 
    11501162                        </File> 
    11511163                        <File 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r2594 r2598  
    145145                                OptimizeForWindowsApplication="TRUE" 
    146146                                AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(QTDIR)\include\Qt&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include&quot;;QtInterface;..\src\sparsehash\src\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;$(NOINHERIT)" 
    147                                 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;USE_CG;USE_VERBOSE_PVS;QT_OPENGL_LIB;QT_DLL;TRV000" 
     147                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;USE_CG;USE_VERBOSE_PVS;QT_OPENGL_LIB;QT_DLL" 
    148148                                StringPooling="TRUE" 
    149149                                MinimalRebuild="TRUE" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2593 r2598  
    116116        mSamplesStat.Reset(); 
    117117        //mStats.open("mystats.log"); 
     118 
     119        mRandomViewCellsHandler = new RandomViewCellsHandler(this); 
    118120} 
    119121 
     
    157159 
    158160        return (int)passSamples.size(); 
     161} 
     162 
     163 
     164ViewCellsManager::~ViewCellsManager() 
     165{ 
     166        // HACK: if view cells tree does not  
     167        // handle view cells, we have to do it here 
     168        // question: rather create view cells resource manager? 
     169        if (!ViewCellsTreeConstructed()) 
     170        { 
     171                CLEAR_CONTAINER(mViewCells); 
     172        } 
     173        else 
     174        { 
     175                DEL_PTR(mViewCellsTree); 
     176        } 
     177 
     178        DEL_PTR(mMixtureDistribution); 
     179        DEL_PTR(mRandomViewCellsHandler); 
    159180} 
    160181 
     
    341362        } 
    342363        return NULL; 
    343 } 
    344  
    345  
    346 bool ViewCellsManager::ExportRandomViewCells(const string &filename, 
    347                                                                                          const vector<ViewCellPoints *> &viewCells) 
    348 { 
    349         std::ofstream outStream; 
    350         outStream.open(filename.c_str()); 
    351  
    352         vector<ViewCellPoints *>::const_iterator vit, vit_end = viewCells.end(); 
    353      
    354         for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    355         { 
    356                 ViewCell *vc = (*vit)->first; 
    357  
    358                 outStream << "v " << vc->GetId() << endl; 
    359  
    360                 SimpleRayContainer viewPoints; 
    361          
    362                 SimpleRayContainer::const_iterator pit, pit_end = (*vit)->second.end(); 
    363  
    364                 for (pit = (*vit)->second.begin(); pit != pit_end; ++ pit) 
    365                 { 
    366                         const Vector3 pt = (*pit).mOrigin; 
    367                         const Vector3 dir = (*pit).mDirection; 
    368  
    369                         outStream << "p " << pt.x  << " " << pt.y  << " " << pt.z  
    370                                       << " "  << dir.x << " " << dir.y << " " << dir.z << endl; 
    371                 } 
    372         } 
    373  
    374         return true; 
    375 } 
    376  
    377  
    378 bool ViewCellsManager::GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells, 
    379                                                                                            const int nViewCells, 
    380                                                                                            const int nViewPoints) 
    381 { 
    382         ViewCellContainer rViewCells; 
    383  
    384         cout << "generating " << nViewCells << " random view cells" << endl; 
    385         ///GenerateRandomViewCells(rViewCells, nViewCells); 
    386  
    387         //cout << "finished" << endl; 
    388  
    389         //for (int i = 0; i < viewCells.size(); ++ i) 
    390         //      cout << "vc " << i << ": " << viewCells[i]->GetId() << endl; 
    391  
    392         cout << "generating " << nViewPoints << " view points per view cell" << endl; 
    393              
    394         int generatedViewCells = 0; 
    395         int i = 0; 
    396     while (generatedViewCells < nViewCells) 
    397         { 
    398                 ++ i; 
    399                  
    400                 const int idx = (int)RandomValue(0.0f, (float)mViewCells.size() - 0.5f); 
    401                          
    402                 ViewCell *viewCell = GetViewCell(idx); 
    403                  
    404                 cout << "testing view cell: " << viewCell->GetId() << endl; 
    405  
    406                 if (!viewCell->Mailed()) 
    407                 { 
    408                         viewCell->Mail(); 
    409  
    410                         SimpleRayContainer viewPoints; 
    411                          
    412                         // generate random view points 
    413                         if (IsValidViewSpace(viewCell) &&  
    414                                 GenerateViewPoints(viewCell, nViewPoints, viewPoints)) 
    415                         { 
    416                                 Debug << "vc: " << viewCell->GetId() << endl; 
    417  
    418                                 ViewCellPoints *vcPts = new ViewCellPoints(); 
    419                                 viewCells.push_back(vcPts); 
    420  
    421                                 // valid view cell found 
    422                                 vcPts->first = viewCell; 
    423  
    424                                 // generate view points 
    425                                 ++ generatedViewCells; 
    426  
    427                                 SimpleRayContainer::const_iterator pit, pit_end = viewPoints.end(); 
    428  
    429                                 for (pit = viewPoints.begin(); pit != pit_end; ++ pit) 
    430                                 { 
    431                                         Debug << "vp: " << (*pit) << endl; 
    432                                         vcPts->second.push_back(*pit);   
    433                                 } 
    434                                 cout << "view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;       
    435                         } 
    436                         else 
    437                         { 
    438                                 cout << "error: invalid view cell " << generatedViewCells << " with id " << viewCell->GetId() << endl;   
    439                         } 
    440                 } 
    441  
    442                 if (i > nViewCells * 1000000) // safety 
    443                 { 
    444                         cout << "big error" << endl; 
    445                         break; 
    446                 } 
    447                 cout << "processd view cells " << generatedViewCells << " of " << nViewCells << endl << endl; 
    448         } 
    449  
    450         return true; 
    451 } 
    452  
    453  
    454 bool ViewCellsManager::ImportRandomViewCells(const string &filename,  
    455                                                                                          vector<ViewCellPoints *> &viewCells) 
    456 { 
    457         ifstream inStream(filename.c_str()); 
    458         if (!inStream.is_open()) 
    459                 return false; 
    460  
    461         ViewCellPoints *currentViewCell = NULL; 
    462  
    463         string buf; 
    464         while (!(getline(inStream, buf)).eof()) 
    465         { 
    466                 switch (buf[0]) 
    467                 { 
    468                 case 'v': 
    469                         { 
    470                                 int id; 
    471                                 sscanf(buf.c_str(), "v %d", &id); 
    472                          
    473                                 currentViewCell = new ViewCellPoints(); 
    474                                 currentViewCell->first = GetViewCellById(id); 
    475                                                  
    476                                 viewCells.push_back(currentViewCell); 
    477                                 break; 
    478                         } 
    479                 case 'p': 
    480                         { 
    481                                 Vector3 pt, dir; 
    482                                 sscanf(buf.c_str(), "p %f %f %f %f %f %f", &pt.x, &pt.y, &pt.z, &dir.x, &dir.y, &dir.z); 
    483                                  
    484                                 SimpleRay ray(pt, dir, 0, 1); 
    485                                 currentViewCell->second.push_back(ray); 
    486                                 break; 
    487                         } 
    488                 default: 
    489                         break; 
    490                 } 
    491         } 
    492  
    493         return true; 
    494 } 
    495  
    496  
    497 bool ViewCellsManager::ImportRandomViewCells(const string &filename) 
    498 { 
    499         return ImportRandomViewCells(filename, mViewCellPoints); 
    500 } 
    501  
    502  
    503 bool ViewCellsManager::GenerateViewPoints(ViewCell *viewCell,  
    504                                                                                   const int numViewPoints, 
    505                                                                                   SimpleRayContainer &viewPoints) 
    506 { 
    507         bool success = true; 
    508         int generatedPts = 0; 
    509         int i = 0; 
    510  
    511         cout << "generating view points for view cell " << viewCell->GetId() << endl; 
    512  
    513         while (generatedPts < numViewPoints) 
    514         { 
    515                 SimpleRay pt; 
    516  
    517                 if (GenerateViewPoint(viewCell, pt)) 
    518                 { 
    519                         ++ generatedPts; 
    520                         cout << "generated view point " << generatedPts << endl; 
    521                         viewPoints.push_back(pt); 
    522                 } 
    523  
    524                 // savety criterium 
    525                 if (++ i > numViewPoints * 3) 
    526                 { 
    527                         return false; 
    528                 } 
    529         } 
    530          
    531         cout << "view point generation finished" << endl; 
    532  
    533         return true; 
    534 } 
    535  
    536  
    537 bool ViewCellsManager::ExportRandomViewCells(const string &filename) 
    538 { 
    539         const int numViewCells = 100; 
    540         const int numViewPoints = 10; 
    541  
    542         preprocessor->mViewCellsManager-> 
    543                 GenerateRandomViewCells(mViewCellPoints, numViewCells, numViewPoints); 
    544  
    545         //cout << "exporting random view cells" << endl; 
    546         return preprocessor->mViewCellsManager->ExportRandomViewCells(filename,  mViewCellPoints); 
    547 } 
    548  
    549  
    550 bool ViewCellsManager::GenerateViewPoint(ViewCell *viewCell,  
    551                                                                                  SimpleRay &ray) 
    552 { 
    553         // do not use this function since it could return different  
    554         // viewpoints for different executions of the algorithm 
    555  
    556         int tries = 0; 
    557         Vector3 viewPoint, direction; 
    558         const int maxTries = 10; 
    559  
    560         while (1)  
    561         { 
    562                 // hack 
    563                 if (!viewCell->GetMesh()) 
    564                         CreateMesh(viewCell); 
    565  
    566         Mesh *mesh = viewCell->GetMesh(); 
    567                 AxisAlignedBox3 box = mesh->mBox; 
    568                  
    569                 Vector3 pVector = Vector3(Random(1.0f), 
    570                                                                   Random(1.0f), 
    571                                                                   Random(1.0f)); 
    572  
    573                 viewPoint =  box.GetPoint(pVector); 
    574          
    575                 const Vector3 dVector = Vector3(2 * M_PI * Random(1.0f), M_PI * Random(1.0f), 0.0f); 
    576                 direction = Normalize(Vector3(sin(dVector.x), 0.0f, cos(dVector.x))); 
    577  
    578                 ViewCell *v = GetViewCell(viewPoint); 
    579  
    580                 if (v && v->GetValid()) 
    581                 { 
    582                         mPreprocessor->GetRenderer()->mViewPoint = viewPoint; 
    583                         mPreprocessor->GetRenderer()->mViewDirection = direction; 
    584                  
    585                         if (mPreprocessor->GetRenderer()->ValidViewPoint()) 
    586                         { 
    587                                 cout << "view point valid " << viewPoint << " " << direction << endl; 
    588                                 break; 
    589                         } 
    590                          
    591                 } 
    592  
    593                 if (++ tries > maxTries) 
    594                 { 
    595                         cerr << "error: no view point computed" << endl; 
    596                         return false; 
    597                 } 
    598         } 
    599  
    600         ray = SimpleRay(viewPoint, direction, 0, 1); 
    601         //cout << "view point generated: " << viewPoint << " " << direction << endl; 
    602  
    603         return true; 
    604 } 
    605  
    606  
    607 bool ViewCellsManager::IsValidViewSpace(ViewCell *vc) 
    608 { 
    609         SimpleRay simpleRay; 
    610         //check if view point can be generated 
    611         return GenerateViewPoint(vc, simpleRay); 
    612 } 
    613  
    614  
    615 bool ViewCellsManager::GenerateRandomViewCells(ViewCellContainer &viewCells,  
    616                                                                                            const int numViewCells) 
    617 { 
    618         int generatedViewCells = 0; 
    619         //HaltonSequence halton; 
    620         //float r[1]; 
    621  
    622         ViewCell::NewMail(); 
    623  
    624         while (generatedViewCells < numViewCells) 
    625         { 
    626                 // savety criterium 
    627                 const int tries = 100000 + generatedViewCells; 
    628                 int i = 0; 
    629  
    630                 // generate next view cell 
    631                 while (1) 
    632                 { 
    633                         //halton.GetNext(1, r); 
    634                         //const int idx = (int)(r[0] * mViewCells.size() - 1.0f); 
    635                         const int idx = (int)RandomValue(0.0f, (float)mViewCells.size() - 0.5f); 
    636                          
    637                         ViewCell *viewCell = GetViewCell(idx); 
    638  
    639                         if (!viewCell->Mailed()) 
    640                         { 
    641                                 viewCell->Mail(); 
    642  
    643                                 // check for valid view space 
    644                                 if (IsValidViewSpace(viewCell)) 
    645                                 { 
    646                                         // valid view cell found 
    647                                         viewCells.push_back(viewCell); 
    648  
    649                         ++ generatedViewCells; 
    650                                         //cout << "view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;     
    651                                         break; 
    652                                 } 
    653                                 else 
    654                                 { 
    655                                         cout << "error: invalid view cell " << generatedViewCells << " with id " << viewCell->GetId() << endl;   
    656                                 } 
    657                         } 
    658  
    659                         if (++ i == tries) // no new view cell fond 
    660                         { 
    661                                 cerr << "big error! no view cell found" << endl; 
    662                                 return false; 
    663                         }                
    664                 }                        
    665         } 
    666  
    667         return true; 
    668 } 
    669  
    670  
    671 ViewCellsManager::~ViewCellsManager() 
    672 { 
    673         // HACK: if view cells tree does not  
    674         // handle view cells, we have to do it here 
    675         // question: rather create view cells resource manager? 
    676         if (!ViewCellsTreeConstructed()) 
    677         { 
    678                 CLEAR_CONTAINER(mViewCells); 
    679         } 
    680         else 
    681         { 
    682                 DEL_PTR(mViewCellsTree); 
    683         } 
    684  
    685         DEL_PTR(mMixtureDistribution); 
    686         CLEAR_CONTAINER(mViewCellPoints); 
    687364} 
    688365 
     
    73877064} 
    73887065 
    7389 } 
     7066 
     7067ViewCellPointsList *ViewCellsManager::GetViewCellPointsList() 
     7068{ 
     7069        return mRandomViewCellsHandler->GetViewCellPointsList(); 
     7070} 
     7071 
     7072 
     7073bool ViewCellsManager::ExportRandomViewCells(const string &filename) 
     7074{ 
     7075        // export ten view cells with 100 random view points inside each 
     7076        const int numViewCells = 100; 
     7077        const int numViewPoints = 10; 
     7078 
     7079        //cout << "exporting random view cells" << endl; 
     7080        return mRandomViewCellsHandler->ExportRandomViewCells(filename); 
     7081} 
     7082 
     7083 
     7084bool ViewCellsManager::ImportViewCellsList(const string &filename) 
     7085{ 
     7086        return mRandomViewCellsHandler->ImportViewCellsList(filename); 
     7087} 
     7088 
     7089 
     7090} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r2586 r2598  
    77#include "Containers.h" 
    88#include "ViewCell.h" 
     9#include "RandomViewCellsHandler.h" 
     10 
    911 
    1012#define TEST_PACKETS 0 
     
    4547struct BspRay; 
    4648class BspTree; 
    47  
     49//class RandomViewCellsHandler; 
    4850 
    4951 
     
    7779}; 
    7880 
    79 typedef pair<ViewCell *, SimpleRayContainer> ViewCellPoints; 
    8081 
    8182struct VizBuffer 
     
    507508        */ 
    508509        int GetNumViewCells() const; 
    509  
    510         bool GenerateRandomViewCells(ViewCellContainer &viewCells,  
    511                                                                  const int numViewCells); 
    512  
    513         bool GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells, 
    514                                                                  const int nViewCells, 
    515                                                                  const int nViewPoints); 
    516  
    517  
    518         bool GenerateViewPoints(ViewCell *viewCell,  
    519                                                         const int numViewPoints, 
    520                                                         SimpleRayContainer &viewPoints); 
    521  
    522         bool ImportRandomViewCells(const string &filename,  
    523                                                            vector<ViewCellPoints *> &viewCells); 
    524  
    525         bool ImportRandomViewCells(const string &filename); 
    526  
    527         bool ExportRandomViewCells(const string &filename, 
    528                                                            const vector<ViewCellPoints *> &viewCells); 
    529  
     510        /** Returns the stored list of view cells and view points. 
     511        */ 
     512        ViewCellPointsList *GetViewCellPointsList(); 
     513        /** Exports list of random view cells. 
     514        */ 
    530515        bool ExportRandomViewCells(const string &filename); 
    531  
    532         bool GenerateViewPoint(ViewCell *viewCell, SimpleRay &ray); 
    533  
    534         bool IsValidViewSpace(ViewCell *vc); 
     516        /** Imports list of random view cells and view points. 
     517        */ 
     518        bool ImportViewCellsList(const string &filename); 
    535519 
    536520 
     
    642626        { 
    643627                mPreprocessor = p; 
    644         } 
    645  
    646         vector<ViewCellPoints *> *GetViewCellPoints() 
    647         { 
    648                 return &mViewCellPoints; 
    649628        } 
    650629 
     
    822801        bool mCompressViewCells; 
    823802 
    824         vector<ViewCellPoints *> mViewCellPoints; 
     803        /// Handler for generating and loading random view cells. 
     804        RandomViewCellsHandler *mRandomViewCellsHandler; 
    825805 
    826806        /// holds the current view cell statistics 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r2593 r2598  
    298298        { 
    299299                cout << "importing random view cells" << endl; 
    300                 preprocessor->mViewCellsManager->ImportRandomViewCells(viewCellPointsFile); 
     300                preprocessor->mViewCellsManager->ImportViewCellsList(viewCellPointsFile); 
    301301                cout << "finished" << endl; 
    302302        } 
Note: See TracChangeset for help on using the changeset viewer.