Changeset 678


Ignore:
Timestamp:
03/07/06 11:09:10 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
6 edited

Legend:

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

    r676 r678  
    23032303{ 
    23042304        BspNode *lastNode; 
     2305 
    23052306        do 
    23062307        { 
     
    23552356 
    23562357        PolygonContainer candidates; 
     2358        vector<Plane3> candidatePlanes; 
    23572359 
    23582360        // bounded planes are added to the polygons (reverse polygons 
    23592361        // as they have to be outfacing 
     2362        // comment: why is this? 
    23602363        for (int i = 0; i < (int)halfSpaces.size(); ++ i) 
    23612364        { 
     
    23652368                { 
    23662369                        candidates.push_back(p->CreateReversePolygon()); 
     2370 
     2371                        Plane3 candidatePlane = p->GetSupportingPlane();//halfSpaces[i]; 
     2372                        //candidatePlane.ReverseOrientation(); 
     2373                        candidatePlanes.push_back(candidatePlane); 
     2374 
    23672375                        DEL_PTR(p); 
    23682376                } 
     
    23772385                        vertices.push_back(mBox.GetFace(i).mVertices[j]); 
    23782386 
     2387                Polygon3 *poly = new Polygon3(vertices); 
    23792388                candidates.push_back(new Polygon3(vertices)); 
    2380         } 
     2389                candidatePlanes.push_back(poly->GetSupportingPlane()); 
     2390        } 
     2391 
    23812392 
    23822393        for (int i = 0; i < (int)candidates.size(); ++ i) 
     
    24262437                 
    24272438                if (candidates[i]) 
    2428                         geom.mPolys.push_back(candidates[i]); 
     2439                { 
     2440                        geom.Add(candidates[i], candidatePlanes[i]); 
     2441                //      geom.mPolys.push_back(candidates[i]); 
     2442                } 
    24292443        } 
    24302444} 
     
    24762490                                        { 
    24772491                                                const int cf = 
    2478                                                         Polygon3::ClassifyPlane(geom->mPolys, 
     2492                                                        Polygon3::ClassifyPlane(geom->GetPolys(), 
    24792493                                                                                                        halfSpaces[i], 
    24802494                                                                                                        mEpsilon); 
     
    24902504                                        // TODO: why is this wrong?? 
    24912505                                        // test all planes of current node if still adjacent 
    2492                                         for (int i = 0; (i < (int)nodeGeom.mPolys.size()) && isAdjacent; ++ i) 
     2506                                        for (int i = 0; (i < nodeGeom.Size()) && isAdjacent; ++ i) 
    24932507                                        { 
    2494                                                 Polygon3 *poly = nodeGeom.mPolys[i]; 
     2508                                                Polygon3 *poly = nodeGeom.GetPolys()[i]; 
    24952509 
    24962510                                                const int cf = 
    2497                                                         Polygon3::ClassifyPlane(geom->mPolys, 
     2511                                                        Polygon3::ClassifyPlane(geom->GetPolys(), 
    24982512                                                                                                        poly->GetSupportingPlane(), 
    24992513                                                                                                        mEpsilon); 
     
    25162530                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    25172531 
    2518                         const int cf = Polygon3::ClassifyPlane(nodeGeom.mPolys, 
     2532                        const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(), 
    25192533                                                                                                   interior->GetPlane(), 
    25202534                                                                                                   mEpsilon); 
     
    25842598                        ConstructGeometry(interior, geom); 
    25852599 
    2586                         const int cf = Polygon3::ClassifyPlane(geom.mPolys,  
     2600                        const int cf = Polygon3::ClassifyPlane(geom.GetPolys(),  
    25872601                                                                                                   halfspace,  
    25882602                                                                                                   mEpsilon); 
     
    28802894         
    28812895        PolygonContainer::const_iterator it, it_end = rhs.mPolys.end(); 
     2896 
     2897        int i = 0; 
     2898 
    28822899        for (it = rhs.mPolys.begin(); it != it_end; ++ it) 
    28832900        { 
    28842901                Polygon3 *poly = *it; 
    2885                 mPolys.push_back(new Polygon3(*poly)); 
     2902                Add(new Polygon3(*poly), rhs.mPlanes[i ++]); 
    28862903        } 
    28872904} 
     
    28912908{ 
    28922909        CLEAR_CONTAINER(mPolys); 
     2910} 
     2911 
     2912 
     2913int BspNodeGeometry::Size() const 
     2914{ 
     2915        return (int)mPolys.size(); 
     2916} 
     2917 
     2918 
     2919const PolygonContainer &BspNodeGeometry::GetPolys() 
     2920{ 
     2921        return mPolys; 
     2922} 
     2923 
     2924 
     2925void BspNodeGeometry::Add(Polygon3 *p, const Plane3 &plane) 
     2926{ 
     2927    mPolys.push_back(p); 
     2928        mPlanes.push_back(plane); 
    28932929} 
    28942930 
     
    29232959                        const Vector3 v2 = poly->mVertices[i + 1] - center; 
    29242960 
    2925                         volume += f * (DotProd(v0, CrossProd(v1, v2))); 
     2961                        // more robust version using abs and the center of mass 
     2962                        volume += fabs (f * (DotProd(v0, CrossProd(v1, v2)))); 
    29262963                } 
    29272964        } 
     
    29532990 
    29542991        return center / (float)n; 
     2992} 
     2993 
     2994 
     2995bool BspNodeGeometry::Valid() const 
     2996{ 
     2997        if (mPolys.size() < 4) 
     2998                return false; 
     2999         
     3000        return true; 
    29553001} 
    29563002 
     
    30033049 
    30043050                                        if (frontPoly->Valid(epsilon)) 
    3005                                                 front.mPolys.push_back(frontPoly); 
     3051                                        { 
     3052                                                front.Add(frontPoly, mPlanes[i]); 
     3053                                        } 
    30063054                                        else 
     3055                                        { 
    30073056                                                DEL_PTR(frontPoly); 
    3008  
     3057                                        } 
    30093058                                        if (backPoly->Valid(epsilon)) 
    3010                                                 back.mPolys.push_back(backPoly); 
     3059                                        { 
     3060                                                back.Add(backPoly, mPlanes[i]); 
     3061                                        } 
    30113062                                        else 
     3063                                        { 
    30123064                                                DEL_PTR(backPoly); 
     3065                                        } 
    30133066                                } 
    30143067                                 
    30153068                                break; 
    30163069                        case Polygon3::BACK_SIDE: 
    3017                                 back.mPolys.push_back(new Polygon3(mPolys[i]->mVertices));                       
     3070                 
     3071                                back.Add(new Polygon3(mPolys[i]->mVertices), mPlanes[i]); 
    30183072                                break; 
    30193073                        case Polygon3::FRONT_SIDE: 
    3020                                 front.mPolys.push_back(new Polygon3(mPolys[i]->mVertices));      
     3074 
     3075                                front.Add(new Polygon3(mPolys[i]->mVertices), mPlanes[i]); 
    30213076                                break; 
     3077                        // only put into back container (split should have no effect ...) 
    30223078                        case Polygon3::COINCIDENT: 
     3079 
     3080                                back.Add(new Polygon3(mPolys[i]->mVertices), mPlanes[i]); 
    30233081                                //front.mPolys.push_back(CreateReversePolygon(mPolys[i])); 
    3024                                 back.mPolys.push_back(new Polygon3(mPolys[i]->mVertices)); 
    30253082                                break; 
    30263083                        default: 
     
    30333090        { 
    30343091                // add polygon with normal pointing into positive half space to back cell 
    3035                 back.mPolys.push_back(planePoly); 
     3092                back.Add(planePoly, splitPlane); 
     3093                //back.mPolys.push_back(planePoly); 
     3094 
    30363095                // add polygon with reverse orientation to front cell 
    3037                 front.mPolys.push_back(planePoly->CreateReversePolygon()); 
     3096                Plane3 reversePlane(splitPlane); 
     3097                reversePlane.ReverseOrientation(); 
     3098                front.Add(planePoly->CreateReversePolygon(), reversePlane); 
     3099                //front.mPolys.push_back(planePoly->CreateReversePolygon()); 
    30383100        } 
    30393101} 
     
    30493111        for (int i = 0; (i < (int)mPolys.size()) && planePoly; ++ i) 
    30503112        { 
     3113#if 0 
    30513114                Plane3 plane = mPolys[i]->GetSupportingPlane(); 
    3052  
     3115#else 
     3116                Plane3 plane = mPlanes[i]; 
     3117         
     3118#endif 
    30533119                /// don't use epsilon here to get exact split planes 
    30543120                const int cf =  
    3055                         planePoly->ClassifyPlane(plane, Limits::Small); 
     3121                        planePoly->ClassifyPlane(plane, epsilon); 
    30563122                         
    30573123                // split new polygon with all previous planes 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h

    r666 r678  
    4040        */ 
    4141        float GetArea() const; 
    42          
     42        /** Returns volume of this node geometry. 
     43        */ 
    4344        float GetVolume() const; 
    4445 
     
    6970        Vector3 CenterOfMass() const; 
    7071 
    71         /** The polygons the geometry consists of. 
    72         */ 
    73         PolygonContainer mPolys; 
    74  
     72        bool Valid() const; 
     73 
     74         
    7575        friend ostream &operator<<(ostream &s, const BspNodeGeometry &a) 
    7676        { 
     
    8282        } 
    8383 
     84        int Size() const; 
     85        const PolygonContainer &GetPolys(); 
     86 
     87        void Add(Polygon3 *p, const Plane3 &plane); 
     88 
     89protected: 
     90        /** The polygons the geometry consists of. 
     91        */ 
     92        PolygonContainer mPolys; 
     93 
     94        /** The corresponding set of planes for the polygons. 
     95                Need this because of precision issues. 
     96        */ 
     97        vector<Plane3> mPlanes; 
    8498}; 
    8599 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r667 r678  
    17161716                                                   0.0001f); 
    17171717 
    1718                 if ((int)back.mPolys.size() >= 3) 
    1719                         exporter->ExportPolygons(back.mPolys); 
     1718                if (back.Size() >= 3) 
     1719                        exporter->ExportPolygons(back.GetPolys()); 
    17201720        } 
    17211721        else 
    17221722        { 
    17231723                 
    1724                 exporter->ExportPolygons(geom.mPolys); 
     1724                exporter->ExportPolygons(geom.GetPolys()); 
    17251725        } 
    17261726} 
     
    31643164                                        BspNodeGeometry geom; 
    31653165                                        mVspBspTree->ConstructGeometry(leaf, geom); 
    3166                                         exporter->ExportPolygons(geom.mPolys); 
     3166                                        exporter->ExportPolygons(geom.GetPolys()); 
    31673167                                } 
    31683168                        } 
     
    34863486                                                           0.0001f); 
    34873487 
    3488                         if ((int)back.mPolys.size() >= 3) 
    3489                                 exporter->ExportPolygons(back.mPolys); 
     3488                        if (back.Size() >= 3) 
     3489                                exporter->ExportPolygons(back.GetPolys()); 
    34903490                } 
    34913491        } 
     
    34953495                mVspBspTree->ConstructGeometry(vc, geom); 
    34963496                         
    3497                 exporter->ExportPolygons(geom.mPolys); 
     3497                exporter->ExportPolygons(geom.GetPolys()); 
    34983498        } 
    34993499} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r676 r678  
    186186        mSplitCandidates = new vector<SortableEntry>; 
    187187 
    188         Debug << "here3" << endl; 
    189188        Debug << endl; 
    190189} 
     
    463462 
    464463        // first node is kd node, i.e. an axis aligned box 
    465         if (1) 
     464        if (0) 
    466465        tData.mIsKdNode = true; 
    467466        else 
     
    13481347        if (1) 
    13491348        { 
    1350                 PolygonContainer::const_iterator it, it_end = tData.mGeometry->mPolys.end(); 
    1351  
    1352                 for(it = tData.mGeometry->mPolys.begin(); it < it_end; ++ it) 
     1349                PolygonContainer::const_iterator it, it_end = tData.mGeometry->GetPolys().end(); 
     1350 
     1351                for(it = tData.mGeometry->GetPolys().begin(); it < it_end; ++ it) 
    13531352                        box.Include(*(*it)); 
    13541353        } 
     
    14021401                                        pos = box.Max(); pos[axis] = nPosition[axis]; 
    14031402                                        AxisAlignedBox3 bBox(box.Min(), pos); 
    1404                                         bBox.ExtractPolys(nBackGeom[axis]->mPolys); 
    1405                                          
     1403                                        // TODO 
     1404#if 0 
     1405                                                bBox.ExtractPolys(nBackGeom[axis]->GetPolys()); 
     1406#endif                                   
    14061407                                        pos = box.Min(); pos[axis] = nPosition[axis]; 
    14071408                                        AxisAlignedBox3 fBox(pos, box.Max()); 
    1408                                         fBox.ExtractPolys(nFrontGeom[axis]->mPolys); 
     1409                                        // TODO 
     1410#if 0 
     1411                                                fBox.ExtractPolys(nFrontGeom[axis]->GetPolys()); 
     1412#endif 
    14091413                                } 
    14101414                                else 
     
    15691573                DEL_PTR(bGeom); 
    15701574        } 
    1571          
    1572  
    1573 #ifdef _DEBUG 
     1575     
     1576 
     1577        if (lowestCost > 10) 
     1578                Debug << "warning!! lowest cost: " << lowestCost << endl; 
     1579         
     1580//#ifdef _DEBUG 
    15741581        Debug << "plane lowest cost: " << lowestCost << endl; 
    1575 #endif 
     1582//#endif 
    15761583 
    15771584        if (lowestCost > mTermMaxCostRatio) 
     
    17161723                        Debug << "vol f " << pFront << " b " << pBack << " p " << pOverall << endl; 
    17171724                        Debug << "real vol f " << pFront << " b " << geomBack.GetVolume() << " p " << pOverall << endl; 
    1718                         Debug << "polys f" << (int)geomFront.mPolys.size() << " b " << (int)geomFront.mPolys.size() << " data " << (int)data.mGeometry->mPolys.size() << endl; 
     1725                        Debug << "polys f " << geomFront.Size() << " b " << geomBack.Size() << " data " << data.mGeometry->Size() << endl; 
    17191726                } 
    17201727 
     
    18071814                                                                  candidatePlane, 
    18081815                                                                  mBox, 
    1809                                                                   0.0000001f); 
     1816                                                                  0.000000001f); 
    18101817                                                                  //mEpsilon); 
    18111818 
     
    18201827                if (1) 
    18211828                { 
    1822                         if (pFront <= 0) 
    1823                         { 
    1824                                 //Debug << "error f: " << pFront << endl; 
    1825                                 return 999; 
    1826                         } 
    1827  
    1828                         if (pBack <= 0)  
    1829                         { 
    1830                                 //Debug << "error b: " << pBack << endl; 
     1829                        if ((pFront <= 0) || (pBack <= 0) ||  
     1830                                !geomFront.Valid() || !geomBack.Valid()) 
     1831                        { 
     1832                                Debug << "error f: " << pFront << " b: " << pBack << endl; 
    18311833                                return 999; 
    18321834                        } 
     
    25272529 
    25282530        PolygonContainer candidatePolys; 
     2531        vector<Plane3> candidatePlanes; 
    25292532 
    25302533        // bounded planes are added to the polygons (reverse polygons 
    2531         // as they have to be outfacing 
     2534        // as they have to be outfacing) 
    25322535        for (int i = 0; i < (int)halfSpaces.size(); ++ i) 
    25332536        { 
     
    25372540                { 
    25382541                        candidatePolys.push_back(p->CreateReversePolygon()); 
     2542                        // Why? 
     2543                        Plane3 candidatePlane = p->GetSupportingPlane(); //halfSpaces[i]; 
     2544                        //candidatePlane.ReverseOrientation(); 
     2545                        candidatePlanes.push_back(candidatePlane); 
     2546 
    25392547                        DEL_PTR(p); 
    25402548                } 
     
    25492557                        vertices.push_back(mBox.GetFace(i).mVertices[j]); 
    25502558 
    2551                 candidatePolys.push_back(new Polygon3(vertices)); 
     2559                Polygon3 *poly = new Polygon3(vertices); 
     2560 
     2561                candidatePolys.push_back(poly); 
     2562                candidatePlanes.push_back(poly->GetSupportingPlane()); 
    25522563        } 
    25532564 
     
    25872598                                        DEL_PTR(backPoly); 
    25882599                                        break; 
     2600 
    25892601                                case Polygon3::BACK_SIDE: 
    25902602                                        DEL_PTR(candidatePolys[i]); 
     
    25992611 
    26002612                if (candidatePolys[i]) 
    2601                         geom.mPolys.push_back(candidatePolys[i]); 
     2613                { 
     2614                        geom.Add(candidatePolys[i], candidatePlanes[i]); 
     2615                        //      geom.mPolys.push_back(candidates[i]); 
     2616                } 
    26022617        } 
    26032618} 
     
    26672682                                        { 
    26682683                                                const int cf = 
    2669                                                         Polygon3::ClassifyPlane(geom->mPolys, 
     2684                                                        Polygon3::ClassifyPlane(geom->GetPolys(), 
    26702685                                                                                                        halfSpaces[i], 
    26712686                                                                                                        mEpsilon); 
     
    26812696                                        // TODO: why is this wrong?? 
    26822697                                        // test all planes of current node if still adjacent 
    2683                                         for (int i = 0; (i < (int)nodeGeom.mPolys.size()) && isAdjacent; ++ i) 
     2698                                        for (int i = 0; (i < nodeGeom.Size()) && isAdjacent; ++ i) 
    26842699                                        { 
    2685                                                 Polygon3 *poly = nodeGeom.mPolys[i]; 
     2700                                                Polygon3 *poly = nodeGeom.GetPolys()[i]; 
    26862701 
    26872702                                                const int cf = 
    2688                                                         Polygon3::ClassifyPlane(geom->mPolys, 
     2703                                                        Polygon3::ClassifyPlane(geom->GetPolys(), 
    26892704                                                                                                        poly->GetSupportingPlane(), 
    26902705                                                                                                        mEpsilon); 
     
    27072722                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    27082723 
    2709                         const int cf = Polygon3::ClassifyPlane(nodeGeom.mPolys, 
     2724                        const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(), 
    27102725                                                                                                   interior->GetPlane(), 
    27112726                                                                                                   mEpsilon); 
     
    27992814                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    28002815 
    2801                         const int cf = Polygon3::ClassifyPlane(nodeGeom.mPolys, 
     2816                        const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(), 
    28022817                                                                                                   interior->GetPlane(), 
    28032818                                                                                                   mEpsilon); 
     
    28702885 
    28712886                        const int cf =  
    2872                                 Polygon3::ClassifyPlane(geom.mPolys, halfspace, mEpsilon); 
     2887                                Polygon3::ClassifyPlane(geom.GetPolys(), halfspace, mEpsilon); 
    28732888 
    28742889                        if (cf == Polygon3::BACK_SIDE) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h

    r676 r678  
    129129                float GetCost() const 
    130130                { 
    131                         //cout << "here " << mPriority << endl; 
     131                        //cout << mPriority << endl; 
    132132                        return mPriority; 
    133133                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp

    r580 r678  
    277277                        } 
    278278 
    279                         ExportPolygons(cell->mPolys); 
     279                        ExportPolygons(cell->GetPolys()); 
    280280                } 
    281281                 
     
    971971                tree.ConstructGeometry(*it, geom); 
    972972                 
    973                 ExportPolygons(geom.mPolys); 
     973                ExportPolygons(geom.GetPolys()); 
    974974        } 
    975975} 
Note: See TracChangeset for help on using the changeset viewer.