Changeset 329


Ignore:
Timestamp:
10/14/05 18:29:26 (19 years ago)
Author:
mattausch
Message:

worked on ray based subdivision

Location:
trunk/VUT
Files:
17 edited

Legend:

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

    r326 r329  
    5656 
    5757Sampling { 
    58         totalSamples    100 
     58        totalSamples    1000000 
    5959        samplesPerPass  20 
    6060} 
    6161 
    6262ViewCells { 
    63         hierarchyType bspTree 
     63        # hierarchy kdTree 
     64        hierarchy bspTree 
     65        # hierarchy sceneDependent 
     66         
    6467        height 5.0 
    6568        maxViewCells 0 
    66         #hierarchyType kdTree 
    67         #hierarchyType sceneDependent 
     69         
    6870#       filename ../data/atlanta/atlanta_viewcells_large.x3d 
    6971#       filename ../data/vienna/viewcells-25-sel.x3d 
     
    7375 
    7476BspTree { 
    75 #       constructionMethod fromRays 
    76 #       constructionMethod fromViewCells 
    77         constructionMethod fromSceneGeometry 
     77        Construction { 
     78                input fromRays 
     79        #       input fromViewCells 
     80        #       input fromSceneGeometry 
     81                samples 50000 
     82                sideTolerance 0.002 
     83        } 
     84 
    7885 
    7986        # random polygon       = 1 
     
    101108        #splitPlaneStrategy 72 
    102109         
    103         splitPlaneStrategy 66 
     110        splitPlaneStrategy 8 
    104111         
    105112        maxCandidates 50 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r321 r329  
    16741674        { 
    16751675                GetVertex(i, vtx); 
    1676                 side[i] = plane.Side(vtx, SIDE_TOLERANCE); 
     1676                side[i] = plane.Side(vtx); 
    16771677                if (side[i] > 0) 
    16781678                        onFrontSide = true; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r321 r329  
    11501150                 "10"); 
    11511151 
    1152   RegisterOption("ViewCells.hierarchyType", 
     1152  RegisterOption("ViewCells.hierarchy", 
    11531153                 optString, 
    1154                  "-view_cells_hierarchy_type", 
     1154                 "-view_cells_hierarchy", 
    11551155                 "bspTree"); 
    11561156 
     
    11651165                 "5.0"); 
    11661166 
    1167   RegisterOption("BspTree.constructionMethod", 
     1167  RegisterOption("BspTree.Construction.input", 
    11681168          optString, 
    1169           "-bsp_construction_method=", 
     1169          "-bsp_construction_input=", 
    11701170          "fromViewCells"); 
     1171   
     1172  RegisterOption("BspTree.Construction.samples", 
     1173          optInt, 
     1174          "-bsp_construction_samples=", 
     1175          "100000"); 
     1176 
     1177  RegisterOption("BspTree.Construction.sideTolerance", 
     1178          optFloat, 
     1179          "-bsp_construction_side_tolerance=", 
     1180          "0.002"); 
     1181 
    11711182 
    11721183  RegisterOption("BspTree.Termination.maxPolygons", 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h

    r311 r329  
    162162   
    163163  void AddPassingRay(const Ray &ray, const int contributions) { 
    164           Debug << "here2" << endl; 
    165164    mPassingRays.AddRay(ray, contributions); 
    166         Debug << "here4" << endl; 
     165        Debug << "adding passing ray" << endl; 
    167166  } 
    168167   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r327 r329  
    66#include "Ray.h" 
    77 
     8float Polygon3::sSideTolerance = 0.002f; 
     9float Polygon3::sSideToleranceSqrt = 0.000004f; 
     10 
    811Polygon3::Polygon3():  
    912mMaterial(NULL), mParent(NULL), mPiercingRays(NULL) 
     
    1518 
    1619Polygon3::Polygon3(MeshInstance *parent):  
    17 mMaterial(NULL), mParent(parent) 
     20mMaterial(NULL), mParent(parent), mPiercingRays(NULL) 
    1821{} 
    1922 
    20 Polygon3::Polygon3(Face *face, Mesh *parentMesh) 
     23Polygon3::Polygon3(Face *face, Mesh *parentMesh): 
     24mMaterial(NULL), mParent(NULL), mPiercingRays(NULL) 
    2125{        
    2226        VertexIndexContainer::iterator it = face->mVertexIndices.begin(); 
     
    5155        Vector3 ptA = mVertices.back(); 
    5256         
    53         int sideA = partition.Side(ptA, SIDE_TOLERANCE); 
     57        int sideA = partition.Side(ptA, sSideTolerance); 
    5458         
    5559        VertexContainer::const_iterator it; 
     
    6064        { 
    6165                Vector3 ptB = *it; 
    62                 int sideB = partition.Side(ptB, SIDE_TOLERANCE); 
     66                int sideB = partition.Side(ptB, sSideTolerance); 
    6367         
    6468                // vertices on different sides => split 
     
    7276                                // test if split point not too close to previous split point 
    7377                                if (!foundSplit ||  
    74                                         (SqrDistance(splitPt, splitPts.back()) > SIDE_TOLERANCE_SQRD)) 
     78                                        (SqrDistance(splitPt, splitPts.back()) > sSideToleranceSqrt)) 
    7579                                { 
    7680                                        // add vertex to both polygons 
     
    9397                                        // test if split point not too close to previous split point 
    9498                                if (!foundSplit ||  
    95                                         (SqrDistance(splitPt, splitPts.back()) > SIDE_TOLERANCE_SQRD)) 
     99                                        (SqrDistance(splitPt, splitPts.back()) > sSideToleranceSqrt)) 
    96100                                { 
    97101                                        // add vertex to both polygons 
     
    151155        for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
    152156        { 
    153                 int side = plane.Side(*it, SIDE_TOLERANCE); 
     157                int side = plane.Side(*it, sSideTolerance); 
    154158                 
    155159                if (side > 0) 
     
    361365void Polygon3::AddPiercingRay(Ray *ray) 
    362366{ 
    363         if (!mPiercingRays) 
    364                 mPiercingRays = new RayContainer(); 
    365         //if (binary_search(mPiercingRays.begin(), mPiercingRays.end(), ray)) return false; 
    366          
    367         mPiercingRays->push_back(ray); 
    368 } 
     367        GetPiercingRays()->push_back(ray); 
     368} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r327 r329  
    104104        /// Rays piercing this polygon 
    105105        RayContainer *mPiercingRays; 
     106 
     107        static float sSideTolerance; 
     108        static float sSideToleranceSqrt; 
    106109}; 
    107110 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r327 r329  
    4848        // parse type of view cells 
    4949        char viewCellsStr[64]; 
    50         environment->GetStringValue("ViewCells.hierarchyType", viewCellsStr); 
     50        environment->GetStringValue("ViewCells.hierarchy", viewCellsStr); 
    5151 
    5252        int vcType = BSP_VIEW_CELLS; 
    5353   
    5454        if (strcmp(viewCellsStr, "bspTree") == 0) 
    55                 vcType = BSP_VIEW_CELLS; 
     55        { 
     56                Debug << "here bsp" << endl; 
     57        mViewCellsType = BSP_VIEW_CELLS; 
     58        } 
    5659        else if (strcmp(viewCellsStr, "kdTree") == 0) 
    57                 vcType = KD_VIEW_CELLS; 
     60                { 
     61                Debug << "here kd" << endl; 
     62        mViewCellsType = KD_VIEW_CELLS; 
     63        } 
    5864        else if (strcmp(viewCellsStr, "sceneDependent") == 0) 
    59                 vcType = SCENE_DEPENDENT; 
     65        { 
     66                //TODO 
     67        } 
    6068        else 
    6169        { 
     
    6472        } 
    6573 
    66         // decide about view cell subdivision type used for preprocessing 
    67         switch (vcType) 
    68         { 
    69         case BSP_VIEW_CELLS: 
    70         case KD_VIEW_CELLS: 
    71                 mViewCellsType = vcType; 
    72                 break; 
    73         case SCENE_DEPENDENT: 
    74                 mViewCellsType = BSP_VIEW_CELLS; // TODO 
    75                 break; 
    76         } 
     74        if (mViewCellsType == KD_VIEW_CELLS) 
     75                Debug << "kdtree" << endl; 
     76        else if (mViewCellsType == BSP_VIEW_CELLS) 
     77                Debug << "bsptree" << endl; 
    7778 
    7879        return true; 
     
    143144} 
    144145 
    145  
    146 bool 
    147 Preprocessor::BuildBspTree() 
    148 { 
    149         DEL_PTR(mBspTree); 
    150          
    151         mBspTree = new BspTree(&mUnbounded); 
    152  
    153         ObjectContainer objects; 
    154         RayContainer *rays = new RayContainer(); 
    155  
    156         switch (BspTree::sConstructionMethod) 
    157         { 
    158         case BspTree::FROM_INPUT_VIEW_CELLS: 
    159                 mBspTree->Construct(mViewCells); 
    160                 break; 
    161         case BspTree::FROM_SCENE_GEOMETRY: 
    162                 DeleteViewCells(); // we generate new view cells 
    163                 mSceneGraph->CollectObjects(&objects); 
    164                 mBspTree->Construct(objects, &mViewCells); 
    165                 break; 
    166         case BspTree::FROM_RAYS: 
    167                 DeleteViewCells(); // we generate new view cells 
    168                 mSceneGraph->CollectObjects(&objects); 
    169                 mBspTree->Construct(rays, &mViewCells); 
    170                 break; 
    171         default: 
    172                 Debug << "Error: Method not available\n"; 
    173                 break; 
    174         } 
    175         return true; 
    176 } 
    177  
    178  
    179  
    180146void 
    181147Preprocessor::KdTreeStatistics(ostream &s) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r321 r329  
    3030        Preprocessor(); 
    3131 
    32    ~Preprocessor(); 
     32   virtual ~Preprocessor(); 
    3333 
    3434  /** Load the input scene.  
     
    7171      entities should be used to drive the heuristical construction (only occluders by default) 
    7272  */ 
    73   virtual bool BuildBspTree(); 
     73  virtual bool BuildBspTree() = 0; 
    7474 
    7575  /** Compute visibility method. This method has to be reimplemented by the actual 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r327 r329  
    1313  environment->GetIntValue("Sampling.samplesPerPass", mSamplesPerPass); 
    1414  environment->GetIntValue("Sampling.totalSamples", mTotalSamples); 
    15    
     15  environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples); 
     16 
    1617  mKdPvsDepth = 100; 
    1718  mStats.open("stats.log"); 
    1819 
     20} 
     21 
     22SamplingPreprocessor::~SamplingPreprocessor() 
     23{ 
     24        // clean up 
     25        if (mSampleRays) 
     26        { 
     27                CLEAR_CONTAINER (*mSampleRays); 
     28                DEL_PTR (mSampleRays); 
     29        } 
    1930} 
    2031 
     
    3849    node = node->mParent; 
    3950  return node; 
     51} 
     52 
     53bool 
     54SamplingPreprocessor::BuildBspTree() 
     55{ 
     56        // delete old tree 
     57        DEL_PTR(mBspTree); 
     58        mBspTree = new BspTree(&mUnbounded); 
     59 
     60        ObjectContainer objects; 
     61         
     62        switch (BspTree::sConstructionMethod) 
     63        { 
     64        case BspTree::FROM_INPUT_VIEW_CELLS: 
     65                mBspTree->Construct(mViewCells); 
     66                break; 
     67        case BspTree::FROM_SCENE_GEOMETRY: 
     68                 
     69                DeleteViewCells(); // we generate new view cells 
     70                mSceneGraph->CollectObjects(&objects); 
     71                mBspTree->Construct(objects, &mViewCells); 
     72                 
     73                break; 
     74        case BspTree::FROM_RAYS: 
     75                DeleteViewCells(); // we generate new view cells 
     76                mSceneGraph->CollectObjects(&objects); 
     77                mBspTree->Construct(mSampleRays, &mViewCells); 
     78                break; 
     79        default: 
     80                Debug << "Error: Method not available\n"; 
     81                break; 
     82        } 
     83         
     84        return true; 
    4085} 
    4186 
     
    106151        // cast ray to KD tree to find intersection with other objects 
    107152        mKdTree->CastRay(ray); 
    108  
     153        cout << "k"; 
    109154        if (mViewCellsType == BSP_VIEW_CELLS) 
    110155        { 
    111156                // cast ray to BSP tree to get intersection with view cells 
    112                 mBspTree->CastRay(ray); 
    113                  
    114                 sampleContributions += AddObjectSamples(object, ray); 
     157                if (mBspTree) 
     158                { 
     159                        cout << "uhhhhhhh year" << endl; 
     160                        mBspTree->CastRay(ray); 
     161                 
     162                        sampleContributions += AddObjectSamples(object, ray); 
    115163                                 
    116                 if (!ray.intersections.empty()) // second intersection found 
    117                 { 
    118                         sampleContributions +=  
    119                                 AddObjectSamples(ray.intersections[0].mObject, ray); 
     164                        if (!ray.intersections.empty()) // second intersection found 
     165                        { 
     166                                sampleContributions +=  
     167                                        AddObjectSamples(ray.intersections[0].mObject, ray); 
     168                        } 
    120169                } 
    121170        } 
    122171        else 
    123172        { 
     173                cout << "z" << endl; 
    124174                if (ray.leaves.size()) { 
    125175                        sampleContributions += AddNodeSamples(object, ray); 
     
    238288  { 
    239289          int idx = Random((int)mViewCells.size()); 
    240           Debug << "output view cell no. " << idx << endl; 
     290          Debug << "output view cell=" << idx << endl; 
    241291          pvsViewCells.push_back(mViewCells[Random((int)mViewCells.size())]); 
    242292  } 
     
    246296 
    247297  vector<Ray> viewCellRays; // used for BSP tree construction 
    248   const int fromRaysBspThresh = 1000; 
     298  
     299  mSampleRays = new RayContainer(); 
     300  //mSampleRays->reserve(mBspConstructionSamples); 
    249301 
    250302  while (totalSamples < mTotalSamples) { 
     
    254306                int index = 0; 
    255307                         
    256                 // construct Bsp tree if not 
    257                 if ((mViewCellsType == Preprocessor::BSP_VIEW_CELLS) && 
    258                         !mBspTree->GetRoot() && (totalSamples >= fromRaysBspThresh)) 
    259                 { 
    260                         BuildBspTree(); 
    261                 } 
    262  
     308                cout << "totalSamples: "  << totalSamples; 
    263309                for (i = 0; i < objects.size(); i++) { 
     310                        printf("\nsampling object %d of %d, samples %d\n", i, (int)objects.size(), passSamples); 
     311 
    264312                        KdNode *nodeToSample = NULL; 
    265313                        Intersectable *object = objects[i]; 
     
    324372                        bool viewcellSample = true; 
    325373                        int sampleContributions; 
     374                         
    326375                        if (viewcellSample) { 
    327376                                nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point)); 
    328377                                 
    329378                                for (int k=0; k < mSamplesPerPass; k++) { 
    330                                          
    331379                                        if (nodeToSample) { 
    332380                                                int maxTries = 5; 
     
    336384                                                         
    337385                                                        if (DotProd(direction, normal) > Limits::Small) 
    338                                                                 break; 
     386                                                                break;                                                   
    339387                                                } 
    340388                                                 
     
    348396                                        // construct a ray 
    349397                                        SetupRay(ray, point, direction); 
    350                                          
     398                                         cout << "s"; 
    351399                                        sampleContributions = CastRay(object, ray); 
    352                                          
     400                                        cout << "r"; 
    353401                                        if (mViewCellsType == BSP_VIEW_CELLS)  
    354402                                        { 
    355403                                                // save rays for bsp tree construction 
    356                                                 if (!mBspTree->GetRoot() && (totalSamples < fromRaysBspThresh)) 
     404                                                if ((BspTree::sConstructionMethod = BspTree::FROM_RAYS) && 
     405                                                        (totalSamples < mBspConstructionSamples)) 
    357406                                                { 
    358                                                         viewCellRays.push_back(ray); 
     407                                                        //cout << "pushing back sampling ray << " << mSampleRays->size() << endl; 
     408                                                        mSampleRays->push_back(new Ray(ray)); 
    359409                                                } 
    360                                                 // check whether we can add this to the rays 
    361                                                 for (int k = 0; k < ray.viewCells.size(); ++ k) 
    362                                                         for (int j = 0; j < (int)pvsViewCells.size(); ++ j)  
    363                                                                 if (pvsViewCells[j] == ray.viewCells[k])  
    364                                                                 { 
    365                                                                         vcRays[j].push_back(ray); 
    366                                                                 } 
     410                                                else 
     411                                                { 
     412                                                        // construct BSP tree using the samples 
     413                                                        if (!mBspTree) 
     414                                                        { 
     415                                                                Debug << "Building bsp tree" << endl; 
     416                                                                BuildBspTree(); 
     417 
     418                                                                CLEAR_CONTAINER (*mSampleRays); 
     419                                                                DEL_PTR (mSampleRays); 
     420                                                        } 
     421                                                        // check whether we can add this to the rays 
     422                                                        for (int k = 0; k < ray.viewCells.size(); ++ k) 
     423                                                                for (int j = 0; j < (int)pvsViewCells.size(); ++ j)  
     424                                                                        if (pvsViewCells[j] == ray.viewCells[k])  
     425                                                                        { 
     426                                                                                vcRays[j].push_back(ray); 
     427                                                                        } 
     428                                                }                                
    367429                                        } 
     430                 
    368431                                } 
    369432                        } else { 
     
    371434                                // get random visible mesh 
    372435                                //                              object->GetRandomVisibleMesh(Plane3(normal, point)); 
    373                                  
    374                                  
    375                         } 
    376                                  
     436                        } 
     437                 
    377438                        // NOTE: should be inside loop 
    378439                        if ( i < pvsOut ) 
    379440                                rays[i].push_back(ray); 
    380                          
     441                 
    381442                        if (!ray.intersections.empty()) { 
    382443                                        // check whether we can add this to the rays 
     
    387448                                } 
    388449                        } 
    389                          
     450                 
    390451                        passSamples++; 
    391                          
     452                 
    392453                        if (sampleContributions) { 
    393454                                passContributingSamples++; 
     
    395456                        } 
    396457                } 
    397                  
     458                cout << "pass samples: " << passSamples << endl; 
    398459                totalSamples += passSamples; 
    399460                 
     
    439500                        << endl; 
    440501        } 
    441    
     502 
    442503        if (mViewCellsType == KD_VIEW_CELLS)     
    443504                cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r308 r329  
    2323  ofstream mStats; 
    2424  ObjectContainer mObjects; 
     25  RayContainer *mSampleRays; 
     26  int mBspConstructionSamples; 
    2527 
    2628  SamplingPreprocessor(); 
     29 
     30  ~SamplingPreprocessor(); 
    2731 
    2832  virtual bool ComputeVisibility(); 
     
    5458        */ 
    5559        int AddObjectSamples(Intersectable *obj, const Ray &ray); 
     60 
     61        bool BuildBspTree(); 
    5662}; 
    5763 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r328 r329  
    286286        return splits; 
    287287} 
     288 
    288289void BspInterior::InheritRays(const Polygon3 &poly,  
    289290                                                      Polygon3 &front_piece,  
     
    427428{        
    428429        std::stack<BspTraversalData> tStack; 
    429                  
    430         // traverse tree or create new one 
    431         BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 
     430         
     431        // traverse existing tree or create new tree 
     432    BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 
    432433 
    433434        tStack.push(BspTraversalData(firstNode, polys, 0, mRootCell, new RayContainer())); 
     
    497498                else // reached leaf => subdivide current viewcell 
    498499                { 
    499                         BspNode *root = Subdivide(tStack, tData);                
    500  
    501                         if (viewCells && root->IsLeaf()) 
    502                         {        
    503                                 // generate new view cell for each leaf 
    504                                 ViewCell *viewCell = new ViewCell(); 
    505                                 viewCells->push_back(viewCell); 
     500                        // root of the new subtree 
     501                        BspNode *subRoot = Subdivide(tStack, tData);             
     502 
     503                        // generate new view cell for each leaf 
     504                        if (viewCells && subRoot->IsLeaf()) 
     505                                GenerateViewCell(dynamic_cast<BspLeaf *>(subRoot), *viewCells); 
     506                } 
     507        } 
     508} 
     509 
     510void BspTree::GenerateViewCell(BspLeaf *leaf, ViewCellContainer &viewCells) const 
     511{ 
     512        ViewCell *viewCell = new ViewCell(); 
     513        viewCells.push_back(viewCell); 
    506514                                 
    507                                 dynamic_cast<BspLeaf *>(root)->SetViewCell(viewCell); 
    508                         } 
    509  
    510                         if (!mRoot) // tree empty => new root 
    511                                 mRoot = root; 
    512                 } 
    513         } 
     515        leaf->SetViewCell(viewCell); 
    514516} 
    515517 
     
    593595 
    594596        // construct tree from the view cell polygons 
    595         Construct(polys, NULL); 
     597        Construct(polys, new RayContainer()); 
    596598} 
    597599 
     
    608610 
    609611        // construct tree from polygon soup 
    610         Construct(polys, NULL, viewCells); 
     612        Construct(polys, new RayContainer(), viewCells); 
    611613} 
    612614 
     
    664666{ 
    665667        std::stack<BspTraversalData> tStack; 
    666          
     668 
    667669        BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell, rays); 
     670 
    668671        tStack.push(tData); 
    669672 
    670673        long startTime = GetTime(); 
    671         Debug << "**** Contructing tree using scene geometry ****\n"; 
     674        cout << "**** Contructing tree using scene geometry ****\n"; 
     675 
    672676        while (!tStack.empty())  
    673677        { 
     
    676680 
    677681                // subdivide leaf node 
    678                 BspNode *root = Subdivide(tStack, tData); 
    679  
    680                 if (viewCells && root->IsLeaf()) 
    681                 {       // generate new view cell for each leaf 
    682                         ViewCell *viewCell = new ViewCell(); 
    683                         viewCells->push_back(viewCell); 
    684  
    685                         dynamic_cast<BspLeaf *>(root)->SetViewCell(viewCell); 
    686                 } 
    687  
    688                 // empty tree => new root corresponding to unbounded space 
    689                 if (!mRoot)  
    690                         mRoot = root; 
    691         } 
    692  
    693         Debug << "**** Finished tree construction ****\n"; 
     682                BspNode *subRoot = Subdivide(tStack, tData); 
     683 
     684                if (viewCells && subRoot->IsLeaf()) 
     685                        GenerateViewCell(dynamic_cast<BspLeaf *>(subRoot), *viewCells); 
     686        } 
     687 
     688        cout << "**** Finished tree construction ****\n"; 
    694689        Debug << "BSP tree contruction time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    695690} 
     
    716711                leaf->ProcessPolygons(tData.mPolygons, sStoreSplitPolys); 
    717712                DEL_PTR(tData.mPolygons); 
    718  
    719                 if (tData.mRays) 
    720                         CLEAR_CONTAINER(*tData.mRays); 
    721713                DEL_PTR(tData.mRays); 
    722714 
     
    724716        } 
    725717 
    726  
    727718        //-- continue subdivision 
     719 
    728720        PolygonContainer coincident; 
    729  
    730         BspSplitData splitData; 
    731                  
    732         splitData.mPolys = tData.mPolygons; 
    733         splitData.mFrontPolys = new PolygonContainer(), 
    734         splitData.mBackPolys = new PolygonContainer(); 
    735         splitData.mCoincident = &coincident; 
    736          
    737         splitData.mRays = tData.mRays; 
    738         splitData.mFrontRays = new RayContainer(); 
    739         splitData.mBackRays = new RayContainer(); 
     721         
     722        PolygonContainer *frontPolys = new PolygonContainer(); 
     723        PolygonContainer *backPolys = new PolygonContainer(); 
     724 
     725        RayContainer *frontRays = new RayContainer(); 
     726        RayContainer *backRays = new RayContainer(); 
     727         
    740728 
    741729        // create new interior node and two leaf nodes 
    742         BspInterior *interior =  
    743                 SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode), splitData); 
     730        BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode),  
     731                                                                                  *tData.mPolygons, 
     732                                                                                  *frontPolys, 
     733                                                                                  *backPolys, 
     734                                                                                   coincident, 
     735                                                                                   *tData.mRays, 
     736                                                                                   *frontRays, 
     737                                                                                   *backRays); 
    744738 
    745739        ViewCell *frontViewCell = mRootCell; 
     
    757751        ExtractViewCells(&backViewCell, 
    758752                                         &frontViewCell, 
    759                                          *splitData.mCoincident, 
     753                                         coincident, 
    760754                                         interior->mPlane, 
    761                                          splitData.mBackPolys->empty(), 
    762                                          splitData.mFrontPolys->empty()); 
     755                                         backPolys->empty(), 
     756                                         frontPolys->empty()); 
    763757         
    764758        // don't need coincident polygons anymore 
     
    767761        // push the children on the stack 
    768762        tStack.push(BspTraversalData(interior->GetBack(),  
    769                                                                  splitData.mBackPolys,  
     763                                                                 backPolys,  
    770764                                                                 tData.mDepth + 1,  
    771765                                                                 backViewCell,  
    772                                                                  splitData.mBackRays)); 
     766                                                                 backRays)); 
    773767 
    774768        tStack.push(BspTraversalData(interior->GetFront(),  
    775                                                                  splitData.mFrontPolys,  
     769                                                                 frontPolys,  
    776770                                                                 tData.mDepth + 1,  
    777771                                                                 frontViewCell,  
    778                                                                  splitData.mFrontRays)); 
     772                                                                 frontRays)); 
    779773 
    780774        // cleanup 
     
    817811 
    818812BspInterior *BspTree::SubdivideNode(BspLeaf *leaf,  
    819                                                                         BspSplitData &splitData) 
     813                                                                        PolygonContainer &polys, 
     814                                                                        PolygonContainer &frontPolys, 
     815                                                                        PolygonContainer &backPolys, 
     816                                                                        PolygonContainer &coincident, 
     817                                                                        RayContainer &rays, 
     818                                                                        RayContainer &backRays, 
     819                                                                        RayContainer &frontRays) 
    820820{ 
    821821        mStat.nodes += 2; 
     
    823823        // select subdivision plane 
    824824        BspInterior *interior =  
    825                 new BspInterior(SelectPlane(leaf, *splitData.mPolys, *splitData.mRays));  
     825                new BspInterior(SelectPlane(leaf, polys, rays));  
    826826 
    827827#ifdef _DEBUG 
    828828        Debug << interior << endl; 
    829829#endif 
    830  
     830         
    831831        // partition rays 
    832         interior->SplitRays(*splitData.mRays,  
    833                                                 *splitData.mFrontRays,  
    834                                                 *splitData.mBackRays); 
    835          
     832        interior->SplitRays(rays, frontRays, backRays); 
     833        Debug << "jdfjfj43" << endl; 
    836834        // split polygons with split plane 
    837         mStat.splits +=interior->SplitPolygons(*splitData.mPolys,  
    838                                                                                *splitData.mFrontPolys,  
    839                                                                        *splitData.mBackPolys,  
    840                                                                        *splitData.mCoincident,  
     835        mStat.splits +=interior->SplitPolygons(polys,  
     836                                                                               frontPolys,  
     837                                                                       backPolys,  
     838                                                                       coincident,  
    841839                                                                       sStoreSplitPolys); 
    842  
    843840        BspInterior *parent = leaf->GetParent(); 
    844841 
    845842        // replace a link from node's parent 
    846         if (parent) 
     843        if (!leaf->IsRoot()) 
    847844        { 
    848845                parent->ReplaceChildLink(leaf, interior); 
    849846                interior->SetParent(parent); 
     847        } 
     848        else // new root 
     849        { 
     850                mRoot = interior; 
    850851        } 
    851852 
     
    11991200        char constructionMethodStr[60]; 
    12001201         
    1201         environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr); 
     1202        environment->GetStringValue("BspTree.Construction.input", constructionMethodStr); 
    12021203 
    12031204        sConstructionMethod = FROM_INPUT_VIEW_CELLS; 
     
    12301231 
    12311232        environment->GetBoolValue("BspTree.storeSplitPolys", sStoreSplitPolys); 
     1233 
     1234        environment->GetFloatValue("BspTree.Construction.sideTolerance", Polygon3::sSideTolerance); 
     1235        Polygon3::sSideToleranceSqrt = Polygon3::sSideTolerance * Polygon3::sSideTolerance; 
    12321236 
    12331237    Debug << "BSP max depth: " << sTermMaxDepth << endl; 
     
    14711475} 
    14721476 
     1477 
    14731478//} // GtpVisibilityPreprocessor 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r328 r329  
    276276                {} 
    277277    }; 
    278  
    279         /** given as argument for a node subdivision. 
    280                 Stores the polyons and rays and the returned  
    281                 front and back fragments. 
    282         */ 
    283         struct BspSplitData 
    284         { 
    285                 PolygonContainer *mPolys; 
    286                 PolygonContainer *mFrontPolys; 
    287                 PolygonContainer *mBackPolys; 
    288                 PolygonContainer *mCoincident; 
    289                 RayContainer *mRays; 
    290                 RayContainer *mBackRays; 
    291                 RayContainer *mFrontRays; 
    292         }; 
    293  
     278         
    294279        typedef std::stack<BspTraversalData> BspTraversalStack; 
    295280 
     
    427412        /** Subdivide leaf. 
    428413                @param leaf the leaf to be subdivided 
    429                 @param splitData data relevant for the splti 
     414                 
     415                @param polys the polygons to be split 
     416                @param frontPolys returns the polygons in front of the split plane 
     417                @param backPolys returns the polygons in the back of the split plane 
     418                 
     419                @param rays the polygons to be filtered 
     420                @param frontRays returns the polygons in front of the split plane 
     421                @param backRays returns the polygons in the back of the split plane 
     422 
    430423                @returns the root of the subdivision 
    431424        */ 
    432425        BspInterior *SubdivideNode(BspLeaf *leaf,  
    433                                                            BspSplitData &splitData); 
     426                                                           PolygonContainer &polys, 
     427                                                           PolygonContainer &frontPolys, 
     428                                                           PolygonContainer &backPolys, 
     429                                                           PolygonContainer &coincident, 
     430                                                           RayContainer &rays, 
     431                                                           RayContainer &backRays, 
     432                                                           RayContainer &frontRays); 
    434433 
    435434        /** Filters polygons down the tree. 
     
    528527 
    529528 
     529        /** Generates new view cell for a leaf and stores it back in the container. 
     530        */ 
     531        void BspTree::GenerateViewCell(BspLeaf *leaf, ViewCellContainer &viewCells) const; 
     532 
    530533        /// Pointer to the root of the tree 
    531534        BspNode *mRoot; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r327 r329  
    615615} 
    616616 
     617 
    617618struct BspSplitData 
    618619{ 
     
    628629        {};      
    629630        BspSplitData(BspNode *node,  
    630                                  vector<Plane3 *> planes,  
    631                                  vector<bool> sides,  
    632                                  bool isFront):  
     631                                vector<Plane3 *> planes,  
     632                                vector<bool> sides,  
     633                                bool isFront):  
    633634        mNode(node), mPlanes(planes),  
    634635        mSides(sides), mIsFront(isFront) 
     
    686687 
    687688                        tData.mPlanes.push_back(interior->GetPlane()); // add plane to split planes 
     689 
    688690                        if (planePoly->Valid()) 
    689691                                polys.push_back(planePoly); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r313 r329  
    7878  static ViewCellContainer foundViewCells; // todo: remove this 
    7979protected: 
     80 
    8081  virtual void 
    8182  ExportSceneNode(SceneGraphNode *node); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/common.h

    r312 r329  
    127127#define MAX_FLOAT  1e30f 
    128128 
    129 // tolerance value for side relation 
    130 #define SIDE_TOLERANCE 0.002f // TODO: Test different values 
    131 #define SIDE_TOLERANCE_SQRD 0.000004f 
     129 
     130// tolerance value for polygon area 
    132131#define AREA_LIMIT 0.0001f 
    133132 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r322 r329  
    4242          !(BspTree::sConstructionMethod == BspTree::FROM_RAYS)) // construct tree later 
    4343  { 
     44          Debug << "do1" << endl; 
    4445          if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS) 
    4546          { 
     
    5657          } 
    5758         
     59          Debug << "do2" << endl; 
    5860          p->BuildBspTree(); 
    5961          p->Export("vc_bsptree.x3d", false, false, true); 
     
    6264          bool exportSplits = false; 
    6365          environment->GetBoolValue("BspTree.exportSplits", exportSplits); 
    64  
     66Debug << "do3" << endl; 
    6567          // export the bsp splits 
    6668          if (exportSplits) 
Note: See TracChangeset for help on using the changeset viewer.