Changeset 491


Ignore:
Timestamp:
01/03/06 18:37:32 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
9 edited

Legend:

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

    r490 r491  
    1313#;../data/vienna/vienna-plane.x3d 
    1414#       filename ../data/vienna/viewcells-25-sel.x3d 
    15 #       filename ../data/atlanta/atlanta2.x3d 
     15        filename ../data/atlanta/atlanta2.x3d 
    1616#       filename ../data/soda/soda.dat 
    17         filename ../data/soda/soda5.dat 
     17#       filename ../data/soda/soda5.dat 
    1818} 
    1919 
     
    2828VssPreprocessor { 
    2929        samplesPerPass  100000 
    30         initialSamples 5000000 
     30        initialSamples 1000000 
    3131        vssSamples 200000 
    3232        vssSamplesPerPass 100000 
    3333        useImportanceSampling true 
    34         loadInitialSamples  false 
    35         storeInitialSamples true 
     34        loadInitialSamples  true 
     35        storeInitialSamples false 
    3636} 
    3737 
     
    152152        loadFromFile false 
    153153        #type kdTree 
    154         #type vspKdTree 
     154        type vspKdTree 
    155155        #type bspTree 
    156156        type vspBspTree 
     
    159159         
    160160        height 5.0 
    161         maxViewCells 100 
    162         maxPvs 90 
     161        maxViewCells 500 
     162        maxPvs 200 
    163163         
    164164         
     
    178178                #colorCode MergedTreeDiff 
    179179                colorCode Random 
    180                 exportRays true 
     180                exportRays false 
    181181                exportGeometry true 
    182182        } 
     
    208208                minPvs                  50 
    209209                minRays                 300 
    210                 minSize                 0.1 
     210                minSize                 0.001 
    211211                maxCostRatio            0.9 
    212212                missTolerance           4 
     
    266266        Termination { 
    267267                # parameters used for autopartition 
    268                 minRays                 1 
     268                minRays                 20 
    269269                minPolygons             -1 
    270270                maxDepth                30 
    271271                minPvs                  20 
    272                 minArea                 0.0001 
     272                #minArea                0.0001 
     273                #minArea                0.000 
    273274                maxRayContribution      0.005 
    274275                maxCostRatio            0.9 
    275                 missTolerance           2 
     276                missTolerance           4 
    276277                #maxAccRayLength        100 
    277278                 
    278                 maxViewCells            1000 
     279                maxViewCells            5000 
    279280                 
    280281                # used for pvs criterium 
     
    291292        PostProcess { 
    292293                maxCostRatio 0.1 
    293                 minViewCells 200 
    294                 maxPvsSize   500 
    295                 useRaysForMerge false 
     294                minViewCells 500 
     295                maxPvsSize   1000 
     296                useRaysForMerge true 
    296297        } 
    297298} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r490 r491  
    255255 
    256256 
     257// use ascii format to store rays 
     258#define USE_ASCII 0 
     259 
     260 
    257261inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
    258262{ 
     
    268272        environment->GetStringValue("Preprocessor.samplesFilename", fileName); 
    269273         
    270         Vector3 origin, termination; 
    271         // HACK: needed only for lower_bound algorithm 
    272         MeshInstance object(NULL); 
    273         ifstream samplesIn(fileName); 
    274  
     274    Vector3 origin, termination; 
     275        // HACK: needed only for lower_bound algorithm to find the  
     276        // intersected objects 
     277        MeshInstance sObj(NULL); 
     278        MeshInstance tObj(NULL); 
     279 
     280#if USE_ASCII 
     281        ifstream samplesIn(fileName, ios::binary); 
    275282        if (!samplesIn.is_open()) 
    276283                return false; 
    277284 
    278285        string buf; 
    279          
    280286        while (!(getline(samplesIn, buf)).eof()) 
    281287        { 
    282                 sscanf(buf.c_str(), "%f %f %f %f %f %f %d",  
     288                sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d",  
    283289                           &origin.x, &origin.y, &origin.z, 
    284                            &termination.x, &termination.y, &termination.z, &(object.mId)); 
    285                  
    286                 if (1) 
     290                           &termination.x, &termination.y, &termination.z,  
     291                           &(sObj.mId), &(tObj.mId)); 
     292                 
     293                Intersectable *sourceObj = NULL; 
     294                Intersectable *termObj = NULL; 
     295                 
     296                if (sObj.mId >= 0) 
    287297                { 
    288298                        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 
     299                                lower_bound(objects.begin(), objects.end(), &sObj, ilt); 
     300                        sourceObj = *oit; 
     301                } 
     302                 
     303                if (tObj.mId >= 0) 
    294304                { 
    295                         samples.push_back(new VssRay(origin, termination, NULL, objects[object.mId])); 
    296                 } 
    297         } 
    298          
     305                        ObjectContainer::iterator oit = 
     306                                lower_bound(objects.begin(), objects.end(), &tObj, ilt); 
     307                        termObj = *oit; 
     308                } 
     309 
     310                samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 
     311        } 
     312#else 
     313        ifstream samplesIn(fileName, ios::binary); 
     314        if (!samplesIn.is_open()) 
     315                return false; 
     316 
     317        while (1) 
     318        { 
     319                 samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 
     320                 samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 
     321                 samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int)); 
     322                 samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int)); 
     323                 
     324                 if (samplesIn.eof()) 
     325                        break; 
     326 
     327                Intersectable *sourceObj = NULL; 
     328                Intersectable *termObj = NULL; 
     329                 
     330                if (sObj.mId >= 0) 
     331                { 
     332                        ObjectContainer::iterator oit = 
     333                                lower_bound(objects.begin(), objects.end(), &sObj, ilt); 
     334                        sourceObj = *oit; 
     335                } 
     336                 
     337                if (tObj.mId >= 0) 
     338                { 
     339                        ObjectContainer::iterator oit = 
     340                                lower_bound(objects.begin(), objects.end(), &tObj, ilt); 
     341                        termObj = *oit; 
     342                } 
     343 
     344                samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 
     345        } 
     346 
     347#endif 
    299348        samplesIn.close(); 
    300349 
     
    304353bool Preprocessor::WriteSamples(const VssRayContainer &samples) const 
    305354{ 
    306         char buf[100]; 
    307         environment->GetStringValue("Preprocessor.samplesFilename", buf); 
    308         ofstream samplesOut(buf); 
     355        char fileName[100]; 
     356        environment->GetStringValue("Preprocessor.samplesFilename", fileName); 
     357         
    309358 
    310359        VssRayContainer::const_iterator it, it_end = samples.end(); 
    311360         
     361#if USE_ASCII 
     362        ofstream samplesOut(fileName); 
    312363        if (!samplesOut.is_open()) 
    313364                return false; 
     
    316367        { 
    317368                VssRay *ray = *it; 
    318          
     369                int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;                
     370                int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;        
     371 
    319372                samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " "  
    320373                                   << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " "  
    321                                    << ray->mTerminationObject->mId << "\n"; 
    322         } 
     374                                   << sourceid << " " << termid << "\n"; 
     375        } 
     376#else 
     377        ofstream samplesOut(fileName, ios::binary); 
     378        if (!samplesOut.is_open()) 
     379                return false; 
     380 
     381        for (it = samples.begin(); it != it_end; ++ it) 
     382        {        
     383                VssRay *ray = *it; 
     384                Vector3 origin(ray->GetOrigin()); 
     385                Vector3 termination(ray->GetTermination()); 
     386                 
     387                int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;                
     388                int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;                
     389 
     390                samplesOut.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 
     391                samplesOut.write(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 
     392                samplesOut.write(reinterpret_cast<char *>(&sourceid), sizeof(int)); 
     393                samplesOut.write(reinterpret_cast<char *>(&termid), sizeof(int)); 
     394    } 
     395#endif 
    323396        samplesOut.close(); 
    324  
    325397        return true; 
    326398} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r490 r491  
    314314                polys.pop_back(); 
    315315 
    316                 //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 
    317  
    318                 // classify polygon 
     316                //-- classify polygon 
    319317                const int cf = poly->ClassifyPlane(plane, mEpsilon); 
    320318 
     
    387385        app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 
    388386 
    389         app << "#N_SPLITS ( Number of splits )\n" << splits << "\n"; 
     387        app << "#N_POLYSPLITS ( Number of polygon splits )\n" << polySplits << "\n"; 
     388 
     389        app << "#AXIS_ALIGNED_SPLITS (number of axis aligned splits)\n" << splits[0] + splits[1] + splits[2] << endl; 
     390 
     391        app << "#N_SPLITS ( Number of splits in axes x y z\n"; 
     392 
     393        for (int i = 0; i < 3; ++ i) 
     394                app << splits[i] << " "; 
     395        app << endl; 
    390396 
    391397        app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maximum depth )\n"  
     
    420426 
    421427        app << "#N_ROUTPUT_INPUT_POLYGONS ( ratio polygons after subdivision / input polygons )\n" << 
    422                  (polys + splits) / (double)polys << endl; 
     428                 (polys + polySplits) / (double)polys << endl; 
    423429         
    424430        app << "===== END OF BspTree statistics ==========\n"; 
     
    529535                                CLEAR_CONTAINER(coincident); 
    530536 
    531                                 mStat.splits += splits; 
     537                                mStat.polySplits += splits; 
    532538 
    533539                                // push the children on the stack 
     
    962968        startTime = GetTime(); 
    963969        // subdivide polygons with plane 
    964         mStat.splits += SplitPolygons(interior->GetPlane(), 
    965                                                                   *tData.mPolygons,  
    966                                           *frontData.mPolygons,  
    967                                                                   *backData.mPolygons,  
    968                                                                   coincident); 
     970        mStat.polySplits += SplitPolygons(interior->GetPlane(), 
     971                                                                          *tData.mPolygons,  
     972                                                                          *frontData.mPolygons,  
     973                                                                          *backData.mPolygons,  
     974                                                                          coincident); 
    969975 
    970976        Debug << "time used for polygon splitting: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r490 r491  
    9393        int nodes; 
    9494        // number of splits 
    95         int splits; 
     95        int splits[3]; 
     96         
    9697        // totals number of rays 
    9798        int rays; 
     
    129130        /// number of invalid leaves 
    130131        int invalidLeaves; 
     132        /// polygon splits  
     133        int polySplits; 
    131134 
    132135        // Constructor 
     
    146149        { 
    147150                nodes = 0; 
    148                 splits = 0; 
     151                for (int i = 0; i < 3; ++ i) 
     152                        splits[i] = 0; 
    149153                 
    150154                maxDepth = 0; 
     
    165169                maxPvs = 0; 
    166170                invalidLeaves = 0; 
     171                polySplits = 0; 
    167172        } 
    168173 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r490 r491  
    16431643 
    16441644 
    1645 /**********************************************************************/ 
    1646 /*                 VspBspViewCellsManager implementation              */ 
    1647 /**********************************************************************/ 
     1645/************************************************************************/ 
     1646/*                 VspBspViewCellsManager implementation                */ 
     1647/************************************************************************/ 
    16481648 
    16491649 
     
    17221722         
    17231723        Debug << mVspBspTree->GetStatistics() << endl; 
     1724 
    17241725        // collapse invalid regions 
     1726        cout << "collapsing invalid tree regions ... "; 
    17251727        mVspBspTree->CollapseTree(mVspBspTree->GetRoot());  
     1728        cout << "finished" << endl; 
     1729        cout << "reseting view cell stats ... "; 
    17261730        ResetViewCells(); 
     1731        cout << "finished" << endl; 
    17271732         
    17281733        Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 
    1729          
     1734 
     1735        if (1) // export initial view cells 
     1736        { 
     1737                cout << "exporting initial view cells (=leaves) ... "; 
     1738                Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 
     1739         
     1740                if (exporter) 
     1741                { 
     1742                        //exporter->SetWireframe(); 
     1743                        exporter->SetFilled(); 
     1744                        ExportViewCells(exporter); 
     1745 
     1746                        //if (mExportRays) 
     1747                        //      exporter->ExportRays(postProcessRays, RgbColor(1, 1, 0)); 
     1748                         
     1749                        if (mExportGeometry) 
     1750                                exporter->ExportGeometry(objects); 
     1751                         
     1752                        delete exporter; 
     1753                } 
     1754                cout << "finished" << endl; 
     1755        } 
     1756 
    17301757        long startTime = GetTime(); 
     1758        cout << "Computing remaining ray contributions ... "; 
    17311759        // recast rest of rays 
    17321760        ComputeSampleContributions(savedRays); 
    1733          
     1761        cout << "finished" << endl; 
     1762 
    17341763        Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3  
    17351764                  << " secs" << endl; 
     
    18061835    Debug << ss << endl; 
    18071836 
    1808         if (1) // export view cells 
    1809         { 
    1810                 cout << "exporting initial view cells (=leaves) ... "; 
    1811                 Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 
    1812          
    1813                 if (exporter) 
    1814                 { 
    1815                         //exporter->SetWireframe(); 
    1816                         exporter->SetFilled(); 
    1817                         ExportViewCells(exporter); 
    1818  
    1819                         if (mExportRays) 
    1820                         { 
    1821                                 exporter->ExportRays(postProcessRays, RgbColor(1, 1, 0)); 
    1822                         } 
    1823  
    1824                         if (mExportGeometry) 
    1825                         { 
    1826                                 Material m; 
    1827                                 m.mDiffuseColor = RgbColor(0, 1, 0); 
    1828                                 exporter->SetForcedMaterial(m); 
    1829                                 exporter->SetFilled(); 
    1830  
    1831                                 exporter->ExportGeometry(objects); 
    1832                         } 
    1833  
    1834                         delete exporter; 
    1835                 } 
    1836                 cout << "finished" << endl; 
    1837         } 
    1838  
    18391837        //-- merge or subdivide view cells 
    18401838        int merged = 0; 
     
    18531851                  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 
    18541852         
     1853        cout << "reseting view cell stats ... "; 
    18551854        ResetViewCells(); 
     1855        cout << "finished" << endl; 
     1856 
    18561857        //BspLeaf::NewMail(); 
    18571858        if (1) // export merged view cells 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r490 r491  
    3434 
    3535float BspMergeCandidate::sOverallCost = 0; 
     36 
     37 
     38/// Adds object to the pvs of the front and back node 
     39inline void AddObject2Pvs(Intersectable *object, 
     40                                                  const int side, 
     41                                                  int &pvsBack, 
     42                                                  int &pvsFront) 
     43{ 
     44        if (!object) 
     45                return; 
     46 
     47        if (side <= 0) 
     48        { 
     49                if (!object->Mailed() && !object->Mailed(2)) 
     50                { 
     51                        ++ pvsBack; 
     52 
     53                        if (object->Mailed(1)) 
     54                                object->Mail(2); 
     55                        else 
     56                                object->Mail(); 
     57                } 
     58        } 
     59 
     60        if (side >= 0) 
     61        { 
     62                if (!object->Mailed(1) && !object->Mailed(2)) 
     63                { 
     64                        ++ pvsFront; 
     65 
     66                        if (object->Mailed()) 
     67                                object->Mail(2); 
     68                        else 
     69                                object->Mail(1); 
     70                } 
     71        } 
     72} 
     73 
    3674 
    3775/****************************************************************/ 
     
    509547 
    510548        // subdivide polygons 
    511         mStat.splits += SplitPolygons(interior->GetPlane(), 
    512                                                                   *tData.mPolygons, 
    513                                           *frontData.mPolygons, 
    514                                                                   *backData.mPolygons, 
    515                                                                   coincident); 
     549        SplitPolygons(interior->GetPlane(), 
     550                                  *tData.mPolygons, 
     551                      *frontData.mPolygons, 
     552                                  *backData.mPolygons, 
     553                                  coincident); 
    516554 
    517555 
     
    755793 
    756794float VspBspTree::SelectAxisAlignedPlane(Plane3 &plane, 
    757                                                                                  const VspBspTraversalData &tData) 
     795                                                                                 const VspBspTraversalData &tData, 
     796                                                                                 int &bestAxis) 
    758797{ 
    759798        AxisAlignedBox3 box; 
     
    771810        float nPosition[3]; 
    772811        float nCostRatio[3]; 
    773         int bestAxis = -1; 
     812        bestAxis = -1; 
    774813 
    775814        const int sAxis = box.Size().DrivingAxis(); 
     
    815854        Vector3 normal(0,0,0); normal[bestAxis] = 1; 
    816855        plane = Plane3(normal, nPosition[bestAxis]); 
    817  
     856         
    818857        return nCostRatio[bestAxis]; 
    819858} 
     859 
     860 
     861float VspBspTree::EvalCostRatio(const VspBspTraversalData &tData, 
     862                                                                const AxisAlignedBox3 &box, 
     863                                                                const int axis, 
     864                                                                const float position, 
     865                                                                int &raysBack, 
     866                                                                int &raysFront, 
     867                                                                int &pvsBack, 
     868                                                                int &pvsFront) 
     869{ 
     870        raysBack = 0; 
     871        raysFront = 0; 
     872        pvsFront = 0; 
     873        pvsBack = 0; 
     874 
     875        Intersectable::NewMail(3); 
     876 
     877        // eval pvs size 
     878        const int pvsSize = tData.mPvs; 
     879 
     880        // create unique ids for pvs heuristics 
     881        GenerateUniqueIdsForPvs(); 
     882 
     883        // this is the main ray classification loop! 
     884        for(RayInfoContainer::iterator ri = tData.mRays->begin(); 
     885                        ri != tData.mRays->end(); ++ ri) 
     886        { 
     887                if (!(*ri).mRay->IsActive()) 
     888                        continue; 
     889 
     890                // determine the side of this ray with respect to the plane 
     891                float t; 
     892                int side = (*ri).ComputeRayIntersection(axis, position, t); 
     893                         
     894                if (side <= 0) 
     895                        ++ raysBack; 
     896 
     897                if (side >= 0) 
     898                        ++ raysFront; 
     899 
     900                AddObjToPvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 
     901        } 
     902 
     903        //-- only one of these options should be one 
     904 
     905        if (0) //-- only pvs 
     906        { 
     907                const float sum = float(pvsBack + pvsFront); 
     908                const float oldCost = (float)pvsSize; 
     909 
     910                return sum / oldCost; 
     911        } 
     912 
     913        //-- pvs + probability heuristics 
     914        float pBack, pFront, pOverall; 
     915 
     916        if (0) 
     917        { 
     918                // box length substitute for probability 
     919                const float minBox = box.Min(axis); 
     920                const float maxBox = box.Max(axis); 
     921 
     922                pBack = position - minBox; 
     923                pFront = maxBox - position; 
     924                pOverall = maxBox - minBox; 
     925        } 
     926 
     927        if (1) //-- area substitute for probability 
     928        { 
     929                 
     930                const bool useMidSplit = true; 
     931                //const bool useMidSplit = false; 
     932                         
     933                pOverall = box.SurfaceArea(); 
     934                         
     935                if (!useMidSplit) 
     936                { 
     937                        Vector3 pos = box.Max(); pos[axis] = position; 
     938                        pBack = AxisAlignedBox3(box.Min(), pos).SurfaceArea(); 
     939 
     940                        pos = box.Min(); pos[axis] = position; 
     941                        pFront = AxisAlignedBox3(pos, box.Max()).SurfaceArea(); 
     942                } 
     943                else 
     944                { 
     945                        //-- simplified computation for mid split 
     946                        const int axis2 = (axis + 1) % 3; 
     947                        const int axis3 = (axis + 2) % 3; 
     948 
     949                        const float faceArea =  
     950                                (box.Max(axis2) - box.Min(axis2)) * 
     951                                (box.Max(axis3) - box.Min(axis3)); 
     952 
     953                        pBack = pFront = pOverall * 0.5f + faceArea; 
     954                } 
     955        } 
     956 
     957        //-- ray density substitute for probability 
     958        if (0) 
     959        { 
     960                pBack = (float)raysBack; 
     961                pFront = (float)raysFront; 
     962                pOverall = (float)tData.mRays->size(); 
     963        } 
     964 
     965        //Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl; 
     966        //Debug << pFront << " " << pBack << " " << pOverall << endl; 
     967 
     968        // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 
     969        const float newCost = pvsBack * pBack + pvsFront * pFront; 
     970        //  float oldCost = leaf->mRays.size(); 
     971        const float oldCost = (float)pvsSize * pOverall; 
     972 
     973        return  (mCtDivCi + newCost) / oldCost; 
     974} 
     975 
    820976 
    821977 
     
    835991                        return true; 
    836992                } 
    837                 else 
    838                 { 
    839                         //-- choose plane on midpoint of a ray 
    840                         const int candidateIdx = (int)RandomValue(0, (Real)((int)data.mRays->size() - 1)); 
    841  
    842                         const Vector3 minPt = (*data.mRays)[candidateIdx].ExtrapOrigin(); 
    843                         const Vector3 maxPt = (*data.mRays)[candidateIdx].ExtrapTermination(); 
    844  
    845                         const Vector3 pt = (maxPt + minPt) * 0.5; 
    846  
    847                         const Vector3 normal = (*data.mRays)[candidateIdx].mRay->GetDir(); 
    848  
    849                         plane = Plane3(normal, pt); 
    850                         return true; 
    851                 } 
    852  
    853                 return false; 
    854993        } 
    855994 
     
    9381077        // intermediate plane 
    9391078        Plane3 plane; 
     1079        bool useAxisAlignedPlane = false; 
    9401080 
    9411081        const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 
     
    9671107        } 
    9681108 
    969 #if 0 
    970         //-- choose candidate planes extracted from rays 
    971         //-- different methods are available 
    972         for (int i = 0; i < mMaxRayCandidates; ++ i) 
    973         { 
    974                 plane = ChooseCandidatePlane3(*data.mRays); 
    975                 candidateCost = SplitPlaneCost(plane, data); 
    976  
    977                 if (candidateCost < lowestCost) 
    978                 { 
    979                         bestPlane = plane; 
    980                         lowestCost = candidateCost; 
    981                 } 
    982         } 
    983 #endif 
    984  
    985         // axis aligned splits 
    986         candidateCost = SelectAxisAlignedPlane(plane, data); 
     1109        //-- axis aligned splits 
     1110        int axis; 
     1111        candidateCost = SelectAxisAlignedPlane(plane, data, axis); 
    9871112 
    9881113        if (candidateCost < lowestCost) 
    989         { 
     1114        {        
     1115                if (!useAxisAlignedPlane) 
     1116                { 
     1117                        useAxisAlignedPlane = true; 
     1118                        //! error also computed if cost ratio is missed 
     1119                        ++ mStat.splits[axis]; 
     1120                } 
     1121 
    9901122                bestPlane = plane; 
    9911123                lowestCost = candidateCost; 
     
    10311163        if (mSplitPlaneStrategy & PVS) 
    10321164        { 
     1165// matt: change back!! 
     1166Intersectable::NewMail(3); 
    10331167                // create unique ids for pvs heuristics 
    1034                 GenerateUniqueIdsForPvs(); 
     1168                //GenerateUniqueIdsForPvs(); 
    10351169 
    10361170                if (mPvsUseArea) // use front and back cell areas to approximate volume 
     
    10561190        bool useRand; 
    10571191 
    1058         // choose test polyongs randomly if over threshold 
     1192        // choose test rays randomly if too much 
    10591193        if ((int)data.mRays->size() > mMaxTests) 
    10601194        { 
     
    10951229 
    10961230                        // add the termination object 
    1097                         AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 
     1231                        //AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 
     1232                        AddObject2Pvs(ray->mTerminationObject, cf, frontPvs, backPvs); 
    10981233                        // add the source object 
    1099                         AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 
    1100  
    1101                         // use number or length of rays to approximate volume 
     1234                        //AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 
     1235 
     1236                        // use number of rays to approximate volume 
    11021237                        if (!mPvsUseArea) 
    11031238                        { 
    1104                                 float len = 1; 
    1105  
    1106                                 if (pvsUseLen) // use length of rays 
    1107                                         len = rayInf.SqrSegmentLength(); 
    1108  
    1109                                 pOverall += len; 
    1110  
    1111                                 if (cf == 1) 
    1112                                         pFront += len; 
    1113                                 else if (cf == -1) 
    1114                                         pBack += len; 
    1115                                 else if (cf == 0) 
    1116                                 { 
    1117                                         // use length of rays to approximate volume 
    1118                                         if (pvsUseLen) 
    1119                                         { 
    1120                                                 float newLen = len * 
    1121                                                         (rayInf.GetMaxT() - t) / 
    1122                                                         (rayInf.GetMaxT() - rayInf.GetMinT()); 
    1123  
    1124                                                 if (candidatePlane.Side(rayInf.ExtrapOrigin()) <= 0) 
    1125                                                 { 
    1126                                                         pBack += newLen; 
    1127                                                         pFront += len - newLen; 
    1128                                                 } 
    1129                                                 else 
    1130                                                 { 
    1131                                                         pFront += newLen; 
    1132                                                         pBack += len - newLen; 
    1133                                                 } 
    1134                                         } 
    1135                                         else 
    1136                                         { 
    1137                                                 ++ pFront; 
    1138                                                 ++ pBack; 
    1139                                         } 
    1140                                 } 
     1239                                ++ pOverall; 
     1240 
     1241                                if (cf >= 0) 
     1242                                        ++ pFront; 
     1243                                if (cf <= 0) 
     1244                                        ++ pBack; 
    11411245                        } 
    11421246                } 
     
    12151319        } 
    12161320} 
     1321 
    12171322 
    12181323void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves) const 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r489 r491  
    421421        */ 
    422422        float SelectAxisAlignedPlane(Plane3 &plane,  
    423                                                                  const VspBspTraversalData &tData); 
     423                                                                 const VspBspTraversalData &tData, 
     424                                                                 int &bestAxis); 
    424425 
    425426        /** Sorts split candidates for surface area heuristics for axis aligned splits. 
     
    438439                                                                  float &position); 
    439440 
     441        /** Evaluates cost ratio for axis aligned splits. 
     442        */ 
     443        float EvalCostRatio(const VspBspTraversalData &tData, 
     444                                                const AxisAlignedBox3 &box, 
     445                                                const int axis, 
     446                                                const float position, 
     447                                                int &raysBack, 
     448                                                int &raysFront, 
     449                                                int &pvsBack, 
     450                                                int &pvsFront); 
     451 
    440452        /** Selects an axis aligned split plane. 
    441                 Returns true if split is valied 
     453                @Returns true if split is valied 
    442454        */ 
    443455        bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r486 r491  
    831831        return  (mCtDivCi + newCost) / oldCost; 
    832832} 
     833 
    833834 
    834835float VspKdTree::BestCostRatioRegular(VspKdLeaf *leaf, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r490 r491  
    1212#include "RenderSimulator.h" 
    1313 
    14 bool useViewSpaceBox = true; 
     14bool useViewSpaceBox = false; 
    1515bool use2dSampling = false; 
    16 bool useViewspacePlane = true; 
     16bool useViewspacePlane = false; 
    1717 
    1818VssPreprocessor::VssPreprocessor(): 
     
    464464          WriteSamples(mVssRays); 
    465465          cout << "finished\n" << endl; 
    466   } 
    467  
    468   //VssRayContainer dummyRays; 
    469   //LoadSamples(dummyRays, mObjects); 
    470   //Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 
     466 
     467          /*VssRayContainer dummyRays; 
     468          LoadSamples(dummyRays, mObjects); 
     469          Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 
     470 
     471          for (int i = 0; i < (int)mVssRays.size(); ++ i) 
     472          { 
     473                  Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl; 
     474                  Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl; 
     475          }*/ 
     476  } 
    471477 
    472478  //int numExportRays = 10000; 
Note: See TracChangeset for help on using the changeset viewer.