Changeset 1695


Ignore:
Timestamp:
10/29/06 15:20:18 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1686 r1695  
    421421                void EvalCandidate(bool computeSplitplane = true) 
    422422                { 
     423                        mDirty = false; 
    423424                        sBvHierarchy->EvalSubdivisionCandidate(*this, computeSplitplane); 
    424425                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1684 r1695  
    13921392                                        "300000"); 
    13931393 
     1394        RegisterOption("ViewCells.Evaluation.samplesForStats", 
     1395                                        optInt, 
     1396                                        "view_cells_evaluation_samples_for_stats=", 
     1397                                        "300000"); 
     1398 
    13941399        RegisterOption("ViewCells.exportToFile", 
    13951400                                        optBool, 
     
    18041809                                        "preprocessor_kd_tree_filename=", 
    18051810                                        "vienna_kdtree.bin.gz"); 
    1806          
     1811 
     1812        RegisterOption("Preprocessor.exportObj",  
     1813                                        optBool, 
     1814                                        "preprocessor_export_obj=", 
     1815                                        "false"); 
     1816 
    18071817 
    18081818        /*************************************************************************/ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1694 r1695  
    13281328        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    13291329 
    1330  
    13311330        /////////////////////////// 
    13321331        //-- compute bounding box of object space 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp

    r1655 r1695  
    204204                                sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    205205                                vertices.push_back(Vector3(x,y,z)); 
    206                                 //Debug << "vertex: " << vertices.back() << endl; 
     206                                //cout << "vertex: " << vertices.back() << endl; 
    207207                                break; 
    208208                        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h

    r1667 r1695  
    254254                void EvalCandidate(bool computeSplitplane = true) 
    255255                { 
    256                         //if (computeSplitplane) TODO 
     256                        mDirty = false; 
     257                        // todo: avoid computing split plane 
    257258                        sOspTree->EvalSubdivisionCandidate(*this);       
    258259                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1664 r1695  
    158158        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", mApplyVisibilityFilter ); 
    159159        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 
    160                                                           mApplyVisibilitySpatialFilter ); 
     160                                                                                          mApplyVisibilitySpatialFilter ); 
    161161        Environment::GetSingleton()->GetFloatValue("Preprocessor.visibilityFilterWidth", mVisibilityFilterWidth); 
    162162 
     163        Environment::GetSingleton()->GetBoolValue("Preprocessor.exportObj", mExportObj); 
     164         
     165        Debug << "******* Preprocessor Options **********" << endl; 
    163166        Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl; 
    164167        Debug << "load meshes: " << mLoadMeshes << endl; 
     168        Debug << "load meshes: " << mLoadMeshes << endl; 
     169        Debug << "export obj: " << mExportObj << endl; 
    165170} 
    166171 
     
    298303 
    299304        return true; 
     305} 
     306 
     307 
     308bool Preprocessor::ExportObj(const string filename, const ObjectContainer &objects) 
     309{ 
     310        ofstream samplesOut(filename.c_str()); 
     311 
     312        if (!samplesOut.is_open()) 
     313                return false; 
     314 
     315        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     316 
     317        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     318        { 
     319                Intersectable *obj = *oit; 
     320 
     321                if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 
     322                { 
     323                        Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 
     324 
     325                        samplesOut << "v " << tri.mVertices[0].x << " " << tri.mVertices[0].y << " " << tri.mVertices[0].z << endl; 
     326                        samplesOut << "v " << tri.mVertices[1].x << " " << tri.mVertices[1].y << " " << tri.mVertices[1].z << endl; 
     327                        samplesOut << "v " << tri.mVertices[2].x << " " << tri.mVertices[2].y << " " << tri.mVertices[2].z << endl; 
     328                } 
     329                else 
     330                { 
     331                        cout << "not implemented intersectable type " << obj->Type() << endl; 
     332                } 
     333        } 
     334 
     335        // write faces 
     336        int i = 1; 
     337        for (oit = objects.begin(); oit != oit_end; ++ oit, i += 3) 
     338        { 
     339                Intersectable *obj = *oit; 
     340                if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 
     341                { 
     342                        Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 
     343                        samplesOut << "f " << i << " " << i + 1 << " " << i + 2 << endl; 
     344                } 
     345                else 
     346                { 
     347                        cout << "not implemented intersectable type " << obj->Type() << endl; 
     348                } 
     349        } 
     350 
     351        return true; 
     352 
    300353} 
    301354 
     
    323376        cout << "number of input files: " << files << endl; 
    324377        bool result = false; 
     378        bool isObj = false; 
    325379 
    326380        // root for different files 
     
    357411                else if (strstr(filename.c_str(), ".obj")) 
    358412                { 
     413                        isObj = true; 
     414 
    359415                        // hack: load binary dump 
    360416                        string binFile = ReplaceSuffix(filename, ".obj", ".bin"); 
     
    417473 
    418474                        SceneGraphNode *node = new SceneGraphNode(); 
    419                         const bool success = parser->ParseFile( 
    420                                 filename,  
    421                                 node, 
    422                                 mLoadMeshes, 
    423                                 fi); 
     475                        const bool success =  
     476                                parser->ParseFile(filename, node, mLoadMeshes, fi); 
    424477 
    425478                        if (success)  
     
    943996        case SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION: 
    944997                return new SpatialBoxBasedDistribution(*this); 
     998        case SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION: 
     999                return new ReverseObjectBasedDistribution(*this); 
    9451000        //case OBJECTS_INTERIOR_DISTRIBUTION: 
    9461001        //      return new ObjectsInteriorDistribution(*this); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1658 r1695  
    100100        /** Export preprocessor data. 
    101101        */ 
    102         bool Export( 
    103                 const string filename,  
    104                 const bool scene,  
    105                 const bool kdtree);   
     102        bool Export(const string filename, const bool scene, const bool kdtree);   
    106103 
    107104        virtual void KdTreeStatistics(ostream &s); 
     
    114111        */ 
    115112        bool LoadSamples(VssRayContainer &samples, 
    116                 ObjectContainer &objects) const; 
     113                                         ObjectContainer &objects) const; 
    117114 
    118115        /** Exports samples to file. 
     
    124121        bool ExportKdTree(const string filename); 
    125122 
    126         virtual bool 
    127                 GenerateRays( 
    128                 const int number, 
    129                 const int raysType, 
    130                 SimpleRayContainer &rays 
    131                 ); 
    132  
    133         bool GenerateRayBundle( 
    134                 SimpleRayContainer &rayBundle, 
    135                 const SimpleRay &mainRay, 
    136                 const int number, 
    137                 const int shuffleType) const; 
     123        virtual bool GenerateRays(const int number, 
     124                                                          const int raysType, 
     125                                                          SimpleRayContainer &rays); 
     126 
     127        bool GenerateRayBundle(SimpleRayContainer &rayBundle, 
     128                                                   const SimpleRay &mainRay, 
     129                                                   const int number, 
     130                                                   const int shuffleType) const; 
    138131 
    139132        virtual void CastRays(SimpleRayContainer &rays, 
    140                 VssRayContainer &vssRays, 
    141                 const bool castDoubleRays, 
    142                 const bool pruneInvalidRays = true); 
     133                                                  VssRayContainer &vssRays, 
     134                                                  const bool castDoubleRays, 
     135                                                  const bool pruneInvalidRays = true); 
    143136 
    144137        /** Returns a view cells manager of the given name. 
     
    153146        bool InitRayCast(const string externKdTree, const string internKdTree); 
    154147 
     148bool ExportObj(const string filename, const ObjectContainer &objects); 
    155149 
    156150        //////////////////////////////////////////////// 
     
    206200  bool mStopComputation; 
    207201   
     202        bool mExportObj; 
     203 
     204 
    208205protected: 
    209206 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1692 r1695  
    151151} 
    152152 
     153 
     154bool ReverseObjectBasedDistribution::GenerateSample(SimpleRay &ray) const 
     155{ 
     156        Vector3 origin, direction;  
     157 
     158        mPreprocessor.mViewCellsManager->GetViewPoint(origin); 
     159 
     160        Vector3 point; 
     161        Vector3 normal; 
     162        //cout << "y"; 
     163        const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 
     164 
     165        Intersectable *object = mPreprocessor.mObjects[i]; 
     166 
     167        object->GetRandomSurfacePoint(point, normal); 
     168        direction = origin - point; 
     169 
     170        // $$ jb the pdf is yet not correct for all sampling methods! 
     171        const float c = Magnitude(direction); 
     172 
     173        if (c <= Limits::Small)  
     174                return false; 
     175 
     176        // $$ jb the pdf is yet not correct for all sampling methods! 
     177        const float pdf = 1.0f; 
     178        //cout << "p: " << point << " "; 
     179        direction *= 1.0f / c; 
     180        ray = SimpleRay(point, direction, pdf); 
     181         
     182        return true; 
     183} 
     184 
    153185#if 0 
    154186bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray) const 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1520 r1695  
    2727                 VSS_BASED_DISTRIBUTION, 
    2828                 OBJECT_DIRECTION_BASED_DISTRIBUTION, 
    29                  OBJECTS_INTERIOR_DISTRIBUTION 
     29                 OBJECTS_INTERIOR_DISTRIBUTION, 
     30                 REVERSE_OBJECT_BASED_DISTRIBUTION 
    3031         }; 
    3132 
     
    5354         
    5455         ObjectBasedDistribution(const Preprocessor &preprocessor): 
     56         SamplingStrategy(preprocessor) {} 
     57 
     58         virtual bool GenerateSample(SimpleRay &ray) const; 
     59}; 
     60 
     61 
     62class ReverseObjectBasedDistribution: public SamplingStrategy 
     63{ 
     64 public: 
     65         
     66         ReverseObjectBasedDistribution(const Preprocessor &preprocessor): 
    5567         SamplingStrategy(preprocessor) {} 
    5668 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h

    r1684 r1695  
    2222        enum {OBJECT_SPACE, VIEW_SPACE}; 
    2323 
    24         SubdivisionCandidate(): mRenderCostDecrease(0) {}; 
     24        SubdivisionCandidate(): mRenderCostDecrease(0), mDirty(true) {}; 
    2525 
    2626        virtual ~SubdivisionCandidate() {}; 
     
    130130 
    131131        int mMailbox; 
     132 
     133        bool mDirty; 
    132134}; 
    133135 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1667 r1695  
    15271527        tqueue.push(mRoot); 
    15281528 
     1529        //cout << "exporting stats ... " << endl; 
    15291530        int numViewCells = 1; 
    15301531         
     
    15341535        const int rootPvs = GetPvsSize(mRoot); 
    15351536        const int rootEntries = GetPvsEntries(mRoot); 
    1536  
    1537         cout << "exporting stats ... " << endl; 
    1538          
    15391537        float totalRenderCost, avgRenderCost, expectedCost; 
    15401538 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1694 r1695  
    3838// HACK 
    3939const static bool SAMPLE_AFTER_SUBDIVISION = true; 
    40 const static bool CLAMP_TO_BOX = false; 
     40const static bool CLAMP_TO_BOX = true; 
    4141 
    4242template <typename T> class myless 
     
    7272 
    7373        mViewCellsTree->SetViewCellsManager(this); 
    74         //mViewCellsTree = new ViewCellsTree(this); 
    7574} 
    7675 
     
    112111         
    113112        // sampling type for view cells construction samples 
    114         if (strcmp(buf, "box") == 0) 
     113        if (strcmp(buf, "object") == 0) 
     114        { 
     115                mSamplingType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 
     116        } 
     117        else if (strcmp(buf, "box") == 0) 
    115118        { 
    116119                mSamplingType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; 
     
    123126        { 
    124127                mSamplingType = SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION; 
     128        } 
     129        else if (strcmp(buf, "reverse_object") == 0) 
     130        { 
     131                mSamplingType = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION; 
    125132        } 
    126133        /*else if (strcmp(buf, "interior") == 0) 
     
    137144        Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.samplingType", buf); 
    138145         
    139         if (strcmp(buf, "box") == 0) 
     146        if (strcmp(buf, "object") == 0) 
     147        { 
     148                mEvaluationSamplingType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 
     149        } 
     150        else if (strcmp(buf, "box") == 0) 
    140151        { 
    141152                mEvaluationSamplingType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; 
     
    148159        { 
    149160                mEvaluationSamplingType = SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION; 
     161        } 
     162        else if (strcmp(buf, "reverse_object") == 0) 
     163        { 
     164                mEvaluationSamplingType = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION; 
    150165        } 
    151166        /*else if (strcmp(buf, "interior") == 0) 
     
    155170        else 
    156171        { 
     172                mEvaluationSamplingType = -1; 
    157173                Debug << "error! wrong sampling type" << endl; 
    158174                exit(0); 
     
    868884        int castSamples = 0; 
    869885        char str[64];  
     886        int oldSamples = 0; 
     887 
     888        int samplesForStats; 
    870889 
    871890        Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", samplesPerPass); 
     891        Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesForStats", samplesForStats); 
    872892        Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samples", numSamples); 
    873893 
     
    924944 
    925945                Real timeDiff = TimeDiff(startTime, GetTime()); 
    926                 Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 
    927                 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 
    928  
     946                 
     947                cout << "finished in " << timeDiff * 1e-3f << " secs" << endl; 
    929948                cout << "computing sample contributions of " << (int)evaluationSamples.size()  << " samples ... "; 
     949                 
     950                Debug << "finished in " << timeDiff * 1e-3f << " secs" << endl; 
    930951                Debug << "computing sample contributions of " << (int)evaluationSamples.size()  << " samples ... "; 
    931952 
     
    938959                Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 
    939960 
    940                 startTime = GetTime(); 
    941                 cout << "compute new statistics ... " << endl; 
    942  
    943                 /////////// 
    944                 //-- output stats 
    945  
    946                 sprintf(str, "-%09d-eval.log", castSamples); 
    947                 string fileName = string(statsPrefix) + string(str); 
    948  
    949                 /////////////// 
    950                 //-- propagate pvs or pvs size information 
    951  
    952                 ObjectPvs pvs; 
    953                 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 
    954  
    955                 ExportStats(fileName); 
    956  
    957                 timeDiff = TimeDiff(startTime, GetTime()); 
    958                 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 
    959                 Debug << "statistis compted in " << timeDiff * 1e-3 << " secs" << endl; 
    960          
     961                if ((castSamples >= samplesForStats + oldSamples) || (castSamples >= numSamples)) 
     962                { 
     963                        oldSamples += samplesForStats; 
     964 
     965                        /////////// 
     966                        //-- output stats 
     967 
     968                        sprintf(str, "-%09d-eval.log", castSamples); 
     969                        string fileName = string(statsPrefix) + string(str); 
     970 
     971                        /////////////// 
     972                        //-- propagate pvs or pvs size information 
     973 
     974                        startTime = GetTime(); 
     975                        ObjectPvs pvs; 
     976 
     977                        cout << "updating pvs for contribution ... " << endl; 
     978 
     979                        UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 
     980 
     981                        timeDiff = TimeDiff(startTime, GetTime()); 
     982                        cout << "finished updating the pvs in " << timeDiff * 1e-3 << " secs" << endl; 
     983                        Debug << "pvs evaluated in " << timeDiff * 1e-3 << " secs" << endl; 
     984                 
     985                        startTime = GetTime(); 
     986                        cout << "compute new statistics ... " << endl; 
     987 
     988                        ExportStats(fileName); 
     989 
     990                        timeDiff = TimeDiff(startTime, GetTime()); 
     991                        cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 
     992                        Debug << "statistis computed in " << timeDiff * 1e-3 << " secs" << endl; 
     993                } 
     994 
    961995                disposeRays(evaluationSamples, NULL); 
    962996        } 
     
    9661000        //-- histogram 
    9671001 
     1002        const int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot()); 
    9681003        bool useHisto; 
    9691004        int histoStepSize; 
     
    9711006        Environment::GetSingleton()->GetBoolValue("ViewCells.Evaluation.histogram", useHisto); 
    9721007        Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.histoStepSize", histoStepSize); 
    973  
    974         const int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot()); 
    975  
    9761008 
    9771009        if (useHisto) 
     
    25292561        // reset recursive pvs 
    25302562        pvs.Clear(); 
     2563 
     2564        // pvss of child nodes 
    25312565        vector<ObjectPvs> pvsList; 
    25322566 
    25332567        ViewCellContainer::const_iterator vit, vit_end = interior->mChildren.end(); 
    2534  
    2535         for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit) 
    2536         { 
    2537                 ObjectPvs objPvs; 
     2568        pvsList.resize((int)interior->mChildren.size()); 
     2569        int i = 0; 
     2570        for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ i) 
     2571        { 
     2572                //ObjectPvs objPvs; 
    25382573                 
    25392574                ////////////////// 
    25402575                //-- recursivly compute child pvss 
    25412576 
    2542                 UpdatePvsForEvaluation(*vit, objPvs); 
     2577                UpdatePvsForEvaluation(*vit, pvsList[i]/*objPvs*/); 
    25432578 
    25442579                // store pvs in vector 
    2545                 pvsList.push_back(objPvs); 
     2580                //pvsList.push_back(objPvs); 
    25462581        } 
    25472582 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1686 r1695  
    480480                void EvalCandidate(bool computeSplitplane = true) 
    481481                { 
     482                        mDirty = false; 
    482483                        sVspTree->EvalSubdivisionCandidate(*this, computeSplitplane); 
    483484                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1694 r1695  
    9494 
    9595 
    96 static string GetInternKdTreeName(const string &filename) 
     96static string GetInternFilename(const string &filename, const string newSuffix) 
    9797{ 
    9898        vector<string> filenames; 
     
    118118                        strippedFilename = string(str); 
    119119 
    120                         delete []str; 
     120                        delete [] str; 
    121121                } 
    122122                 
     
    125125                if (i == (int)filenames.size() - 1) 
    126126                { 
    127                         if (preprocessor->mLoadMeshes) 
    128                         { 
    129                                 suffix = ".kdm";         
    130                         } 
    131                         else 
    132                         { 
    133                                 suffix = ".kdt"; 
    134                         } 
     127                        suffix = newSuffix; 
    135128                } 
    136129 
     
    200193        Environment::GetSingleton()->GetStringValue("Scene.filename", buff); 
    201194        string filename(buff); 
    202         const string dummyname = GetInternKdTreeName(filename); 
     195         
    203196 
    204197        if (!preprocessor->LoadScene(filename)) 
     
    218211         
    219212        const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf"); 
    220         const string internKdTree = GetInternKdTreeName(filename); 
     213        const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ? ".kdm" : ".kdt"); 
    221214 
    222215        //-- initialize external ray casters 
     216         
    223217        if (preprocessor->InitRayCast(externKdTree, internKdTree)) 
    224218        { 
     
    230224                Cleanup(); 
    231225                exit(1); 
     226        } 
     227 
     228         
     229        // export objects as obj 
     230        if (preprocessor->mExportObj) 
     231        { 
     232                if (strstr(filename.c_str(), ".obj")) 
     233                { 
     234                        cerr << "already in obj format" << endl; 
     235                        if (1) 
     236                        preprocessor->ExportObj("test.obj", preprocessor->mObjects); 
     237                } 
     238                else 
     239                { 
     240                        const string objname = GetInternFilename(filename, ".obj"); 
     241 
     242                        //cout << "exporting scene to " << objname << endl; 
     243                        bool success = preprocessor->ExportObj(objname, preprocessor->mObjects); 
     244 
     245                        if (success) 
     246                        { 
     247                                cout << "finished exporting obj" << endl; 
     248                        } 
     249                        else 
     250                        { 
     251                                cerr << "error exporting " << objname << endl; 
     252                        } 
     253                } 
    232254        } 
    233255 
Note: See TracChangeset for help on using the changeset viewer.