Ignore:
Timestamp:
09/08/05 18:45:51 (19 years ago)
Author:
mattausch
Message:

added viewcell loader

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

Legend:

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

    r242 r261  
    77 
    88#include "Material.h" 
     9#include "Containers.h" 
    910 
    1011class KdTree; 
     
    5354   
    5455 
     56  virtual void  
     57  ExportViewCells(ViewCellContainer *viewCells) = 0; 
     58 
    5559  virtual void 
    5660  ExportIntersectable(Intersectable *object) = 0; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Parser.h

    r162 r261  
    1414  Parser() {} 
    1515  virtual bool ParseFile(const string filename, SceneGraphNode **root) = 0; 
    16    
    1716}; 
    1817 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r260 r261  
    22#include "Mesh.h" 
    33 
    4 #define SIDE_TOLERANCE 0.002 // TODO: Test different values 
     4#define SIDE_TOLERANCE 0.002f // TODO: Test different values 
    55 
    66Polygon3::Polygon3(): mMaterial(NULL) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r260 r261  
    77#include "Environment.h" 
    88 
    9    
    10 bool 
    11 Preprocessor::LoadViewcells(const string filename) 
     9 
     10Preprocessor::~Preprocessor() 
    1211{ 
    13    
    14   return true; 
     12  // delete view cells 
     13  while (!mViewCells.empty()) 
     14  { 
     15          DEL_PTR(mViewCells.back()); 
     16          mViewCells.pop_back(); 
     17  } 
     18 
     19  // delete psp tree 
     20  DEL_PTR(mBspTree); 
    1521} 
    1622 
    1723bool 
    18 Preprocessor::GenerateViewcells() 
     24Preprocessor::LoadViewCells(const string filename) 
     25{ 
     26        X3dParser *parser = new X3dParser; 
     27 
     28        delete parser; 
     29 
     30        bool result = parser->ParseFile(filename, mViewCells); 
     31 
     32        if (result) 
     33        { 
     34                Exporter *exporter = Exporter::GetExporter(filename); 
     35 
     36                if (exporter)  
     37                        exporter->ExportViewCells(&mViewCells); 
     38 
     39                GenerateViewCells(); 
     40        } 
     41        return result; 
     42} 
     43 
     44bool 
     45Preprocessor::GenerateViewCells() 
    1946{ 
    2047        return BuildBspTree(); 
     
    3865  bool result = parser->ParseFile(filename, &mSceneGraph->mRoot); 
    3966   
     67  delete parser; 
     68 
    4069  return result; 
    4170} 
     
    90119        { 
    91120        case BspTree::VIEWCELLS: 
    92  
    93                 mViewcells.clear(); 
     121                // derive view cells from the scene objects 
     122                //ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells); 
    94123                 
    95                 // derive viewcells from the scene objects 
    96                 ViewCell::DeriveViewCells(objects, mViewcells, maxViewCells); 
    97                  
    98                 mBspTree->Construct(mViewcells); 
     124                mBspTree->Construct(mViewCells); 
    99125                break; 
    100126        case BspTree::SCENE_GEOMETRY: 
    101                 mBspTree->Construct(objects); 
     127                CLEAR_CONTAINER(mViewCells); 
     128                mBspTree->Construct(objects, &mViewCells); 
     129                break; 
     130        case BspTree::RAYS: 
     131                CLEAR_CONTAINER(mViewCells); 
     132                mBspTree->Construct(objects, &mViewCells); 
    102133                break; 
    103134        default: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h

    r242 r261  
    2525class Preprocessor { 
    2626public: 
     27   ~Preprocessor(); 
     28 
    2729  /** Load the input scene.  
    2830      @param filename file to load 
     
    3739        @return true on success 
    3840  */ 
    39   virtual bool LoadViewcells(const string filename); 
     41  virtual bool LoadViewCells(const string filename); 
    4042   
    4143  /** Generate the viewCells automatically. The particular algorithm to be used depends 
     
    4547      @return true on successful viewcell generation. 
    4648  */ 
    47   virtual bool GenerateViewcells(); 
     49  virtual bool GenerateViewCells(); 
    4850   
    4951  /** Export all preprocessed data in a XML format understandable by the 
     
    9698  ObjectContainer mOccludees; 
    9799  /// list of all loaded/generated viewcells 
    98   ViewCellContainer mViewcells; 
     100  ViewCellContainer mViewCells; 
    99101   
    100102  BspTree * mBspTree; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp

    r260 r261  
    77ViewCell::ViewCell(Mesh *mesh): mMesh(mesh), mPvs(NULL)  
    88{ 
     9} 
     10 
     11ViewCell::~ViewCell() 
     12{ 
     13        // NOTE: should I really do this here? 
     14        DEL_PTR(mMesh); 
    915} 
    1016 
     
    7783} 
    7884 
    79 ViewCell *ViewCell::Convert2ViewCell(Face *face, float scale) 
     85ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height) 
    8086{ 
    81         // TODO: delete mesh 
     87        // one mesh per view cell 
    8288        Mesh *mesh = new Mesh(); 
    83         mesh->mFaces.push_back(face); 
    84      
     89         
     90        //-- construct prism 
    8591 
     92        // bottom  
     93        mesh->mFaces.push_back(new Face(0,1,2)); 
     94        // top 
     95    mesh->mFaces.push_back(new Face(5,4,3)); 
     96        // sides 
     97        mesh->mFaces.push_back(new Face(0, 3, 4, 1)); 
     98        mesh->mFaces.push_back(new Face(1, 4, 5, 2)); 
     99        mesh->mFaces.push_back(new Face(0, 2, 5, 3)); 
     100 
     101 
     102        //--- extrude new vertices for top of prism 
     103        Vector3 triNorm = baseTri.GetNormal(); 
     104 
     105        Triangle3 topTri;        
     106 
     107        // add base vertices and calculate top vertices 
     108        for (int i = 0; i < 3; ++i) 
     109        { 
     110                 mesh->mVertices.push_back(baseTri.mVertices[i]); 
     111                 topTri.mVertices[i] = baseTri.mVertices[i] + height * triNorm; 
     112        } 
     113 
     114        // add top vertices      
     115        for (int i = 0; i < 3; ++i) 
     116                mesh->mVertices.push_back(topTri.mVertices[1]); 
     117         
    86118        return new ViewCell(mesh); 
    87119} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h

    r260 r261  
    1111class BspInterior; 
    1212class BspPvs; 
     13struct Triangle3; 
    1314/** 
    1415        View cell represented as a mesh 
     
    5253                                                                const int maxViewCells); 
    5354 
    54         static ViewCell *Convert2ViewCell(Face *face); 
     55        /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector. 
     56                @param the base triangle 
     57                @param the height of the newly created view cell 
     58        */ 
     59        static ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height); 
     60 
    5561protected: 
    5662 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r260 r261  
    463463 
    464464 
    465 ViewCellContainer *BspTree::Construct(const ObjectContainer &objects) 
     465void BspTree::Construct(const ObjectContainer &objects, ViewCellContainer *viewCells) 
    466466{ 
    467467#ifdef _DEBUG 
     
    479479        Construct(polys); 
    480480 
    481         return NULL;// TODO 
    482 } 
    483  
    484 ViewCellContainer *BspTree::Construct(const RayContainer &rays) 
     481        // TODO: generate view cells 
     482} 
     483 
     484void BspTree::Construct(const RayContainer &rays, ViewCellContainer *viewCells) 
    485485{ 
    486486        // TODO 
    487         return NULL; 
    488487} 
    489488 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r260 r261  
    262262                @returns list of view cells. 
    263263        */ 
    264         ViewCellContainer *Construct(const ObjectContainer &objects); 
     264        void Construct(const ObjectContainer &objects, ViewCellContainer *viewCells); 
    265265 
    266266        /** Constructs tree using the given number of rays 
     
    268268                @returns list of view cells. 
    269269        */ 
    270         ViewCellContainer *Construct(const RayContainer &rays); 
     270        void Construct(const RayContainer &rays, ViewCellContainer *viewCells); 
    271271 
    272272        int CollectLeafPvs(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r260 r261  
    120120} 
    121121 
     122void X3dExporter::ExportViewCells(ViewCellContainer *viewCells) 
     123{ 
     124        ViewCellContainer::iterator it, it_end = viewCells->end(); 
     125 
     126        for (it = viewCells->begin(); it != it_end; ++it) 
     127                ExportViewCell(*it); 
     128} 
    122129void 
    123 X3dExporter::ExportViewCell(ViewCell *object) 
    124 { 
    125         if (object->GetMesh()) 
    126                 ExportMesh(object->GetMesh()); 
     130X3dExporter::ExportViewCell(ViewCell *viewCell) 
     131{ 
     132        if (viewCell->GetMesh()) 
     133                ExportMesh(viewCell->GetMesh()); 
    127134} 
    128135 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r260 r261  
    99 
    1010#include "Exporter.h" 
     11#include "Containers.h" 
    1112 
    1213class SceneGraphNode; 
     
    6465  ExportViewCell(ViewCell *viewCell); 
    6566 
     67  virtual void  
     68  ExportViewCells(ViewCellContainer *viewCells); 
     69 
    6670protected: 
    6771  virtual void 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp

    r260 r261  
    2727#include "Mesh.h" 
    2828#include "SceneGraph.h" 
     29#include "Triangle3.h" 
     30#include "ViewCell.h" 
    2931 
    3032// --------------------------------------------------------------------------- 
     
    376378 
    377379/*********************************************************** 
    378  *         class X3dViewCellsParser implemenation          * 
     380 *         class X3dViewCellsParseHandlers implemenation          * 
    379381 ***********************************************************/ 
    380382 
     
    383385//  StdInParseHandlers: Constructors and Destructor 
    384386// --------------------------------------------------------------------------- 
    385 X3dViewCellsParser::X3dViewCellsParser(ViewCellContainer *viewCells) : 
     387X3dViewCellsParseHandlers::X3dViewCellsParseHandlers(ViewCellContainer *viewCells) : 
    386388  mElementCount(0) 
    387389  , mAttrCount(0) 
     
    392394} 
    393395 
    394 X3dViewCellsParser::~X3dViewCellsParser() 
     396X3dViewCellsParseHandlers::~X3dViewCellsParseHandlers() 
    395397{ 
    396398} 
     
    400402//  StdInParseHandlers: Implementation of the SAX DocumentHandler interface 
    401403// --------------------------------------------------------------------------- 
    402 void X3dViewCellsParser::endElement(const XMLCh* const name) 
     404void X3dViewCellsParseHandlers::endElement(const XMLCh* const name) 
    403405{ 
    404406  StrX lname(name); 
     
    409411 
    410412void 
    411 X3dViewCellsParser::EndShape() 
    412 { 
    413 } 
    414  
    415 void 
    416 X3dViewCellsParser::StartIndexedFaceSet( 
     413X3dViewCellsParseHandlers::EndShape() 
     414{ 
     415} 
     416 
     417void 
     418X3dViewCellsParseHandlers::StartIndexedFaceSet( 
    417419                                      AttributeList&  attributes) 
    418420{ 
    419421        int len = attributes.getLength(); 
    420422        int i; 
    421         VertexIndexContainer vertices; 
    422  
     423         
    423424        for (i=0; i < len; i++)  
    424425        { 
     
    430431                         
    431432                        // handle coordIndex 
    432                         vertices.clear(); 
    433433                        const char *ptr = attrValue.LocalForm(); 
    434434                        char *endptr; 
    435435                 
    436                         while(1) 
     436                        while (1) 
    437437                        { 
    438438                                int index = strtol(ptr, &endptr, 10); 
    439439                                 
    440                                 if (ptr == endptr || index == -1)  
     440                                if (ptr == endptr) 
     441                                        break; 
     442 
     443                                if (index != -1)  
    441444                                { 
    442                                         if (vertices.size() > 2)  
    443                                         { 
    444                                                 // the base of all view cells is a triangle. 
    445                                                 Face *face = new Face(vertices); 
    446                                                  
    447                                                 mViewCells->push_back(ViewCell::Convert2ViewCell(face));                                                 
    448                                         } 
    449                                         vertices.clear(); 
    450                                          
    451                                         if (ptr == endptr) 
    452                                                 break; 
    453                                 }  
    454                                 else  
    455                                 { 
    456                                         vertices.push_back(index); 
     445                                        mCurrentVertexIndices.push_back(index); 
    457446                                } 
    458447                     
     
    465454 
    466455void 
    467 X3dViewCellsParser::StartCoordinate( 
     456X3dViewCellsParseHandlers::StartCoordinate( 
    468457                                  AttributeList&  attributes) 
    469458{ 
     
    511500                                vertices.push_back(v); 
    512501                        } 
    513                         mCurrentMesh->mVertices = vertices; 
    514502                } 
    515503        } 
    516 } 
    517  
    518  
    519 void 
    520 X3dViewCellsParser::startElement(const XMLCh* const name, 
     504 
     505 
     506 
     507    for (int i = 0; i < mCurrentVertexIndices.size(); i+=3) 
     508        { 
     509                Triangle3 baseTri(vertices[mCurrentVertexIndices[i]],  
     510                                                  vertices[mCurrentVertexIndices[i+1]], 
     511                                                  vertices[mCurrentVertexIndices[i+2]]); 
     512 
     513            // create view cell from base triangle 
     514                const float height = 10; 
     515                mViewCells->push_back(ViewCell::ExtrudeViewCell(baseTri, height)); 
     516        } 
     517} 
     518 
     519 
     520void 
     521X3dViewCellsParseHandlers::startElement(const XMLCh* const name, 
    521522                               AttributeList&  attributes) 
    522523{ 
     
    525526   
    526527  if (element == "IndexedFaceSet") { 
    527     // create a new mesh node in the scene graph 
     528    // create the viewcells from individual triangles 
    528529    StartIndexedFaceSet(attributes); 
    529530  } 
    530  
    531   if (element == "Shape") { 
    532     cout<<"+"; 
    533     mCurrentMesh = new Mesh; 
    534   } 
     531         
     532  // do nothing 
     533  //if (element == "Shape") {} 
    535534   
    536535  if (element == "Coordinate") { 
    537     if (mCurrentMesh) 
     536          // add coordinates to the triangles 
    538537      StartCoordinate(attributes); 
    539538  } 
    540    
    541   if (element == "Material") { 
    542     StartMaterial(attributes); 
    543   } 
     539  // ignore material 
     540  //if (element == "Material") {} 
    544541 
    545542  mElementCount++; 
     
    548545 
    549546void 
    550 X3dViewCellsParser::characters(const XMLCh* const chars, 
     547X3dViewCellsParseHandlers::characters(const XMLCh* const chars, 
    551548                             const unsigned int length) 
    552549{ 
     
    555552 
    556553void 
    557 X3dViewCellsParser::ignorableWhitespace(const XMLCh* const chars, 
     554X3dViewCellsParseHandlers::ignorableWhitespace(const XMLCh* const chars, 
    558555                                      const unsigned int length) 
    559556{ 
     
    562559 
    563560void 
    564 X3dViewCellsParser::resetDocument() 
     561X3dViewCellsParseHandlers::resetDocument() 
    565562{ 
    566563  mAttrCount = 0; 
     
    576573// --------------------------------------------------------------------------- 
    577574void 
    578 X3dViewCellsParser::error(const SAXParseException& e) 
     575X3dViewCellsParseHandlers::error(const SAXParseException& e) 
    579576{ 
    580577  XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId()) 
     
    585582 
    586583void 
    587 X3dViewCellsParser::fatalError(const SAXParseException& e) 
     584X3dViewCellsParseHandlers::fatalError(const SAXParseException& e) 
    588585{ 
    589586  XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId()) 
     
    594591 
    595592void 
    596 X3dViewCellsParser::warning(const SAXParseException& e) 
     593X3dViewCellsParseHandlers::warning(const SAXParseException& e) 
    597594{ 
    598595  XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId()) 
     
    604601 
    605602bool 
    606 X3dParser::ParseFile(const string filename, 
    607                      SceneGraphNode **root) 
     603X3dParser::ParseFile(const string filename, ViewCellContainer &viewCells) 
    608604{ 
    609605  // Initialize the XML4C system 
     
    637633  //  to do. 
    638634  // 
    639   *root = new SceneGraphNode; 
    640   X3dViewCellsParser handler(*root); 
     635  X3dViewCellsParseHandlers handler(&viewCells); 
    641636  parser->setDocumentHandler(&handler); 
    642637  parser->setErrorHandler(&handler); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.h

    r260 r261  
    33 
    44#include "Parser.h" 
    5 #include "ViewCells.h" 
     5#include "Containers.h" 
     6 
     7class ViewCell; 
    68 
    79class X3dParser : public Parser 
     
    1113   
    1214  bool ParseFile(const string filename, SceneGraphNode **root); 
    13   bool ParseViewCells(const string filename, ViewCellContainer *viewCells); 
     15  bool ParseFile(const string filename, ViewCellContainer &viewCells); 
    1416}; 
    1517 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h

    r260 r261  
    66// --------------------------------------------------------------------------- 
    77#include <xercesc/sax/HandlerBase.hpp> 
     8#include "Mesh.h" 
    89 
    910XERCES_CPP_NAMESPACE_USE 
     
    113114  //  Constructors and Destructor 
    114115  // ----------------------------------------------------------------------- 
    115   X3dViewCellsParseHandlers(ViewCellContainer *mViewCells;); 
     116  X3dViewCellsParseHandlers(ViewCellContainer *mViewCells); 
    116117  ~X3dViewCellsParseHandlers(); 
    117118   
     
    151152 
    152153  ViewCellContainer *mViewCells; 
    153    
     154  VertexIndexContainer mCurrentVertexIndices; 
     155 
    154156  // Handlers for X3D 
    155157  void 
  • trunk/VUT/GtpVisibilityPreprocessor/src/common.h

    r235 r261  
    131131#endif 
    132132 
     133#ifndef CLEAR_CONTAINER 
     134#define CLEAR_CONTAINER(co) while (!co.empty()) {delete co.back(); co.pop_back();} 
     135#endif 
     136 
    133137inline 
    134138int signum(const Real a, const Real thresh = TRASH) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r260 r261  
    3535  environment->GetStringValue("Scene.viewcells", buff); 
    3636 
    37   p->GenerateViewcells(); 
     37  string viewCellsFile(buff); 
     38  p->LoadViewCells(viewCellsFile); 
     39 
    3840  p->BspTreeStatistics(Debug); 
    3941#endif 
     
    4547  } 
    4648   
    47   //  p->LoadViewcells("viewcells.wrl"); 
     49    
    4850  if (1) { 
    4951    p->ComputeVisibility(); 
     
    6466  } 
    6567 
    66    
     68  // clean up 
     69  DEL_PTR(p); 
     70  DEL_PTR(environment); 
     71 
    6772  return 0; 
    6873} 
Note: See TracChangeset for help on using the changeset viewer.