Changeset 327


Ignore:
Timestamp:
10/13/05 17:58:37 (19 years ago)
Author:
mattausch
Message:

worked on the ray based subdivision. finished extracting polygons from rays

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h

    r308 r327  
    2424class Face { 
    2525public: 
    26   Face():mVertexIndices() {} 
     26  Face(): mVertexIndices() {} 
    2727  Face(const int a, const int b, const int c):mVertexIndices(3) { 
    2828    mVertexIndices[0] = a; 
     
    3131  } 
    3232 
    33   Face(const int a, const int b, const int c, const int d):mVertexIndices(4) { 
     33  Face(const int a, const int b, const int c, const int d):  
     34  mVertexIndices(4) { 
    3435    mVertexIndices[0] = a; 
    3536    mVertexIndices[1] = b; 
     
    4142   
    4243  /// list of vertex pointers 
    43   VertexIndexContainer mVertexIndices; 
     44  VertexIndexContainer mVertexIndices;   
    4445}; 
    4546 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h

    r290 r327  
    88class Plane3 { 
    99public: 
     10 
    1011  Vector3 mNormal; 
    1112  float mD; 
     
    2829    mD = -DotProd(normal, point); 
    2930  } 
     31 
     32  // relation of objects with the plane 
     33  enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; 
    3034 
    3135  float Distance(const Vector3 &v) const { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r322 r327  
    132132        int classification = ClassifyPlane(plane); 
    133133         
    134         if (classification == BACK_SIDE) 
     134        if (classification == Plane3::BACK_SIDE) 
    135135                return -1; 
    136         else if (classification == FRONT_SIDE) 
     136        else if (classification == Plane3::FRONT_SIDE) 
    137137                return 1; 
    138138 
     
    161161                if (onFrontSide && onBackSide) // split  
    162162                { 
    163                         return SPLIT; 
     163                        return Plane3::SPLIT; 
    164164                } 
    165165                // 3 vertices enough to decide coincident 
    166166                else if (((++ count) >= 3) && !onFrontSide && !onBackSide) 
    167167                {    
    168                         return COINCIDENT;  
     168                        return Plane3::COINCIDENT;  
    169169                } 
    170170        } 
     
    172172        if (onBackSide) 
    173173        { 
    174                 return BACK_SIDE; 
     174                return Plane3::BACK_SIDE; 
    175175        } 
    176176        else if (onFrontSide) 
    177177        { 
    178                 return FRONT_SIDE; 
    179         } 
    180  
    181         return COINCIDENT; // plane and polygon are coincident 
     178                return Plane3::FRONT_SIDE; 
     179        } 
     180 
     181        return Plane3::COINCIDENT; // plane and polygon are coincident 
    182182} 
    183183 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r321 r327  
    4242                @param splitPts returns the split points 
    4343        */ 
    44         void Polygon3::Split(const Plane3 &partition,  
    45                                                 Polygon3 &front,  
    46                                                 Polygon3 &back,  
    47                                                 VertexContainer &splitPts); 
     44        void Split(const Plane3 &partition,  
     45                          Polygon3 &front,  
     46                          Polygon3 &back,  
     47                          VertexContainer &splitPts); 
    4848 
    4949        /** Returns the area of this polygon. 
    5050        */ 
    5151        float GetArea() const; 
    52  
    53         enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; 
    5452 
    5553        /** Classify polygon with respect to the plane. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r321 r327  
    152152 
    153153        ObjectContainer objects; 
    154         RayContainer rays; 
     154        RayContainer *rays = new RayContainer(); 
    155155 
    156156        switch (BspTree::sConstructionMethod) 
     
    167167                DeleteViewCells(); // we generate new view cells 
    168168                mSceneGraph->CollectObjects(&objects); 
    169                 mBspTree->Construct(objects, rays, &mViewCells); 
     169                mBspTree->Construct(rays, &mViewCells); 
    170170                break; 
    171171        default: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp

    r191 r327  
    11#include "Ray.h" 
    2  
     2#include "Plane3.h" 
    33 
    44// ========================================================= 
     
    158158} 
    159159 
     160int Ray::ClassifyPlane(const Plane3 &plane, float minT, float maxT) 
     161{ 
     162        Vector3 entp = Extrap(minT); 
     163        Vector3 extp = Extrap(maxT); 
     164   
     165        int entSide = plane.Side(entp); 
     166        int extSide = plane.Side(extp); 
     167 
     168        if ((entSide == 0) && (extSide == 0))  
     169        { 
     170                return Plane3::COINCIDENT; 
     171        } 
     172        else if ((entSide <= 0) && (entSide <= 0)) 
     173        { 
     174                return Plane3::BACK_SIDE; 
     175        } 
     176        else if ((entSide >= 0) && (entSide >= 0)) 
     177        { 
     178                return Plane3::FRONT_SIDE; 
     179        } 
     180         
     181        return Plane3::SPLIT; 
     182} 
     183 
    160184ostream & 
    161185operator<<(ostream &s, const PassingRaySet &set) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r308 r327  
    6060  vector<MeshInstance *> meshes; 
    6161  vector<ViewCell *> viewCells; 
    62  
     62   
    6363  // constructors 
    6464  Ray(const Vector3 &wherefrom, 
     
    188188  void SetDepth(int newDepth) { depth = newDepth;} 
    189189   
     190  /** Classifies ray with respect to the plane. 
     191  */ 
     192  int ClassifyPlane(const Plane3 &plane, float minT, float maxT); 
     193 
    190194private: 
    191195  Vector3 loc, dir;             // Describes ray origin and vector 
     
    222226 
    223227  friend class AxisAlignedBox3; 
    224   friend class Plane; 
     228  friend class Plane3; 
    225229 
    226230  // for CKDR GEMS 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r322 r327  
    114114                sampleContributions += AddObjectSamples(object, ray); 
    115115                                 
    116                 if (ray.intersections.size() > 0) // second intersection found 
     116                if (!ray.intersections.empty()) // second intersection found 
    117117                { 
    118118                        sampleContributions +=  
     
    379379                                rays[i].push_back(ray); 
    380380                         
    381                         if (ray.intersections.size()) { 
     381                        if (!ray.intersections.empty()) { 
    382382                                        // check whether we can add this to the rays 
    383383                                for (int j = 0; j < pvsOut; j++) { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r326 r327  
    1212#include <iomanip> 
    1313#include "Exporter.h" 
     14#include "Plane3.h" 
    1415 
    1516int BspTree::sTermMaxPolygons = 10; 
     
    160161{ 
    161162        Polygon3 *splitPoly = NULL; 
     163 
    162164#ifdef _Debug 
    163165        Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 
     
    170172                //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 
    171173 
    172                 // get polygon classification 
     174                // classify polygon 
    173175                int classification = poly->ClassifyPlane(mPlane); 
    174176 
     
    180182                switch (classification) 
    181183                { 
    182                         case Polygon3::COINCIDENT: 
     184                        case Plane3::COINCIDENT: 
    183185                                coincident.push_back(poly); 
    184186                                break;                   
    185                         case Polygon3::FRONT_SIDE:       
     187                        case Plane3::FRONT_SIDE:         
    186188                                frontPolys.push_back(poly); 
    187189                                break; 
    188                         case Polygon3::BACK_SIDE: 
     190                        case Plane3::BACK_SIDE: 
    189191                                backPolys.push_back(poly); 
    190192                                break; 
    191                         case Polygon3::SPLIT: 
     193                        case Plane3::SPLIT: 
    192194                                front_piece = new Polygon3(poly->mParent); 
    193195                                back_piece = new Polygon3(poly->mParent); 
     
    505507        mStat.polys = AddToPolygonSoup(viewCells, *polys); 
    506508 
    507         // construct tree from viewcell polygons 
    508         Construct(polys); 
     509        // construct tree from the view cell polygons 
     510        Construct(polys, NULL); 
    509511} 
    510512 
     
    521523 
    522524        // construct tree from polygon soup 
    523         Construct(polys, viewCells); 
    524 } 
    525  
    526 void BspTree::Construct(const ObjectContainer &objects, 
    527                                                 const RayContainer &rays,  
     525        Construct(polys, NULL, viewCells); 
     526} 
     527 
     528void BspTree::Construct(RayContainer *rays,  
    528529                                                ViewCellContainer *viewCells) 
    529530{ 
    530531        PolygonContainer *polys = new PolygonContainer(); 
    531532         
    532         // copy mesh instance polygons into one big polygon soup 
    533         mStat.polys = AddToPolygonSoup(objects, *polys); 
    534  
    535         RayContainer::const_iterator rit, rit_end = rays.end(); 
     533        RayContainer::const_iterator rit, rit_end = rays->end(); 
    536534 
    537535        long startTime = GetTime(); 
    538         Debug << "**** Casting rays into polygons ****\n"; 
    539  
    540         //-- cast rays into all polygons 
    541         for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     536        Debug << "**** Extracting polygons from rays ****\n"; 
     537 
     538        std::map<Face *, Polygon3 *> facePolyMap; 
     539 
     540        //-- extract polygons from faces stored in the rays 
     541        for (rit = rays->begin(); rit != rit_end; ++ rit) 
    542542        { 
    543543                Ray *ray = *rit; 
    544  
    545                 PolygonContainer::const_iterator pit, pit_end = polys->end(); 
    546                  
    547                 for (pit = polys->begin(); pit != pit_end; ++ pit) 
    548                 { 
    549                         Polygon3 *poly = *pit; 
     544         
     545                for (int i = 0; i < (int)ray->intersections.size(); ++ i) 
     546                { 
     547                        MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->intersections[i].mObject); 
     548                        Face *face = obj->GetMesh()->mFaces[i]; 
    550549                         
    551                         float t = 0; 
    552                         float nearestT = 0; 
    553  
    554                         if (poly->CastRay(*ray, t, nearestT) > 0) 
    555                                 poly->AddPiercingRay(ray); 
    556                 } 
    557         } 
    558  
    559         Debug << "**** Finished ray casting ****\n"; 
     550                         std::map<Face *, Polygon3 *>::iterator it= facePolyMap.find(face); 
     551 
     552                         if (it != facePolyMap.end())  
     553                         { 
     554                                 (*it).second->AddPiercingRay(ray); 
     555                         }  
     556                         else 
     557                         { 
     558                                 Polygon3 *poly = new Polygon3(face, obj->GetMesh()); 
     559                                 polys->push_back(poly); 
     560                                 poly->AddPiercingRay(ray); 
     561 
     562                                 facePolyMap[face] = poly; 
     563                         } 
     564                } 
     565        } 
     566 
     567         
     568        mStat.polys = (int)polys->size(); 
     569 
     570        Debug << "**** Finished polygon extraction ****\n"; 
    560571        Debug << "ray casting time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    561572 
    562         Construct(polys, viewCells); 
    563 } 
    564  
    565 void BspTree::Construct(PolygonContainer *polys, ViewCellContainer *viewCells) 
     573        Construct(polys, rays, viewCells); 
     574} 
     575 
     576void BspTree::Construct(PolygonContainer *polys, RayContainer *rays, ViewCellContainer *viewCells) 
    566577{ 
    567578        std::stack<BspTraversalData> tStack; 
    568579         
    569         BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell); 
     580        BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell, rays); 
    570581        tStack.push(tData); 
    571582 
     
    670681                RayContainer *backRays = new RayContainer(); 
    671682 
    672                 Plane3 plane; 
    673                 SplitRays(plane, *tData.mRays, *frontRays, *backRays); 
     683                SplitRays(interior->mPlane, *tData.mRays, *frontRays, *backRays); 
    674684        } 
    675685 
     
    10221032                if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 
    10231033                { 
    1024                         if (classification == Polygon3::COINCIDENT) 
     1034                        if (classification == Plane3::COINCIDENT) 
    10251035                                sumPolyArea += (*it)->GetArea(); 
    10261036                        //totalArea += area; 
     
    10311041                { 
    10321042                        float blockedRays = (float)(*it)->GetPiercingRays()->size(); 
    1033                         if (classification == Polygon3::COINCIDENT) 
     1043                        if (classification == Plane3::COINCIDENT) 
    10341044                        { 
    10351045                                sumBlockedRays += blockedRays; 
     
    10441054                        MeshInstance *viewCell = (*it)->mParent; 
    10451055                 
    1046                         if (classification == Polygon3::FRONT_SIDE) 
     1056                        if (classification == Plane3::FRONT_SIDE) 
    10471057                                frontViewCells.push_back(viewCell); 
    1048                         else if (viewCell && (classification == Polygon3::BACK_SIDE)) 
     1058                        else if (viewCell && (classification == Plane3::BACK_SIDE)) 
    10491059                                backViewCells.push_back(viewCell); 
    10501060                } 
     
    12491259 
    12501260        // bound ray 
    1251         if ((ray.GetType() == Ray::LOCAL_RAY)   &&  
    1252                 ((int)ray.intersections.size() > 0) && 
     1261        if ((ray.GetType() == Ray::LOCAL_RAY) &&  
     1262                (!ray.intersections.empty())      && 
    12531263            (ray.intersections[0].mT <= maxt)) 
    12541264        { 
     
    13831393} 
    13841394 
     1395 
    13851396void BspTree::SplitRays(const Plane3 plane, 
    1386                                                 RayContainer &rays,  
    1387                                                 RayContainer &frontRays,  
    1388                                                 RayContainer &backRays) 
     1397                                           RayContainer &rays,  
     1398                                           RayContainer &frontRays,  
     1399                                           RayContainer &backRays) 
    13891400{ 
    13901401        while (!rays.empty()) 
    13911402        { 
    1392                 //TODO 
     1403                Ray *ray = rays.back(); 
     1404                rays.pop_back(); 
     1405 
     1406                //-- ray-plane intersection 
     1407                float maxT = 1e6; 
     1408                float minT = 0; 
     1409         
     1410                // test with tree bounding box 
     1411                if (!mBox.GetMinMaxT(*ray, &minT, &maxT)) 
     1412                        continue; 
     1413 
     1414                if (minT < 0) // start ray from origin 
     1415                        minT = 0; 
     1416 
     1417                // bound ray 
     1418                if ((ray->GetType() == Ray::LOCAL_RAY) &&  
     1419                        (ray->intersections.empty())      && 
     1420                        (ray->intersections[0].mT <= maxT)) 
     1421                { 
     1422                        maxT = ray->intersections[0].mT; 
     1423                } 
     1424                 
     1425                int classification = ray->ClassifyPlane(plane, minT, maxT); 
     1426                 
     1427                switch (classification) 
     1428                { 
     1429                case Plane3::COINCIDENT: 
     1430                        break; 
     1431                case Plane3::BACK_SIDE: 
     1432                        backRays.push_back(ray); 
     1433                        break; 
     1434                case Plane3::FRONT_SIDE: 
     1435                        frontRays.push_back(ray); 
     1436                        break; 
     1437                case Plane3::SPLIT: 
     1438                        frontRays.push_back(ray); 
     1439                        backRays.push_back(ray); 
     1440                        //extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 
     1441                        break; 
     1442                default: 
     1443                        break; 
     1444                } 
    13931445        } 
    13941446} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r325 r327  
    287287        void Construct(const ObjectContainer &objects, ViewCellContainer *viewCells); 
    288288 
    289         /** Constructs the tree from the given list of polygons. 
    290                 @param viewCells if not NULL, new view cells are  
    291                 created in the leafs and stored in the conatainer 
    292         */ 
    293         void Construct(PolygonContainer *polys, ViewCellContainer *viewCells = NULL); 
    294          
    295         /** Constructs the tree from a list of scene geometry and a  
    296                 given bundle of rays. 
    297                 @param objects list of objects 
     289        /** Constructs the tree from  a given bundle of rays. 
    298290                @param rays the bundle of sample rays 
    299291                @param viewCells if not NULL, new view cells are  
    300292                created in the leafs and stored in the conatainer 
    301293        */ 
    302         void Construct(const ObjectContainer &objects, 
    303                                    const RayContainer &rays,  
     294        void Construct(RayContainer *rays,  
    304295                                   ViewCellContainer *viewCells = NULL); 
    305296 
     
    353344        }; 
    354345 
    355         /** Evaluates the contribution of the candidate split plane. 
    356                 @note the polygons can be reordered in the process. 
    357                 @returns the cost of the candidate split plane 
    358         */ 
    359         float SplitPlaneCost(PolygonContainer &polys,  
    360                                                  const Plane3 &candidatePlane, 
    361                                                  const RayContainer &rays); 
    362346 
    363347        /** Evaluates tree stats in the BSP tree leafs. 
     
    371355        */ 
    372356        BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData); 
     357 
     358        /** Constructs the tree from the given list of polygons. 
     359                @param rayContainer stores bundle of rays on which subdivision may be based 
     360                @param viewCells if not NULL, new view cells are  
     361                created in the leafs and stored in the conatainer 
     362        */ 
     363        void Construct(PolygonContainer *polys, RayContainer *rays, ViewCellContainer *viewCells = NULL); 
    373364 
    374365        /** Selects the best possible splitting plane.  
     
    381372                                           PolygonContainer &polys, 
    382373                                           const RayContainer &ray); 
     374 
     375        /** Evaluates the contribution of the candidate split plane. 
     376                @note the polygons can be reordered in the process. 
     377                @returns the cost of the candidate split plane 
     378        */ 
     379        float SplitPlaneCost(PolygonContainer &polys,  
     380                                                 const Plane3 &candidatePlane, 
     381                                                 const RayContainer &rays); 
    383382 
    384383        /** Filters next view cell down the tree and inserts it into the appropriate leaves 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r322 r327  
    667667                                Polygon3 *backPoly = new Polygon3(); 
    668668 
    669                                 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 
     669                                if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Plane3::SPLIT) 
    670670                                { 
    671671                                        planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 
Note: See TracChangeset for help on using the changeset viewer.