Ignore:
Timestamp:
01/13/06 17:39:43 (18 years ago)
Author:
mattausch
Message:
 
Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
14 edited

Legend:

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

    r534 r535  
    2828  mPlanes.push_back(Plane3(-CrossProd(directions[3], directions[0]), center)); 
    2929 
    30  
    3130  // now make sure all planes contain the spatial box 
    3231  int i, j; 
    33   for (i=0; i < mPlanes.size(); i++) { 
    34         for (j=0; j < 8; j++) { 
    35           float dist = mPlanes[i].Distance(box.GetVertex(j)); 
    36           if (dist > 0) 
    37                 mPlanes[i].mD -= dist; 
    38         } 
     32  for (i=0; i < mPlanes.size(); i++)  
     33  { 
     34          float maxDist = 0; 
     35           
     36          for (j=0; j < 8; j++)  
     37          { 
     38                float dist = mPlanes[i].Distance(box.GetVertex(j)); 
     39         
     40                if (dist > maxDist) 
     41                        maxDist = dist; 
     42          } 
     43 
     44          mPlanes[i].mD -= maxDist; 
    3945  } 
    4046 
     
    8591} 
    8692 
     93 
    8794Vector3 Beam::GetMainDirection() const 
    8895{ 
    89          Vector3 directions[4]; 
    90           
    91          directions[0] = VssRay::GetDirection(mDirBox.Min().x, mDirBox.Min().y); 
    92          directions[1] = VssRay::GetDirection(mDirBox.Max().x, mDirBox.Min().y); 
    93          directions[2] = VssRay::GetDirection(mDirBox.Max().x, mDirBox.Max().y); 
    94          directions[3] = VssRay::GetDirection(mDirBox.Min().x, mDirBox.Max().y); 
    95  
    96         const Vector3 mainDir = directions[0] + directions[1] + directions[2] + directions[3]; 
    97         return Normalize(mainDir); 
     96        const Vector3 dCenter = mDirBox.Center(); 
     97        return VssRay::GetDirection(dCenter.x, dCenter.y); 
    9898} 
    9999 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r490 r535  
    2323class RssTree; 
    2424class Mesh; 
     25class Beam; 
    2526 
    2627class Exporter 
     
    117118                                 const Vector3 direction) = 0; 
    118119 
     120  virtual void ExportBeam(const Beam &beam, const AxisAlignedBox3 &box) = 0; 
     121 
    119122  void SetExportRayDensity(const bool d) { mExportRayDensity = d; } 
    120123   
  • trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp

    r532 r535  
    6767        RenderMeshInstance((MeshInstance *)object); 
    6868        break; 
     69  case Intersectable::VIEW_CELL: 
     70          RenderViewCell(dynamic_cast<ViewCell *>(object)); 
     71          break; 
    6972  default: 
    7073        cerr<<"Rendering this object not yet implemented\n"; 
     
    7376} 
    7477 
     78 
     79void 
     80GlRenderer::RenderViewCell(ViewCell *vc) 
     81{ 
     82        if (vc->GetMesh()) 
     83                RenderMesh(vc->GetMesh()); 
     84} 
    7585 
    7686void 
  • trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h

    r532 r535  
    8181  void SetupFalseColor(const int id); 
    8282  void RenderIntersectable(Intersectable *); 
     83  void RenderViewCell(ViewCell *vc); 
    8384  void RenderMeshInstance(MeshInstance *mi); 
    8485  void RenderMesh(Mesh *m); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r532 r535  
    10081008  { 
    10091009          vector<KdNode *>::const_iterator it, it_end = beam.mKdNodes.end(); 
    1010  
     1010         
    10111011          Intersectable::NewMail(); 
    10121012          for (it = beam.mKdNodes.begin(); it != it_end; ++ it) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r508 r535  
    27232723} 
    27242724 
    2725 void BspNodeGeometry::ComputeBoundingBox(AxisAlignedBox3 &box) 
     2725void BspNodeGeometry::IncludeInBox(AxisAlignedBox3 &box) 
    27262726{ 
    27272727        Polygon3::IncludeInBox(mPolys, box); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r532 r535  
    4646        /** Computes bounding box of the geometry. 
    4747        */ 
    48         void ComputeBoundingBox(AxisAlignedBox3 &box); 
     48        void IncludeInBox(AxisAlignedBox3 &box); 
    4949 
    5050        /** Splits the polygon and returns the part of the polygon inside of the node geometry. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r532 r535  
    24432443int VspBspViewCellsManager::CastBeam(Beam &beam) 
    24442444{ 
    2445         return 0; 
    2446 } 
     2445        return mVspBspTree->CastBeam(beam); 
     2446} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r532 r535  
    2929const float VspBspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 
    3030 
     31int BspMergeCandidate::sMaxPvsSize = 0; 
    3132 
    3233int VspBspTree::sFrontId = 0; 
     
    311312 
    312313        mMaxPvs = (int)(mMaxPvsRatio * (float)numObj); 
    313         Debug << "maximal pvs where view cell is valid: " << mMaxPvs << endl; 
     314         
     315        Debug << "maximal pvs (i.e., view cell considered as valid: " << mMaxPvs << endl; 
    314316        //-- store rays 
    315317        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
     
    424426                 (data.mArea <= mTermMinArea) || 
    425427                 (mStat.Leaves() >= mMaxViewCells) || 
    426                  (data.GetAvgRayContribution() >= mTermMaxRayContribution) || 
     428                 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 
    427429                 (data.mDepth >= mTermMaxDepth)); 
    428430} 
     
    21592161typedef pair<BspNode *, BspNodeGeometry *> bspNodePair; 
    21602162 
     2163 
    21612164int VspBspTree::CastBeam(Beam &beam) 
    21622165{ 
     
    21762179                 
    21772180                AxisAlignedBox3 box; 
    2178                 geom->ComputeBoundingBox(box); 
    2179  
    2180                 int side = beam.ComputeIntersection(box); 
     2181                box.Initialize(); 
     2182                geom->IncludeInBox(box); 
     2183 
     2184                Debug << "box:\n " << box << endl;; 
     2185                const int side = beam.ComputeIntersection(box); 
    21812186                 
    21822187                switch (side)  
    21832188                { 
    21842189                case -1: 
     2190                        Debug << "here999" << endl; 
    21852191                        CollectViewCells(node, beam.mViewCells, true); 
    21862192                        break; 
    21872193                case 0: 
     2194                         
    21882195                        if (node->IsLeaf()) 
    21892196                        { 
    2190                                 BspLeaf *leaf = dynamic_cast<BspLeaf *>(leaf); 
     2197                                Debug << "here2" << endl; 
     2198                                BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     2199                         
    21912200                                if (!leaf->GetViewCell()->Mailed() && leaf->TreeValid()) 
     2201                                { 
     2202                                        leaf->GetViewCell()->Mail(); 
    21922203                                        beam.mViewCells.push_back(leaf->GetViewCell()); 
     2204                                } 
    21932205                        } 
    21942206                        else  
    21952207                        { 
     2208                                Debug << "here77" << endl; 
    21962209                                BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     2210                         
    21972211                                BspNode *first = interior->GetBack(); 
    21982212                                BspNode *second = interior->GetFront(); 
    2199                  
     2213             
     2214                                BspNodeGeometry *firstGeom = new BspNodeGeometry(); 
     2215                                BspNodeGeometry *secondGeom = new BspNodeGeometry(); 
     2216 
     2217                                ConstructGeometry(first, *firstGeom); 
     2218                                ConstructGeometry(second, *secondGeom); 
     2219 
    22002220                                // decide on the order of the nodes 
    22012221                                if (DotProd(beam.mPlanes[0].mNormal,  
     
    22032223                                { 
    22042224                                        swap(first, second); 
     2225                                        swap(firstGeom, secondGeom); 
    22052226                                } 
    22062227 
    2207                                 BspNodeGeometry *leftGeom = new BspNodeGeometry(); 
    2208                                 BspNodeGeometry *rightGeom = new BspNodeGeometry(); 
    2209  
    2210                                 ConstructGeometry(first, *leftGeom); 
    2211                                 ConstructGeometry(second, *rightGeom); 
    2212  
    2213                                 nodeStack.push(bspNodePair(first, leftGeom)); 
    2214                                 nodeStack.push(bspNodePair(second, rightGeom)); 
     2228                                nodeStack.push(bspNodePair(first, firstGeom)); 
     2229                                nodeStack.push(bspNodePair(second, secondGeom)); 
    22152230                        } 
     2231                         
    22162232                        break; 
     2233                        Debug << "culling!!" << endl; 
    22172234                        // default: cull 
    22182235                } 
     2236                Debug << "here4" << endl; 
    22192237                DEL_PTR(geom); 
     2238                 
    22202239        } 
    22212240 
     
    24712490int VspBspTree::MergeViewCells(const VssRayContainer &rays) 
    24722491{ 
     2492        BspMergeCandidate::sMaxPvsSize = mMaxPvs; 
     2493 
    24732494        MergeStatistics mergeStats; 
    24742495        mergeStats.Start(); 
     
    28662887 
    28672888        mMergeCost = newCost - oldCost; 
    2868 //      if (vcPvs > sMaxPvsSize) // strong penalty if pvs size too large 
    2869 //              mMergeCost += 1.0; 
     2889        if (newPvs > sMaxPvsSize) // strong penalty if pvs size too large 
     2890                mMergeCost += 1.0; 
    28702891} 
    28712892 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r534 r535  
    354354  } 
    355355} 
    356  
    357  
    358 void VssPreprocessor::TestBeamCasting(VssTree *tree, ViewCellsManager *vm) 
     356#include "ViewCellBsp.h" 
     357 
     358void VssPreprocessor::TestBeamCasting(VssTree *tree,  
     359                                                                          ViewCellsManager *vm,  
     360                                                                          const ObjectContainer &objects) 
    359361{ 
    360362        vector<VssTreeLeaf *> leaves; 
    361363        tree->CollectLeaves(leaves); 
    362364 
    363         for (int i = 0; i < 10; ++i) 
     365        Exporter *exporter = Exporter::GetExporter("shafts.x3d"); 
     366 
     367        exporter->SetWireframe(); 
     368        exporter->ExportGeometry(objects); 
     369        exporter->SetFilled(); 
     370        //Randomize(); 
     371        for (int i = 0; i < 1; ++ i) 
    364372        { 
    365373                const int index = (int)RandomValue(0, (Real)((int)leaves.size() - 1)); 
     
    367375 
    368376                Beam beam; 
    369                 AxisAlignedBox3 dirBox =tree->GetDirBBox(leaf); 
     377                AxisAlignedBox3 dirBox = tree->GetDirBBox(leaf); 
    370378                AxisAlignedBox3 box = tree->GetBBox(leaf); 
    371379                 
    372                 beam.Construct(dirBox, box); 
     380                beam.Construct(box, dirBox); 
    373381 
    374382                // collect kd leaves and view cells 
     
    387395 
    388396                Debug << "beam statistics: " << stats << endl << endl; 
    389         } 
    390  
     397                 
     398                AxisAlignedBox3 sbox = mSceneGraph->GetBox(); 
     399                Vector3 bmin = sbox.Min() - 150.0f; 
     400                Vector3 bmax = sbox.Max() + 150.0f; 
     401                AxisAlignedBox3 vbox(bmin, bmax); 
     402                 
     403                exporter->ExportBeam(beam, vbox); 
     404 
     405                bool exportViewCells = false; 
     406                 
     407                if (exportViewCells) 
     408                { 
     409                        exporter->SetWireframe(); 
     410                         
     411                        ViewCellContainer::const_iterator it, it_end = beam.mViewCells.end(); 
     412                         
     413                        for (it = beam.mViewCells.begin(); it != beam.mViewCells.end(); ++ it) 
     414                        { 
     415                                BspNodeGeometry geom; 
     416                                AxisAlignedBox3 vbox; 
     417                                vbox.Initialize(); 
     418                                mVspBspTree->ConstructGeometry(*it, geom); 
     419                                geom->IncludeInBox(vbox); 
     420                                exporter->ExportBox(vbox); 
     421                                //exporter->ExportViewCell(*it); 
     422                        } 
     423                } 
     424        } 
     425        delete exporter; 
    391426} 
    392427 
     
    600635  int pass = 0; 
    601636 
    602   if (mTestBeamSampling) 
    603           TestBeamCasting(vssTree, mViewCellsManager); 
    604  
     637   
    605638  // cast view cell samples 
    606639  while (1) { 
     
    670703  } 
    671704 
    672  
     705  Debug << vssTree->stat << endl; 
    673706  VssRayContainer viewCellRays; 
    674707   
     
    681714  //-- post process view cells 
    682715  mViewCellsManager->PostProcess(mObjects, viewCellRays); 
     716 
     717  if (mTestBeamSampling) 
     718          TestBeamCasting(vssTree, mViewCellsManager, mObjects); 
    683719 
    684720  //-- several visualizations and statistics 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h

    r532 r535  
    105105  void CastRay(const BspTree &tree, const VssRay & vssRay); 
    106106 
    107   void TestBeamCasting(VssTree *tre, ViewCellsManager *vm); 
     107  void TestBeamCasting(VssTree *tre, ViewCellsManager *vm, const ObjectContainer &objects); 
    108108 
    109109  bool mTestBeamSampling; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r503 r535  
    1313#include "VspBspTree.h" 
    1414#include "RssTree.h" 
     15#include "Beam.h" 
    1516 
    1617 
     
    12341235  stream<<">"<<endl; 
    12351236  stream<<"</Viewpoint>"<<endl; 
    1236    
    1237 } 
     1237 
     1238} 
     1239 
     1240 
     1241 
     1242void X3dExporter::ExportBeam(const Beam &beam, const AxisAlignedBox3 &box) 
     1243{ 
     1244        PolygonContainer polys; 
     1245        //ExportBox(beam.mBox); 
     1246 
     1247        for (int i = 0; i < beam.mPlanes.size(); ++ i) 
     1248        { 
     1249                Polygon3 *poly = box.CrossSection(beam.mPlanes[i]); 
     1250                 
     1251                for (int j = 0; (j < beam.mPlanes.size()) && poly; ++ j) 
     1252                { 
     1253                        if (j != i) 
     1254                        { 
     1255                                Polygon3 *front = new Polygon3(); 
     1256                                Polygon3 *back = new Polygon3(); 
     1257                                 
     1258                                poly->Split(beam.mPlanes[j], *front, *back, Limits::Small); 
     1259                                DEL_PTR(poly); 
     1260                                DEL_PTR(front); 
     1261 
     1262                                if (!back->Valid(Limits::Small)) 
     1263                                        DEL_PTR(back); 
     1264                                poly = back; 
     1265                        } 
     1266                } 
     1267                if (poly) 
     1268                        polys.push_back(poly); 
     1269        } 
     1270 
     1271 
     1272        ExportPolygons(polys); 
     1273        CLEAR_CONTAINER(polys); 
     1274} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h

    r486 r535  
    2323class BspNode; 
    2424//class VspKdViewCell; 
    25  
     25class Beam; 
    2626 
    2727class X3dExporter : public Exporter 
     
    121121  ExportBspSplits(const VspBspTree &tree, const bool exportDepth); 
    122122 
     123  virtual void ExportBeam(const Beam &beam, const AxisAlignedBox3 &box); 
     124 
    123125protected: 
    124126 
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r534 r535  
    288288                minPolygons             -1 
    289289                maxDepth                30 
    290                 minPvs                  20 
     290                minPvs                  2 
    291291                #minArea                0.0001 
    292292                minArea                 0.000 
Note: See TracChangeset for help on using the changeset viewer.