Changeset 535 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 01/13/06 17:39:43 (18 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Beam.cpp
r534 r535 28 28 mPlanes.push_back(Plane3(-CrossProd(directions[3], directions[0]), center)); 29 29 30 31 30 // now make sure all planes contain the spatial box 32 31 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; 39 45 } 40 46 … … 85 91 } 86 92 93 87 94 Vector3 Beam::GetMainDirection() const 88 95 { 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); 98 98 } 99 99 -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r490 r535 23 23 class RssTree; 24 24 class Mesh; 25 class Beam; 25 26 26 27 class Exporter … … 117 118 const Vector3 direction) = 0; 118 119 120 virtual void ExportBeam(const Beam &beam, const AxisAlignedBox3 &box) = 0; 121 119 122 void SetExportRayDensity(const bool d) { mExportRayDensity = d; } 120 123 -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r532 r535 67 67 RenderMeshInstance((MeshInstance *)object); 68 68 break; 69 case Intersectable::VIEW_CELL: 70 RenderViewCell(dynamic_cast<ViewCell *>(object)); 71 break; 69 72 default: 70 73 cerr<<"Rendering this object not yet implemented\n"; … … 73 76 } 74 77 78 79 void 80 GlRenderer::RenderViewCell(ViewCell *vc) 81 { 82 if (vc->GetMesh()) 83 RenderMesh(vc->GetMesh()); 84 } 75 85 76 86 void -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h
r532 r535 81 81 void SetupFalseColor(const int id); 82 82 void RenderIntersectable(Intersectable *); 83 void RenderViewCell(ViewCell *vc); 83 84 void RenderMeshInstance(MeshInstance *mi); 84 85 void RenderMesh(Mesh *m); -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
r532 r535 1008 1008 { 1009 1009 vector<KdNode *>::const_iterator it, it_end = beam.mKdNodes.end(); 1010 1010 1011 1011 Intersectable::NewMail(); 1012 1012 for (it = beam.mKdNodes.begin(); it != it_end; ++ it) -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r508 r535 2723 2723 } 2724 2724 2725 void BspNodeGeometry:: ComputeBoundingBox(AxisAlignedBox3 &box)2725 void BspNodeGeometry::IncludeInBox(AxisAlignedBox3 &box) 2726 2726 { 2727 2727 Polygon3::IncludeInBox(mPolys, box); -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r532 r535 46 46 /** Computes bounding box of the geometry. 47 47 */ 48 void ComputeBoundingBox(AxisAlignedBox3 &box);48 void IncludeInBox(AxisAlignedBox3 &box); 49 49 50 50 /** Splits the polygon and returns the part of the polygon inside of the node geometry. -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r532 r535 2443 2443 int VspBspViewCellsManager::CastBeam(Beam &beam) 2444 2444 { 2445 return 0;2446 } 2445 return mVspBspTree->CastBeam(beam); 2446 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r532 r535 29 29 const float VspBspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 30 30 31 int BspMergeCandidate::sMaxPvsSize = 0; 31 32 32 33 int VspBspTree::sFrontId = 0; … … 311 312 312 313 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; 314 316 //-- store rays 315 317 for (rit = sampleRays.begin(); rit != rit_end; ++ rit) … … 424 426 (data.mArea <= mTermMinArea) || 425 427 (mStat.Leaves() >= mMaxViewCells) || 426 (data.GetAvgRayContribution() > =mTermMaxRayContribution) ||428 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 427 429 (data.mDepth >= mTermMaxDepth)); 428 430 } … … 2159 2161 typedef pair<BspNode *, BspNodeGeometry *> bspNodePair; 2160 2162 2163 2161 2164 int VspBspTree::CastBeam(Beam &beam) 2162 2165 { … … 2176 2179 2177 2180 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); 2181 2186 2182 2187 switch (side) 2183 2188 { 2184 2189 case -1: 2190 Debug << "here999" << endl; 2185 2191 CollectViewCells(node, beam.mViewCells, true); 2186 2192 break; 2187 2193 case 0: 2194 2188 2195 if (node->IsLeaf()) 2189 2196 { 2190 BspLeaf *leaf = dynamic_cast<BspLeaf *>(leaf); 2197 Debug << "here2" << endl; 2198 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 2199 2191 2200 if (!leaf->GetViewCell()->Mailed() && leaf->TreeValid()) 2201 { 2202 leaf->GetViewCell()->Mail(); 2192 2203 beam.mViewCells.push_back(leaf->GetViewCell()); 2204 } 2193 2205 } 2194 2206 else 2195 2207 { 2208 Debug << "here77" << endl; 2196 2209 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2210 2197 2211 BspNode *first = interior->GetBack(); 2198 2212 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 2200 2220 // decide on the order of the nodes 2201 2221 if (DotProd(beam.mPlanes[0].mNormal, … … 2203 2223 { 2204 2224 swap(first, second); 2225 swap(firstGeom, secondGeom); 2205 2226 } 2206 2227 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)); 2215 2230 } 2231 2216 2232 break; 2233 Debug << "culling!!" << endl; 2217 2234 // default: cull 2218 2235 } 2236 Debug << "here4" << endl; 2219 2237 DEL_PTR(geom); 2238 2220 2239 } 2221 2240 … … 2471 2490 int VspBspTree::MergeViewCells(const VssRayContainer &rays) 2472 2491 { 2492 BspMergeCandidate::sMaxPvsSize = mMaxPvs; 2493 2473 2494 MergeStatistics mergeStats; 2474 2495 mergeStats.Start(); … … 2866 2887 2867 2888 mMergeCost = newCost - oldCost; 2868 // if (vcPvs > sMaxPvsSize) // strong penalty if pvs size too large2869 //mMergeCost += 1.0;2889 if (newPvs > sMaxPvsSize) // strong penalty if pvs size too large 2890 mMergeCost += 1.0; 2870 2891 } 2871 2892 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r534 r535 354 354 } 355 355 } 356 357 358 void VssPreprocessor::TestBeamCasting(VssTree *tree, ViewCellsManager *vm) 356 #include "ViewCellBsp.h" 357 358 void VssPreprocessor::TestBeamCasting(VssTree *tree, 359 ViewCellsManager *vm, 360 const ObjectContainer &objects) 359 361 { 360 362 vector<VssTreeLeaf *> leaves; 361 363 tree->CollectLeaves(leaves); 362 364 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) 364 372 { 365 373 const int index = (int)RandomValue(0, (Real)((int)leaves.size() - 1)); … … 367 375 368 376 Beam beam; 369 AxisAlignedBox3 dirBox = tree->GetDirBBox(leaf);377 AxisAlignedBox3 dirBox = tree->GetDirBBox(leaf); 370 378 AxisAlignedBox3 box = tree->GetBBox(leaf); 371 379 372 beam.Construct( dirBox, box);380 beam.Construct(box, dirBox); 373 381 374 382 // collect kd leaves and view cells … … 387 395 388 396 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; 391 426 } 392 427 … … 600 635 int pass = 0; 601 636 602 if (mTestBeamSampling) 603 TestBeamCasting(vssTree, mViewCellsManager); 604 637 605 638 // cast view cell samples 606 639 while (1) { … … 670 703 } 671 704 672 705 Debug << vssTree->stat << endl; 673 706 VssRayContainer viewCellRays; 674 707 … … 681 714 //-- post process view cells 682 715 mViewCellsManager->PostProcess(mObjects, viewCellRays); 716 717 if (mTestBeamSampling) 718 TestBeamCasting(vssTree, mViewCellsManager, mObjects); 683 719 684 720 //-- several visualizations and statistics -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
r532 r535 105 105 void CastRay(const BspTree &tree, const VssRay & vssRay); 106 106 107 void TestBeamCasting(VssTree *tre, ViewCellsManager *vm );107 void TestBeamCasting(VssTree *tre, ViewCellsManager *vm, const ObjectContainer &objects); 108 108 109 109 bool mTestBeamSampling; -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r503 r535 13 13 #include "VspBspTree.h" 14 14 #include "RssTree.h" 15 #include "Beam.h" 15 16 16 17 … … 1234 1235 stream<<">"<<endl; 1235 1236 stream<<"</Viewpoint>"<<endl; 1236 1237 } 1237 1238 } 1239 1240 1241 1242 void 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 23 23 class BspNode; 24 24 //class VspKdViewCell; 25 25 class Beam; 26 26 27 27 class X3dExporter : public Exporter … … 121 121 ExportBspSplits(const VspBspTree &tree, const bool exportDepth); 122 122 123 virtual void ExportBeam(const Beam &beam, const AxisAlignedBox3 &box); 124 123 125 protected: 124 126 -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r534 r535 288 288 minPolygons -1 289 289 maxDepth 30 290 minPvs 2 0290 minPvs 2 291 291 #minArea 0.0001 292 292 minArea 0.000
Note: See TracChangeset
for help on using the changeset viewer.