Changeset 752


Ignore:
Timestamp:
04/20/06 13:25:41 (18 years ago)
Author:
mattausch
Message:

after rendering workshop submissioin
x3dparser can use def - use constructs
implemented improved evaluation (samples are only stored in leaves, only propagate pvs size)

Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj

    r734 r752  
    2020                                Name="VCCLCompilerTool" 
    2121                                Optimization="0" 
    22                                 AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;..\include..\support;"..\include  ..\support";..\include;"$(QTDIR)\include\QtCore";"$(CG_INC_PATH)";"$(QTDIR)\include";"$(QTDIR)\include\QtOpenGl";"$(QTDIR)\include\QtGui";"$(GTPDIR)\NonGTP\Zlib\include";..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Devil\include" 
     22                                AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;..\include..\support;"..\include  ..\support";..\include;"$(QTDIR)\include\QtCore";"$(CG_INC_PATH)";"$(QTDIR)\include";"$(QTDIR)\include\QtOpenGl";"$(QTDIR)\include\QtGui";"$(GTPDIR)\NonGTP\Zlib\include";..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Devil\include;..\src" 
    2323                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB" 
    2424                                MinimalRebuild="TRUE" 
     
    250250                        </File> 
    251251                        <File 
     252                                RelativePath="..\src\ply.h"> 
     253                        </File> 
     254                        <File 
     255                                RelativePath="..\src\plyfile.c"> 
     256                        </File> 
     257                        <File 
     258                                RelativePath="..\src\PlyParser.cpp"> 
     259                        </File> 
     260                        <File 
     261                                RelativePath="..\src\PlyParser.h"> 
     262                        </File> 
     263                        <File 
    252264                                RelativePath="..\src\Polygon3.cpp"> 
    253265                        </File> 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r746 r752  
    10781078                                 "kd_term_min_cost=", 
    10791079                                 "10"); 
    1080    
     1080 
     1081  RegisterOption("KdTree.Termination.maxNodes", 
     1082                                 optInt, 
     1083                                 "kd_term_max_nodes=", 
     1084                                 "200000"); 
     1085 
    10811086  RegisterOption("KdTree.Termination.maxDepth", 
    10821087                                 optInt, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r746 r752  
    11341134  cb = new QCheckBox("Render errors", vbox); 
    11351135  vbox->layout()->addWidget(cb); 
    1136   cb->setChecked(true); 
     1136  cb->setChecked(false); 
    11371137  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); 
    11381138 
     
    12291229  mCutViewCells = false; 
    12301230  mCutScene = false; 
    1231   mRenderErrors = true; 
     1231  mRenderErrors = false; 
    12321232  mRenderFilter = true; 
    12331233  mShowRenderCost = false; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r667 r752  
    2222{ 
    2323  mRoot = new KdLeaf(NULL, 0); 
     24  environment->GetIntValue("KdTree.Termination.maxNodes", mTermMaxNodes); 
    2425  environment->GetIntValue("KdTree.Termination.maxDepth", mTermMaxDepth); 
    2526  environment->GetIntValue("KdTree.Termination.minCost", mTermMinCost); 
     
    6162 
    6263  mBox.Initialize(); 
    63    
    6464  ObjectContainer::const_iterator mi; 
    6565  for ( mi = leaf->mObjects.begin(); 
    6666        mi != leaf->mObjects.end(); 
    6767        mi++) { 
    68     mBox.Include((*mi)->GetBox()); 
    69   } 
    70  
    71   cout <<"KdTree Root Box:"<< mBox<<endl; 
     68        //      cout<<(*mi)->GetBox()<<endl; 
     69        mBox.Include((*mi)->GetBox()); 
     70  } 
     71 
     72  cout <<"KdTree Root Box:"<<mBox<<endl; 
    7273  mRoot = Subdivide(TraversalData(leaf, mBox, 0)); 
    7374 
     
    9091  AxisAlignedBox3 backBox, frontBox; 
    9192 
    92    
    9393  while (!tStack.empty()) { 
    94  
    95 #if 0 
    96     if ( GetMemUsage() > maxMemory ) { 
     94        //      cout<<mStat.Nodes()<<" "<<mTermMaxNodes<<endl; 
     95        if (mStat.Nodes() > mTermMaxNodes) { 
     96          //    if ( GetMemUsage() > maxMemory ) { 
    9797      // count statistics on unprocessed leafs 
    9898      while (!tStack.empty()) { 
    99         EvaluateLeafStats(tStack.top()); 
    100         tStack.pop(); 
     99                EvaluateLeafStats(tStack.top()); 
     100                tStack.pop(); 
    101101      } 
    102102      break; 
    103103    } 
    104 #endif 
    105  
     104           
     105         
    106106    TraversalData data = tStack.top(); 
    107107    tStack.pop(); 
    108108     
    109109    KdNode *node = SubdivideNode((KdLeaf *) data.mNode, 
    110                                  data.mBox, 
    111                                  backBox, 
    112                                  frontBox 
    113                                  ); 
    114     if (result == NULL) 
     110                                                                 data.mBox, 
     111                                                                 backBox, 
     112                                                                 frontBox 
     113                                                                 ); 
     114 
     115        if (result == NULL) 
    115116      result = node; 
    116117     
     
    146147int 
    147148KdTree::SelectPlane(KdLeaf *leaf, 
    148                     const AxisAlignedBox3 &box, 
    149                     float &position 
    150                     ) 
     149                                        const AxisAlignedBox3 &box, 
     150                                        float &position 
     151                                        ) 
    151152{ 
    152153  int axis = -1; 
     
    164165      bool mOnlyDrivingAxis = false; 
    165166      if (mOnlyDrivingAxis) { 
    166                                 axis = box.Size().DrivingAxis(); 
    167                                 costRatio = BestCostRatio(leaf, 
    168                                                                                                                                         box, 
    169                                                                                                                                         axis, 
    170                                                                                                                                         position, 
    171                                                                                                                                         objectsBack, 
    172                                                                                                                                         objectsFront); 
     167                axis = box.Size().DrivingAxis(); 
     168                costRatio = BestCostRatio(leaf, 
     169                                                                  box, 
     170                                                                  axis, 
     171                                                                  position, 
     172                                                                  objectsBack, 
     173                                                                  objectsFront); 
    173174      } else { 
    174                                 costRatio = MAX_FLOAT; 
    175                                 for (int i=0; i < 3; i++) { 
    176                                         float p; 
    177                                         float r = BestCostRatio(leaf, 
    178                                                                                                                                         box, 
    179                                                                                                                                         i, 
    180                                                                                                                                         p, 
    181                                                                                                                                         objectsBack, 
    182                                                                                                                                         objectsFront); 
    183                                         if (r < costRatio) { 
    184                                                 costRatio = r; 
    185                                                 axis = i; 
    186                                                 position = p; 
    187                                         } 
    188                                 } 
     175                costRatio = MAX_FLOAT; 
     176                for (int i=0; i < 3; i++) { 
     177                  float p; 
     178                  float r = BestCostRatio(leaf, 
     179                                                                  box, 
     180                                                                  i, 
     181                                                                  p, 
     182                                                                  objectsBack, 
     183                                                                  objectsFront); 
     184                  if (r < costRatio) { 
     185                        costRatio = r; 
     186                        axis = i; 
     187                        position = p; 
     188                  } 
     189                } 
    189190      } 
    190191       
    191192      if (costRatio > mMaxCostRatio) { 
    192                                 //      cout<<"Too big cost ratio "<<costRatio<<endl; 
    193                                 axis = -1; 
     193                //cout<<"Too big cost ratio "<<costRatio<<endl; 
     194                axis = -1; 
    194195      } 
    195196      break; 
     
    394395 
    395396    splitCandidates->push_back(SortableEntry(SortableEntry::BOX_MIN, 
    396                                             box.Min(axis), 
    397                                             *mi) 
    398                                ); 
     397                                                                                        box.Min(axis), 
     398                                                                                        *mi) 
     399                                                           ); 
    399400     
    400401     
    401402    splitCandidates->push_back(SortableEntry(SortableEntry::BOX_MAX, 
    402                                             box.Max(axis), 
    403                                             *mi) 
    404                                ); 
     403                                                                                        box.Max(axis), 
     404                                                                                        *mi) 
     405                                                           ); 
    405406  } 
    406407   
     
    411412float 
    412413KdTree::BestCostRatio( 
    413                                                                                         KdLeaf *node, 
    414                                                                                         const AxisAlignedBox3 &box, 
    415                                                                                         const int axis, 
    416                                                                                         float &position, 
    417                                                                                         int &objectsBack, 
    418                                                                                         int &objectsFront 
    419                                                                                         ) 
     414                                          KdLeaf *node, 
     415                                          const AxisAlignedBox3 &box, 
     416                                          const int axis, 
     417                                          float &position, 
     418                                          int &objectsBack, 
     419                                          int &objectsFront 
     420                                          ) 
    420421{ 
    421422 
     
    472473      float sum; 
    473474      if (mSahUseFaces) 
    474                                 sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 
     475                sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 
    475476      else 
    476                                 sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
     477                sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
    477478       
    478479      //      cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 
     
    480481       
    481482      if (sum < minSum) { 
    482                                 minSum = sum; 
    483                                 position = (*ci).value; 
    484                                  
    485                                 objectsBack = objectsLeft; 
    486                                 objectsFront = objectsRight; 
     483                minSum = sum; 
     484                position = (*ci).value; 
     485                 
     486                objectsBack = objectsLeft; 
     487                objectsFront = objectsRight; 
    487488      } 
    488489    } 
     
    530531  float position; 
    531532  int axis; 
     533 
    532534   
    533535  while (1) { 
     
    538540 
    539541      if (entp[axis] <= position) { 
    540                                 if (extp[axis] <= position) { 
    541                                         node = in->mBack; 
    542                                         // cases N1,N2,N3,P5,Z2,Z3 
    543                                         continue; 
    544                                 } else { 
    545                                         // case N4 
    546                                         node = in->mBack; 
    547                                         farChild = in->mFront; 
    548                                 } 
     542                if (extp[axis] <= position) { 
     543                  node = in->mBack; 
     544                  // cases N1,N2,N3,P5,Z2,Z3 
     545                  continue; 
     546                } else { 
     547                  // case N4 
     548                  node = in->mBack; 
     549                  farChild = in->mFront; 
     550                } 
    549551      } 
    550552      else { 
    551                                 if (position <= extp[axis]) { 
    552                                         node = in->mFront; 
    553                                         // cases P1,P2,P3,N5,Z1 
    554                                         continue; 
    555                                 } else { 
    556                                         node = in->mFront; 
    557                                         farChild = in->mBack; 
    558                                         // case P4 
    559                                 } 
    560                         } 
     553                if (position <= extp[axis]) { 
     554                  node = in->mFront; 
     555                  // cases P1,P2,P3,N5,Z1 
     556                  continue; 
     557                } else { 
     558                  node = in->mFront; 
     559                  farChild = in->mBack; 
     560                  // case P4 
     561                } 
     562          } 
    561563      // $$ modification 3.5.2004 - hints from Kamil Ghais 
    562564      // case N4 or P4 
     
    565567      extp = ray.GetLoc() + ray.GetDir()*tdist; 
    566568      maxt = tdist; 
    567                 } else { 
    568                         // compute intersection with all objects in this leaf 
    569                         KdLeaf *leaf = (KdLeaf *) node; 
    570                         if (ray.mFlags & Ray::STORE_KDLEAVES) 
    571                                 ray.kdLeaves.push_back(leaf); 
    572                          
    573                         ObjectContainer::const_iterator mi; 
    574                         for ( mi = leaf->mObjects.begin(); 
    575                                                 mi != leaf->mObjects.end(); 
    576                                                 mi++) { 
    577                                 Intersectable *object = *mi; 
    578                                 if (!object->Mailed() ) { 
    579                                         object->Mail(); 
    580                                         if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 
    581                                                 ray.testedObjects.push_back(object); 
    582                                         hits += object->CastRay(ray); 
    583                                 } 
    584                         } 
    585                          
    586                         if (hits && ray.GetType() == Ray::LOCAL_RAY) 
    587                                 if (ray.intersections[0].mT <= maxt) 
    588                                         break; 
    589                          
    590                         // get the next node from the stack 
    591                         if (tStack.empty()) 
    592                                 break; 
    593                          
    594                         entp = extp; 
    595                         mint = maxt; 
    596                         if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
    597                                 break; 
    598                          
    599                         RayTraversalData &s  = tStack.top(); 
    600                         node = s.mNode; 
    601                         extp = s.mExitPoint; 
    602                         maxt = s.mMaxT; 
    603                         tStack.pop(); 
     569        } else { 
     570          // compute intersection with all objects in this leaf 
     571          KdLeaf *leaf = (KdLeaf *) node; 
     572          if (ray.mFlags & Ray::STORE_KDLEAVES) 
     573                ray.kdLeaves.push_back(leaf); 
     574           
     575          ObjectContainer::const_iterator mi; 
     576          for ( mi = leaf->mObjects.begin(); 
     577                        mi != leaf->mObjects.end(); 
     578                        mi++) { 
     579                Intersectable *object = *mi; 
     580                if (!object->Mailed() ) { 
     581                  object->Mail(); 
     582                  if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 
     583                        ray.testedObjects.push_back(object); 
     584                  hits += object->CastRay(ray); 
    604585                } 
     586          } 
     587           
     588          if (hits && ray.GetType() == Ray::LOCAL_RAY) 
     589                if (ray.intersections[0].mT <= maxt) 
     590                  break; 
     591           
     592          // get the next node from the stack 
     593          if (tStack.empty()) 
     594                break; 
     595           
     596          entp = extp; 
     597          mint = maxt; 
     598          if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 
     599                break; 
     600           
     601          RayTraversalData &s  = tStack.top(); 
     602          node = s.mNode; 
     603          extp = s.mExitPoint; 
     604          maxt = s.mMaxT; 
     605          tStack.pop(); 
     606        } 
    605607  } 
    606608  return hits; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r512 r752  
    221221 
    222222    bool operator<( 
    223                    const TraversalData &b) const { 
     223                                   const TraversalData &b) const { 
    224224      KdLeaf *leafa = (KdLeaf *) mNode; 
    225225      KdLeaf *leafb = (KdLeaf *) b.mNode; 
    226226      return  
    227         leafa->mObjects.size()*mBox.SurfaceArea() 
    228         < 
    229         leafb->mObjects.size()*b.mBox.SurfaceArea(); 
     227                leafa->mObjects.size()*mBox.SurfaceArea() 
     228                < 
     229                leafb->mObjects.size()*b.mBox.SurfaceArea(); 
    230230    } 
    231231 
     
    514514 
    515515 
    516  
     516  int mTermMaxNodes; 
    517517  float mSplitBorder; 
    518518  int mTermMaxDepth; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r750 r752  
    77int Intersectable::sReservedMailboxes = 1; 
    88 
     9struct SortableVertex { 
     10 
     11  Vector3 vertex; 
     12 
     13  int originalId; 
     14  int newId; 
     15  int finalPos; 
     16 
     17  SortableVertex() {} 
     18 
     19  SortableVertex(const Vector3 &v, 
     20                                 const int id): 
     21        vertex(v), 
     22        originalId(id), 
     23        newId(id) 
     24  {} 
     25   
     26  friend bool operator<(const SortableVertex &a, 
     27                                                const SortableVertex &b) 
     28  { 
     29        if (a.vertex.x < b.vertex.x) 
     30          return true; 
     31        else 
     32          if (a.vertex.x > b.vertex.x) 
     33                return false; 
     34         
     35        if (a.vertex.y < b.vertex.y) 
     36          return true; 
     37        else 
     38          if (a.vertex.y > b.vertex.y) 
     39                return false; 
     40         
     41        if (a.vertex.z < b.vertex.z) 
     42          return true; 
     43        else 
     44          //      if (a.z > b.z) 
     45          return false; 
     46         
     47        //      return false; 
     48  } 
     49 
     50}; 
     51 
    952void 
    1053Mesh::Preprocess() 
    1154{ 
    12         Cleanup(); 
    13          
    14         mBox.Initialize(); 
     55  Cleanup(); 
     56         
     57  mBox.Initialize(); 
    1558  VertexContainer::const_iterator vi = mVertices.begin(); 
    1659  for (; vi != mVertices.end(); vi++) { 
    1760    mBox.Include(*vi); 
    1861  } 
     62 
    1963   
    2064  /** true if it is a watertight convex mesh */ 
     
    2872    cout<<"KD"; 
    2973    mKdTree->Construct(); 
    30  
     74         
    3175    if (mKdTree->GetRoot()->IsLeaf()) { 
    3276      cout<<"d"; 
    3377      delete mKdTree; 
    34                         mKdTree = NULL; 
     78          mKdTree = NULL; 
    3579    } 
     80  } 
     81} 
     82 
     83 
     84void 
     85Mesh::IndexVertices() 
     86{ 
     87  int i; 
     88  // check whether the vertices can be simplfied and reindexed 
     89  vector<SortableVertex> svertices(mVertices.size()); 
     90 
     91  for (i=0; i < mVertices.size(); i++) 
     92        svertices[i] = SortableVertex(mVertices[i], i); 
     93 
     94  sort(svertices.begin(), svertices.end()); 
     95 
     96  for (i=0; i < svertices.size() - 1; i++) 
     97        if (svertices[i].vertex == svertices[i+1].vertex) 
     98          svertices[i+1].newId = svertices[i].newId; 
     99 
     100  // remove the same vertices 
     101  int k = 0; 
     102  mVertices[0] = svertices[0].vertex; 
     103  svertices[0].finalPos = 0; 
     104   
     105  for (i=1; i < svertices.size(); i++) { 
     106        if (svertices[i].newId != svertices[i-1].newId) 
     107          k++; 
     108         
     109        mVertices[k] = svertices[i].vertex; 
     110        svertices[i].finalPos = k; 
     111  } 
     112 
     113  mVertices.resize(k + 1); 
     114   
     115  vector<int> remapBuffer(svertices.size()); 
     116  for (i = 0; i < svertices.size(); i++) 
     117        remapBuffer[svertices[i].originalId] = svertices[i].finalPos; 
     118   
     119  // remap all faces 
     120   
     121  for (int faceIndex = 0; faceIndex < mFaces.size(); faceIndex++) { 
     122        Face *face = mFaces[faceIndex]; 
     123        for (int i = 0; i < face->mVertexIndices.size(); i++) { 
     124          face->mVertexIndices[i] = remapBuffer[face->mVertexIndices[i]]; 
     125        } 
    36126  } 
    37127} 
     
    49139  return box; 
    50140} 
    51  
    52141 
    53142int 
     
    251340    ExtractVerts(&u1, &v1, paxis ); 
    252341   
     342  //$$JB changed 12.4.2006 from 0 ^^ 
    253343  if (0 && size <= 4) { 
    254344    // assume a convex face 
     
    463553} 
    464554 
     555void 
     556Mesh::AssignRandomMaterial() 
     557{ 
     558  if (!mMaterial) 
     559        mMaterial = new Material; 
     560  *mMaterial = RandomMaterial(); 
     561 
     562} 
    465563 
    466564 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h

    r750 r752  
    1818 
    1919/// vertex index container 
    20 typedef std::vector<int> VertexIndexContainer; 
     20typedef std::vector<short> VertexIndexContainer; 
    2121 
    2222 
    2323/** Patch used as an element of the mesh */ 
    24 class Face { 
     24struct Face { 
     25 
    2526public: 
    2627  Face(): mVertexIndices() {} 
     28 
    2729  Face(const int a, const int b, const int c):mVertexIndices(3) { 
    2830    mVertexIndices[0] = a; 
     
    3941  } 
    4042 
    41   Face(const VertexIndexContainer &vertices):mVertexIndices(vertices) {} 
     43  Face(const VertexIndexContainer &vertices):mVertexIndices(vertices.size()) { 
     44        for (int i=0;  i < vertices.size(); i++) 
     45          mVertexIndices[i] = vertices[i]; 
     46  } 
    4247   
    4348  /// list of vertex pointers 
     
    7479      delete mFaces[i]; 
    7580  } 
    76  
     81   
     82 
     83  void Clear() { 
     84        mVertices.clear(); 
     85        mFaces.clear(); 
     86  } 
     87   
     88  void IndexVertices(); 
     89   
     90  void AssignRandomMaterial(); 
    7791  void AddTriangle(const Triangle3 &triangle); 
    7892  void AddRectangle(const Rectangle3 &triangle); 
     
    155169        return s<<"Mesh #vertices="<<(int)mVertices.size()<<" #faces="<<(int)mFaces.size(); 
    156170  } 
    157  
     171   
    158172  friend Mesh *CreateBox(const AxisAlignedBox3 &box); 
    159173}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp

    r469 r752  
    291291int 
    292292MeshKdTree::CastRay( 
    293                                                                                 Ray &ray, 
    294                                                                                 MeshInstance *instance 
    295                                                                                 ) 
     293                                        Ray &ray, 
     294                                        MeshInstance *instance 
     295                                        ) 
    296296{ 
    297297  int hits = 0; 
     
    303303   
    304304  AxisAlignedBox3 box = GetBox(); 
     305 
    305306  if (!box.GetMinMaxT(ray, &mint, &maxt)) 
    306307    return 0; 
     
    308309  if (mint < 0) 
    309310    mint = 0; 
    310  
    311  
    312         if (ray.GetType() == Ray::LOCAL_RAY && 
    313                         ray.intersections.size() && ray.intersections[0].mT < mint) { 
    314                 return 0; 
    315         } 
    316  
     311   
     312 
     313  if (ray.GetType() == Ray::LOCAL_RAY && 
     314          ray.intersections.size() && ray.intersections[0].mT < mint) { 
     315        return 0; 
     316  } 
     317   
    317318  maxt += Limits::Threshold; 
    318319   
     
    324325  float position; 
    325326  int axis; 
    326    
     327 
    327328  while (1) { 
    328329    if (!node->IsLeaf()) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp

    r749 r752  
    22using namespace std; 
    33#include <ply.h> 
     4#include <stdio.h> 
    45 
    56#include "PlyParser.h" 
     
    910 
    1011 
    11  
    12  
     12// int facesPerMesh = 100000000; 
     13int facesPerMesh = 30; 
     14bool useRandomMaterial = false; 
     15bool indexVertices = true; 
    1316 
    1417/* user's vertex and face definitions for a polygonal object */ 
     
    3336}; 
    3437 
     38 
    3539PlyProperty vert_props[] = { /* list of property information for a vertex */ 
    3640  {"x", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,x), 0, 0, 0, 0}, 
     
    4751static PlyFace **flist; 
    4852 
     53 
    4954bool 
    50 PlyParser::ParseFile(const string filename, 
    51                                          SceneGraphNode **root, 
    52                                          const bool loadPolygonsAsMeshes) 
     55PlyParser::ParseSingleFile(const string filename, 
     56                                                   SceneGraphNode *root) 
    5357{ 
    54  
    55   /* user's vertex and face definitions for a polygonal object */ 
     58  /*** the PLY object ***/ 
     59  int nverts; 
     60  Vertex **vlist; 
     61  PlyOtherElems *other_elements = NULL; 
     62  PlyOtherProp *vert_other; 
     63  int nelems; 
     64  char **elist; 
     65  int num_comments; 
     66  char **comments; 
     67  int num_obj_info; 
     68  char **obj_info; 
     69  int file_type; 
    5670   
    57  
    58  
    59 typedef double Matrix[4][4]; 
    60  
    61 /*** the PLY object ***/ 
    62  
    63  int nverts; 
    64  Vertex **vlist; 
    65  PlyOtherElems *other_elements = NULL; 
    66  PlyOtherProp *vert_other; 
    67  int nelems; 
    68  char **elist; 
    69  int num_comments; 
    70  char **comments; 
    71  int num_obj_info; 
    72  char **obj_info; 
    73  int file_type; 
    74   
    75  int i,j; 
    76  PlyFile *ply; 
    77  int nprops; 
    78  int num_elems; 
    79  PlyProperty **plist; 
    80  char *elem_name; 
    81  float version; 
    82   
     71  int i,j; 
     72  PlyFile *ply; 
     73  int nprops; 
     74  int num_elems; 
     75  PlyProperty **plist; 
     76  char *elem_name; 
     77  float version; 
     78   
    8379  
    8480  /*** Read in the original PLY object ***/ 
     
    169165 ply_close (ply); 
    170166 
    171  
    172  
    173  
    174  *root = new SceneGraphNode; 
    175  SceneGraphNode *currentNode = *root; 
    176  
    177  
    178  cerr<<"Baking faces into eshes"<<endl; 
     167 SceneGraphNode *currentNode = root; 
     168 
     169 cerr<<"Baking faces into meshes"<<endl; 
     170 
    179171 // bake the faces into meshes 
    180  Mesh *mesh = NULL; 
    181  int facesPerMesh = 100; 
     172 Mesh meshProxy; 
     173 // only one face per mesh 
     174 VertexContainer vertices; 
     175 
    182176 for (i = 0; i < nfaces; i++) { 
    183177   if (i % facesPerMesh == 0) { 
    184          if (mesh) { 
    185                  mesh->Preprocess; 
    186                  // make an instance of this mesh 
    187                  MeshInstance *mi = new MeshInstance(mesh); 
    188                  currentNode->mGeometry.push_back(mi); 
    189            } 
    190            mesh = new Mesh(); 
     178         if (meshProxy.mFaces.size()) { 
     179 
     180           if (indexVertices) 
     181                 meshProxy.IndexVertices(); 
     182            
     183           Mesh *mesh = new Mesh(meshProxy.mVertices.size(), 
     184                                                         meshProxy.mFaces.size()); 
     185            
     186            
     187           //      cout<<"C="<<mesh->mVertices.capacity(); 
     188           mesh->mVertices = meshProxy.mVertices; 
     189           //      cout<<" NC="<<mesh->mVertices.capacity()<<" S="<<mesh->mVertices.size()<<endl; 
     190            
     191           mesh->mFaces = meshProxy.mFaces; 
     192            
     193           if (useRandomMaterial) 
     194                 mesh->AssignRandomMaterial(); 
     195 
     196           mesh->Preprocess(); 
     197           // make an instance of this mesh 
     198           MeshInstance *mi = new MeshInstance(mesh); 
     199           currentNode->mGeometry.push_back(mi); 
    191200         } 
     201 
     202         meshProxy.Clear(); 
     203   } 
    192204                  
    193         // only one face per mesh 
    194         VertexIndexContainer vc; 
    195          
    196         // add vertices 
    197         for (int k  = 0; k < flist[i]->nverts; k++) { 
    198            Vertex *v = vlist[flist[i]->verts[k]]; 
    199            vc.push_back(mesh->mVertices.size()); 
    200            mesh->mVertices.push_back(Vector3(v->x, v->y, v->z)); 
    201         } 
    202          
    203          mesh->mFaces.push_back(new Face(vc)); 
     205  // only one face per mesh 
     206  VertexIndexContainer vc; 
     207   
     208  // add vertices 
     209  for (int k  = 0; k < flist[i]->nverts; k++) { 
     210         Vertex *v = vlist[flist[i]->verts[k]]; 
     211         vc.push_back(meshProxy.mVertices.size()); 
     212         meshProxy.mVertices.push_back(Vector3(v->x, v->y, v->z)); 
     213  } 
     214   
     215   meshProxy.mFaces.push_back(new Face(vc)); 
    204216 } 
    205217  
     218 if (meshProxy.mFaces.size()) { 
     219 
     220   if (indexVertices) 
     221         meshProxy.IndexVertices(); 
     222 
     223   Mesh *mesh = new Mesh(meshProxy.mVertices.size(), 
     224                                                 meshProxy.mFaces.size()); 
     225 
     226   mesh->mVertices = meshProxy.mVertices; 
     227    
     228   mesh->mFaces = meshProxy.mFaces; 
     229    
     230   if (useRandomMaterial) 
     231         mesh->AssignRandomMaterial(); 
     232    
     233   mesh->Preprocess(); 
     234   // make an instance of this mesh 
     235   MeshInstance *mi = new MeshInstance(mesh); 
     236   currentNode->mGeometry.push_back(mi); 
     237 } 
     238 
     239 // make sure that no face gets deleted by the destructor! 
     240 meshProxy.Clear(); 
     241 
    206242 for (i=0; i < nverts; i++) 
    207243   free(vlist[i]); 
     244 
    208245 free(vlist); 
    209246 
    210247 for (i=0; i < nfaces; i++) 
    211248   free(flist[i]); 
     249 
    212250 free(flist); 
    213  
     251  
    214252  
    215253 return true; 
     254 
     255 
    216256} 
     257 
     258bool 
     259PlyParser::ParseFile(const string filename, 
     260                                         SceneGraphNode **root, 
     261                                         const bool loadPolygonsAsMeshes) 
     262{ 
     263  vector<string> filelist; 
     264   
     265  if (strstr(filename.c_str(), ".plb")) { 
     266        // parse the filelist 
     267        FILE *f = fopen(filename.c_str(), "rt"); 
     268        char s[64]; 
     269        if (!f) { 
     270          cerr<<"Cannot open .plb file"<<endl; 
     271          exit(1); 
     272        } 
     273        while (fgets(s,64,f)) { 
     274          // remove nl 
     275          s[strlen(s)-1] = 0; 
     276          filelist.push_back(s); 
     277        } 
     278        fclose(f); 
     279 
     280  } else 
     281        filelist.push_back(filename); 
     282 
     283  *root = new SceneGraphNode; 
     284 
     285  for (int i=0; i < filelist.size(); i++) { 
     286        if (!ParseSingleFile(filelist[i], *root)) { 
     287          cerr<<"Ply parse error. Quiting ...\n"; 
     288          exit(1); 
     289        } 
     290  } 
     291  return true; 
     292} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h

    r749 r752  
    1717 
    1818  bool ParseFile(const string filename, ViewCellsManager &viewCells) { return false; } 
    19    
     19 
     20  bool 
     21  ParseSingleFile(const string filename, 
     22                                  SceneGraphNode *root); 
     23         
    2024}; 
    2125 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h

    r750 r752  
    1212class Polygon3; 
    1313class Plane3; 
    14 class Face; 
     14struct Face; 
    1515class Intersectable; 
    1616class AxisAlignedBox3; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r750 r752  
    1919static void AddGeometry(SceneGraph *scene) 
    2020{ 
     21        scene->mRoot->UpdateBox(); 
     22 
    2123        AxisAlignedBox3 sceneBox = scene->GetBox(); 
    2224 
     
    131133Preprocessor::~Preprocessor() 
    132134{ 
    133   Debug<<"Deleting view cells manager...\n"; 
     135  cout << "cleaning up" << endl; 
     136 
     137  cout << "Deleting view cells manager ... \n"; 
    134138  DEL_PTR(mViewCellsManager); 
    135   Debug<<"done.\n"; 
    136   Debug<<"Deleting bsp tree...\n"; 
     139  cout << "done.\n"; 
     140 
     141  cout << "Deleting bsp tree ... \n"; 
    137142  DEL_PTR(mBspTree); 
    138   Debug<<"done.\n"; 
    139   Debug<<"Deleting kd tree...\n"; 
     143  cout << "done.\n"; 
     144 
     145  cout<<"Deleting kd tree...\n"; 
    140146  DEL_PTR(mKdTree); 
    141   Debug<<"done.\n"; 
    142   Debug<<"Deleting vspkd tree...\n"; 
     147  cout<<"done.\n"; 
     148   
     149  cout<<"Deleting vspkd tree...\n"; 
    143150  DEL_PTR(mVspKdTree); 
    144   Debug<<"done.\n"; 
    145   Debug<<"Deleting vspbsp tree...\n"; 
     151  cout<<"done.\n"; 
     152 
     153  cout<<"Deleting vspbsp tree...\n"; 
    146154  DEL_PTR(mVspBspTree); 
    147   Debug<<"done.\n"; 
     155  cout<<"done.\n"; 
    148156} 
    149157 
     
    213221         
    214222 
    215         if (result) { 
    216           // HACK  
    217         mSceneGraph->mRoot->UpdateBox(); 
    218         AddGeometry(mSceneGraph); 
     223        if (result)  
     224                { 
     225                // HACK  
     226                //AddGeometry(mSceneGraph); 
    219227          mSceneGraph->AssignObjectIds(); 
     228                 
    220229          int intersectables, faces; 
    221230          mSceneGraph->GetStatistics(intersectables, faces); 
     231 
    222232          cout<<filename<<" parsed successfully."<<endl; 
    223233          cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 
    224234          cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl; 
    225235          mSceneGraph->CollectObjects(&mObjects); 
    226           //mSceneGraph->mRoot->UpdateBox(); 
     236          mSceneGraph->mRoot->UpdateBox(); 
    227237 
    228238         /* Exporter *exporter = Exporter::GetExporter("testload.x3d"); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r713 r752  
    9090  */ 
    9191  int AddPvs(const Pvs<T> &pvs); 
     92 
    9293  /** Subtracts one pvs from another one. 
     94  WARNING: could contains bugs 
    9395          @returns new pvs size 
    9496  */ 
     
    113115                                                                          float &pvsEnlargement); 
    114116   
     117 
     118  /** Clears the pvs. 
     119  */ 
     120  void Clear(); 
    115121 
    116122  /** Compute continuous PVS difference */ 
     
    237243} 
    238244 
     245template <typename T> void Pvs<T>::Clear() 
     246{ 
     247        mEntries.clear(); 
     248         
     249 
     250} 
     251 
     252 
    239253template <typename T> 
    240254PvsData<T> *Pvs<T>::Find(T sample) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp

    r746 r752  
    6767        } 
    6868        break; 
     69         
    6970  default: 
    7071        result = Preprocessor::GenerateRays(number, sampleType, rays); 
     
    8081                                                  ) 
    8182{ 
    82   for (int i=0; i < rays.size(); i++) 
     83  for (int i=0; i < rays.size(); i++) { 
    8384        CastRay(rays[i].mOrigin, rays[i].mDirection, rays[i].mPdf, vssRays); 
     85        if (i % 10000 == 0) 
     86          cout<<"."; 
     87  } 
     88  cout<<endl; 
    8489} 
    8590 
     
    298303  exporter->SetFilled(); 
    299304  // $$JB temporarily do not export the scene 
    300   if (1) 
     305  if (0) 
    301306        exporter->ExportScene(mSceneGraph->mRoot); 
    302307  exporter->SetWireframe(); 
     
    435440{ 
    436441  // compute rendering error 
    437   if (renderer) { 
     442  if (renderer && renderer->mPvsStatFrames) { 
    438443        //      emit EvalPvsStat(); 
    439444        //      QMutex mutex; 
     
    504509        SimpleRayContainer rays; 
    505510 
     511        cout<<"Generating initial rays..."<<endl; 
    506512        GenerateRays(mInitialSamples/4, SPATIAL_BOX_BASED_DISTRIBUTION, rays); 
    507513        GenerateRays(mInitialSamples/4, OBJECT_BASED_DISTRIBUTION, rays); 
     
    509515        GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays); 
    510516         
     517        cout<<"Casting initial rays..."<<endl; 
    511518        CastRays(rays, mVssRays); 
    512519 
     
    536543  if (mUseViewcells) { 
    537544 
     545        cout<<"Computing sample contributions..."<<endl; 
    538546        // evaluate contributions of the intitial rays 
    539547        mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
    540          
     548        cout<<"done.\n"; 
    541549         
    542550        mStats << 
     
    559567        Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
    560568        // cull viewcells with PVS > median (0.5f) 
    561         mViewCellsManager->SetValidityPercentage(0, 0.5f);  
     569        //mViewCellsManager->SetValidityPercentage(0, 0.5f);  
     570        mViewCellsManager->SetValidityPercentage(0, 1.0f);  
    562571        Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
    563572         
     
    571580   
    572581  /// compute view cell contribution of rays if view cells manager already constructed 
    573   mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
     582  //  mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
    574583 
    575584  if (mUseImportanceSampling) { 
     
    651660                if (mDirectionalSampling) 
    652661                  rayType = DIRECTION_BASED_DISTRIBUTION; 
    653            
     662 
     663          cout<<"Generating rays..."<<endl; 
     664 
    654665          GenerateRays(mRssSamplesPerPass, rayType, rays); 
     666          cout<<"done."<<endl; 
     667 
     668          cout<<"Casting rays..."<<endl; 
    655669          CastRays(rays, vssRays); 
     670          cout<<"done."<<endl; 
    656671          castRays += rays.size(); 
    657672          if (mUseViewcells) { 
    658673                /// compute view cell contribution of rays 
     674                cout<<"Computing sample contributions..."<<endl; 
    659675                mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 
     676                cout<<"done."<<endl; 
    660677          } 
    661678                 
  • GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp

    r750 r752  
    9696      cout<<"+"; 
    9797      vector<Vector3> vertices; 
    98       vector<int> vertexIndices; 
     98      VertexIndexContainer vertexIndices; 
    9999 
    100100      /* face */ 
     
    133133      int index = (int)currentMesh->mVertices.size(); 
    134134      for (i=0; i < vertices.size(); i++, index++) { 
    135         currentMesh->mVertices.push_back(vertices[i]); 
    136         vertexIndices.push_back(index); 
     135                currentMesh->mVertices.push_back(vertices[i]); 
     136                vertexIndices.push_back(index); 
    137137      } 
    138138       
     
    184184  fclose(file); 
    185185   
    186    
    187186  *proot = root; 
    188187 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r746 r752  
    1818{ 
    1919public: 
    20         //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const 
    2120        bool operator() (T v1, T v2) const 
    2221        { 
     
    3938 
    4039// pvs penalty can be different from pvs size 
    41 inline float EvalPvsPenalty(const int pvs, const int lower, const int upper) 
     40inline static float EvalPvsPenalty(const int pvs, const int lower, const int upper) 
    4241{ 
    4342        // clamp to minmax values 
    44 #if HAS_TO_BE_REDONE 
    4543        if (pvs < lower) 
    4644                return (float)lower; 
    4745        if (pvs > upper) 
    4846                return (float)upper; 
    49 #endif 
     47 
    5048        return (float)pvs; 
    5149} 
     
    7068 
    7169/// Fast computation of merged pvs size 
    72 int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 
     70static int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 
    7371{ 
    7472        // add first pvs 
     
    9997 
    10098// computet render cost of merge 
    101 float ViewCellsTree::ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const 
     99float ViewCellsTree::ComputeMergedPvsCost(const ObjectPvs &pvs1,  
     100                                                                                  const ObjectPvs &pvs2) const 
    102101{ 
    103102        float renderCost = 0; 
     
    143142mParent(NULL), 
    144143mMergeCost(0), 
    145 mIsActive(false) 
     144mIsActive(false), 
     145mPvsSize(0), 
     146mPvsSizeValid(false) 
    146147{ 
    147148} 
     
    156157mMergeCost(0), 
    157158mIsActive(false), 
    158 mLastUpdated(sLastUpdated) 
     159mLastUpdated(sLastUpdated), 
     160mPvsSize(0), 
     161mPvsSizeValid(false) 
    159162{ 
    160163} 
     
    165168        return mPvs; 
    166169} 
     170 
    167171 
    168172ObjectPvs &ViewCell::GetPvs() 
     
    205209{ 
    206210        mArea = area; 
     211} 
     212 
     213 
     214void ViewCell::SetColor(const RgbColor &color)  
     215{ 
     216        mColor = color; 
     217} 
     218 
     219 
     220RgbColor ViewCell::GetColor() const  
     221{ 
     222        return mColor; 
    207223} 
    208224 
     
    367383mUseAreaForPvs(false), 
    368384mViewCellsManager(vcm), 
    369 mIsCompressed(false) 
     385#if 0 
     386mViewCellsStorage(PVS_IN_INTERIORS) 
     387#else 
     388mViewCellsStorage(PVS_IN_LEAVES) 
     389#endif 
    370390{ 
    371391        environment->GetBoolValue("ViewCells.Visualization.exportMergedViewCells", mExportMergedViewCells); 
     
    393413float ViewCellsTree::GetMemUsage() const 
    394414{ 
     415        // TODO 
    395416        return 0; 
    396417                /*(sizeof(ViewCellsTree) + 
     
    513534        // we start with the current view cells from the view cell manager.  
    514535        // The active view cells will change with subsequent merges 
    515         Debug << "here2" << endl; Debug.flush(); 
     536         
    516537        // todo: should rather take initial view cells 
    517538    ViewCellContainer &activeViewCells = mViewCellsManager->GetViewCells(); 
    518         //ViewCellContainer activeViewCells; 
    519          
    520         Debug << "here2.6" << endl; Debug.flush(); 
     539         
     540         
    521541        ViewCell::NewMail(); 
    522542 
     
    704724                Debug << "setting root of the merge history" << endl; 
    705725                mRoot = activeViewCells[0]; 
    706                 Debug << "rootvc volume: " << mRoot->GetVolume() << endl; 
     726                Debug << "volume of the root view cell: " << mRoot->GetVolume() << " " << mViewCellsManager->GetViewSpaceBox().GetVolume() << endl; 
     727        } 
     728        else 
     729        { 
     730                Debug << "big error, root is NULL" << endl; 
    707731        } 
    708732         
     
    803827                        swap(viewCells[i], viewCells.back()); 
    804828                 
    805                 // mail view cell as it has not been merged 
     829                // mail view cell that it has not been merged 
    806830                viewCells[i]->Mail(); 
    807831 
     
    814838        // merged in the mean time 
    815839        ViewCellContainer::const_iterator ait, ait_end = mMergedViewCells.end(); 
     840 
    816841        for (ait = mMergedViewCells.begin(); ait != ait_end; ++ ait) 
    817842        { 
     
    825850        } 
    826851 
     852        // dispose old merged view cells 
    827853        mMergedViewCells.clear(); 
    828854 
     
    836862                const int lower = mViewCellsManager->GetMinPvsSize(); 
    837863                const int upper = mViewCellsManager->GetMaxPvsSize(); 
     864 
    838865                const float penalty = EvalPvsPenalty((*vit)->GetPvs().GetSize(), lower, upper); 
    839866                 
     
    905932        if (!vc) return NULL; 
    906933 
     934        // set to the new parent view cell 
    907935        l->SetParent(vc); 
    908936        r->SetParent(vc); 
     
    932960        pvsDiff = vc->GetPvs().GetSize() - pvs1 - pvs2; 
    933961 
     962 
     963 
     964        //Ždon't store intermediate pvs 
     965        if (mViewCellsStorage == PVS_IN_LEAVES) 
     966        { 
     967                l->mPvsSize = l->GetPvs().GetSize();  
     968                l->mPvsSizeValid = true; 
     969                 
     970                if (!l->IsLeaf()) 
     971                        l->GetPvs().Clear(); 
     972                 
     973                r->mPvsSize = r->GetPvs().GetSize();  
     974                r->mPvsSizeValid = true; 
     975                 
     976                if (!r->IsLeaf()) 
     977                        r->GetPvs().Clear(); 
     978         
     979} 
     980 
     981 
    934982        return vc; 
    935983} 
    936  
    937984 
    938985 
     
    11891236        if (1) 
    11901237        { 
    1191                 const float penalty = EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 
    1192                 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 
     1238                const float penalty =  
     1239                        EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 
     1240                return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) /  
     1241                        (float)mNumActiveViewCells; 
    11931242        } 
    11941243 
     
    12331282bool ViewCellsTree::ValidateMergeCandidate(MergeCandidate &mc) const 
    12341283{ 
     1284        // propagate up so we have only the active view cells 
    12351285        while (mc.mLeftViewCell->mParent) 
    12361286        { 
     
    12431293        } 
    12441294 
     1295        // this view cell was already merged 
     1296        //return mc.mLeftViewCell && (mc.mLeftViewCell != mc.mRightViewCell); 
    12451297        return mc.mLeftViewCell != mc.mRightViewCell; 
    12461298} 
     
    12501302{ 
    12511303        //-- compute pvs difference 
    1252         const float newPvs =  
    1253 #if 1 // not valid if not using const cost per object!! 
    1254                 ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(),  
    1255                                                          mc.mRightViewCell->GetPvs()); 
    1256 #else 
    1257                 ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(),  
    1258                                                          mc.mRightViewCell->GetPvs()); 
    1259 #endif 
     1304        int newPvs; 
     1305        if (1) // not valid if not using const cost per object!! 
     1306                newPvs = ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 
     1307        else 
     1308                newPvs = (int)ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 
    12601309 
    12611310        const float newPenalty = EvalPvsPenalty(newPvs, 
     
    13051354} 
    13061355 
    1307 void ViewCellsTree::CompressViewCellsPvs() 
    1308 { 
    1309         if (!mIsCompressed) 
    1310         { 
    1311                 mIsCompressed = true; 
     1356 
     1357void ViewCellsTree::SetViewCellsStorage(int stype) 
     1358{ 
     1359        if (mViewCellsStorage == stype) 
     1360                return; 
     1361 
     1362        // TODO 
     1363        switch (stype) 
     1364        { 
     1365        case COMPRESSED: 
    13121366                CompressViewCellsPvs(mRoot); 
    1313         } 
    1314 } 
     1367                break; 
     1368        default: 
     1369                break; 
     1370        } 
     1371 
     1372        mViewCellsStorage = stype; 
     1373} 
     1374 
    13151375 
    13161376void ViewCellsTree::CompressViewCellsPvs(ViewCell *root) 
     
    13441404        const float vol = box.GetVolume(); 
    13451405 
     1406        const int rootPvs = GetPvsSize(mRoot); 
     1407 
    13461408        Debug << "vsb volume: " << vol << endl; 
    13471409        Debug << "root volume: " << mRoot->GetVolume() << endl; 
    1348         Debug << "root pvs: " << mRoot->GetPvs().GetSize() << endl; 
     1410        Debug << "root pvs: " << rootPvs << endl; 
    13491411 
    13501412        int totalPvs; 
     
    13521414 
    13531415        float deviation = 0; 
    1354         totalPvs = (int)mRoot->GetPvs().GetSize(); 
    1355         totalRenderCost = avgRenderCost = expectedCost = (float)mRoot->GetPvs().GetSize(); 
     1416        totalPvs = rootPvs; 
     1417        totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs; 
    13561418 
    13571419        ofstream stats; 
    13581420        stats.open(mergeStats.c_str()); 
    13591421 
     1422        //-- first view cell 
    13601423        stats  
    13611424                << "#Pass\n" << 0 << endl 
     
    13641427        << "#RenderCostDecrease\n" << 0 << endl // TODO 
    13651428                << "#TotalRenderCost\n" << totalRenderCost << endl 
    1366                 << "#CurrentPvs\n" << mRoot->GetPvs().GetSize() << endl 
     1429                << "#CurrentPvs\n" << rootPvs << endl 
    13671430                << "#ExpectedCost\n" << expectedCost << endl 
    13681431                << "#AvgRenderCost\n" << avgRenderCost << endl 
     
    13831446                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    13841447                         
    1385                         const int parentPvs = interior->GetPvs().GetSize(); 
     1448                        const int parentPvs = GetPvsSize(interior); 
    13861449                        const float parentCost = (float)parentPvs * interior->GetVolume(); 
    13871450                        float childCost = 0; 
     
    13941457                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
    13951458                        { 
    1396                                 childCost += (float)(*it)->GetPvs().GetSize() * (*it)->GetVolume(); 
    1397                                 childPvs += (*it)->GetPvs().GetSize(); 
     1459                                int pvsSize = GetPvsSize(*it); 
     1460                                childCost += (float) pvsSize * (*it)->GetVolume(); 
     1461                                childPvs += pvsSize; 
    13981462 
    13991463                                tqueue.push(*it); 
     
    14161480                                << "#RenderCostDecrease\n" << costDecr << endl // TODO 
    14171481                                << "#TotalRenderCost\n" << totalRenderCost << endl 
    1418                                 << "#CurrentPvs\n" << vc->GetPvs().GetSize() << endl 
     1482                                << "#CurrentPvs\n" << parentPvs << endl 
    14191483                                << "#ExpectedCost\n" << expectedCost << endl 
    14201484                                << "#AvgRenderCost\n" << avgRenderCost << endl 
     
    14321496 
    14331497 
    1434 #if 0 
    1435 float ViewCellsTree::ComputeVolume(ViewCell *vc) 
    1436 { 
    1437         if (vc->IsLeaf()) 
    1438         { 
    1439                 return vc->GetVolume(); 
    1440         } 
    1441         else 
    1442         { 
    1443                 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    1444  
    1445                 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
    1446  
    1447                 float volume = 0; 
    1448  
    1449                 for (it = interior->mChildren.begin(); it != it_end; ++ it) 
    1450                 { 
    1451                         volume += ComputeVolume(*it);    
    1452                 } 
    1453  
    1454                 interior->SetVolume(volume); 
    1455                 return volume; 
    1456         } 
    1457 } 
    1458 #endif 
    1459  
    14601498void ViewCellsTree::SetRoot(ViewCell *root) 
    14611499{ 
     
    15581596        } 
    15591597 
    1560         int dummy = interior->GetPvs().GetSize(); 
     1598        /*int dummy = interior->GetPvs().GetSize(); 
    15611599 
    15621600        for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 
    15631601        { 
    15641602                dummy += (*cit)->GetPvs().GetSize(); 
    1565         } 
    1566  
    1567 } 
    1568  
    1569  
     1603        }*/ 
     1604 
     1605} 
     1606 
     1607// TODO 
    15701608void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const 
    15711609{ 
    15721610        Intersectable::NewMail(); 
    15731611 
    1574         if (!mIsCompressed) 
     1612        if (mViewCellsStorage == PVS_IN_INTERIORS) 
    15751613                pvs = vc->GetPvs(); 
    15761614 
     
    16121650int ViewCellsTree::GetPvsSize(ViewCell *vc) const 
    16131651{ 
     1652        int pvsSize = 0; 
     1653 
     1654        if (vc->IsLeaf()) 
     1655        { 
     1656                pvsSize = vc->GetPvs().GetSize(); 
     1657        } 
     1658         
     1659 
    16141660        Intersectable::NewMail(); 
    16151661 
    1616         if (!mIsCompressed) 
    1617                 return vc->GetPvs().GetSize(); 
    1618  
    1619  
    1620         ////////////////////////777 
     1662        ////////////////////////// 
     1663        switch (mViewCellsStorage) 
     1664        { 
     1665        case PVS_IN_LEAVES: //-- store pvs only in leaves 
     1666                {                        
     1667                        if (vc->mPvsSizeValid) 
     1668                        { 
     1669                                pvsSize = vc->mPvsSize; 
     1670                                break; 
     1671                        } 
     1672         
     1673                        //-- if no valid pvs size stored as a scalar=> compute new pvs size 
     1674                        ViewCellContainer leaves; 
     1675                        CollectLeaves(vc, leaves); 
     1676 
     1677                        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     1678 
     1679                        Intersectable::NewMail(); 
     1680 
     1681                        // sum different intersectables 
     1682                        for (it = leaves.begin(); it != it_end; ++ it) 
     1683                        { 
     1684                                ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 
     1685 
     1686                                // mail all from first pvs 
     1687                                for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     1688                                { 
     1689                                        Intersectable *intersect = (*oit).first; 
     1690 
     1691                                        if (!intersect->Mailed()) 
     1692                                        { 
     1693                                                ++ pvsSize; 
     1694                                                intersect->Mail();                                       
     1695                                        } 
     1696                                } 
     1697                        } 
     1698 
     1699                        break; 
     1700                } 
     1701        case COMPRESSED: 
     1702                { 
     1703                        //////////////////////// 
    16211704        //-- compressed pvs 
    16221705 
     1706                        if (vc->mPvsSizeValid) 
     1707                                return vc->mPvsSize; 
     1708 
     1709                        // if no pvs size stored: compute 
    16231710        int pvsSize = 0; 
    16241711        ViewCell *root = vc; 
     
    16531740                } 
    16541741        } 
     1742                        break; 
     1743                } 
     1744        case PVS_IN_INTERIORS: 
     1745        default:Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().GetSize() << endl; 
     1746                pvsSize = vc->GetPvs().GetSize();                
     1747        } 
    16551748 
    16561749        return pvsSize;   
    1657  
    16581750} 
    16591751 
     
    16721764        int pvsSize = 0; 
    16731765        // only count leaves for uncompressed method for fairness 
    1674         if (mIsCompressed || vc->IsLeaf()) 
     1766        if ((mViewCellsStorage == PVS_IN_INTERIORS) || vc->IsLeaf()) 
     1767        { 
    16751768                pvsSize = vc->GetPvs().GetSize(); 
     1769        } 
    16761770 
    16771771        if (!vc->IsLeaf()) 
     
    16911785 
    16921786 
    1693 bool ViewCellsTree::IsCompressed() const 
    1694 { 
    1695         return mIsCompressed; 
     1787int ViewCellsTree::ViewCellsStorage() const 
     1788{ 
     1789        return mViewCellsStorage; 
    16961790} 
    16971791 
     
    18451939        if (!vc->GetValid()) 
    18461940                ++ vcStat.invalid; 
    1847  
    1848         /*ViewCellsContainer leaves; 
    1849         CollectLeaves(vc, leaves); 
    1850  
    1851         vcStat.leaves = (int)leaves.size();*/ 
    18521941} 
    18531942 
     
    19692058void ViewCellsTree::SetActiveSetToLeaves() 
    19702059{ 
     2060        // todo 
    19712061} 
    19722062 
     
    20262116bool MergeCandidate::IsValid() const 
    20272117{ 
     2118        // if one has a parent, it was already merged 
    20282119        return !(mLeftViewCell->mParent || mRightViewCell->mParent); 
    20292120} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r746 r752  
    9090class ViewCell: public MeshInstance 
    9191{ 
     92        friend class ViewCellsTree; 
     93        friend class ViewCellsManager; 
     94        friend class VspBspViewCellsManager; 
     95        friend class BspViewCellsManager; 
     96        friend class VspBspTree; 
     97        friend class BspTree; 
     98 
     99 
    92100public: 
    93101        ViewCell(); 
     
    104112        */ 
    105113        const ObjectPvs &GetPvs() const; 
     114 
    106115        ObjectPvs &GetPvs(); 
    107116 
     117        /** Type of view cells. 
     118        */ 
    108119        int Type() const; 
    109120 
     
    151162        float GetRenderCost() const; 
    152163 
    153   /** set color for visiualizations */ 
    154   void SetColor(const RgbColor &color) { 
    155         mColor = color; 
    156   } 
    157  
    158   /** get color for visualuzations */ 
    159   RgbColor GetColor() const { 
    160         return mColor; 
    161   } 
     164        /** set color for visiualizations. 
     165        */ 
     166        void SetColor(const RgbColor &color); 
     167 
     168        /** get color for visualuzations. 
     169        */ 
     170    RgbColor GetColor() const; 
    162171 
    163172   
     
    173182        virtual bool IsLeaf() const = 0; 
    174183 
    175   static bool SmallerPvs(const ViewCell *a, 
    176                                                  const ViewCell *b) { 
     184        static bool SmallerPvs(const ViewCell *a, const ViewCell *b)  
     185        { 
    177186        return a->GetPvs().GetSize() < b->GetPvs().GetSize(); 
    178187  } 
     
    205214        bool IsActive() const; 
    206215 
     216 
    207217        // last mail id -> warning not thread safe! 
    208218        // both mailId and mailbox should be unique for each thread!!! 
     
    228238        /** color used for consistent visualization */ 
    229239        RgbColor mColor; 
     240 
     241         
     242        /// pvs size, used for lazy pvs computation 
     243        int mPvsSize; 
     244        bool mPvsSizeValid; 
     245 
    230246}; 
    231247 
     
    233249class ViewCellInterior: public ViewCell 
    234250{ 
     251        friend class ViewCellsManager; 
    235252public: 
    236253        ViewCellInterior(); 
     
    292309{ 
    293310        friend class ViewCellsManager; 
     311 
     312 
    294313public: 
    295314        ViewCellsTree(ViewCellsManager *vcm); 
     
    355374        float GetMemoryCost(ViewCell *vc) const; 
    356375 
    357         /** Compresses the pvs of the view cells from the root. 
    358         */ 
    359         void CompressViewCellsPvs(); 
     376        /** Sets method of storage for view cells. 
     377        */ 
     378        void SetViewCellsStorage(int type); 
     379 
     380        /** pvs storage methods */ 
     381        enum {PVS_IN_INTERIORS, COMPRESSED, PVS_IN_LEAVES}; 
    360382 
    361383        /** If view cells in this tree have compressed pvs. 
    362384        */ 
    363         bool IsCompressed() const; 
     385        int ViewCellsStorage() const; 
    364386 
    365387        /** Returns active view cell that is in the path of this view cell. 
     
    485507 
    486508        /// if the view cell tree hold compressed pvs 
    487         bool mIsCompressed; 
     509        int mViewCellsStorage; 
    488510 
    489511        ViewCellsManager *mViewCellsManager; 
     
    494516 
    495517         
    496                  
     518        /** intermediate container of merged view cells. 
     519*/ 
    497520        ViewCellContainer mMergedViewCells; 
    498521         
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r750 r752  
    332332        cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 
    333333 
     334        long startTime = GetTime(); 
     335 
    334336        //-- construction rays => we use uniform samples for this 
    335337        CastPassSamples(mInitialSamples,  
     
    341343         
    342344        // construct view cells 
    343         const int numInitialSamples =  
    344                 ConstructSubdivision(preprocessor->mObjects, initialSamples); 
     345        ConstructSubdivision(preprocessor->mObjects, initialSamples); 
    345346 
    346347        // initial samples count for overall samples ... 
    347         numSamples += numInitialSamples; 
     348        numSamples += mInitialSamples; 
    348349 
    349350        // rays can be passed or deleted 
    350351        disposeRays(initialSamples, outRays); 
    351          
     352 
     353        cout << "time needed for initial construction: " 
     354                 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     355 
     356        Debug << "time needed for initial construction: " 
     357                  << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     358 
     359 
     360        // take post processing time 
     361        startTime = GetTime(); 
     362 
     363 
    352364        // testing the view cell filter functionality    
    353365        if (0) TestFilter(preprocessor->mObjects); 
     
    421433                cout << "total samples: " << numSamples << endl; 
    422434        } 
     435 
    423436         
    424437 
     
    457470        PostProcess(preprocessor->mObjects, postProcessSamples); 
    458471 
     472        cout << "time needed for  post processing (merge) step: " 
     473                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
     474 
     475        Debug << "time needed for  post processing (merge) step: " 
     476                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
     477 
    459478        // only for debugging purpose 
    460479        if (TEST_EMPTY_VIEW_CELLS) 
     
    481500        } 
    482501 
    483         // needed to fix empty view cells 
    484     //SetValidity(0, 99999999999); 
    485  
    486  
    487502        // evaluation of the paritition, i.e., a number of new samples are cast 
    488503        if (mEvaluateViewCells) 
     
    491506        } 
    492507         
    493         if (0) 
    494         { 
    495                 ViewCellContainer leaves; 
    496                 mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves); 
    497                 mViewCellsTree->ResetPvs(); 
    498                 VssRayContainer dummyRays; 
    499                 CastPassSamples(mInitialSamples, mSamplingType, dummyRays); 
    500          
    501                 //ComputeSampleContributions(initialSamples, true, false); 
    502                 ComputeSampleContributions(dummyRays, true, false); 
    503  
    504                 ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    505  
    506                 for (it = leaves.begin(); it != it_end; ++ it) 
    507                 { 
    508                         mViewCellsTree->PropagatePvs(*it); 
    509                 } 
    510  
    511                 mViewCellsTree->ExportStats("dummy.log"); 
    512         } 
    513  
    514508        return numSamples; 
    515509} 
    516510 
    517511 
    518 void ComputeMinMaxRenderCost(float &minRenderCost, 
    519                                                          float &maxRenderCost,  
    520                                                          const ViewCellContainer &viewCells) 
    521 { 
    522         minRenderCost = 1e20f; 
    523         maxRenderCost = -1; 
    524  
    525         ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    526  
    527         for (it = viewCells.begin(); it != it_end; ++ it) 
    528         { 
    529                 const float renderCost = (float)(*it)->GetPvs().GetSize() * (*it)->GetVolume(); 
    530                 if (renderCost > maxRenderCost) 
    531                         maxRenderCost = renderCost; 
    532                 else if (renderCost < minRenderCost) 
    533                         minRenderCost = renderCost; 
    534         } 
    535 } 
    536  
    537  
    538 void ViewCellsManager::EvalViewCellHistogram(const string filename, const int nViewCells) 
     512void ViewCellsManager::EvalViewCellHistogram(const string filename,  
     513                                                                                         const int nViewCells) 
    539514{ 
    540515        std::ofstream outstream; 
     
    554529        Debug << "histogram minrc: " << minRenderCost << " maxrc: " << maxRenderCost << endl; 
    555530 
    556         const int intervals = min(10000, (int)viewCells.size()); 
     531        const int intervals = min(50, (int)viewCells.size()); 
    557532 
    558533        const float range = maxRenderCost - minRenderCost; 
     
    634609        maxPvsSize = viewCells.back()->GetPvs().GetSize(); 
    635610         
     611        minPvsSize = 0; 
     612        maxPvsSize = 1200; 
     613 
    636614        Debug << "histogram minpvssize: " << minPvsSize << " maxpvssize: " << maxPvsSize << endl; 
    637615 
    638         const int intervals = min(10000, (int)viewCells.size()); 
     616        const int intervals = min(20, (int)viewCells.size()); 
    639617        const int range = maxPvsSize - minPvsSize; 
    640618        int stepSize = range / intervals; 
    641619 
     620         
    642621        if (!stepSize) stepSize = 1; 
     622Debug << "stepsize: " << stepSize << endl; 
     623        cout << "stepsize: " << stepSize << endl; 
    643624 
    644625        const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost(); 
     
    756737                castSamples += samplesPerPass; 
    757738 
    758                 cout << "computing sample contributions of " << (int)evaluationSamples.size() << " samples " << endl; 
     739                cout << "computing sample contributions of " << (int)evaluationSamples.size()  
     740                         << " samples " << endl; 
    759741 
    760742                ComputeSampleContributions(evaluationSamples, true, false); 
     
    762744                cout << "compute new statistics ... "; 
    763745 
    764                 ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    765  
    766                 for (it = leaves.begin(); it != it_end; ++ it) 
    767                 { 
    768                         mViewCellsTree->PropagatePvs(*it); 
    769                 } 
     746                // propagate pvs or pvs size information 
     747                ObjectPvs pvs; 
     748                UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 
     749 
    770750 
    771751                // output stats 
     
    819799                } 
    820800#else 
    821                 for (int pass = histoPasses; pass < numLeaves; pass += histoPasses) 
     801                for (int pass = histoPasses; pass <= numLeaves; pass += histoPasses) 
    822802                { 
    823803                        cout << "computing histogram for " << pass << " view cells" << endl; 
     
    830810 
    831811                        ////////////////////////////////////////// 
    832             // --evaluate histogram for pvs size 
     812            //-- evaluate histogram for pvs size 
    833813 
    834814                        cout << "computing pvs histogram for " << pass << " view cells" << endl; 
     
    892872        { 
    893873        case PER_OBJECT: 
    894                 return 1; 
     874                //cout << "perobject" << endl; 
     875                return 1.0f; 
    895876         
    896877        case PER_TRIANGLE: 
     
    906887                } 
    907888        default: 
    908                 return 1; 
     889                cout << "default" << endl; 
     890                return 1.0f; 
    909891        } 
    910892 
    911893        // should not come here 
    912         return 0; 
     894        return 0.0f; 
    913895} 
    914896 
     
    13551337} 
    13561338 
    1357  
     1339// fast way of merging 2 view cells 
    13581340ViewCellInterior *ViewCellsManager::MergeViewCells(ViewCell *left, ViewCell *right) const 
    13591341{ 
    13601342        // generate parent view cell 
    1361         ViewCellInterior *vc = new ViewCellInterior();//GenerateViewCell(); 
    1362  
     1343        ViewCellInterior *vc = new ViewCellInterior(); 
     1344 
     1345        vc->GetPvs().Clear(); 
    13631346        vc->GetPvs() = left->GetPvs(); 
    1364         // merge pvs 
     1347 
     1348        // merge pvs of right cell 
    13651349        vc->GetPvs().Merge(right->GetPvs()); 
    13661350 
     
    13801364        vc->mChildren.push_back(right); 
    13811365 
     1366        // update pvs size 
     1367        vc->mPvsSize = vc->GetPvs().GetSize(); 
     1368        vc->mPvsSizeValid = true; 
     1369 
    13821370        return vc; 
    13831371} 
     
    13861374ViewCellInterior *ViewCellsManager::MergeViewCells(ViewCellContainer &children) const 
    13871375{ 
    1388         ViewCellInterior *vc = new ViewCellInterior();//GenerateViewCell(); 
     1376        ViewCellInterior *vc = new ViewCellInterior(); 
    13891377 
    13901378        ViewCellContainer::const_iterator it, it_end = children.end(); 
     
    13951383                vc->GetPvs().Merge((*it)->GetPvs()); 
    13961384                vc->mChildren.push_back(*it); 
    1397                 //vc->SetupChildLink(*it); 
    13981385        } 
    13991386 
     
    17551742float ViewCellsManager::GetRendercost(ViewCell *viewCell) const 
    17561743{ 
    1757         const ObjectPvs &pvs = viewCell->GetPvs(); 
    1758  
    1759         ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
    1760  
    1761         for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    1762         { 
    1763                  
    1764         } 
    1765  
    17661744        return mViewCellsTree->GetPvsSize(viewCell); 
    17671745} 
     
    20222000        { 
    20232001                cout << "constructing spatial merge tree" << endl; 
     2002 
    20242003                // create spatial merge hierarchy 
    2025                 mViewCellsTree->SetRoot(ConstructSpatialMergeTree(mBspTree->GetRoot())); 
     2004                ViewCell *root = ConstructSpatialMergeTree(mBspTree->GetRoot()); 
     2005                mViewCellsTree->SetRoot(root); 
     2006 
     2007                // compute pvs 
     2008                ObjectPvs pvs; 
     2009                UpdatePvsForEvaluation(root, pvs); 
    20262010        } 
    20272011 
     
    20372021        cout << "finished" << endl; 
    20382022        cout << "merged view cells in " 
    2039                  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
     2023                 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    20402024 
    20412025        Debug << "Postprocessing: Merged view cells in " 
    2042                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 
     2026                << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl << endl; 
    20432027         
    20442028 
     
    20762060        } 
    20772061 
    2078         if (1) // export merged view cells 
     2062        if (1) // export merged view cells using pvs color coding 
    20792063        { 
    20802064                mColorCode = 1; 
     
    20872071                { 
    20882072                        //exporter->SetWireframe(); 
    2089                          
     2073                        //exporter->SetForcedMaterial(RandomMaterial()); 
     2074 
    20902075                        if (mExportGeometry) 
    20912076                                exporter->ExportGeometry(objects); 
     
    26292614ViewCell *BspViewCellsManager::ConstructSpatialMergeTree(BspNode *root) 
    26302615{ 
     2616        // terminate recursion 
    26312617        if (root->IsLeaf()) 
    26322618        { 
    2633                 ViewCell *viewCell = dynamic_cast<BspLeaf *>(root)->GetViewCell(); 
    2634  
    2635                 viewCell->SetMergeCost(0.0f); 
    2636  
    2637                 return viewCell; 
     2619                BspLeaf *leaf = dynamic_cast<BspLeaf *>(root); 
     2620                leaf->GetViewCell()->SetMergeCost(0.0f); 
     2621                return leaf->GetViewCell(); 
    26382622        } 
    26392623         
     
    26412625        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    26422626                 
     2627        // evaluate merge cost for priority traversal 
    26432628        float mergeCost = 1.0f / (float)root->mTimeStamp; 
    2644         //Debug << "timestamp: " << root->mTimeStamp; 
    2645         //Debug << "merge cost: " << mergeCost << endl; 
    2646  
    26472629        viewCellInterior->SetMergeCost(mergeCost); 
    26482630 
     
    26522634        BspNode *back = interior->GetBack(); 
    26532635 
    2654         // recursivly compute child hierarchies 
     2636 
     2637        //-- recursivly compute child hierarchies 
    26552638        ViewCell *backVc = ConstructSpatialMergeTree(back); 
    26562639        ViewCell *frontVc = ConstructSpatialMergeTree(front); 
    26572640 
     2641 
     2642        viewCellInterior->SetupChildLink(backVc); 
    26582643        viewCellInterior->SetupChildLink(frontVc); 
    2659         viewCellInterior->SetupChildLink(backVc); 
    2660  
     2644 
     2645        volume += backVc->GetVolume(); 
     2646        volume += frontVc->GetVolume();  
     2647 
     2648        viewCellInterior->SetVolume(volume); 
     2649 
     2650        return viewCellInterior; 
     2651} 
     2652 
     2653 
     2654void BspViewCellsManager::UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) 
     2655{ 
     2656        // terminate traversal 
     2657        if (root->IsLeaf()) 
     2658        { 
     2659                pvs = root->GetPvs(); 
     2660 
     2661                root->mPvsSize = pvs.GetSize(); 
     2662                root->mPvsSizeValid = true; 
     2663 
     2664                return; 
     2665        } 
     2666 
     2667        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 
     2668        ViewCellContainer::const_iterator vit, vit_end = interior->mChildren.end(); 
     2669 
     2670        vector<ObjectPvs> pvsList; 
     2671         
     2672         
     2673        for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit) 
     2674        { 
     2675                ObjectPvs objPvs; 
     2676                 
     2677                //-- recursivly compute child pvss 
     2678                UpdatePvsForEvaluation(*vit, objPvs); 
     2679 
     2680                // store pvs in vector 
     2681                pvsList.push_back(objPvs); 
     2682        } 
     2683 
     2684#if 1 
     2685        Intersectable::NewMail(); 
     2686 
     2687        //-- faster way of computing pvs: 
     2688        //   construct merged pvs by adding  
     2689        //   and only those of the next pvs which were not mailed. 
     2690        //   note: sumpdf is not correct!! 
     2691        vector<ObjectPvs>::iterator oit = pvsList.begin(); 
     2692 
     2693        for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ oit) 
     2694        { 
     2695                 
     2696        ObjectPvsMap::iterator pit, pit_end = (*oit).mEntries.end(); 
     2697         
     2698                for (pit = (*oit).mEntries.begin(); pit != pit_end; ++ pit) 
     2699                { 
     2700                         
     2701                        Intersectable *intersect = (*pit).first; 
     2702 
     2703                        if (!intersect->Mailed()) 
     2704                        { 
     2705                                pvs.AddSample(intersect, (*pit).second.mSumPdf); 
     2706                                intersect->Mail(); 
     2707                        } 
     2708                } 
     2709        } 
     2710 
     2711        // store pvs in this node 
     2712        if (mViewCellsTree->ViewCellsStorage() == ViewCellsTree::PVS_IN_INTERIORS) 
     2713        { 
     2714                interior->mPvs = pvs; 
     2715        } 
     2716         
     2717        // set new pvs size 
     2718        interior->mPvsSize = pvs.GetSize(); 
     2719        interior->mPvsSizeValid = true; 
     2720 
     2721#else 
     2722        // really merge cells: slow put sumpdf is correct 
     2723        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    26612724 
    26622725        viewCellInterior->GetPvs().Merge(backVc->GetPvs()); 
    26632726        viewCellInterior->GetPvs().Merge(frontVc->GetPvs()); 
    2664  
    2665         volume += backVc->GetVolume(); 
    2666         volume += frontVc->GetVolume();  
    2667  
    2668         viewCellInterior->SetVolume(volume); 
    2669  
    2670         return viewCellInterior; 
    2671 } 
    2672  
     2727#endif 
     2728 
     2729} 
    26732730 
    26742731/************************************************************************/ 
     
    28192876 
    28202877                        ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 
    2821                         // output PVS of view cell 
     2878                        // -- output PVS of view cell 
    28222879                        for (it = vc->GetPvs().mEntries.begin(); it !=  it_end; ++ it) 
    28232880                        { 
     
    34483505        if (SAMPLE_AFTER_SUBDIVISION) 
    34493506                ComputeSampleContributions(savedRays, true, false); 
     3507 
    34503508        cout << "finished" << endl; 
    34513509 
     
    34893547                ViewCell *root = ConstructSpatialMergeTree(mVspBspTree->GetRoot()); 
    34903548                mViewCellsTree->SetRoot(root); 
     3549 
     3550                // compute pvs 
     3551                ObjectPvs pvs; 
     3552                UpdatePvsForEvaluation(root, pvs); 
    34913553        } 
    34923554 
     
    34943556        { 
    34953557                char mstats[100]; 
     3558                ObjectPvs pvs; 
     3559 
    34963560                environment->GetStringValue("ViewCells.mergeStats", mstats); 
    34973561                mViewCellsTree->ExportStats(mstats); 
     
    37283792                Debug << "number of entries before compress: " << pvsEntries << endl; 
    37293793 
    3730                 mViewCellsTree->CompressViewCellsPvs(); 
     3794                mViewCellsTree->SetViewCellsStorage(ViewCellsTree::COMPRESSED); 
    37313795 
    37323796                pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 
     
    37683832ViewCell *VspBspViewCellsManager::ConstructSpatialMergeTree(BspNode *root) 
    37693833{ 
     3834        // terminate recursion 
    37703835        if (root->IsLeaf()) 
    37713836        { 
    3772                 ViewCell *viewCell = dynamic_cast<BspLeaf *>(root)->GetViewCell(); 
    3773  
    3774                 viewCell->SetMergeCost(0.0f); 
    3775  
    3776                 return viewCell; 
    3777         } 
     3837                BspLeaf *leaf = dynamic_cast<BspLeaf *>(root); 
     3838                leaf->GetViewCell()->SetMergeCost(0.0f); 
     3839                return leaf->GetViewCell(); 
     3840        } 
     3841         
    37783842         
    37793843        BspInterior *interior = dynamic_cast<BspInterior *>(root); 
    37803844        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    37813845                 
     3846        // evaluate merge cost for priority traversal 
    37823847        float mergeCost = 1.0f / (float)root->mTimeStamp; 
    3783         //Debug << "timestamp: " << root->mTimeStamp; 
    3784         //Debug << "merge cost: " << mergeCost << endl; 
    3785  
    37863848        viewCellInterior->SetMergeCost(mergeCost); 
    37873849 
     
    37913853        BspNode *back = interior->GetBack(); 
    37923854 
    3793         // recursivly compute child hierarchies 
     3855 
     3856        ObjectPvs frontPvs, backPvs; 
     3857 
     3858        //-- recursivly compute child hierarchies 
    37943859        ViewCell *backVc = ConstructSpatialMergeTree(back); 
    37953860        ViewCell *frontVc = ConstructSpatialMergeTree(front); 
    37963861 
     3862 
     3863        viewCellInterior->SetupChildLink(backVc); 
    37973864        viewCellInterior->SetupChildLink(frontVc); 
    3798         viewCellInterior->SetupChildLink(backVc); 
    3799  
     3865 
     3866        volume += backVc->GetVolume(); 
     3867        volume += frontVc->GetVolume();  
     3868 
     3869        viewCellInterior->SetVolume(volume); 
     3870 
     3871        return viewCellInterior; 
     3872} 
     3873 
     3874 
     3875 
     3876void VspBspViewCellsManager::UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) 
     3877{ 
     3878        // terminate traversal 
     3879        if (root->IsLeaf()) 
     3880        { 
     3881                pvs = root->GetPvs(); 
     3882 
     3883                root->mPvsSize = pvs.GetSize(); 
     3884                root->mPvsSizeValid = true; 
     3885 
     3886                return; 
     3887        } 
     3888         
     3889        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 
     3890        ViewCellContainer::const_iterator vit, vit_end = interior->mChildren.end(); 
     3891 
     3892        vector<ObjectPvs> pvsList; 
     3893         
     3894         
     3895        for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit) 
     3896        { 
     3897                ObjectPvs objPvs; 
     3898                 
     3899                //-- recursivly compute child pvss 
     3900                UpdatePvsForEvaluation(*vit, objPvs); 
     3901 
     3902                // store pvs in vector 
     3903                pvsList.push_back(objPvs); 
     3904        } 
     3905 
     3906#if 1 
     3907        Intersectable::NewMail(); 
     3908 
     3909        //-- faster way of computing pvs: 
     3910        //   construct merged pvs by adding  
     3911        //   and only those of the next pvs which were not mailed. 
     3912        //   note: sumpdf is not correct!! 
     3913        vector<ObjectPvs>::iterator oit = pvsList.begin(); 
     3914 
     3915        for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ oit) 
     3916        { 
     3917            ObjectPvsMap::iterator pit, pit_end = (*oit).mEntries.end(); 
     3918         
     3919                for (pit = (*oit).mEntries.begin(); pit != pit_end; ++ pit) 
     3920                { 
     3921                        Intersectable *intersect = (*pit).first; 
     3922 
     3923                        if (!intersect->Mailed()) 
     3924                        { 
     3925                                pvs.AddSample(intersect, (*pit).second.mSumPdf); 
     3926                                intersect->Mail(); 
     3927                        } 
     3928                } 
     3929        } 
     3930 
     3931        // store pvs in this node 
     3932        if (mViewCellsTree->ViewCellsStorage() == ViewCellsTree::PVS_IN_INTERIORS) 
     3933        { 
     3934                interior->mPvs = pvs; 
     3935        } 
     3936         
     3937        // set new pvs size 
     3938        interior->mPvsSize = pvs.GetSize(); 
     3939        interior->mPvsSizeValid = true; 
     3940 
     3941#else 
     3942        // really merge cells: slow put sumpdf is correct 
     3943        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    38003944 
    38013945        viewCellInterior->GetPvs().Merge(backVc->GetPvs()); 
    38023946        viewCellInterior->GetPvs().Merge(frontVc->GetPvs()); 
    3803  
    3804         volume += backVc->GetVolume(); 
    3805         volume += frontVc->GetVolume();  
    3806  
    3807         viewCellInterior->SetVolume(volume); 
    3808  
    3809         return viewCellInterior; 
     3947#endif 
     3948 
    38103949} 
    38113950 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r746 r752  
    4141  ViewCell *mViewCell; 
    4242 
    43   //ViewCellContainer mViewCells; 
    44   /// aggregated pvs 
    45   //ObjectPvs mPvs; 
    46  
    4743  // input parameter is the render budget for the PrVS 
    4844  float mRenderBudget; 
     
    501497        void CreateClipPlane(); 
    502498 
     499        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0; 
     500 
     501 
     502 
    503503        Plane3 mClipPlane; 
    504504        bool mUseClipPlaneForViz; 
     
    633633        bool ExportViewCells(const string filename); 
    634634 
     635        /** Constructs merge hierarchy which corresponds to the spatial hierarchy. 
     636        */ 
    635637        ViewCell *ConstructSpatialMergeTree(BspNode *root); 
    636638 
     639        /** Updates the pvs in the view cells tree. 
     640        */ 
     641        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs); 
    637642 
    638643protected: 
     
    713718                                                                vector<MergeCandidate> &candidates); 
    714719 
     720 
    715721protected: 
    716722 
     723        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {}; 
    717724        /** Collects view cells from a hierarchy. 
    718725        */ 
     
    778785        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates); 
    779786 
     787        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {}; 
    780788protected: 
    781789 
     
    886894        void ExportColor(Exporter *exporter, ViewCell *vc) const; 
    887895 
     896        /** Prepare view cells for use after loading them from disc. 
     897        */ 
    888898        void PrepareLoadedViewCells(); 
    889899 
     900        /** Constructs merge hierarchy which corresponds to the spatial hierarchy. 
     901        */ 
    890902        ViewCell *ConstructSpatialMergeTree(BspNode *root); 
    891903 
     904        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs); 
     905 
     906 
     907        // HACK 
    892908        void TestFilter(const ObjectContainer &objects); 
    893909 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r744 r752  
    472472         
    473473        mSubdivisionStats  
    474                         << "#ViewCells\n1\n" <<  endl 
    475                         << "#RenderCostDecrease\n0\n" << endl  
     474                        << "#ViewCells\n1" <<  endl 
     475                        << "#RenderCostDecrease\n0" << endl  
    476476                        << "#TotalRenderCost\n" << mTotalCost << endl 
    477477                        << "#AvgRenderCost\n" << mTotalPvsSize << endl; 
     
    578578                        << "#ViewCells\n1\n" <<  endl 
    579579                        << "#RenderCostDecrease\n0\n" << endl  
    580                         << "#dummy\n0\n" << endl 
     580                        << "#SplitCandidateCost\n0\n" << endl 
    581581                        << "#TotalRenderCost\n" << mTotalCost << endl 
    582582                        << "#AvgRenderCost\n" << mTotalPvsSize << endl; 
     
    773773                AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 
    774774 
     775                // update single pvs parameter 
     776                viewCell->mPvsSize = viewCell->GetPvs().GetSize();  
     777                viewCell->mPvsSizeValid = true; 
     778 
     779 
    775780                mBspStats.contributingSamples += conSamp; 
    776781                mBspStats.sampleContributions +=(int) sampCon; 
     
    869874                                        << "#ViewCells\n" << mBspStats.Leaves() << endl 
    870875                                        << "#RenderCostDecrease\n" << -costDecr << endl 
    871                                         << "#dummy\n" << splitCandidate.GetCost() << endl 
     876                                        << "#SplitCandidateCost\n" << splitCandidate.GetCost() << endl 
    872877                                        << "#TotalRenderCost\n" << mTotalCost << endl 
    873878                                        << "#AvgRenderCost\n" << (float)mTotalPvsSize / (float)mBspStats.Leaves() << endl; 
     
    902907                float sampCon = 0.0f; 
    903908                AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 
     909 
     910                viewCell->mPvsSize = viewCell->GetPvs().GetSize(); 
     911                viewCell->mPvsSizeValid = true; 
    904912 
    905913                mBspStats.contributingSamples += conSamp; 
     
    17631771                if ((pFront < 0.0) || (pBack < 0.0)) 
    17641772                { 
    1765                         Debug << "vol f " << pFront << " b " << pBack << " p " << pOverall << endl; 
    1766                         Debug << "real vol f " << pFront << " b " << geomBack.GetVolume() << " p " << pOverall << endl; 
    1767                         Debug << "polys f " << geomFront.Size() << " b " << geomBack.Size() << " data " << data.mGeometry->Size() << endl; 
    1768                 } 
    1769  
    1770                 // clamp because of possible precision issues 
    1771                 if (0) 
    1772                 { 
    1773                         if (pFront < 0) pFront = 0; 
    1774                         if (pBack < 0) pBack = 0; 
     1773                        Debug << "ERROR in volume:\n" 
     1774                                  << "volume f :" << pFront << " b: " << pBack << " p: " << pOverall  
     1775                                  << ", real volume f: " << pFront << " b: " << geomBack.GetVolume() 
     1776                                  << ", #polygons f: " << geomFront.Size() << " b: " << geomBack.Size() << " p: " << data.mGeometry->Size() << endl; 
    17751777                } 
    17761778        } 
     
    17951797 
    17961798        //Debug << "decrease: " << oldRenderCost - newRenderCost << endl; 
    1797         return (oldRenderCost - newRenderCost) / mBox.GetVolume(); 
     1799        const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBox.GetVolume(); 
     1800         
     1801 
     1802#if 1 
     1803        // take render cost of node into account 
     1804        const float normalizedOldRenderCost = oldRenderCost / mBox.GetVolume(); 
     1805        //Debug << "rendercostdecr: " << 0.99f * renderCostDecrease << " old render cost: " << 0.01f * normalizedOldRenderCost << endl; 
     1806        //return 0.5f * renderCostDecrease + 0.5f * normalizedOldRenderCost; 
     1807        return 0.99f * renderCostDecrease + 0.01f * normalizedOldRenderCost; 
     1808#else 
     1809        return renderCostDecrease; 
     1810#endif 
    17981811} 
    17991812 
     
    18711884                        !geomFront.Valid() || !geomBack.Valid())) 
    18721885                { 
    1873                         Debug << "error f: " << pFront << " b: " << pBack << endl; 
     1886                        //Debug << "error f: " << pFront << " b: " << pBack << endl; 
     1887                        // high penalty for this split 
    18741888                        return 99999.9f; 
    18751889                } 
     
    18871901 
    18881902        // only render cost heuristics or combined with standard deviation 
    1889         const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit); 
    1890     const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 
    1891         const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 
     1903        const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit); 
     1904    const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit); 
     1905        const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit); 
    18921906                         
    18931907        const float oldRenderCost = pOverall * penaltyOld; 
     
    27622776        BspNodeGeometry nodeGeom; 
    27632777        ConstructGeometry(n, nodeGeom); 
    2764          
     2778        const float eps = 0.01f; 
     2779 
    27652780        // split planes from the root to this node 
    27662781        // needed to verify that we found neighbor leaf 
     
    27992814                                                        Polygon3::ClassifyPlane(geom->GetPolys(), 
    28002815                                                                                                        halfSpaces[i], 
    2801                                                                                                         mEpsilon); 
     2816                                                                                                        eps); 
    28022817 
    28032818                                                if (cf == Polygon3::FRONT_SIDE) 
     
    28182833                                                        Polygon3::ClassifyPlane(geom->GetPolys(), 
    28192834                                                                                                        poly->GetSupportingPlane(), 
    2820                                                                                                         mEpsilon); 
     2835                                                                                                        eps); 
    28212836 
    28222837                                                if (cf == Polygon3::FRONT_SIDE) 
     
    28392854                        const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(), 
    28402855                                                                                                   interior->GetPlane(), 
    2841                                                                                                    mEpsilon); 
     2856                                                                                                   eps); 
    28422857                         
    28432858                        BspNode *front = interior->GetFront(); 
     
    28522867                                                                mBox, 
    28532868                                                                //0.0000001f); 
    2854                                                                 mEpsilon); 
     2869                                                                eps); 
    28552870                 
    28562871                        if (cf == Polygon3::BACK_SIDE) 
     
    28912906        ConstructGeometry(n, nodeGeom); 
    28922907         
     2908        float eps = 0.01f; 
    28932909        // split planes from the root to this node 
    28942910        // needed to verify that we found neighbor leaf 
     
    29322948                        const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(), 
    29332949                                                                                                   interior->GetPlane(), 
    2934                                                                                                    mEpsilon); 
     2950                                                                                                   eps); 
    29352951                         
    29362952                        BspNode *front = interior->GetFront(); 
     
    29452961                                                                mBox, 
    29462962                                                                //0.0000001f); 
    2947                                                                 mEpsilon); 
     2963                                                                eps); 
    29482964                 
    29492965                        if (cf == Polygon3::BACK_SIDE) 
     
    31643180 
    31653181        float t; 
    3166         const float thresh = 1e-6f; // matt: change this 
     3182        const float thresh = 1e-6f; // matt: change this to adjustable value 
    31673183         
    31683184        while (1) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r726 r752  
    100100  string element(lname.LocalForm()); 
    101101   
     102  // only create new mesh instance if define mechanism was not used 
    102103  if (element == "Shape") 
    103104    EndShape(); 
    104   if (1) 
     105 
    105106  if (element == "Transform") 
    106107          EndTransform(); 
     
    138139 
    139140        const int len = attributes.getLength(); 
     141    Matrix4x4 *rotm = NULL; 
     142        Matrix4x4 *scalem = NULL; 
     143        Matrix4x4 *translm = NULL; 
    140144     
    141145        for (int i = 0; i < len; ++ i)  
     
    153157                        if (sscanf(ptr, "%f %f %f %f", &axis.x, &axis.y, &axis.z, &angle) == 4) 
    154158                        { 
    155                                 Matrix4x4 rot = RotationAxisMatrix(axis, angle); 
    156                                 currentTransform *= rot; 
     159                                rotm = new Matrix4x4(RotationAxisMatrix(axis, angle)); 
    157160                        } 
    158161                } 
     
    163166                        if (sscanf(ptr, "%f %f %f %f", &transl.x, &transl.y, &transl.z) == 3) 
    164167                        { 
    165                                 Matrix4x4 tm = TranslationMatrix(transl); 
    166  
    167                                 currentTransform *= tm; 
     168                                translm = new Matrix4x4(TranslationMatrix(transl)); 
    168169                        } 
    169170                } 
     171                else if (attrName == "scale") 
     172                { 
     173                        Vector3 scale; 
     174 
     175                        if (sscanf(ptr, "%f %f %f %f", &scale.x, &scale.y, &scale.z) == 3) 
     176                        { 
     177                                scalem = new Matrix4x4(ScaleMatrix(scale.x, scale.y, scale.z)); 
     178                        } 
     179                } 
     180                // todo: scale orientation 
    170181        } 
    171182         
     183        if (scalem) 
     184                currentTransform *= (*scalem); 
     185        if (rotm) 
     186                currentTransform *= (*rotm); 
     187        if (translm) 
     188                currentTransform *= (*translm); 
     189 
     190        DEL_PTR(scalem); 
     191        DEL_PTR(rotm); 
     192        DEL_PTR(translm); 
     193 
    172194        mTransformations.push(currentTransform); 
    173195} 
     
    180202 
    181203 
    182 void 
    183 X3dParseHandlers::EndShape() 
    184 { 
     204void X3dParseHandlers::EndShape() 
     205{ 
     206        // this shape is a definition => don't create mesh instance 
     207        if (mIsMeshDefinition)  
     208{ 
     209                mMeshDefinitions[mCurrentMeshName.c_str()] = mCurrentMesh; 
     210                //cout << "new definition: " << mCurrentMeshName << endl; 
     211                 
     212                return; 
     213        } 
     214 
     215        // each polygon is one single mesh 
    185216        if (mLoadPolygonsAsMeshes) 
    186217        { 
    187                 vector<VertexIndexContainer>::const_iterator it, it_end = mCurrentVertexIndices.end(); 
     218                 
     219                /*vector<VertexIndexContainer>::const_iterator it,  
     220                        it_end = mCurrentVertexIndices.end(); 
    188221 
    189222                for (it = mCurrentVertexIndices.begin(); it != it_end; ++ it) 
     
    211244                        mCurrentNode->mGeometry.push_back(mi); 
    212245 
    213                 } 
    214  
    215                 delete mCurrentMesh; 
    216                 mCurrentVertices.clear(); 
    217                 mCurrentVertexIndices.clear(); 
     246                }*/ 
     247 
     248                //if (mCurrentMesh->mFaces.empty())     cout << "error!" << endl; 
     249 
     250                FaceContainer::const_iterator fit, fit_end = mCurrentMesh->mFaces.end(); 
     251 
     252                cout << "m"; 
     253                //cout << "m: " << mCurrentMesh->mFaces.size() << endl; 
     254                for (fit = mCurrentMesh->mFaces.begin(); fit != fit_end; ++ fit) 
     255                { 
     256                        cout << "f"; 
     257 
     258                        Face *face = *fit; 
     259                        // only one face per mesh 
     260                        Mesh *mesh = new Mesh(); 
     261                        VertexIndexContainer vc; 
     262                                         
     263                        VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end(); 
     264                         
     265                        int i = 0; 
     266                        for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i) 
     267                        { 
     268                                cout << "i"; 
     269                                int index = (*vit); 
     270                                // add vertices 
     271                                mesh->mVertices.push_back(mCurrentMesh->mVertices[index]); 
     272                                vc.push_back(i); 
     273                        } 
     274 
     275                        mesh->mFaces.push_back(new Face(vc)); 
     276 
     277                        // NOTE: should rather be written into trafo of mesh instance 
     278                        ApplyTransformations(mTransformations, mesh); 
     279 
     280                        mesh->Preprocess(); 
     281                                 
     282                        // make an instance of this mesh 
     283                        MeshInstance *mi = new MeshInstance(mesh); 
     284                        mCurrentNode->mGeometry.push_back(mi); 
     285                } 
     286 
     287                // LEAK!! TODO: delete if not defd 
     288                if (!mUsingMeshDefinition) 
     289                        delete mCurrentMesh; 
     290 
     291                //mCurrentVertices.clear(); 
     292                //mCurrentVertexIndices.clear(); 
    218293        } 
    219294        else 
    220295        {  
    221                 if (mCurrentMesh->mFaces.size())  
     296                if (!mCurrentMesh->mFaces.empty())  
    222297                { 
    223298                        // should rather be written into the transformation 
     
    228303                        // make an instance of this mesh 
    229304                        MeshInstance *mi = new MeshInstance(mCurrentMesh); 
     305 
    230306                        mCurrentNode->mGeometry.push_back(mi); 
    231307                        // set the object id to a unique value 
     
    234310                else  
    235311                { 
     312                        // empty mesh => discard 
    236313                        cout<<"X"; 
     314 
    237315                        delete mCurrentMesh; 
    238316                } 
     
    243321 
    244322 
    245 void 
    246 X3dParseHandlers::StartIndexedFaceSet( 
    247                                                                           AttributeList&  attributes) 
     323void X3dParseHandlers::StartIndexedFaceSet(AttributeList&  attributes) 
    248324{ 
    249325  int len = attributes.getLength(); 
     326 
    250327  int i; 
    251328  VertexIndexContainer vertices; 
    252329   
    253   for (i=0; i < len; i++) { 
    254     string attrName(StrX(attributes.getName(i)).LocalForm()); 
    255     if (attrName == "coordIndex") { 
    256       StrX attrValue(attributes.getValue(i)); 
    257       // handle coordIndex 
    258       vertices.clear(); 
    259       const char *ptr = attrValue.LocalForm(); 
    260       char *endptr; 
    261       while(1) { 
    262         int index = strtol(ptr, &endptr, 10); 
    263         if (ptr == endptr || index == -1) { 
    264           if (vertices.size() > 2) { 
    265                   Face *face = new Face(vertices); 
    266  
    267                    if (!mLoadPolygonsAsMeshes) 
    268                    { 
    269                            mCurrentMesh->mFaces.push_back(face); 
    270                    } 
    271                    else 
    272                    // every polygon is a mesh 
    273                    { 
    274                            mCurrentVertexIndices.push_back(vertices); 
    275                    } 
    276           } 
    277  
    278           vertices.clear(); 
    279           if (ptr == endptr) 
    280             break; 
    281         } else { 
    282           vertices.push_back(index); 
    283         } 
    284         ptr = endptr; 
    285           } 
    286     } 
    287   } 
    288 } 
     330        mIsMeshDefinition = false; 
     331        mUsingMeshDefinition = false; 
     332        for (i = 0; i < len; ++ i)  
     333        { 
     334                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     335           
     336                // this is a definition of a mesh 
     337                if (attrName == "DEF") 
     338                { 
     339                        mIsMeshDefinition = true; 
     340                        StrX attrValue(attributes.getValue(i)); 
     341                        const char *ptr = attrValue.LocalForm(); 
     342                        mCurrentMeshName = ptr; 
     343 
     344                        cout << "d"; 
     345                } 
     346                 
     347                // we use an already defined mesh 
     348                if (attrName == "USE") 
     349                { 
     350                        StrX attrValue(attributes.getValue(i)); 
     351 
     352                        // discard new mesh and assign defined mesh 
     353                        DEL_PTR(mCurrentMesh); 
     354                        const char *ptr = attrValue.LocalForm(); 
     355 
     356                        mCurrentMesh = mMeshDefinitions[ptr]; 
     357                        mUsingMeshDefinition = true; 
     358                        cout << "u"; 
     359                } 
     360                 
     361                if (attrName == "coordIndex")  
     362                { 
     363                        StrX attrValue(attributes.getValue(i)); 
     364                        // handle coordIndex 
     365                        vertices.clear(); 
     366                        const char *ptr = attrValue.LocalForm(); 
     367                   
     368                        char *endptr; 
     369           
     370                        while (1)  
     371                        { 
     372                                int index = strtol(ptr, &endptr, 10); 
     373                                   
     374                                if (ptr == endptr || index == -1)  
     375                                { 
     376                                        if (vertices.size() > 2)  
     377                                        { 
     378                                                Face *face = new Face(vertices);                  
     379                                                mCurrentMesh->mFaces.push_back(face); 
     380                                        }  
     381                           
     382                                        vertices.clear(); 
     383                   
     384                                        if (ptr == endptr) 
     385                                                break; 
     386                           
     387                                  }  
     388                                  else  
     389                                  { 
     390                                          vertices.push_back(index); 
     391                                  } 
     392                                  ptr = endptr; 
     393                        } 
     394                } 
     395        } 
     396} 
     397 
    289398 
    290399void 
     
    358467                                vertices.push_back(v); 
    359468                        } 
    360                         if (mLoadPolygonsAsMeshes) 
    361                         { 
    362                                 mCurrentVertices = vertices; 
    363                         } 
    364                         else 
    365                         { 
    366                                 mCurrentMesh->mVertices = vertices; 
    367                         } 
     469                         
     470                        mCurrentMesh->mVertices = vertices; 
    368471                } 
    369472        } 
     
    388491  } 
    389492   
    390   if (element == "Coordinate") { 
     493  if (element == "Coordinate")  
     494  { 
    391495    if (mCurrentMesh) 
    392496      StartCoordinate(attributes); 
     
    396500    StartMaterial(attributes); 
    397501  } 
    398 if (1) 
     502   
    399503  if (element == "Transform") { 
    400504          StartTransform(attributes); 
     
    599703X3dViewCellsParseHandlers::EndShape() 
    600704{ 
     705        // currently processing no shape 
    601706} 
    602707 
     
    607712        int len = attributes.getLength(); 
    608713        int i; 
     714         
    609715        // clear previous vertex indices 
    610716        mCurrentVertexIndices.clear(); 
     717 
     718 
    611719        for (i=0; i < len; i++)  
    612720        { 
    613721                string attrName(StrX(attributes.getName(i)).LocalForm()); 
    614722             
     723 
    615724                if (attrName == "coordIndex")  
    616725                { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h

    r712 r752  
    1818class Material; 
    1919class ViewCellsManager; 
     20 
     21struct ltstr 
     22{ 
     23  bool operator()(const string &s1, const string &s2) const 
     24  { 
     25    return s1 < s2; 
     26  } 
     27}; 
     28 
     29typedef map<string, Mesh *, ltstr> MeshDefinitions; 
     30typedef map<string, Material *, ltstr> MaterialDefinitions; 
    2031 
    2132class X3dParseHandlers : public HandlerBase 
     
    6677  vector<VertexIndexContainer> mCurrentVertexIndices; 
    6778  VertexContainer mCurrentVertices; 
     79  string mCurrentMeshName; 
    6880 
    6981  Material *mCurrentMaterial; 
     82   
    7083  bool mLoadPolygonsAsMeshes; 
    7184 
    7285  typedef stack<Matrix4x4> TrafoStack; 
    7386 
     87  bool mUsingMeshDefinition; 
    7488  // stack of accumulated transformations 
    7589  TrafoStack mTransformations; 
    7690 
     91  MaterialDefinitions mMaterialDefinitions; 
     92  MeshDefinitions mMeshDefinitions; 
     93 
     94  bool mIsMeshDefinition; 
    7795  // Handlers for X3D 
    7896  void 
Note: See TracChangeset for help on using the changeset viewer.