Changeset 312


Ignore:
Timestamp:
10/09/05 00:38:18 (19 years ago)
Author:
mattausch
Message:

bsp split exporter added

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
22 edited

Legend:

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

    r310 r312  
    99#       filename vienna.x3d 
    1010#       filename ../data/vienna/vienna-simple.x3d 
    11         filename ../data/vienna/vienna-buildings.x3d 
     11#       filename ../data/vienna/vienna-buildings.x3d 
    1212#       filename ../data/vienna/viewcells-25-sel.x3d 
    13 #       filename ../data/atlanta/atlanta2.x3d 
     13        filename ../data/atlanta/atlanta2.x3d 
    1414#       filename ../data/soda/soda.dat 
    1515#       filename ../data/soda/soda5.dat 
     
    5656 
    5757Sampling { 
    58         totalSamples    1000000 
    59         samplesPerPass  5 
     58        totalSamples    100000 
     59        samplesPerPass  10 
    6060} 
    6161 
    6262ViewCells { 
    6363        hierarchyType bspTree 
     64        height 5.0 
    6465        #hierarchyType kdTree 
    6566        #hierarchyType sceneDependent 
    6667#       filename ../data/atlanta/atlanta_viewcells_large.x3d 
    67 #       filename ../data/atlanta/atlanta_viewcells_large2.x3d 
    6868        filename ../data/vienna/viewcells-25-sel.x3d 
    6969#       filename ../data/vienna/viewcells-25.x3d 
     
    8484        # vertical axis        = 64 
    8585         
    86         splitPlaneStrategy 66 
     86        splitPlaneStrategy 8 
    8787        # least splits + balanced polygons 
    8888        #splitPlaneStrategy 12 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r302 r312  
    125125    b->SetValue(mMax.x, mMin.y, mMax.z); 
    126126    break; 
     127  } 
     128} 
     129 
     130// returns the vertex indices in the range <0..7>, v = 4.x + 2.y + z, where 
     131// x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate) 
     132void 
     133AxisAlignedBox3::GetEdge(const int edge, int  &aIdx, int &bIdx) const 
     134{ 
     135  switch(edge) { 
     136  case 0: aIdx = 0; bIdx = 1; break; 
     137  case 1: aIdx = 0; bIdx = 2; break; 
     138  case 2: aIdx = 0; bIdx = 4; break; 
     139  case 3: aIdx = 7; bIdx = 6; break; 
     140  case 4: aIdx = 7; bIdx = 5; break; 
     141  case 5: aIdx = 7; bIdx = 3; break; 
     142  case 6: aIdx = 1; bIdx = 3; break; 
     143  case 7: aIdx = 1; bIdx = 5; break; 
     144  case 8: aIdx = 2; bIdx = 3; break; 
     145  case 9: aIdx = 2; bIdx = 6; break; 
     146  case 10: aIdx = 4; bIdx = 6; break; 
     147  case 11: aIdx = 4; bIdx = 5; break; 
    127148  } 
    128149} 
     
    10231044}; 
    10241045 
     1046 
    10251047// The fast computation of arctangent .. the maximal error is less 
    10261048// than 4.1 degrees, according to Graphics GEMSII, 1991, pages 389--391 
     
    16241646  return Rectangle3(v[0], v[1], v[2], v[3]); 
    16251647} 
     1648/* 
     1649const int AxisAlignedBox3::complEdgeTbl[12][3] = 
     1650{ 
     1651        {3, 4, 5}, 
     1652        {3, 4, 5}, 
     1653        {3, 4, 5}, 
     1654        {0, 1, 2}, 
     1655        {0, 1, 2}, 
     1656        {0, 1, 2}, 
     1657        {9, 10, 11}, 
     1658        {8, 9, 10}, 
     1659        {7, 10, 11}, 
     1660        {6, 7, 11}, 
     1661        {6, 7, 8}, 
     1662        {6, 8, 9}, 
     1663}; 
     1664*/ 
     1665// TODO: use a table to avoid normal and distance computations 
     1666Polygon3 *AxisAlignedBox3::BoundPlane(const Plane3 &plane) 
     1667{ 
     1668        Vector3 ptA, ptB; 
     1669        int sideA = 0, sideB = 0; 
     1670 
     1671        VertexContainer vertices; 
     1672 
     1673        int side[8]; 
     1674 
     1675        bool onFrontSide, onBackSide = false; 
     1676 
     1677        Vector3 vtx; 
     1678        for (int i = 0; i < 8; ++i) 
     1679        { 
     1680                GetVertex(i, vtx); 
     1681                side[i] = plane.Side(vtx, SIDE_TOLERANCE); 
     1682                if (side[i] > 0) 
     1683                        onFrontSide = true; 
     1684                else if (side[i] < 0) 
     1685                        onBackSide = true; 
     1686                else // vertex coincident => push_back 
     1687                        vertices.push_back(vtx); 
     1688        } 
     1689 
     1690        // does not intersect 
     1691        if (!onFrontSide && !onBackSide) 
     1692                return NULL; 
     1693 
     1694        for (int i = 0; i < 12; ++ i) 
     1695        { 
     1696                int aIdx, bIdx; 
     1697                GetEdge(i, aIdx, bIdx); 
     1698 
     1699                ptA = GetVertex(aIdx); 
     1700                ptB = GetVertex(bIdx); 
     1701 
     1702                int sideA = side[aIdx]; 
     1703                int sideB = side[bIdx]; 
     1704 
     1705                if (((sideA > 0) && (sideB < 0)) || (sideA < 0) && (sideB > 0)) 
     1706                        vertices.push_back(plane.FindIntersection(ptA, ptB));    
     1707        } 
     1708 
     1709        if (vertices.size() == 4) 
     1710        { 
     1711                float maxDist = 0; 
     1712                int maxIdx = 0; 
     1713 
     1714                for (int i = 1; i < 4; ++ i) 
     1715                { 
     1716                        float dist = SqrDistance(vertices[0], vertices[i]); 
     1717                        if (dist > maxDist) 
     1718                        { 
     1719                                maxDist = dist; 
     1720                                maxIdx = i; 
     1721                        } 
     1722                } 
     1723                // illformed polygon = swap 
     1724                if ((maxIdx == 1) || (maxIdx == 3) ) 
     1725                { 
     1726                        Vector3 vtx = vertices[maxIdx]; 
     1727                        vertices[maxIdx] = vertices[2]; 
     1728                        vertices[2] = vtx; 
     1729                } 
     1730        } 
     1731 
     1732        // wrong surface orientation? 
     1733    Vector3 norm = Normalize(CrossProd(vertices[0] - vertices[1], 
     1734                                                                           vertices[2] - vertices[1])); 
     1735 
     1736        Polygon3 *planePoly = new Polygon3(); 
     1737 
     1738        if (DotProd(norm, plane.mNormal) > 0) 
     1739                for (int i = 0; i < (int)vertices.size(); ++ i) 
     1740                        planePoly->mVertices.push_back(vertices[i]); 
     1741        else 
     1742        { 
     1743                for (int i = (int)vertices.size() - 1; i >= 0; -- i) 
     1744                        planePoly->mVertices.push_back(vertices[i]); 
     1745        } 
     1746 
     1747        //Debug << *planePoly << "\narea: " << planePoly->GetArea() << endl; 
     1748         
     1749        return planePoly; 
     1750} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h

    r302 r312  
    77#include "Plane3.h" 
    88 
    9 class Plane3; 
    109class Ray; 
    1110class Polygon3; 
     
    302301  float ProjectToSphereSA(const Vector3 &viewpoint, int *tcase) const; 
    303302 
     303  /** Returns vertex indices of edge. 
     304  */ 
     305  void GetEdge(const int edge, int  &aIdx, int &bIdx) const; 
     306 
     307  /** Bounds plane with box. Returns polygon resulting from the bounded 
     308          plane. 
     309  */ 
     310  Polygon3 *BoundPlane(const Plane3 &plane); 
    304311 
    305312#define __EXTENT_HACK 
     
    353360  static const int fsvertices[27][9]; 
    354361 
     362  // table storing the complementary edges of each edge 
     363  //static const int complEdgeTbl[12][3]; 
     364 
    355365  // input and output operator with stream 
    356366  friend ostream& operator<<(ostream &s, const AxisAlignedBox3 &A); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h

    r308 r312  
    2424    mWidth = 640; 
    2525    mHeight = 480; 
    26     mFovy = 60*M_PI/180.0f; 
     26    mFovy = 60.0*M_PI/180.0; 
    2727  } 
    2828   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r311 r312  
    11601160                 "atlanta_viewcells_large.x3d"); 
    11611161 
     1162   RegisterOption("ViewCells.height", 
     1163                 optFloat, 
     1164                 "-view_cells_height=", 
     1165                 "5.0"); 
    11621166 
    11631167  RegisterOption("BspTree.constructionMethod", 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r261 r312  
    5656  virtual void  
    5757  ExportViewCells(ViewCellContainer *viewCells) = 0; 
    58  
     58  virtual void  
     59  ExportViewCell(ViewCell *viewCell) = 0; 
    5960  virtual void 
    6061  ExportIntersectable(Intersectable *object) = 0; 
     62 
     63  virtual void ExportBspSplits(const BspTree &tree) = 0; 
    6164 
    6265  void SetExportRayDensity(const bool d) { mExportRayDensity = d; } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r308 r312  
    55#include "AxisAlignedBox3.h" 
    66 
    7 // tolerance value for side relation 
    8 #define SIDE_TOLERANCE 0.002f // TODO: Test different values 
    9 #define SIDE_TOLERANCE_SQRD 0.000004f 
    10 #define AREA_LIMIT 0.0001f 
    11  
    127Polygon3::Polygon3(): mMaterial(NULL), mParent(NULL) 
    138{} 
     
    1712 
    1813Polygon3::Polygon3(MeshInstance *parent): mMaterial(NULL), mParent(parent) 
    19 { 
    20 } 
     14{} 
     15 
     16 
    2117Polygon3::Polygon3(Face *face, Mesh *parentMesh) 
    2218{        
     
    4137Vector3 Polygon3::GetNormal() const  
    4238{ 
    43     return Normalize(CrossProd(mVertices[0]-mVertices[1], 
    44                                                            mVertices[2]-mVertices[1])); 
    45 } 
    46  
    47 void Polygon3::Split(Plane3 *partition, Polygon3 *front, Polygon3 *back) 
     39    return Normalize(CrossProd(mVertices[0] - mVertices[1], 
     40                                                           mVertices[2] - mVertices[1])); 
     41} 
     42 
     43void Polygon3::Split(const Plane3 &partition,  
     44                                         Polygon3 &front,  
     45                                         Polygon3 &back,  
     46                                         VertexContainer &splitPts) 
    4847{ 
    4948        Vector3 ptA = mVertices.back(); 
    5049         
    51         int sideA = partition->Side(ptA, SIDE_TOLERANCE); 
     50        int sideA = partition.Side(ptA, SIDE_TOLERANCE); 
    5251         
    5352        VertexContainer::const_iterator it; 
    54         bool foundSplit = false; 
    55  
    56         Vector3 prevSplitPt(ptA); 
    57  
     53         
    5854        // find line - plane intersections 
    5955        for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
    6056        { 
    6157                Vector3 ptB = *it; 
    62                 int sideB = partition->Side(ptB, SIDE_TOLERANCE); 
     58                int sideB = partition.Side(ptB, SIDE_TOLERANCE); 
    6359         
    6460                // vertices on different sides => split 
     
    6864                        { 
    6965                                //-- plane - line intersection 
    70                                 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 
     66                                Vector3 splitPt = partition.FindIntersection(ptA, ptB); 
    7167                         
    72                                 if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 
     68                                // test if split point not too close to previous split point 
     69                                if ((splitPts.size() == 0) ||  
     70                                        (SqrDistance(splitPt, splitPts.back()) > SIDE_TOLERANCE_SQRD)) 
    7371                                { 
    7472                                        // add vertex to both polygons 
    75                                         front->mVertices.push_back(splitPt); 
    76                                         back->mVertices.push_back(splitPt); 
    77  
    78                                         foundSplit = true; 
    79                                         prevSplitPt = splitPt; 
     73                                        front.mVertices.push_back(splitPt); 
     74                                        back.mVertices.push_back(splitPt); 
     75                                         
     76                                        splitPts.push_back(splitPt); 
    8077                                } 
    8178                        } 
    82                         front->mVertices.push_back(ptB); 
     79                        front.mVertices.push_back(ptB); 
    8380                } 
    8481                else if (sideB < 0) 
     
    8784                        { 
    8885                                //-- plane - line intersection 
    89                                 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 
    90                          
    91                                 if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 
     86                                Vector3 splitPt = partition.FindIntersection(ptA, ptB); 
     87                                // test if split point not too close to other split point 
     88                                        // test if split point not too close to previous split point 
     89                                if ((splitPts.size() == 0) ||  
     90                                        (SqrDistance(splitPt, splitPts.back()) > SIDE_TOLERANCE_SQRD)) 
    9291                                { 
    9392                                        // add vertex to both polygons 
    94                                         front->mVertices.push_back(splitPt); 
    95                                         back->mVertices.push_back(splitPt); 
    96  
    97                                         foundSplit = true; 
    98                                         prevSplitPt = splitPt; 
     93                                        front.mVertices.push_back(splitPt); 
     94                                        back.mVertices.push_back(splitPt); 
     95 
     96                                        splitPts.push_back(splitPt); 
    9997                                }        
    10098                        } 
    101                         back->mVertices.push_back(ptB); 
     99                        back.mVertices.push_back(ptB); 
    102100                } 
    103101                else 
    104102                { 
    105103                        // vertex on plane => add vertex to both polygons 
    106                         front->mVertices.push_back(ptB); 
    107                         back->mVertices.push_back(ptB);  
     104                        front.mVertices.push_back(ptB); 
     105                        back.mVertices.push_back(ptB);  
    108106                } 
    109107         
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r308 r312  
    2525        Polygon3(const VertexContainer &vertices); 
    2626        Polygon3(MeshInstance *parent); 
    27  
     27         
    2828        /** Copies all the vertices of the face. 
    2929        */ 
     
    3636        /** Splits polygon. 
    3737                @param partition the split plane 
    38                 @param front the front polygon 
    39                 @param back the back polygon 
     38                @param front returns the front the front polygon 
     39                @param back returns the back polygon 
     40                @param splitPts returns the split points 
    4041        */ 
    41         void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back); 
     42        void Polygon3::Split(const Plane3 &partition,  
     43                                                 Polygon3 &front,  
     44                                                 Polygon3 &back,  
     45                                                 VertexContainer &splitPts); 
    4246 
    4347        /** Returns the area of this polygon. 
     
    6973        bool Valid() const;  
    7074 
     75        /** Returns the surface normal. 
     76        */ 
    7177        Vector3 GetNormal() const; 
    7278 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r310 r312  
    2727Preprocessor::LoadViewCells(const string filename) 
    2828{ 
    29         return X3dParser().ParseFile(filename, mViewCells); 
     29        X3dParser parser; 
     30        environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 
     31          
     32        return parser.ParseFile(filename, mViewCells); 
    3033} 
    3134 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r311 r312  
    9898 
    9999typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap; 
     100typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ViewCellPvsMap; 
     101typedef PvsData<Intersectable *> ViewCellPvsData; 
    100102typedef PvsData<KdNode *> KdPvsData; 
    101  
    102103//typedef Pvs<KdNode *> KdPvs; 
    103104typedef Pvs<Intersectable *> ViewCellPvs; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r311 r312  
    243243                        Intersectable *object = objects[i]; 
    244244                 
    245                         int pvsSize = object->mKdPvs.GetSize(); 
    246                          
     245                        int pvsSize = 0; 
     246                        if (mViewCellsType == KD_VIEW_CELLS) 
     247                                pvsSize = object->mKdPvs.GetSize(); 
     248                                                 
    247249                        if (0 && pvsSize) { 
    248250                                // mail all nodes from the pvs 
     
    407409    exporter->SetExportRayDensity(true); 
    408410    exporter->ExportKdTree(*mKdTree); 
     411 
    409412        if (mViewCellsType == BSP_VIEW_CELLS)    
    410413                exporter->ExportBspTree(*mBspTree); 
     
    429432 
    430433  if (1) { 
     434         
     435      if (mViewCellsType == BSP_VIEW_CELLS) 
     436          { 
     437                   int limit = Min((int)mViewCells.size(), 1); 
     438 
     439                   //char s[64]; sprintf(s, "bsp-pvs%04d.x3d", k); 
     440                   Exporter *exporter = Exporter::GetExporter("bsp-pvs.x3d"); 
     441                   exporter->SetFilled(); 
     442 
     443                   Intersectable::NewMail(); 
     444 
     445                   for (int j = 0; j < limit; ++ j) 
     446                   {                    
     447                           // j random view cells 
     448                           int k = Random((int)mViewCells.size()); 
     449 
     450                           Debug << "next vc: " << k << endl; 
     451                           ViewCellPvsMap::iterator it = mViewCells[k]->GetPvs().mEntries.begin(); 
     452 
     453                           Material m;//= RandomMaterial(); 
     454                           m.mDiffuseColor = RgbColor(0, 1, 0); 
     455                           exporter->SetForcedMaterial(m); 
     456 
     457                           exporter->ExportViewCell(mViewCells[k]); 
     458 
     459                           m.mDiffuseColor = RgbColor(1, 0, 0); 
     460                           exporter->SetForcedMaterial(m); 
     461 
     462                           Debug << "pvs size: " << mViewCells[k]->GetPvs().GetSize() << " of " << objects.size() << endl; 
     463 
     464                           for (; it != mViewCells[k]->GetPvs().mEntries.end(); ++ it)  
     465                           { 
     466                                   Intersectable *intersect = (*it).first; 
     467                                   if (!intersect->Mailed()) 
     468                                   { 
     469                                           exporter->ExportIntersectable(intersect); 
     470                                           intersect->Mail(); 
     471                                   } 
     472                            
     473                           } 
     474                   } 
     475                         
     476                   // output rest of the objects 
     477                   Material m;//= RandomMaterial(); 
     478                   m.mDiffuseColor = RgbColor(0, 0, 1); 
     479                   exporter->SetForcedMaterial(m); 
     480 
     481                   for (int j = 0; j < objects.size(); ++ j) 
     482                           if (!objects[j]->Mailed()) 
     483                           { 
     484                                   exporter->ExportIntersectable(objects[j]); 
     485                                   objects[j]->Mail(); 
     486                           } 
     487 
     488                   DEL_PTR(exporter); 
     489          }        
     490 
    431491    for (int k=0; k < pvsOut; k++) { 
    432492      Intersectable *object = objects[k]; 
     
    436496      exporter->SetWireframe(); 
    437497 
    438           if (mViewCellsType == BSP_VIEW_CELLS) 
     498         
     499          KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
     500          Intersectable::NewMail(); 
     501                   
     502          // avoid adding the object to the list 
     503          object->Mail(); 
     504          ObjectContainer visibleObjects; 
     505 
     506          for (; i != object->mKdPvs.mEntries.end(); i++)  
    439507          { 
    440  
     508                  KdNode *node = (*i).first; 
     509                  exporter->ExportBox(mKdTree->GetBox(node)); 
     510                  mKdTree->CollectObjects(node, visibleObjects); 
    441511          } 
    442           else 
    443           { 
    444                   KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    445                   Intersectable::NewMail(); 
    446                    
    447                   // avoid adding the object to the list 
    448                   object->Mail(); 
    449                   ObjectContainer visibleObjects; 
    450  
    451                   for (; i != object->mKdPvs.mEntries.end(); i++)  
    452                   { 
    453                           KdNode *node = (*i).first; 
    454                           exporter->ExportBox(mKdTree->GetBox(node)); 
    455                           mKdTree->CollectObjects(node, visibleObjects); 
    456                   } 
    457  
    458                   exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 
    459                   exporter->SetFilled(); 
    460  
    461                   for (int j = 0; j < visibleObjects.size(); j++) 
    462                           exporter->ExportIntersectable(visibleObjects[j]); 
     512 
     513          exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 
     514          exporter->SetFilled(); 
     515 
     516          for (int j = 0; j < visibleObjects.size(); j++) 
     517                  exporter->ExportIntersectable(visibleObjects[j]); 
    463518         
    464519 
    465                   Material m; 
    466               m.mDiffuseColor = RgbColor(1, 0, 0); 
    467                   exporter->SetForcedMaterial(m); 
    468                   exporter->ExportIntersectable(object); 
    469           } 
    470  
    471       delete exporter; 
     520          Material m; 
     521          m.mDiffuseColor = RgbColor(1, 0, 0); 
     522          exporter->SetForcedMaterial(m); 
     523          exporter->ExportIntersectable(object); 
     524 
     525          delete exporter; 
    472526    } 
    473527  } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/UnigraphicsParser.cpp

    r179 r312  
    117117 
    118118      // add vertices to the mesh vertex list 
    119       int index = currentMesh->mVertices.size(); 
     119      int index = (int)currentMesh->mVertices.size(); 
    120120      for (i=0; i < vertices.size(); i++, index++) { 
    121121        currentMesh->mVertices.push_back(vertices[i]); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r308 r312  
    6969        // add base vertices and calculate top vertices 
    7070        for (int i = 0; i < 3; ++i) 
    71         { 
    72                  mesh->mVertices.push_back(baseTri.mVertices[i]); 
    73                  topTri.mVertices[i] = baseTri.mVertices[i] + height * triNorm; 
    74         } 
    75  
     71                 mesh->mVertices.push_back(baseTri.mVertices[i] + height * 0.5 * triNorm); 
     72         
    7673        // add top vertices      
    7774        for (int i = 0; i < 3; ++i) 
    78                 mesh->mVertices.push_back(topTri.mVertices[i]); 
     75                mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm); 
    7976         
    8077        mesh->Preprocess(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r311 r312  
    173173                Polygon3 *back_piece = NULL; 
    174174         
     175                VertexContainer splitVertices; 
     176 
    175177                switch (classification) 
    176178                { 
     
    192194 
    193195                                //-- split polygon into front and back part 
    194                                 poly->Split(&mPlane, front_piece, back_piece); 
     196                                poly->Split(mPlane, *front_piece, *back_piece, splitVertices); 
    195197 
    196198                                ++ splits; // increase number of splits 
     
    365367 
    366368        // extract polygons that guide the split process 
    367         mStat.polys += AddMesh2Polygons(viewCell->GetMesh(), *polys, viewCell); 
     369        mStat.polys += AddMeshToPolygons(viewCell->GetMesh(), *polys, viewCell); 
    368370        mBox.Include(viewCell->GetBox()); // add to BSP aabb 
    369371 
     
    399401                                int splits = 0; 
    400402                 
    401                                 // split viecell polygons with respect to split plane 
     403                                // split viewcell polygons with respect to split plane 
    402404                                interior->SplitPolygons(tData.mPolygons,  
    403405                                                                                frontPolys,  
     
    445447                                 
    446448                                dynamic_cast<BspLeaf *>(root)->SetViewCell(viewCell); 
    447                 } 
     449                        } 
     450 
    448451                        if (!mRoot) // tree empty => new root 
    449452                                mRoot = root; 
     
    452455} 
    453456 
    454 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent) 
     457int BspTree::AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent) 
    455458{ 
    456459        FaceContainer::const_iterator fi; 
     
    481484                { 
    482485                        mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 
    483                         AddMesh2Polygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 
     486                        AddMeshToPolygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 
    484487                } 
    485488        } 
     
    514517                { 
    515518                        mBox.Include(object->GetBox()); // add to BSP tree aabb 
    516                         AddMesh2Polygons(mesh, polys, mViewCell); 
     519                        AddMeshToPolygons(mesh, polys, mViewCell); 
    517520                } 
    518521        } 
     
    545548        mStat.polys = Copy2PolygonSoup(objects, *polys); 
    546549 
    547         bool tmpStorePolys = mStoreSplitPolys; 
    548         mStoreSplitPolys = false; 
    549  
    550550        // construct tree from polygon soup 
    551551        Construct(polys, viewCells); 
    552  
    553         mStoreSplitPolys = tmpStorePolys; 
    554         // filter scene bounding box down the tree in order to store split polygons 
    555         if (mStoreSplitPolys) 
    556         { 
    557                 Mesh *polyMesh = new Mesh(); 
    558  
    559                 for (int i = 0; i < 6; ++i) 
    560                         polyMesh->AddRectangle(mBox.GetFace(i)); 
    561  
    562                 PolygonContainer *polys = new PolygonContainer(); 
    563                                 AddMesh2Polygons(polyMesh, *polys, NULL); 
    564                  
    565                 InsertPolygons(polys); 
    566  
    567                 delete polyMesh; 
    568         } 
    569552} 
    570553 
     
    579562         
    580563        BspTraversalData tData(new BspLeaf(), polys, 0, mViewCell); 
    581  
    582564        tStack.push(tData); 
    583565 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r310 r312  
    443443                @returns number of polygons 
    444444        */ 
    445         int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 
     445        int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 
    446446 
    447447        /** returns next candidate index and reorders polygons so no candidate is chosen two times 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r311 r312  
    115115{ 
    116116  // $$JB$$ 
    117   // in the future check whether the mesh was not already exportet 
     117  // in the future check whether the mesh was not already exported 
    118118  // and use a reference to the that mesh instead 
    119119  ExportMesh(object->GetMesh()); 
     
    610610  return true; 
    611611} 
     612 
     613struct BspSplitData 
     614{ 
     615        /// the current node 
     616        BspNode *mNode; 
     617 
     618        PolygonContainer *mPolygons; 
     619        vector<Plane3 *> mPlanes; 
     620        vector<bool> mSides; 
     621        bool mIsFront; 
     622 
     623        BspSplitData(BspNode *node, PolygonContainer *polys):  
     624        mNode(node), mPolygons(polys), mIsFront(false) 
     625        {};      
     626        BspSplitData(BspNode *node,  
     627                                 PolygonContainer *polys,  
     628                                 vector<Plane3 *> planes,  
     629                                 vector<bool> sides,  
     630                                 bool isFront):  
     631        mNode(node), mPolygons(polys), mPlanes(planes),  
     632        mSides(sides), mIsFront(isFront) 
     633        {}; 
     634}; 
     635 
     636void X3dExporter::ExportBspSplits(const BspTree &tree) 
     637{ 
     638        int mask = Random(50000); 
     639         
     640        std::stack<BspSplitData> tStack; 
     641 
     642        BspSplitData tData(tree.GetRoot(), new PolygonContainer()); 
     643        tStack.push(tData); 
     644   
     645        while (!tStack.empty()) 
     646        { 
     647                // filter polygons donw the tree 
     648                BspSplitData tData = tStack.top(); 
     649            tStack.pop();        
     650                 
     651                if (!tData.mNode->IsLeaf()) 
     652                { 
     653                        BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 
     654 
     655                        tData.mPlanes.push_back(interior->GetPlane()); 
     656                        tData.mSides.push_back(tData.mIsFront); 
     657 
     658                        // bounded plane is added to the polygons 
     659                        Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(*tData.mPlanes.back()); 
     660                 
     661                        PolygonContainer *frontPolys = new PolygonContainer(); 
     662                        PolygonContainer *backPolys = new PolygonContainer(); 
     663                        PolygonContainer coincident; 
     664 
     665                        int splits = 0; 
     666                 
     667                        // split polygons with respect to split plane 
     668                        interior->SplitPolygons(tData.mPolygons,  
     669                                                                        frontPolys,  
     670                                                                        backPolys, 
     671                                                                        &coincident, 
     672                                                                        splits,  
     673                                                                        false); 
     674 
     675                        // do all the splits with the previous planes 
     676                        for (int i = 0; i < (int)tData.mPlanes.size(); ++i) 
     677                        { 
     678                                VertexContainer splitPts; 
     679                                Polygon3 *frontPoly = new Polygon3(); 
     680                                Polygon3 *backPoly = new Polygon3(); 
     681 
     682                                if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 
     683                                { 
     684                                        planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 
     685                                        DEL_PTR(planePoly); 
     686 
     687                                        if(tData.mSides[i] == true) 
     688                                        { 
     689                                                planePoly = frontPoly; 
     690                                                DEL_PTR(backPoly); 
     691                                        } 
     692                                        else 
     693                                        { 
     694                                                Debug << "take backpoly" << endl; 
     695                                                planePoly = backPoly; 
     696                                                DEL_PTR(frontPoly); 
     697                                        } 
     698                                } 
     699                        } 
     700 
     701                        PolygonContainer *polys; 
     702                        BspNode *next; 
     703                        bool side = false; 
     704 
     705                        // random decision 
     706                        if (mask & 1) 
     707                        { 
     708                                next = interior->GetBack(); 
     709                                polys = backPolys; 
     710                                CLEAR_CONTAINER(*frontPolys); 
     711                                DEL_PTR(frontPolys); 
     712                                side = false; 
     713                        } 
     714                        else 
     715                        { 
     716                                next = interior->GetFront(); 
     717                                polys = frontPolys; 
     718                                 
     719                                CLEAR_CONTAINER(*backPolys); 
     720                                DEL_PTR(backPolys); 
     721                                side = true; 
     722                        } 
     723 
     724                        mask = mask >> 1; 
     725                        polys->push_back(planePoly); 
     726 
     727                        // push the children on the stack 
     728                        tStack.push(BspSplitData(next, polys, tData.mPlanes,  
     729                                                                         tData.mSides, side)); 
     730                        //tStack.push(BspSplitData(interior->GetBack(), backPolys,  
     731                        //                                               tData.mPlanes, tData.mSides, false)); 
     732 
     733                        // clean up 
     734                        CLEAR_CONTAINER(coincident); // NOTE: should contain nothing 
     735                        CLEAR_CONTAINER(*tData.mPolygons); 
     736                        DEL_PTR(tData.mPolygons); 
     737                } 
     738                else // reached leaf 
     739                { 
     740                        //Debug << "\nsplits: " << endl; 
     741                        //for (int i = 0; i < (int)tData.mSides.size(); ++ i)Debug << " " << tData.mSides[i]; 
     742                        ExportPolygons(tData.mPolygons); 
     743                         
     744                        // clean up 
     745                        CLEAR_CONTAINER(*tData.mPolygons); 
     746                        DEL_PTR(tData.mPolygons); 
     747                } 
     748        } 
     749} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r292 r312  
    6969  virtual void  
    7070  ExportViewCells(ViewCellContainer *viewCells); 
    71 static ViewCellContainer foundViewCells; // todo: delete later 
     71 
     72  virtual void ExportBspSplits(const BspTree &tree); 
     73 
     74  static ViewCellContainer foundViewCells; // todo: remove this 
    7275protected: 
    7376  virtual void 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r294 r312  
    385385//  StdInParseHandlers: Constructors and Destructor 
    386386// --------------------------------------------------------------------------- 
    387 X3dViewCellsParseHandlers::X3dViewCellsParseHandlers(ViewCellContainer *viewCells) : 
     387X3dViewCellsParseHandlers::X3dViewCellsParseHandlers(ViewCellContainer *viewCells,  
     388                                                                                                         float viewCellHeight) : 
    388389  mElementCount(0) 
    389390  , mAttrCount(0) 
     
    391392  , mSpaceCount(0) 
    392393  , mViewCells(viewCells) 
     394  , mViewCellHeight(viewCellHeight) 
    393395{ 
    394396} 
     
    505507 
    506508 
    507     for (int i = 0; i < mCurrentVertexIndices.size(); i+=3) 
     509    for (int i = 0; i < mCurrentVertexIndices.size(); i += 3) 
    508510        { 
    509                 Triangle3 baseTri(vertices[mCurrentVertexIndices[i]],  
    510                                                   vertices[mCurrentVertexIndices[i+1]], 
    511                                                   vertices[mCurrentVertexIndices[i+2]]); 
     511                Triangle3 baseTri(vertices[mCurrentVertexIndices[i + 0]],  
     512                                                  vertices[mCurrentVertexIndices[i + 1]], 
     513                                                  vertices[mCurrentVertexIndices[i + 2]]); 
    512514 
    513515                // create view cell from base triangle 
    514                 const float height = 10; 
    515                 mViewCells->push_back(ViewCell::ExtrudeViewCell(baseTri, height)); 
     516                mViewCells->push_back(ViewCell::ExtrudeViewCell(baseTri, mViewCellHeight)); 
    516517 
    517518                Mesh *mesh = mViewCells->back()->GetMesh(); 
     
    640641  //  to do. 
    641642  // 
    642   X3dViewCellsParseHandlers handler(&viewCells); 
     643  X3dViewCellsParseHandlers handler(&viewCells, mViewCellHeight); 
    643644  parser->setDocumentHandler(&handler); 
    644645  parser->setErrorHandler(&handler); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.h

    r261 r312  
    1010{ 
    1111public: 
    12   X3dParser():Parser() {} 
     12  X3dParser():Parser(), mViewCellHeight(5.0f) {} 
    1313   
    1414  bool ParseFile(const string filename, SceneGraphNode **root); 
    1515  bool ParseFile(const string filename, ViewCellContainer &viewCells); 
     16 
     17  float mViewCellHeight; 
    1618}; 
    1719 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h

    r261 r312  
    114114  //  Constructors and Destructor 
    115115  // ----------------------------------------------------------------------- 
    116   X3dViewCellsParseHandlers(ViewCellContainer *mViewCells); 
     116  X3dViewCellsParseHandlers(ViewCellContainer *mViewCells, float viewCellHeight); 
    117117  ~X3dViewCellsParseHandlers(); 
    118118   
     
    152152 
    153153  ViewCellContainer *mViewCells; 
     154  float mViewCellHeight; 
     155 
    154156  VertexIndexContainer mCurrentVertexIndices; 
    155157 
  • trunk/VUT/GtpVisibilityPreprocessor/src/common.h

    r262 r312  
    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 
     132#define AREA_LIMIT 0.0001f 
     133 
    129134#ifndef DEL_PTR 
    130135#define DEL_PTR(ptr) do {if (ptr) {        \ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r310 r312  
    5858          p->BspTreeStatistics(Debug); 
    5959          p->Export("vc_bsptree2.x3d", false, false, true); 
    60   
     60          // export the bsp splits 
     61          Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 
     62 
     63          if (exporter)  
     64          {      
     65                  Debug << "Exporting bsp splits" << endl; 
     66                  exporter->ExportBspSplits(*p->mBspTree); 
     67                  delete exporter; 
     68          } 
    6169#if 0 
    6270          //-- export the complementary view cells 
Note: See TracChangeset for help on using the changeset viewer.