Changeset 306


Ignore:
Timestamp:
10/04/05 03:05:08 (19 years ago)
Author:
mattausch
Message:

fixed polygon area, eval candidate plane

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
5 edited

Legend:

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

    r305 r306  
    7373        # vertical axis        = 64 
    7474         
    75         splitPlaneStrategy 64 
     75        splitPlaneStrategy 32 
    7676        # least splits + balanced polygons 
    7777        #splitPlaneStrategy 12 
     
    9292        constructionMethod viewCells 
    9393#       constructionMethod sceneGeometry 
    94         maxCandidates 25 
     94        maxCandidates 50 
    9595        maxViewCells 999999 
    9696        Termination { 
    97                 maxPolysForAxisAligned 50 
     97                maxPolysForAxisAligned 100 
    9898                maxPolygons 0 
    99                 maxDepth 100 
     99                maxDepth 200 
    100100        } 
    101101} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r301 r306  
    3737#endif 
    3838        return Plane3(mVertices[0], mVertices[1], mVertices[2]); 
     39} 
     40 
     41Vector3 Polygon3::GetNormal() const  
     42{ 
     43    return Normalize(CrossProd(mVertices[0]-mVertices[1], 
     44                                                           mVertices[2]-mVertices[1])); 
    3945} 
    4046 
     
    109115float Polygon3::GetArea() const 
    110116{ 
    111         VertexContainer vtx; 
    112  
    113         //-- rotate polygon to lie in xy plane 
    114         Vector3 v1 = mVertices[0] - mVertices[1]; 
    115         Vector3 v2 = mVertices[2] - mVertices[1]; 
    116         Vector3 n = Normalize(CrossProd(v2,v1)); 
    117  
    118         Matrix4x4 rot = GenRotation(v1, v2, n); 
    119  
    120         VertexContainer::const_iterator it, it_end = mVertices.end(); 
    121  
    122         for (it = mVertices.begin(); it != it_end; ++it) 
    123                 vtx.push_back(rot * (*it)); 
    124  
    125         //-- compute area 
    126         Vector3 last = vtx.back(); 
    127  
    128         float area = 0.0f; 
    129         for (it = vtx.begin(); it != vtx.end(); ++it) 
    130         { 
    131                 area += last.y * (*it).x - last.x * (*it).y; 
    132  
    133                 last = *it; 
    134         } 
    135         //Debug << "area: " << area * 0.5 << endl; 
    136         return area * 0.5f; 
     117        Vector3 v = CrossProd(mVertices.back(), mVertices.front()); 
     118     
     119    for (int i=0; i < mVertices.size() - 1; ++i) 
     120                v += CrossProd(mVertices[i], mVertices[i+1]); 
     121     
     122    //Debug << "area2: " << 0.5f * fabs(DotProd(GetNormal(), v)) << endl;   
     123 
     124        return 0.5f * fabs(DotProd(GetNormal(), v)); 
    137125} 
    138126 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r299 r306  
    6969        bool Valid() const;  
    7070 
     71        Vector3 GetNormal() const; 
     72 
    7173        /** Includes polygons to axis aligned box. 
    7274        */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r305 r306  
    2929float BspTree::sBalancedViewCellsFactor = 2.0f; 
    3030float BspTree::sVerticalSplitsFactor = 1.0f; // very important criterium for 2.5d scenes 
    31  
     31float BspTree::sLargestPolyAreaFactor = 1.0f; 
    3232 
    3333/** Evaluates split plane classification with respect to the plane's  
     
    365365 
    366366        // extract polygons that guide the split process 
    367         mStat.polys += AddMesh2Polygons(viewCell->GetMesh(), *polys); 
     367        mStat.polys += AddMesh2Polygons(viewCell->GetMesh(), *polys, viewCell); 
    368368        mBox.Include(viewCell->GetBox()); // add to BSP aabb 
    369369 
     
    460460                polys.push_back(poly); 
    461461 
    462                 if (!poly->Valid()) 
    463                         Debug << "Input polygon not valid: " << *poly  
    464                                   << endl << "Area: " << poly->GetArea() << endl; 
     462                //if (!poly->Valid()) 
     463                //      Debug << "Input polygon not valid: " << *poly << endl << "Area: " << poly->GetArea() << endl; 
    465464                 
    466465                ++ polysNum; 
     
    511510                { 
    512511                        mBox.Include(object->GetBox()); // add to BSP tree aabb 
    513                         AddMesh2Polygons(mesh, polys); 
     512                        AddMesh2Polygons(mesh, polys, mViewCell); 
    514513                } 
    515514        } 
     
    907906         
    908907        int candidateIdx = limit; 
    909         PolygonContainer debugPolys;bool dist = true; 
     908         
    910909        for (int i = 0; i < limit; ++ i) 
    911910        { 
     
    922921                        lowestCost = candidateCost; 
    923922                } 
    924                 for (int i=0; i < debugPolys.size(); ++i) 
    925                         if (polys[candidateIdx] == debugPolys[i]) 
    926                         { 
    927                                 Debug << "FATAL ERROR" << endl; 
    928                                 dist = false; 
    929                         } 
    930                 debugPolys.push_back(polys[candidateIdx]); 
    931923        } 
    932924         
    933925        //Debug << "Plane lowest cost: " << lowestCost << endl; 
    934         if (!dist) 
    935                 Debug << "FATAL ERROR DUPLICATE TESTS!!" << endl; 
    936926        return polys[bestPlaneIdx]->GetSupportingPlane(); 
    937927} 
     
    941931        int candidateIdx = Random(currentIdx--); 
    942932         
     933        //Debug << "new candidate " << candidateIdx << endl; 
     934 
    943935        // swap candidates to avoid testing same plane 2 times 
    944936        Polygon3 *p = polys[candidateIdx]; 
     
    958950                // we put a penalty on the dot product between the "tiny" vertical axis 
    959951                // and the split plane axis 
    960                 // NOTE: weight with poly size because vertical split more important if too many polygons 
    961952                val += sVerticalSplitsFactor *  
    962                            fabs(DotProd(candidatePlane.mNormal, tinyAxis)) * (float)polys.size(); 
    963         } 
     953                           fabs(DotProd(candidatePlane.mNormal, tinyAxis)); 
     954        } 
     955 
    964956        //-- strategies where the effect of the split plane on the polygons is tested 
    965         if ((sSplitPlaneStrategy & BALANCED_POLYS)     ||  
    966                 (sSplitPlaneStrategy & LEAST_SPLITS)       || 
    967                 (sSplitPlaneStrategy & LARGEST_POLY_AREA)) 
    968         { 
    969                 PolygonContainer::const_iterator it, it_end = polys.end(); 
    970                 float sumBalancedPolys = 0; 
    971                 float sumSplits = 0; 
    972  
    973                 for (it = polys.begin(); it != it_end; ++ it) 
    974                 { 
    975                         int classification = (*it)->ClassifyPlane(candidatePlane); 
    976  
    977                         if (sSplitPlaneStrategy & BALANCED_POLYS) 
    978                                 sumBalancedPolys += sBalancedPolysTable[classification]; 
    979                                  
    980                         if (sSplitPlaneStrategy & LEAST_SPLITS) 
    981                                 sumSplits += sLeastSplitsTable[classification]; 
    982  
    983                         if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 
    984                         { 
    985                                 if (classification == Polygon3::COINCIDENT) 
    986                                 {        
    987                                         float area = (*it)->GetArea(); 
    988                                         //Debug << "polygon area: " << area << " "; 
    989                                         if (area) val += 100.0f/area; 
    990                                 } 
     957        if (!((sSplitPlaneStrategy & BALANCED_POLYS) || 
     958                  (sSplitPlaneStrategy & LEAST_SPLITS)   || 
     959                  (sSplitPlaneStrategy & LARGEST_POLY_AREA) || 
     960                  (sSplitPlaneStrategy & BALANCED_VIEW_CELLS))) 
     961                return val; 
     962         
     963        PolygonContainer::const_iterator it, it_end = polys.end(); 
     964        float sumBalancedPolys = 0; 
     965        float sumSplits = 0; 
     966        float sumPolyArea = 0; 
     967        float sumBalancedViewCells = 0; 
     968        //float totalArea = 0; 
     969 
     970        // container for view cells 
     971        ObjectContainer frontViewCells; 
     972        ObjectContainer backViewCells; 
     973 
     974        for (it = polys.begin(); it != it_end; ++ it) 
     975        { 
     976                int classification = (*it)->ClassifyPlane(candidatePlane); 
     977 
     978                if (sSplitPlaneStrategy & BALANCED_POLYS) 
     979                        sumBalancedPolys += sBalancedPolysTable[classification]; 
     980                 
     981                if (sSplitPlaneStrategy & LEAST_SPLITS) 
     982                        sumSplits += sLeastSplitsTable[classification]; 
     983 
     984                if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 
     985                { 
     986                        if (classification == Polygon3::COINCIDENT) 
     987                        {                
     988                                float area = (*it)->GetArea(); 
     989                                //Debug << "polygon area: " << area << " "; 
     990                                sumPolyArea += area; 
    991991                        } 
    992                 } 
    993                 val += sBalancedPolysFactor * fabs(sumBalancedPolys) +  
    994                            sLeastSplitsFactor * sumSplits; 
    995         } 
    996          
    997         if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
    998         { 
    999                 // store view cells 
    1000                 ObjectContainer frontViewCells; 
    1001                 ObjectContainer backViewCells; 
    1002  
    1003                 float sumBalancedViewCells = 0; 
    1004  
    1005                 PolygonContainer::const_iterator it, it_end = polys.end(); 
     992                        //totalArea += area; 
     993                } 
     994 
     995                // order back and front view cells according to classificaion 
     996                if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
     997                { 
     998                        Intersectable *viewCell = (*it)->mParent; 
    1006999                 
    1007                 for (it = polys.begin(); it != it_end; ++ it) 
    1008                 { 
    1009                         int classification = (*it)->ClassifyPlane(candidatePlane); 
    1010                         Intersectable *viewCell = (*it)->mParent; 
    1011                          
    1012                         if (viewCell && (classification == Polygon3::FRONT_SIDE)) 
     1000                        if (classification == Polygon3::FRONT_SIDE) 
    10131001                                frontViewCells.push_back(viewCell); 
    10141002                        else if (viewCell && (classification == Polygon3::BACK_SIDE)) 
    10151003                                backViewCells.push_back(viewCell); 
    10161004                } 
    1017  
     1005        } 
     1006 
     1007        if (sSplitPlaneStrategy & BALANCED_POLYS) 
     1008                val += sBalancedPolysFactor * fabs(sumBalancedPolys) / (float)polys.size(); 
     1009 
     1010        if (sSplitPlaneStrategy & LEAST_SPLITS)     
     1011                val += sLeastSplitsFactor * sumSplits / (float)polys.size(); 
     1012 
     1013        if ((sSplitPlaneStrategy & LARGEST_POLY_AREA) && sumPolyArea)  
     1014                val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; // HACK 
     1015 
     1016        if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 
     1017        { 
    10181018                // count number of unique view cells 
    10191019                sort(frontViewCells.begin(), frontViewCells.end()); 
     
    10211021 
    10221022                ObjectContainer::const_iterator frontIt, frontIt_end = frontViewCells.end(); 
    1023                  
     1023         
    10241024                Intersectable *intersect = NULL; 
    10251025                // increase counter for view cells in front of plane 
    1026         for (frontIt = frontViewCells.begin(); frontIt != frontIt_end; ++frontIt) 
     1026                for (frontIt = frontViewCells.begin(); frontIt != frontIt_end; ++frontIt) 
    10271027                { 
    10281028                        if (*frontIt != intersect) 
     
    10361036                intersect = NULL; 
    10371037                // decrease counter for view cells on back side of plane 
    1038         for (backIt = backViewCells.begin(); backIt != backIt_end; ++backIt) 
     1038                for (backIt = backViewCells.begin(); backIt != backIt_end; ++backIt) 
    10391039                { 
    10401040                        if (*backIt != intersect) 
    10411041                        { 
    10421042                                intersect = *backIt; 
    1043                                 sumBalancedViewCells -= 1; 
     1043                                sumBalancedViewCells -= 1.0f; 
    10441044                        } 
    10451045                } 
    10461046 
    1047                  val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells); 
     1047                val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells) /  
     1048                        (float)(frontViewCells.size() + backViewCells.size()); 
    10481049        } 
    10491050 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r305 r306  
    436436                @returns number of polygons 
    437437        */ 
    438         int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent = NULL); 
     438        int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent); 
    439439 
    440440        /** A ray is cast possible intersecting the tree. 
     
    545545        static float sBalancedViewCellsFactor; 
    546546        static float sVerticalSplitsFactor; 
     547        static float sLargestPolyAreaFactor; 
    547548         
    548549private: 
Note: See TracChangeset for help on using the changeset viewer.