Ignore:
Timestamp:
03/22/06 10:13:28 (18 years ago)
Author:
mattausch
Message:

added exporter for Vrml
added transformations to x3d loader

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r708 r712  
    12411241        RegisterOption("ViewCells.PostProcess.samples", 
    12421242                                        optInt, 
    1243                                         "view_cells_postprocess_samples=", 
     1243                                        "view_cells_post_process_samples=", 
    12441244                                        "200000"); 
    12451245 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp

    r162 r712  
    11 
    22#include "X3dExporter.h" 
    3  
     3#include "VrmlExporter.h" 
    44 
    55Exporter * 
    66Exporter::GetExporter(const string filename) 
    77{ 
    8   Exporter *e = NULL; 
     8  Exporter *exporter = NULL; 
    99 
    10   if (strstr(filename.c_str(), ".x3d")) { 
    11     e = new X3dExporter(filename); 
    12   } else { 
    13     cerr<<"Error: Currently unsuported export format, filename "<<filename<<endl; 
     10  if (strstr(filename.c_str(), ".x3d"))  
     11  { 
     12          exporter = new X3dExporter(filename); 
     13  }  
     14  else if (strstr(filename.c_str(), ".wrl")) 
     15  { 
     16          exporter = new VrmlExporter(filename); 
    1417  } 
    15   return e; 
     18  else 
     19  { 
     20          cerr<<"Error: Currently unsuported export format, filename " << filename << endl; 
     21  } 
     22 
     23  return exporter; 
    1624} 
    1725 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r694 r712  
    8585        vector<string> filenames; 
    8686        int files = SplitFilenames(filename, filenames); 
    87         cout<<files<<endl; 
     87        cout << "number of input files: " << files << endl; 
    8888        bool result = false; 
    8989        if (files == 1) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp

    r685 r712  
    4848 
    4949 
    50   cerr<<"Preprocessor main finished...\n"; 
     50  cerr << "Preprocessor main finished...\n"; 
    5151   
    5252} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r711 r712  
    1616#include "RssPreprocessor.h" 
    1717 
    18 #define SAMPLE_AFTER_SUBDIVISION 1 
    19 #define TEST_EMPTY_VIEW_CELLS 0 
     18// HACK 
     19const static bool SAMPLE_AFTER_SUBDIVISION = true; 
     20const static bool TEST_EMPTY_VIEW_CELLS = false; 
    2021 
    2122 
     
    289290 
    290291        cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 
     292 
    291293        //-- construction rays => we use uniform samples for this 
    292294        CastPassSamples(mInitialSamples,  
     
    319321        if (1) // export initial view cells 
    320322        { 
    321                 cout << "exporting initial view cells (=leaves) ... "; 
    322                 Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 
    323  
     323                const char filename[] = "view_cells.wrl"; 
     324                Exporter *exporter = Exporter::GetExporter(filename); 
     325 
     326         
    324327                if (exporter) 
    325328                { 
     329                        cout << "exporting initial view cells (=leaves) to " << filename << " ... "; 
    326330                        if (mExportGeometry) 
     331                        { 
    327332                                exporter->ExportGeometry(preprocessor->mObjects); 
    328  
     333                        } 
     334 
     335                        //exporter->SetWireframe(); 
    329336                        ExportViewCellsForViz(exporter); 
    330337 
    331338                        delete exporter; 
    332                 } 
    333                 cout << "finished" << endl; 
     339                        cout << "finished" << endl; 
     340                } 
    334341        } 
    335342 
     
    340347        bool dirSamples = (mSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION); 
    341348 
     349        // -- the main loop 
    342350        while (numSamples < n) 
    343351        { 
     
    362370 
    363371                // TODO: leak? 
    364                 if (SAMPLE_AFTER_SUBDIVISION) 
     372                if (1 || SAMPLE_AFTER_SUBDIVISION) 
    365373                        ComputeSampleContributions(constructionSamples, true, false); 
     374 
    366375                cout << "finished" << endl; 
    367376 
     
    606615                neighborhood.pop_back(); 
    607616         
    608                 cout << "vc idx: " << bestViewCellIdx << endl; 
     617                //cout << "vc idx: " << bestViewCellIdx << endl; 
    609618                if (!bestViewCell || !root) 
    610619                        cout << "warning!!" << endl; 
     
    16891698                mColorCode = 1; 
    16901699 
    1691                 Exporter *exporter = Exporter::GetExporter("final_view_cells.x3d"); 
     1700                Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl"); 
    16921701         
    16931702                cout << "exporting view cells after merge (pvs size) ... ";      
     
    33773386                int savedColorCode = mColorCode; 
    33783387                mColorCode = 0; 
    3379                 Exporter *exporter = Exporter::GetExporter("final_view_cells.x3d"); 
     3388                Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl"); 
    33803389                 
    33813390                if (exporter) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r697 r712  
    715715 
    716716   
    717   int numExportRays = 2000; 
    718   //int numExportRays = 0; 
     717  //int numExportRays = 2000; 
     718  int numExportRays = 0; 
    719719 
    720720  if (numExportRays) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp

    r706 r712  
    438438        stream << "</Shape>" << endl; 
    439439} 
     440 
    440441 
    441442void X3dExporter::ExportPolygons(const PolygonContainer &polys) 
     
    11381139void X3dExporter::ExportGeometry(const ObjectContainer &objects) 
    11391140{ 
    1140 #if 1 
    1141         for (int j = 0; j < objects.size(); ++ j) 
    1142                 ExportIntersectable(objects[j]); 
    1143 #else 
    1144         // hack 
     1141        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     1142 
     1143        if (1) 
     1144        { 
     1145                for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1146                { 
     1147                        if (1) 
     1148                        { 
     1149                                SetForcedMaterial(RandomMaterial()); 
     1150                        } 
     1151 
     1152                        ExportIntersectable(*oit); 
     1153                } 
     1154 
     1155                return; 
     1156        } 
     1157 
     1158        // hack: all object exported as one mesh 
    11451159        PolygonContainer polys; 
    1146         for (int j = 0; j < objects.size(); ++ j){ 
    1147                 polys.push_back(new Polygon3(dynamic_cast<MeshInstance *>(objects[j])->GetMesh()->mVertices)); 
     1160 
     1161        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1162        { 
     1163                polys.push_back(new Polygon3(dynamic_cast<MeshInstance *>(*oit)->GetMesh()->mVertices)); 
    11481164        } 
    11491165 
    11501166        Mesh dummyMesh; 
    1151         PolygonContainer::const_iterator it, it_end = polys.end(); 
    1152  
    1153         for (it = polys.begin(); it != it_end; ++ it) 
    1154           { 
    1155                 (*it)->AddToMesh(dummyMesh); 
    1156           } 
     1167        PolygonContainer::const_iterator pit, pit_end = polys.end(); 
     1168 
     1169        for (pit = polys.begin(); pit != pit_end; ++ pit) 
     1170        { 
     1171                (*pit)->AddToMesh(dummyMesh); 
     1172        } 
     1173         
    11571174        ExportMesh(&dummyMesh); 
     1175 
    11581176        CLEAR_CONTAINER(polys); 
    1159 #endif 
    11601177} 
    11611178 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r703 r712  
    6969{ 
    7070  mCurrentNode = root; 
     71  // this matrix should never be removed from stack 
     72  //mTransformations.push(IdentityMatrix()); 
    7173} 
    7274 
    7375X3dParseHandlers::~X3dParseHandlers() 
    7476{ 
     77        if (!mTransformations.empty()) 
     78                cout << "error: transformation stack size: " << (int)mTransformations.size() << endl; 
    7579} 
    7680 
     
    8690  if (element == "Shape") 
    8791    EndShape(); 
     92  if (1) 
     93  if (element == "Transform") 
     94          EndTransform(); 
    8895} 
    8996 
     
    100107                (*it) = rot * (*it);         
    101108        } 
     109} 
     110 
     111 
     112void X3dParseHandlers::ApplyTransformation(Mesh *mesh,  
     113                                                                                   const Matrix4x4 &m) const 
     114{ 
     115        VertexContainer::iterator it, it_end = mesh->mVertices.end(); 
     116 
     117        for (it = mesh->mVertices.begin(); it != it_end; ++ it) 
     118        { 
     119                (*it) = m * (*it);         
     120        } 
     121} 
     122 
     123 
     124void X3dParseHandlers::ApplyTransformations(TrafoStack trafos, Mesh *mesh) const 
     125{ 
     126        while (!trafos.empty()) 
     127        { 
     128                const Matrix4x4 m = trafos.top(); 
     129                trafos.pop(); 
     130 
     131                ApplyTransformation(mesh, m); 
     132        } 
     133} 
     134 
     135void X3dParseHandlers::StartTransform(AttributeList&  attributes) 
     136{ 
     137        Matrix4x4 currentTransform = IdentityMatrix(); 
     138 
     139        const int len = attributes.getLength(); 
     140     
     141        for (int i = 0; i < len; ++ i)  
     142        { 
     143                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     144                         
     145                StrX attrValue(attributes.getValue(i)); 
     146                const char *ptr = attrValue.LocalForm(); 
     147                         
     148                if (attrName == "rotation")  
     149                { 
     150                        Vector3 axis; 
     151                        float angle; 
     152                                 
     153                        if (sscanf(ptr, "%f %f %f %f", &axis.x, &axis.y, &axis.z, &angle) == 4) 
     154                        { 
     155                                Matrix4x4 rot = RotationAxisMatrix(axis, angle); 
     156                                currentTransform *= rot; 
     157                        } 
     158                } 
     159                else if (attrName == "translation") 
     160                { 
     161                        Vector3 transl; 
     162                                                         
     163                        if (sscanf(ptr, "%f %f %f %f", &transl.x, &transl.y, &transl.z) == 3) 
     164                        { 
     165                                Matrix4x4 tm = TranslationMatrix(transl); 
     166 
     167                                currentTransform *= tm; 
     168                        } 
     169                } 
     170        } 
     171         
     172        mTransformations.push(currentTransform); 
     173} 
     174 
     175 
     176void X3dParseHandlers::EndTransform() 
     177{ 
     178        mTransformations.pop(); 
    102179} 
    103180 
     
    125202                         
    126203                        mesh->mFaces.push_back(new Face(vc)); 
    127                         if (ROTATE_SCENE) 
    128                                 RotateMesh(mesh); 
     204                         
     205                        // NOTE: should rather be written into trafo of mesh instance 
     206                        ApplyTransformations(mTransformations, mesh); 
     207 
    129208                        mesh->Preprocess(); 
    130209                        // make an instance of this mesh 
     
    142221                if (mCurrentMesh->mFaces.size())  
    143222                { 
    144                         // HACK 
    145                         if (ROTATE_SCENE) 
    146                                 RotateMesh(mCurrentMesh); 
     223                        // should rather be written into the transformation 
     224                        // of a mesh instance 
     225                        ApplyTransformations(mTransformations, mCurrentMesh); 
     226 
    147227                        mCurrentMesh->Preprocess(); 
    148228                        // make an instance of this mesh 
     
    161241        } 
    162242} 
     243 
     244 
    163245void 
    164246X3dParseHandlers::StartIndexedFaceSet( 
     
    313395  if (element == "Material") { 
    314396    StartMaterial(attributes); 
     397  } 
     398if (1) 
     399  if (element == "Transform") { 
     400          StartTransform(attributes); 
    315401  } 
    316402 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h

    r658 r712  
    77#include <xercesc/sax/HandlerBase.hpp> 
    88#include "Mesh.h" 
     9#include <stack> 
    910 
    1011XERCES_CPP_NAMESPACE_USE 
     
    6970  bool mLoadPolygonsAsMeshes; 
    7071 
     72  typedef stack<Matrix4x4> TrafoStack; 
     73 
     74  // stack of accumulated transformations 
     75  TrafoStack mTransformations; 
     76 
    7177  // Handlers for X3D 
    7278  void 
     
    7783  EndShape(); 
    7884 
     85  void EndTransform(); 
     86  void StartTransform(AttributeList&  attributes); 
     87 
    7988  void 
    8089  StartCoordinate( 
     
    8594                AttributeList&  attributes); 
    8695   
    87    
     96  /// applies transformation m to this mesh 
     97  void ApplyTransformation(Mesh *mesh, const Matrix4x4 &m) const; 
     98 
     99  /// transforms mesh using the given transformations 
     100  void ApplyTransformations(TrafoStack trafos, Mesh *mesh) const; 
     101 
     102 
    88103  // ----------------------------------------------------------------------- 
    89104  //  Handlers for the SAX ErrorHandler interface 
Note: See TracChangeset for help on using the changeset viewer.