- Timestamp:
- 10/10/05 04:19:59 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r312 r313 56 56 57 57 Sampling { 58 totalSamples 10000058 totalSamples 200000 59 59 samplesPerPass 10 60 60 } … … 62 62 ViewCells { 63 63 hierarchyType bspTree 64 height 5.0 64 height 7.0 65 maxViewCells 20 65 66 #hierarchyType kdTree 66 67 #hierarchyType sceneDependent 67 #filename ../data/atlanta/atlanta_viewcells_large.x3d68 filename ../data/vienna/viewcells-25-sel.x3d68 filename ../data/atlanta/atlanta_viewcells_large.x3d 69 # filename ../data/vienna/viewcells-25-sel.x3d 69 70 # filename ../data/vienna/viewcells-25.x3d 70 71 # filename ../data/vienna/viewcells-large-sel.x3d … … 84 85 # vertical axis = 64 85 86 86 splitPlaneStrategy 887 splitPlaneStrategy 66 87 88 # least splits + balanced polygons 88 89 #splitPlaneStrategy 12 … … 101 102 102 103 maxCandidates 50 103 maxViewCells 999999104 104 105 Termination { 105 106 maxPolysForAxisAligned 100 -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r312 r313 1646 1646 return Rectangle3(v[0], v[1], v[2], v[3]); 1647 1647 } 1648 1649 // TODO: use a table to avoid normal and distance computations 1650 Polygon3 *AxisAlignedBox3::BoundPlane(const Plane3 &plane) 1651 { 1652 Vector3 ptA, ptB; 1653 int sideA = 0, sideB = 0; 1654 1655 VertexContainer vertices; 1656 1657 int side[8]; 1658 1659 bool onFrontSide, onBackSide = false; 1660 1661 Vector3 vtx; 1662 for (int i = 0; i < 8; ++i) 1663 { 1664 GetVertex(i, vtx); 1665 side[i] = plane.Side(vtx, SIDE_TOLERANCE); 1666 if (side[i] > 0) 1667 onFrontSide = true; 1668 else if (side[i] < 0) 1669 onBackSide = true; 1670 else // vertex coincident => push_back 1671 vertices.push_back(vtx); 1672 } 1673 1674 // does not intersect 1675 if (!onFrontSide && !onBackSide) 1676 return NULL; 1677 1678 for (int i = 0; i < 12; ++ i) 1679 { 1680 int aIdx, bIdx; 1681 GetEdge(i, aIdx, bIdx); 1682 1683 ptA = GetVertex(aIdx); 1684 ptB = GetVertex(bIdx); 1685 1686 int sideA = side[aIdx]; 1687 int sideB = side[bIdx]; 1688 1689 if (((sideA > 0) && (sideB < 0)) || (sideA < 0) && (sideB > 0)) 1690 vertices.push_back(plane.FindIntersection(ptA, ptB)); 1691 } 1692 1693 // illformed polygon => swap 1694 // HACK: cannot work in abitrary cases 1695 if (vertices.size() > 3) 1696 { 1697 for (int j = 0; j < (int)vertices.size() - 1; ++j) 1698 { 1699 float minDist = 99999; 1700 int minIdx = j; 1701 1702 for (int i = j + 1; i < vertices.size(); ++i) 1703 { 1704 float dist = SqrDistance(vertices[j], vertices[i]); 1705 1706 if (dist < minDist) 1707 { 1708 minDist = dist; 1709 minIdx = i; 1710 } 1711 } 1712 1713 Vector3 vtx = vertices[minIdx]; 1714 vertices[minIdx] = vertices[j + 1]; 1715 vertices[j + 1] = vtx; 1716 } 1717 } 1718 1719 Polygon3 *planePoly = new Polygon3(); 1720 1721 // wrong surface orientation? 1722 Vector3 norm = Normalize(CrossProd(vertices[0] - vertices[1], 1723 vertices[2] - vertices[1])); 1724 1725 1726 1727 if (DotProd(norm, plane.mNormal) > 0) 1728 for (int i = 0; i < (int)vertices.size(); ++ i) 1729 planePoly->mVertices.push_back(vertices[i]); 1730 else 1731 { 1732 for (int i = (int)vertices.size() - 1; i >= 0; -- i) 1733 planePoly->mVertices.push_back(vertices[i]); 1734 } 1735 1736 //Debug << *planePoly << "\narea: " << planePoly->GetArea() << endl; 1737 1738 return planePoly; 1739 } 1648 1740 /* 1649 1741 const int AxisAlignedBox3::complEdgeTbl[12][3] = … … 1663 1755 }; 1664 1756 */ 1665 // TODO: use a table to avoid normal and distance computations 1666 Polygon3 *AxisAlignedBox3::BoundPlane(const Plane3 &plane) 1667 { 1668 Vector3 ptA, ptB; 1669 int sideA = 0, sideB = 0; 1670 1671 VertexContainer vertices; 1672 1673 int side[8]; 1674 1675 bool onFrontSide, onBackSide = false; 1676 1677 Vector3 vtx; 1678 for (int i = 0; i < 8; ++i) 1679 { 1680 GetVertex(i, vtx); 1681 side[i] = plane.Side(vtx, SIDE_TOLERANCE); 1682 if (side[i] > 0) 1683 onFrontSide = true; 1684 else if (side[i] < 0) 1685 onBackSide = true; 1686 else // vertex coincident => push_back 1687 vertices.push_back(vtx); 1688 } 1689 1690 // does not intersect 1691 if (!onFrontSide && !onBackSide) 1692 return NULL; 1693 1694 for (int i = 0; i < 12; ++ i) 1695 { 1696 int aIdx, bIdx; 1697 GetEdge(i, aIdx, bIdx); 1698 1699 ptA = GetVertex(aIdx); 1700 ptB = GetVertex(bIdx); 1701 1702 int sideA = side[aIdx]; 1703 int sideB = side[bIdx]; 1704 1705 if (((sideA > 0) && (sideB < 0)) || (sideA < 0) && (sideB > 0)) 1706 vertices.push_back(plane.FindIntersection(ptA, ptB)); 1707 } 1708 1709 if (vertices.size() == 4) 1710 { 1711 float maxDist = 0; 1712 int maxIdx = 0; 1713 1714 for (int i = 1; i < 4; ++ i) 1715 { 1716 float dist = SqrDistance(vertices[0], vertices[i]); 1717 if (dist > maxDist) 1718 { 1719 maxDist = dist; 1720 maxIdx = i; 1721 } 1722 } 1723 // illformed polygon = swap 1724 if ((maxIdx == 1) || (maxIdx == 3) ) 1725 { 1726 Vector3 vtx = vertices[maxIdx]; 1727 vertices[maxIdx] = vertices[2]; 1728 vertices[2] = vtx; 1729 } 1730 } 1731 1732 // wrong surface orientation? 1733 Vector3 norm = Normalize(CrossProd(vertices[0] - vertices[1], 1734 vertices[2] - vertices[1])); 1735 1736 Polygon3 *planePoly = new Polygon3(); 1737 1738 if (DotProd(norm, plane.mNormal) > 0) 1739 for (int i = 0; i < (int)vertices.size(); ++ i) 1740 planePoly->mVertices.push_back(vertices[i]); 1741 else 1742 { 1743 for (int i = (int)vertices.size() - 1; i >= 0; -- i) 1744 planePoly->mVertices.push_back(vertices[i]); 1745 } 1746 1747 //Debug << *planePoly << "\narea: " << planePoly->GetArea() << endl; 1748 1749 return planePoly; 1750 } 1757 1758 /* 1759 inline void addEdge(int idx, int ptAIdx, int ptBIdx) 1760 { 1761 edgeTable[idx].push_back(edge(ptAIdx, ptBIdx)); 1762 } 1763 int AxisAlignedBox3::CreateEdgeTable() 1764 { 1765 //-- four vertices pattern 1 (3 + reflection) 1766 int idx = getIdx(1) + getIdx(2) + getIdx(5) + getIdx(6); 1767 addEdge(idx, 1, 0); addEdge(idx, 3, 2); addEdge(idx, 7, 6; addEdge(idx, 4, 5); 1768 int idx = 255 - idx; 1769 addEdge(idx, 4, 5); addEdge(idx, 7, 6); addEdge(idx, 3, 2); addEdge(idx, 1, 0); 1770 1771 int idx = getIdx(0) + getIdx(1) + getIdx(2) + getIdx(3); 1772 addEdge(idx, 0, 4); addEdge(idx, 3, 7); addEdge(idx, 2, 6); addEdge(idx, 1, 5); 1773 int idx = 255 - idx; 1774 addEdge(idx, 1, 5); addEdge(idx, 2, 6); addEdge(idx, 3, 7); addEdge(idx, 0, 4); 1775 1776 int idx = getIdx(2) + getIdx(6) + getIdx(7) + getIdx(3); 1777 addEdge(idx, 0, 3); addEdge(idx, 4, 7); addEdge(idx, 5, 6); addEdge(idx, 1, 2); 1778 int idx = 255 - idx; 1779 addEdge(idx, 1, 2); addEdge(idx, 5, 6); addEdge(idx, 4, 7); addEdge(idx, 0, 3); 1780 1781 1782 //-- four vertices pattern 2 (12 + reflection 1783 int idx = getIdx(0) + getIdx(4); 1784 addEdge(idx, 0, 1); addEdge(idx, 0, 3); addEdge(idx, 4, 7; addEdge(idx, 4, 5); 1785 } 1786 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r312 r313 1195 1195 "20"); 1196 1196 1197 RegisterOption(" BspTree.maxViewCells",1197 RegisterOption("ViewCells.maxViewCells", 1198 1198 optInt, 1199 "- bsp_max_viewcells=",1200 " 999999");1199 "-view_cells_max_viewcells=", 1200 "0"); 1201 1201 } 1202 1202 -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r312 r313 55 55 56 56 virtual void 57 ExportViewCells( ViewCellContainer *viewCells) = 0;57 ExportViewCells(const ViewCellContainer &viewCells) = 0; 58 58 virtual void 59 59 ExportViewCell(ViewCell *viewCell) = 0; … … 61 61 ExportIntersectable(Intersectable *object) = 0; 62 62 63 virtual void ExportBspSplits(const BspTree &tree) = 0; 64 63 virtual void 64 ExportBspSplitPlanes(const BspTree &tree) = 0; 65 virtual void 66 ExportBspSplits(const BspTree &tree) = 0; 67 65 68 void SetExportRayDensity(const bool d) { mExportRayDensity = d; } 66 69 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r312 r313 28 28 { 29 29 X3dParser parser; 30 int maxViewCells = 0; 30 31 environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 31 32 return parser.ParseFile(filename, mViewCells); 32 environment->GetIntValue("ViewCells.maxViewCells", maxViewCells); 33 34 bool loaded = parser.ParseFile(filename, mViewCells); 35 36 if (maxViewCells > 0) 37 { 38 while (mViewCells.size() > maxViewCells) 39 { 40 ViewCell *vc = mViewCells.back(); 41 DEL_PTR(vc); 42 mViewCells.pop_back(); 43 } 44 } 45 return loaded; 33 46 } 34 47 … … 84 97 85 98 int maxViewCells = 0; 86 environment->GetIntValue(" BspTree.maxViewCells", maxViewCells);99 environment->GetIntValue("ViewCells.maxViewCells", maxViewCells); 87 100 88 101 mSceneGraph->CollectObjects(&objects); -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r312 r313 67 67 68 68 // add object to view cell 69 for (j=0; j < ray.viewCells.size(); j++)69 for (j=0; j < ray.viewCells.size(); ++ j) 70 70 { 71 71 ViewCell *vc = ray.viewCells[j]; 72 73 for (int i = 0; i < 5; ++ i) 74 if (vc == mViewCells[i]) 75 Debug << "adding sample to vc " << i << endl; 72 76 contributingSamples += vc->GetPvs().AddSample(obj); 73 77 } 74 78 75 79 if (mPass > 1) 76 for (j=1; j < ((int)ray.viewCells.size() - 1); j++)80 for (j=1; j < ((int)ray.viewCells.size() - 1); ++ j) 77 81 { 78 82 ray.viewCells[j]->AddPassingRay(ray, contributingSamples ? 1 : 0); … … 112 116 sampleContributions += AddObjectSamples(object, ray); 113 117 114 if (ray.intersections.size() > 0) // view cellfound118 if (ray.intersections.size() > 0) // second intersection found 115 119 { 116 120 sampleContributions += … … 230 234 231 235 int pvsOut = Min((int)objects.size(), 10); 232 236 int vcPvsOut = Min((int)mViewCells.size(), 5); 237 233 238 vector<Ray> rays[10]; 234 239 vector<Ray> vcRays[5]; 240 235 241 while (totalSamples < mTotalSamples) { 236 242 int passContributingSamples = 0; … … 330 336 sampleContributions = CastRay(object, ray); 331 337 338 if (mViewCellsType == BSP_VIEW_CELLS) 339 { 340 // check whether we can add this to the rays 341 for (int k = 0; k < ray.viewCells.size(); ++ k) 342 for (int j = 0; j < vcPvsOut; ++ j) 343 if (mViewCells[j] == ray.viewCells[k]) 344 { 345 Debug << "Pushing back ray" << endl; 346 vcRays[j].push_back(ray); 347 } 348 } 332 349 } 333 350 } else { … … 350 367 } 351 368 } 352 369 353 370 passSamples++; 354 371 … … 369 386 int pvsSize = 0; 370 387 371 if (mViewCellsType == BSP_VIEW_CELLS) 372 { 388 if (mViewCellsType == BSP_VIEW_CELLS) { 373 389 for (i=0; i < mViewCells.size(); i++) { 374 390 ViewCell *vc = mViewCells[i]; 375 391 pvsSize += vc->GetPvs().GetSize(); 376 392 } 377 } else 378 { 393 } else { 379 394 for (i=0; i < objects.size(); i++) { 380 395 Intersectable *object = objects[i]; … … 435 450 if (mViewCellsType == BSP_VIEW_CELLS) 436 451 { 437 int limit = Min((int)mViewCells.size(), 1); 438 439 //char s[64]; sprintf(s, "bsp-pvs%04d.x3d", k); 440 Exporter *exporter = Exporter::GetExporter("bsp-pvs.x3d"); 441 exporter->SetFilled(); 442 443 Intersectable::NewMail(); 444 445 for (int j = 0; j < limit; ++ j) 446 { 447 // j random view cells 448 int k = Random((int)mViewCells.size()); 449 450 Debug << "next vc: " << k << endl; 451 ViewCellPvsMap::iterator it = mViewCells[k]->GetPvs().mEntries.begin(); 452 for (int j = 0; j < vcPvsOut; ++ j) 453 { 454 ViewCell *vc = mViewCells[j]; 455 456 Intersectable::NewMail(); 457 458 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", j); 459 Exporter *exporter = Exporter::GetExporter(s); 460 exporter->SetFilled(); 461 462 ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 452 463 453 464 Material m;//= RandomMaterial(); … … 455 466 exporter->SetForcedMaterial(m); 456 467 457 exporter->ExportViewCell(mViewCells[k]); 468 exporter->ExportViewCell(vc); 469 470 Debug << "pvs size: " << (int)vc->GetPvs().GetSize() << " of " << objects.size(); 471 Debug << " exporting rays: " << (int)vcRays[j].size() << endl; 472 473 exporter->SetWireframe(); 474 475 m.mDiffuseColor = RgbColor(1, 0, 1); 476 exporter->SetForcedMaterial(m); 477 478 exporter->ExportBspTree(*mBspTree); 479 exporter->ExportRays(vcRays[j], 1000, RgbColor(0, 1, 0)); 458 480 459 481 m.mDiffuseColor = RgbColor(1, 0, 0); 460 482 exporter->SetForcedMaterial(m); 461 483 462 Debug << "pvs size: " << mViewCells[k]->GetPvs().GetSize() << " of " << objects.size() << endl; 463 464 for (; it != mViewCells[k]->GetPvs().mEntries.end(); ++ it) 484 // output pvs of view cell 485 for (; it != vc->GetPvs().mEntries.end(); ++ it) 465 486 { 466 487 Intersectable *intersect = (*it).first; … … 469 490 exporter->ExportIntersectable(intersect); 470 491 intersect->Mail(); 471 } 472 492 } 473 493 } 494 495 // output rest of the objects 496 if (1) 497 { 498 Material m;//= RandomMaterial(); 499 m.mDiffuseColor = RgbColor(0, 0, 1); 500 exporter->SetForcedMaterial(m); 501 502 for (int j = 0; j < objects.size(); ++ j) 503 if (!objects[j]->Mailed()) 504 { 505 exporter->ExportIntersectable(objects[j]); 506 objects[j]->Mail(); 507 } 508 } 509 DEL_PTR(exporter); 474 510 } 475 476 // output rest of the objects477 Material m;//= RandomMaterial();478 m.mDiffuseColor = RgbColor(0, 0, 1);479 exporter->SetForcedMaterial(m);480 481 for (int j = 0; j < objects.size(); ++ j)482 if (!objects[j]->Mailed())483 {484 exporter->ExportIntersectable(objects[j]);485 objects[j]->Mail();486 }487 488 DEL_PTR(exporter);489 511 } 490 512 … … 529 551 return true; 530 552 } 531 532 533 534 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r312 r313 69 69 // add base vertices and calculate top vertices 70 70 for (int i = 0; i < 3; ++i) 71 mesh->mVertices.push_back(baseTri.mVertices[i] + height * 0.5 * triNorm);71 mesh->mVertices.push_back(baseTri.mVertices[i]); 72 72 73 73 // add top vertices -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r312 r313 261 261 BspTree::BspTree(ViewCell *viewCell): 262 262 mRoot(NULL), 263 m ViewCell(viewCell),263 mRootCell(viewCell), 264 264 //mStoreSplitPolys(true) 265 265 mStoreSplitPolys(false) … … 380 380 BspNode *firstNode = mRoot ? mRoot : new BspLeaf(); 381 381 382 tStack.push(BspTraversalData(firstNode, polys, 0, m ViewCell));382 tStack.push(BspTraversalData(firstNode, polys, 0, mRootCell)); 383 383 384 384 while (!tStack.empty()) … … 410 410 411 411 // extract view cells associated with the split polygons 412 ViewCell *frontViewCell = m ViewCell;413 ViewCell *backViewCell = m ViewCell;412 ViewCell *frontViewCell = mRootCell; 413 ViewCell *backViewCell = mRootCell; 414 414 415 415 if (!viewCells) … … 517 517 { 518 518 mBox.Include(object->GetBox()); // add to BSP tree aabb 519 AddMeshToPolygons(mesh, polys, m ViewCell);519 AddMeshToPolygons(mesh, polys, mRootCell); 520 520 } 521 521 } … … 561 561 std::stack<BspTraversalData> tStack; 562 562 563 BspTraversalData tData(new BspLeaf(), polys, 0, m ViewCell);563 BspTraversalData tData(new BspLeaf(), polys, 0, mRootCell); 564 564 tStack.push(tData); 565 565 … … 601 601 << (int)tData.mPolygons->size() << endl; 602 602 #endif 603 604 603 EvaluateLeafStats(tData); 605 606 604 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 605 606 // add view cell to leaf 607 leaf->SetViewCell(tData.mViewCell); 607 608 608 // add view cell to leaf609 if (!leaf->GetViewCell())610 leaf->SetViewCell(tData.mViewCell);611 612 609 // remaining polygons are discarded or added to node 613 610 leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); … … 629 626 &coincident); 630 627 631 ViewCell *frontViewCell = m ViewCell;632 ViewCell *backViewCell = m ViewCell;628 ViewCell *frontViewCell = mRootCell; 629 ViewCell *backViewCell = mRootCell; 633 630 634 631 #ifdef _DEBUG … … 639 636 #endif 640 637 641 //-- extract view cells from coincident polygons according to plane normal 642 ExtractViewCells(&backViewCell, &frontViewCell, coincident, interior->mPlane, 643 frontPolys->empty(), backPolys->empty()); 638 // extract view cells from coincident polygons according to plane normal 639 // only if front or back polygons are empty 640 ExtractViewCells(&backViewCell, 641 &frontViewCell, 642 coincident, 643 interior->mPlane, 644 backPolys->empty(), 645 frontPolys->empty()); 644 646 645 647 // don't need coincident polygons anymore … … 647 649 648 650 // push the children on the stack 649 // split polygon is only needed in the back leaf651 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, backViewCell)); 650 652 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, frontViewCell)); 651 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, backViewCell));652 653 653 654 // cleanup … … 662 663 const PolygonContainer &coincident, 663 664 const Plane3 splitPlane, 664 const bool extract Front,665 const bool extract Back) const665 const bool extractBack, 666 const bool extractFront) const 666 667 { 667 668 bool foundFront = !extractFront, foundBack = !extractBack; … … 673 674 (it != it_end); ++ it) 674 675 { 675 if (DotProd((*it)->GetSupportingPlane().mNormal, splitPlane.mNormal > 0))676 if (DotProd((*it)->GetSupportingPlane().mNormal, splitPlane.mNormal) > 0) 676 677 { 677 678 *backViewCell = dynamic_cast<ViewCell *>((*it)->mParent); … … 1178 1179 // test with tree bounding box 1179 1180 if (!mBox.GetMinMaxT(ray, &mint, &maxt)) 1180 {1181 1181 return 0; 1182 } 1183 1184 if (mint < 0) 1182 1183 if (mint < 0) // start ray from origin 1185 1184 mint = 0; 1186 1187 maxt += Limits::Threshold; 1185 1186 // bound ray 1187 if ((ray.GetType() == Ray::LOCAL_RAY) && 1188 ((int)ray.intersections.size() > 0) && 1189 (ray.intersections[0].mT <= maxt)) 1190 { 1191 maxt = ray.intersections[0].mT; 1192 } 1188 1193 1189 1194 Vector3 entp = ray.Extrap(mint); … … 1191 1196 1192 1197 BspNode *node = mRoot; 1193 BspNode *farChild ;1198 BspNode *farChild = NULL; 1194 1199 1195 1200 while (1) … … 1213 1218 node = in->GetBack(); 1214 1219 1215 if(extSide <= 0) 1220 if(extSide <= 0) // plane does not split ray => no far child 1216 1221 continue; 1217 1222 … … 1222 1227 node = in->GetFront(); 1223 1228 1224 if (extSide >= 0) 1229 if (extSide >= 0) // plane does not split ray => no far child 1225 1230 continue; 1226 1231 1227 farChild = in->GetBack(); 1232 farChild = in->GetBack(); // plane splits ray 1228 1233 } 1229 1234 else // ray and plane are coincident // WHAT TO DO IN THIS CASE ? … … 1236 1241 tStack.push(BspRayTraversalData(farChild, extp, maxt)); 1237 1242 1238 // find intersection with plane between ray origin and exit point1243 // find intersection of ray segment with plane 1239 1244 extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 1245 1240 1246 } else // reached leaf => intersection with view cell 1241 1247 { 1242 1248 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1243 1244 //ray.mBspLeaves.push_back(leaf); 1245 //Debug << "adding view cell" << leaf->mViewCell; 1249 1246 1250 if (!leaf->mViewCell->Mailed()) 1247 1251 { 1248 1252 ray.viewCells.push_back(leaf->mViewCell); 1249 mViewCell->Mail();1253 leaf->mViewCell->Mail(); 1250 1254 ++ hits; 1251 1255 } 1252 //Debug << "view cell added" << endl;1253 // get the next nodefrom the stack1256 1257 //-- fetch the next far child from the stack 1254 1258 if (tStack.empty()) 1255 1259 break; 1256 1260 1257 1261 entp = extp; 1258 mint = maxt; 1259 BspRayTraversalData &s 1262 mint = maxt; // NOTE: need this? 1263 BspRayTraversalData &s = tStack.top(); 1260 1264 1261 1265 node = s.mNode; 1262 1266 extp = s.mExitPoint; 1263 1267 maxt = s.mMaxT; 1268 1269 //Debug << "leaf: new entrypt: " << entp << " new extp: " << extp << endl; 1264 1270 1265 1271 tStack.pop(); -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r312 r313 30 30 BspRayTraversalData() {} 31 31 32 BspRayTraversalData(BspNode *n, const Vector3 & p, const float maxt):33 mNode(n), mExitPoint( p), mMaxT(maxt)32 BspRayTraversalData(BspNode *n, const Vector3 &extp, const float maxt): 33 mNode(n), mExitPoint(extp), mMaxT(maxt) 34 34 {} 35 35 }; … … 239 239 protected: 240 240 241 /// polygonal representation of this viewcell 242 /// if NULL this note does not correspond to feasible viewcell 241 /// if NULL this does not correspond to feasible viewcell 243 242 ViewCell *mViewCell; 244 243 }; … … 457 456 @param coincident container of polygons coincident to the split plane 458 457 @param splitPlane the split plane which decides about back and front 458 @param extractBack if a back view cell is extracted 459 459 @param extractFront if a front view cell is extracted 460 @param extractBack if a back view cell is extracted461 460 */ 462 461 void ExtractViewCells(ViewCell **backViewCell, … … 464 463 const PolygonContainer &coincident, 465 464 const Plane3 splitPlane, 466 const bool extract Front,467 const bool extract Back) const;465 const bool extractBack, 466 const bool extractFront) const; 468 467 469 468 /** Computes best cost ratio for the suface area heuristics for axis aligned … … 518 517 519 518 /// view cell corresponding to unbounded space 520 ViewCell *m ViewCell;519 ViewCell *mRootCell; 521 520 522 521 public: -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r312 r313 120 120 } 121 121 122 void X3dExporter::ExportViewCells(ViewCellContainer *viewCells) 123 { 124 ViewCellContainer::iterator it, it_end = viewCells->end(); 125 126 for (it = viewCells->begin(); it != it_end; ++it) 122 void 123 X3dExporter::ExportViewCells(const ViewCellContainer &viewCells) 124 { 125 ViewCellContainer::const_iterator it, it_end = viewCells.end(); 126 127 for (it = viewCells.begin(); it != it_end; ++ it) 127 128 ExportViewCell(*it); 128 129 } 130 129 131 void 130 132 X3dExporter::ExportViewCell(ViewCell *viewCell) … … 274 276 } 275 277 276 void X3dExporter::ExportPolygons( PolygonContainer *polys)278 void X3dExporter::ExportPolygons(const PolygonContainer &polys) 277 279 { 278 280 stream << "<Shape>" << endl; … … 314 316 VertexContainer::const_iterator vi; 315 317 316 for (pit = polys ->begin(); pit != polys->end(); ++pit)318 for (pit = polys.begin(); pit != polys.end(); ++pit) 317 319 { 318 320 Polygon3 *poly = *pit; … … 327 329 328 330 stream << "<Coordinate point=\"" << endl; 329 for (pit = polys ->begin(); pit != polys->end(); ++pit)331 for (pit = polys.begin(); pit != polys.end(); ++pit) 330 332 { 331 333 Polygon3 *poly = *pit; … … 453 455 ViewCellContainer::iterator new_end = unique(foundViewCells.begin(), foundViewCells.end()); 454 456 foundViewCells.erase(new_end, foundViewCells.end()); 455 ExportViewCells( &foundViewCells);457 ExportViewCells(foundViewCells); 456 458 457 459 Debug << "Number of view cells after erasing dublicates: " << (int)foundViewCells.size() << endl; … … 533 535 if (vc->mPassingRays.mRays) 534 536 { 535 float importance = vc->mPassingRays.mContributions/(float)vc->mPassingRays.mRays; 537 float importance = 538 vc->mPassingRays.mContributions / (float)vc->mPassingRays.mRays; 536 539 537 540 mForcedMaterial.mDiffuseColor.r = importance; … … 616 619 BspNode *mNode; 617 620 618 PolygonContainer *mPolygons;619 621 vector<Plane3 *> mPlanes; 620 622 vector<bool> mSides; 621 623 bool mIsFront; 622 624 623 BspSplitData(BspNode *node , PolygonContainer *polys):624 mNode(node), m Polygons(polys), mIsFront(false)625 BspSplitData(BspNode *node): 626 mNode(node), mIsFront(false) 625 627 {}; 626 628 BspSplitData(BspNode *node, 627 PolygonContainer *polys,628 629 vector<Plane3 *> planes, 629 630 vector<bool> sides, 630 631 bool isFront): 631 mNode(node), mP olygons(polys), mPlanes(planes),632 mNode(node), mPlanes(planes), 632 633 mSides(sides), mIsFront(isFront) 633 634 {}; … … 636 637 void X3dExporter::ExportBspSplits(const BspTree &tree) 637 638 { 638 int mask = Random(50000);639 640 639 std::stack<BspSplitData> tStack; 641 640 642 BspSplitData tData(tree.GetRoot() , new PolygonContainer());641 BspSplitData tData(tree.GetRoot()); 643 642 tStack.push(tData); 644 643 644 PolygonContainer polys; 645 645 646 while (!tStack.empty()) 646 647 { … … 652 653 { 653 654 BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 654 655 tData.mPlanes.push_back(interior->GetPlane()); 656 tData.mSides.push_back(tData.mIsFront); 655 if (tData.mNode != tree.GetRoot()) 656 tData.mSides.push_back(tData.mIsFront); // add current side 657 657 658 658 // bounded plane is added to the polygons 659 Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(* tData.mPlanes.back());659 Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(*interior->GetPlane()); 660 660 661 PolygonContainer *frontPolys = new PolygonContainer();662 PolygonContainer *backPolys = new PolygonContainer();663 PolygonContainer coincident;664 665 int splits = 0;666 667 // split polygons with respect to split plane668 interior->SplitPolygons(tData.mPolygons,669 frontPolys,670 backPolys,671 &coincident,672 splits,673 false);674 675 661 // do all the splits with the previous planes 676 662 for (int i = 0; i < (int)tData.mPlanes.size(); ++i) … … 692 678 else 693 679 { 694 Debug << "take backpoly" << endl;695 680 planePoly = backPoly; 696 681 DEL_PTR(frontPoly); … … 699 684 } 700 685 701 PolygonContainer *polys; 702 BspNode *next; 703 bool side = false; 704 705 // random decision 706 if (mask & 1) 707 { 708 next = interior->GetBack(); 709 polys = backPolys; 710 CLEAR_CONTAINER(*frontPolys); 711 DEL_PTR(frontPolys); 712 side = false; 713 } 686 tData.mPlanes.push_back(interior->GetPlane()); // add plane to split planes 687 if (planePoly->Valid()) 688 polys.push_back(planePoly); 714 689 else 715 690 { 716 next = interior->GetFront(); 717 polys = frontPolys; 718 719 CLEAR_CONTAINER(*backPolys); 720 DEL_PTR(backPolys); 721 side = true; 691 Debug << "polygon not valid: " << *planePoly << " size: " << planePoly->mVertices.size() << endl; 692 DEL_PTR(planePoly); 722 693 } 723 724 mask = mask >> 1;725 polys->push_back(planePoly);726 727 694 // push the children on the stack 728 tStack.push(BspSplitData(next, polys, tData.mPlanes, 729 tData.mSides, side)); 730 //tStack.push(BspSplitData(interior->GetBack(), backPolys, 731 // tData.mPlanes, tData.mSides, false)); 732 733 // clean up 734 CLEAR_CONTAINER(coincident); // NOTE: should contain nothing 735 CLEAR_CONTAINER(*tData.mPolygons); 736 DEL_PTR(tData.mPolygons); 695 tStack.push(BspSplitData(interior->GetFront(), tData.mPlanes, tData.mSides, true)); 696 tStack.push(BspSplitData(interior->GetBack(), tData.mPlanes, tData.mSides, false)); 737 697 } 738 else // reached leaf 698 } 699 ExportPolygons(polys); 700 CLEAR_CONTAINER(polys); 701 } 702 703 void X3dExporter::ExportBspSplitPlanes(const BspTree &tree) 704 { 705 std::stack<BspNode *> tStack; 706 707 tStack.push(tree.GetRoot()); 708 709 PolygonContainer polys; 710 711 while (!tStack.empty()) 712 { 713 // filter polygons donw the tree 714 BspNode *node = tStack.top(); 715 tStack.pop(); 716 717 if (!node->IsLeaf()) 739 718 { 740 //Debug << "\nsplits: " << endl; 741 //for (int i = 0; i < (int)tData.mSides.size(); ++ i)Debug << " " << tData.mSides[i]; 742 ExportPolygons(tData.mPolygons); 743 744 // clean up 745 CLEAR_CONTAINER(*tData.mPolygons); 746 DEL_PTR(tData.mPolygons); 719 BspInterior *interior = dynamic_cast<BspInterior *>(node); 720 721 // bounded plane is added to the polygons 722 polys.push_back(tree.GetBoundingBox().BoundPlane(*interior->GetPlane())); 723 724 // push the children on the stack 725 tStack.push(interior->GetBack()); 726 tStack.push(interior->GetFront()); 747 727 } 748 728 } 749 } 729 730 ExportPolygons(polys); 731 CLEAR_CONTAINER(polys); 732 } -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r312 r313 50 50 ExportPolygon(Polygon3 *poly); 51 51 52 virtual void ExportPolygons( PolygonContainer *polys);52 virtual void ExportPolygons(const PolygonContainer &polys); 53 53 54 54 virtual bool … … 68 68 69 69 virtual void 70 ExportViewCells( ViewCellContainer *viewCells);70 ExportViewCells(const ViewCellContainer &viewCells); 71 71 72 virtual void ExportBspSplits(const BspTree &tree); 72 virtual void 73 ExportBspSplitPlanes(const BspTree &tree); 74 75 virtual void 76 ExportBspSplits(const BspTree &tree); 73 77 74 78 static ViewCellContainer foundViewCells; // todo: remove this -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h
r312 r313 114 114 // Constructors and Destructor 115 115 // ----------------------------------------------------------------------- 116 X3dViewCellsParseHandlers(ViewCellContainer *mViewCells, float viewCellHeight); 116 X3dViewCellsParseHandlers(ViewCellContainer *mViewCells, 117 float viewCellHeight); 117 118 ~X3dViewCellsParseHandlers(); 118 119 -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r312 r313 63 63 if (exporter) 64 64 { 65 Debug << "Exporting bsp splits" << endl; 65 Debug << "Exporting bsp splits" << endl; 66 Material m; 67 m.mDiffuseColor = RgbColor(1, 0, 0); 68 exporter->SetForcedMaterial(m); 69 exporter->SetWireframe(); 66 70 exporter->ExportBspSplits(*p->mBspTree); 71 72 m.mDiffuseColor = RgbColor(0, 1, 0); 73 exporter->SetForcedMaterial(m); 74 exporter->SetFilled(); 75 76 exporter->ExportViewCells(p->mViewCells); 77 67 78 delete exporter; 68 79 } … … 86 97 { 87 98 Debug << "Exporting complementary view cells" << endl; 88 exporter->ExportViewCells( &vc_compl); // export view cells99 exporter->ExportViewCells(vc_compl); // export view cells 89 100 delete exporter; 90 101 }
Note: See TracChangeset
for help on using the changeset viewer.