Changeset 242 for trunk/VUT


Ignore:
Timestamp:
08/17/05 18:01:16 (19 years ago)
Author:
mattausch
Message:

added output functions and castray method for bsp viewcells

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

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp

    r191 r242  
    9797    exporter->SetWireframe(); 
    9898    exporter->ExportKdTree(*tree); 
     99//      exporter->ExportBspTree(*tree); 
    99100    exporter->ExportRays(rays, 10000); 
    100101    exporter->SetFilled(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r191 r242  
    99 
    1010class KdTree; 
     11class BspTree; 
    1112class SceneGraphNode; 
    1213class Ray; 
     
    4344 
    4445  virtual bool 
     46  ExportBspTree(const BspTree &tree) = 0; 
     47 
     48  virtual bool 
    4549  ExportRays(const vector<Ray> &rays, 
    4650             const float length=1000, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r239 r242  
    22#include "Mesh.h" 
    33 
    4 #define SIDE_TOLERANCE 0.002 
     4#define SIDE_TOLERANCE 0.002 // TODO: Test different values 
    55 
    6 Polygon3::Polygon3() 
     6Polygon3::Polygon3(): mMaterial(NULL) 
    77{} 
    88 
    9 Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices)  
     9Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices), mMaterial(NULL) 
    1010{} 
    1111 
     
    1717        { 
    1818                mVertices.push_back(parent->mVertices[*it]); 
     19                mMaterial = parent->mMaterial; 
     20                 
    1921                Debug << parent->mVertices[*it] << endl; 
    2022        } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r238 r242  
    5959        /// vertices are connected in counterclockwise order. 
    6060        VertexContainer mVertices; 
     61 
     62        /// we can also store materials with polygons 
     63        Material *mMaterial; 
    6164}; 
    6265 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r238 r242  
    121121Preprocessor::Export( const string filename, 
    122122                      const bool scene, 
    123                       const bool kdtree 
     123                      const bool kdtree, 
     124                          const bool bsptree 
    124125                      ) 
    125126{ 
     
    135136    } 
    136137 
     138        if (bsptree) { 
     139                exporter->SetWireframe(); 
     140                exporter->ExportBspTree(*mBspTree); 
     141        } 
     142 
    137143    delete exporter; 
    138144    return true; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r235 r242  
    7676  Export( const string filename, 
    7777          const bool scene, 
    78           const bool kdtree 
     78          const bool kdtree, 
     79          const bool bsptree 
    7980          ); 
    8081   
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r223 r242  
    238238    exporter->SetExportRayDensity(true); 
    239239    exporter->ExportKdTree(*mKdTree); 
     240        exporter->ExportBspTree(*mBspTree); 
     241 
    240242    delete exporter; 
    241243  } 
     
    247249    exporter->SetWireframe(); 
    248250    exporter->ExportKdTree(*mKdTree); 
     251        exporter->ExportBspTree(*mBspTree); 
    249252 
    250253    for (i=0; i < pvsOut; i++)  
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r241 r242  
    77#include "Polygon3.h" 
    88#include "Ray.h" 
    9  
     9#include "AxisAlignedBox3.h" 
    1010#include <stack> 
    1111#include <time.h> 
     
    110110                { 
    111111                        case Polygon3::COINCIDENT: 
    112                                 break; // do nothing 
     112                                break; // TODO: compare normals 
    113113                        case Polygon3::FRONT_SIDE: 
    114114                                frontPolys->push_back(poly); 
     
    676676} 
    677677 
     678AxisAlignedBox3 BspTree::GetBoundingBox() const 
     679{ 
     680        return mBox; 
     681} 
     682 
     683BspNode *BspTree::GetRoot() const 
     684{ 
     685        return mRoot; 
     686} 
     687 
    678688void BspTree::EvaluateLeafStats(const BspTraversalData &data) 
    679689{ 
     
    723733         
    724734        float position; 
    725  
     735         
    726736        while (1) // endless loop 
    727737        { 
     
    742752                        if (entSide < 0) 
    743753                        { 
    744                                 if(extSide > 0) // plane splits ray 
    745                                 { 
    746                                         node = in->GetBack(); 
    747                                         farChild = in->GetFront(); 
    748                                 } else 
    749                                 { 
    750                                         node = in->GetBack(); 
     754                                node = in->GetBack(); 
     755 
     756                                if(extSide <= 0)  
    751757                                        continue; 
    752                                 }  
    753                         } 
     758                                         
     759                                farChild = in->GetFront(); // plane splits ray 
     760 
    754761                        } else if (entSide > 0) 
    755762                        { 
    756                                 if (extSide < 0) // plane splits ray 
    757                                 { 
    758                                         node = in->GetFront(); 
    759                                         farChild = in->GetBack();  
    760                                 } else 
    761                                 { 
    762                                         node = in->GetFront(); 
     763                                node = in->GetFront(); 
     764 
     765                                if (extSide >= 0) 
    763766                                        continue; 
    764                                 } 
     767 
     768                                farChild = in->GetBack();        // plane splits ray                     
    765769                        } 
    766                         else // ray and plane are coincident // DOTO: WHAT IN THIS CASE ? 
     770                        else // ray and plane are coincident // WHAT TO DO IN THIS CASE ? 
    767771                        { 
    768                                 //node = in->GetFront(); 
     772                                node = in->GetFront(); 
    769773                                continue; 
    770774                        } 
    771775 
    772                     // case N4 or P4 
    773                         float tdist = (position - ray.GetLoc(axis)) / ray.GetDir(axis); 
    774       tStack.push(RayTraversalData(farChild, extp, maxt)); 
    775       extp = ray.GetLoc() + ray.GetDir()*tdist; 
    776       maxt = tdist; 
    777                          
    778                         float tDist = 0; 
    779                         extp = splitPlane->FindIntersection(entp, extp, &t); 
    780  
     776                        //-- split 
     777 
     778                        // push data for far child 
    781779                        tStack.push(BspRayTraversalData(farChild, extp, maxt)); 
    782780 
    783                          
    784  
    785                                 maxt = tDist; 
    786                         } 
     781                        // find intersection with plane between ray origin and exit point 
     782                        extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 
    787783                } else // compute intersections with objects in leaf 
    788784                { 
     
    813809                        mint = maxt; 
    814810                        BspRayTraversalData &s  = tStack.top(); 
     811 
    815812                        node = s.mNode; 
    816813                        extp = s.mExitPoint; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r241 r242  
    44#include "Mesh.h" 
    55#include "Containers.h" 
    6  
    7  
    8 #include <queue> 
    96#include <stack> 
    107 
     
    129class Plane3; 
    1310//class Mesh; 
    14  
    15 //namespace GtpVisibilityPreprocessor { 
    1611class BspTree;   
    1712class BspInterior; 
    1813class Polygon3; 
     14class AxisAlignedBox3; 
     15 
     16 
     17//namespace GtpVisibilityPreprocessor { 
    1918 
    2019/** Container storing a soup of polygons used during BSP tree construction 
     
    245244        void Construct(const ObjectContainer &objects); 
    246245 
    247         int BspTree::CollectLeafPvs(); 
     246        int CollectLeafPvs(); 
    248247 
    249248        void CollectLeaves(vector<BspLeaf *> &leaves); 
     249 
     250        /** Returns box which bounds the whole tree. 
     251        */ 
     252        AxisAlignedBox3 GetBoundingBox()const; 
     253 
     254        /** Returns root of BSP tree. 
     255        */ 
     256        BspNode *GetRoot() const; 
    250257 
    251258protected: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r209 r242  
    55#include "Mesh.h" 
    66#include "KdTree.h" 
     7#include "ViewCellBsp.h" 
     8#include "ViewCell.h" 
     9#include "Polygon3.h"; 
    710 
    811 
     
    98101  case Intersectable::TRANSFORMED_MESH_INSTANCE: 
    99102    ExportMeshInstance((MeshInstance *)object); 
     103        break; 
     104  case Intersectable::VIEWCELL: 
     105        ExportViewCell((ViewCell *)object); 
    100106    break; 
    101107  default: 
     
    112118  // and use a reference to the that mesh instead 
    113119  ExportMesh(object->GetMesh()); 
     120} 
     121 
     122void 
     123X3dExporter::ExportViewCell(ViewCell *object) 
     124{ 
     125        if (object->GetMesh()) 
     126                ExportMesh(object->GetMesh()); 
    114127} 
    115128 
     
    183196} 
    184197 
     198 
     199void X3dExporter::ExportPolygon(Polygon3 *poly) 
     200{ 
     201        stream << "<Shape>" << endl; 
     202        stream << "<Appearance>" << endl; 
     203   
     204        // $$ tmp -> random material 
     205   
     206        float r, g, b; 
     207 
     208        if (mUseForcedMaterial)  
     209        { 
     210                r = mForcedMaterial.mDiffuseColor.r; 
     211                g = mForcedMaterial.mDiffuseColor.g; 
     212                b = mForcedMaterial.mDiffuseColor.b; 
     213        }  
     214        else if (poly->mMaterial)  
     215        { 
     216                r = poly->mMaterial->mDiffuseColor.r; 
     217                g = poly->mMaterial->mDiffuseColor.g; 
     218                b = poly->mMaterial->mDiffuseColor.b; 
     219        } else  
     220        { 
     221                r = RandomValue(0.5, 1.0); 
     222                g = RandomValue(0.5, 1.0); 
     223                b = RandomValue(0.5, 1.0); 
     224        } 
     225 
     226        stream << "<Material diffuseColor=\"" << r << " " << g << " " << b  
     227                   << "\" specularColor=\"0.0 0.0 0.0\"/>" << endl; 
     228 
     229    stream << "</Appearance>" << endl; 
     230 
     231 
     232        if (mWireframe) 
     233                stream << "<IndexedLineSet ccw=\"TRUE\" coordIndex=\"" << endl; 
     234        else 
     235                stream << "<IndexedFaceSet ccw=\"TRUE\" coordIndex=\"" << endl; 
     236 
     237        VertexContainer::const_iterator vi = poly->mVertices.begin(); 
     238 
     239        stream << "<Coordinate  point=\"" << endl; 
     240   
     241        for (; vi != poly->mVertices.end(); ++vi)  
     242        { 
     243                stream << (*vi).x << " " << (*vi).y << " " << (*vi).z; 
     244                stream << "," << endl; 
     245        } 
     246   
     247        stream<<"\" >"<<endl; 
     248        stream<<"</Coordinate>"<<endl; 
     249 
     250        if (mWireframe) 
     251                stream << "</IndexedLineSet>" << endl; 
     252        else 
     253                stream << "</IndexedFaceSet>" << endl; 
     254   
     255        stream << "</Shape>" << endl; 
     256} 
     257 
     258 
    185259bool 
    186260X3dExporter::ExportBox(const AxisAlignedBox3 &box) 
     
    209283 
    210284bool 
    211 X3dExporter::ExportKdTree(const KdTree &tree) 
    212 { 
    213   if (mExportRayDensity) { 
     285X3dExporter::ExportBspTree(const BspTree &tree) 
     286{ 
     287        if (mExportRayDensity)  
     288        { 
     289                return false;//ExportKdTreeRayDensity(tree); 
     290        } 
     291   
     292        stack<BspNode *> tStack; 
     293 
     294        tStack.push(tree.GetRoot()); 
     295 
     296        Mesh *mesh = new Mesh; 
     297 
     298        AxisAlignedBox3 box = tree.GetBoundingBox(); 
     299        ExportBox(box); 
     300 
     301        while (!tStack.empty())  
     302        { 
     303                BspNode *node = tStack.top(); 
     304     
     305                tStack.pop(); 
     306         
     307                if (!node->IsLeaf())  
     308                { 
     309                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     310       
     311                        tStack.push(interior->GetFront()); 
     312                        tStack.push(interior->GetBack()); 
     313                } 
     314                else 
     315                { 
     316                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     317                        // NOTE: could also export polygons to see if splits work 
     318                        if (leaf->GetViewCell()) 
     319                                ExportViewCell(leaf->GetViewCell()); 
     320                } 
     321  } 
     322   
     323  ExportMesh(mesh); 
     324  delete mesh; 
     325  return true; 
     326} 
     327 
     328bool X3dExporter::ExportKdTree(const KdTree &tree) 
     329{ 
     330         if (mExportRayDensity) { 
    214331    return ExportKdTreeRayDensity(tree); 
    215332  } 
     
    250367  delete mesh; 
    251368  return true; 
     369        // TODO 
     370        return true; 
    252371} 
    253372 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r191 r242  
    1414class Intersectable; 
    1515class MeshInstance; 
     16class Polygon3; 
     17class ViewCell; 
     18class BspTree; 
    1619 
    1720class X3dExporter : public Exporter 
     
    3437  ExportKdTree(const KdTree &tree); 
    3538   
     39  bool ExportBspTree(const BspTree &tree); 
     40 
    3641  bool 
    3742  ExportScene(SceneGraphNode *root)  
     
    4146  } 
    4247   
     48  virtual void  
     49        ExportPolygon(Polygon3 *poly); 
     50 
    4351  virtual bool 
    4452  ExportBox(const AxisAlignedBox3 &box); 
     
    5361  ExportMesh(Mesh *mesh); 
    5462 
     63  virtual void ExportViewCell(ViewCell *viewCell); 
    5564 
    5665protected: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r237 r242  
    3838  //  p->mSceneGraph->Export("soda.x3d"); 
    3939  if (0) { 
    40     p->Export(filename + "-out.x3d", true, false); 
    41     p->Export(filename + "-kdtree.x3d", false, true); 
     40    p->Export(filename + "-out.x3d", true, false, false); 
     41    p->Export(filename + "-kdtree.x3d", false, true, false); 
    4242  } 
    4343   
Note: See TracChangeset for help on using the changeset viewer.