- Timestamp:
- 10/09/05 00:38:18 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r310 r312 9 9 # filename vienna.x3d 10 10 # filename ../data/vienna/vienna-simple.x3d 11 filename ../data/vienna/vienna-buildings.x3d11 # filename ../data/vienna/vienna-buildings.x3d 12 12 # filename ../data/vienna/viewcells-25-sel.x3d 13 #filename ../data/atlanta/atlanta2.x3d13 filename ../data/atlanta/atlanta2.x3d 14 14 # filename ../data/soda/soda.dat 15 15 # filename ../data/soda/soda5.dat … … 56 56 57 57 Sampling { 58 totalSamples 100000 059 samplesPerPass 558 totalSamples 100000 59 samplesPerPass 10 60 60 } 61 61 62 62 ViewCells { 63 63 hierarchyType bspTree 64 height 5.0 64 65 #hierarchyType kdTree 65 66 #hierarchyType sceneDependent 66 67 # filename ../data/atlanta/atlanta_viewcells_large.x3d 67 # filename ../data/atlanta/atlanta_viewcells_large2.x3d68 68 filename ../data/vienna/viewcells-25-sel.x3d 69 69 # filename ../data/vienna/viewcells-25.x3d … … 84 84 # vertical axis = 64 85 85 86 splitPlaneStrategy 6686 splitPlaneStrategy 8 87 87 # least splits + balanced polygons 88 88 #splitPlaneStrategy 12 -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r302 r312 125 125 b->SetValue(mMax.x, mMin.y, mMax.z); 126 126 break; 127 } 128 } 129 130 // returns the vertex indices in the range <0..7>, v = 4.x + 2.y + z, where 131 // x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate) 132 void 133 AxisAlignedBox3::GetEdge(const int edge, int &aIdx, int &bIdx) const 134 { 135 switch(edge) { 136 case 0: aIdx = 0; bIdx = 1; break; 137 case 1: aIdx = 0; bIdx = 2; break; 138 case 2: aIdx = 0; bIdx = 4; break; 139 case 3: aIdx = 7; bIdx = 6; break; 140 case 4: aIdx = 7; bIdx = 5; break; 141 case 5: aIdx = 7; bIdx = 3; break; 142 case 6: aIdx = 1; bIdx = 3; break; 143 case 7: aIdx = 1; bIdx = 5; break; 144 case 8: aIdx = 2; bIdx = 3; break; 145 case 9: aIdx = 2; bIdx = 6; break; 146 case 10: aIdx = 4; bIdx = 6; break; 147 case 11: aIdx = 4; bIdx = 5; break; 127 148 } 128 149 } … … 1023 1044 }; 1024 1045 1046 1025 1047 // The fast computation of arctangent .. the maximal error is less 1026 1048 // than 4.1 degrees, according to Graphics GEMSII, 1991, pages 389--391 … … 1624 1646 return Rectangle3(v[0], v[1], v[2], v[3]); 1625 1647 } 1648 /* 1649 const int AxisAlignedBox3::complEdgeTbl[12][3] = 1650 { 1651 {3, 4, 5}, 1652 {3, 4, 5}, 1653 {3, 4, 5}, 1654 {0, 1, 2}, 1655 {0, 1, 2}, 1656 {0, 1, 2}, 1657 {9, 10, 11}, 1658 {8, 9, 10}, 1659 {7, 10, 11}, 1660 {6, 7, 11}, 1661 {6, 7, 8}, 1662 {6, 8, 9}, 1663 }; 1664 */ 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 } -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r302 r312 7 7 #include "Plane3.h" 8 8 9 class Plane3;10 9 class Ray; 11 10 class Polygon3; … … 302 301 float ProjectToSphereSA(const Vector3 &viewpoint, int *tcase) const; 303 302 303 /** Returns vertex indices of edge. 304 */ 305 void GetEdge(const int edge, int &aIdx, int &bIdx) const; 306 307 /** Bounds plane with box. Returns polygon resulting from the bounded 308 plane. 309 */ 310 Polygon3 *BoundPlane(const Plane3 &plane); 304 311 305 312 #define __EXTENT_HACK … … 353 360 static const int fsvertices[27][9]; 354 361 362 // table storing the complementary edges of each edge 363 //static const int complEdgeTbl[12][3]; 364 355 365 // input and output operator with stream 356 366 friend ostream& operator<<(ostream &s, const AxisAlignedBox3 &A); -
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h
r308 r312 24 24 mWidth = 640; 25 25 mHeight = 480; 26 mFovy = 60 *M_PI/180.0f;26 mFovy = 60.0*M_PI/180.0; 27 27 } 28 28 -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r311 r312 1160 1160 "atlanta_viewcells_large.x3d"); 1161 1161 1162 RegisterOption("ViewCells.height", 1163 optFloat, 1164 "-view_cells_height=", 1165 "5.0"); 1162 1166 1163 1167 RegisterOption("BspTree.constructionMethod", -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r261 r312 56 56 virtual void 57 57 ExportViewCells(ViewCellContainer *viewCells) = 0; 58 58 virtual void 59 ExportViewCell(ViewCell *viewCell) = 0; 59 60 virtual void 60 61 ExportIntersectable(Intersectable *object) = 0; 62 63 virtual void ExportBspSplits(const BspTree &tree) = 0; 61 64 62 65 void SetExportRayDensity(const bool d) { mExportRayDensity = d; } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r308 r312 5 5 #include "AxisAlignedBox3.h" 6 6 7 // tolerance value for side relation8 #define SIDE_TOLERANCE 0.002f // TODO: Test different values9 #define SIDE_TOLERANCE_SQRD 0.000004f10 #define AREA_LIMIT 0.0001f11 12 7 Polygon3::Polygon3(): mMaterial(NULL), mParent(NULL) 13 8 {} … … 17 12 18 13 Polygon3::Polygon3(MeshInstance *parent): mMaterial(NULL), mParent(parent) 19 { 20 } 14 {} 15 16 21 17 Polygon3::Polygon3(Face *face, Mesh *parentMesh) 22 18 { … … 41 37 Vector3 Polygon3::GetNormal() const 42 38 { 43 return Normalize(CrossProd(mVertices[0]-mVertices[1], 44 mVertices[2]-mVertices[1])); 45 } 46 47 void Polygon3::Split(Plane3 *partition, Polygon3 *front, Polygon3 *back) 39 return Normalize(CrossProd(mVertices[0] - mVertices[1], 40 mVertices[2] - mVertices[1])); 41 } 42 43 void Polygon3::Split(const Plane3 &partition, 44 Polygon3 &front, 45 Polygon3 &back, 46 VertexContainer &splitPts) 48 47 { 49 48 Vector3 ptA = mVertices.back(); 50 49 51 int sideA = partition ->Side(ptA, SIDE_TOLERANCE);50 int sideA = partition.Side(ptA, SIDE_TOLERANCE); 52 51 53 52 VertexContainer::const_iterator it; 54 bool foundSplit = false; 55 56 Vector3 prevSplitPt(ptA); 57 53 58 54 // find line - plane intersections 59 55 for (it = mVertices.begin(); it != mVertices.end(); ++ it) 60 56 { 61 57 Vector3 ptB = *it; 62 int sideB = partition ->Side(ptB, SIDE_TOLERANCE);58 int sideB = partition.Side(ptB, SIDE_TOLERANCE); 63 59 64 60 // vertices on different sides => split … … 68 64 { 69 65 //-- plane - line intersection 70 Vector3 splitPt = partition ->FindIntersection(ptA, ptB);66 Vector3 splitPt = partition.FindIntersection(ptA, ptB); 71 67 72 if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 68 // test if split point not too close to previous split point 69 if ((splitPts.size() == 0) || 70 (SqrDistance(splitPt, splitPts.back()) > SIDE_TOLERANCE_SQRD)) 73 71 { 74 72 // add vertex to both polygons 75 front->mVertices.push_back(splitPt); 76 back->mVertices.push_back(splitPt); 77 78 foundSplit = true; 79 prevSplitPt = splitPt; 73 front.mVertices.push_back(splitPt); 74 back.mVertices.push_back(splitPt); 75 76 splitPts.push_back(splitPt); 80 77 } 81 78 } 82 front ->mVertices.push_back(ptB);79 front.mVertices.push_back(ptB); 83 80 } 84 81 else if (sideB < 0) … … 87 84 { 88 85 //-- plane - line intersection 89 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 90 91 if (!foundSplit || (SqrDistance(splitPt, prevSplitPt) > SIDE_TOLERANCE_SQRD)) 86 Vector3 splitPt = partition.FindIntersection(ptA, ptB); 87 // test if split point not too close to other split point 88 // test if split point not too close to previous split point 89 if ((splitPts.size() == 0) || 90 (SqrDistance(splitPt, splitPts.back()) > SIDE_TOLERANCE_SQRD)) 92 91 { 93 92 // add vertex to both polygons 94 front->mVertices.push_back(splitPt); 95 back->mVertices.push_back(splitPt); 96 97 foundSplit = true; 98 prevSplitPt = splitPt; 93 front.mVertices.push_back(splitPt); 94 back.mVertices.push_back(splitPt); 95 96 splitPts.push_back(splitPt); 99 97 } 100 98 } 101 back ->mVertices.push_back(ptB);99 back.mVertices.push_back(ptB); 102 100 } 103 101 else 104 102 { 105 103 // vertex on plane => add vertex to both polygons 106 front ->mVertices.push_back(ptB);107 back ->mVertices.push_back(ptB);104 front.mVertices.push_back(ptB); 105 back.mVertices.push_back(ptB); 108 106 } 109 107 -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r308 r312 25 25 Polygon3(const VertexContainer &vertices); 26 26 Polygon3(MeshInstance *parent); 27 27 28 28 /** Copies all the vertices of the face. 29 29 */ … … 36 36 /** Splits polygon. 37 37 @param partition the split plane 38 @param front the front polygon 39 @param back the back polygon 38 @param front returns the front the front polygon 39 @param back returns the back polygon 40 @param splitPts returns the split points 40 41 */ 41 void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back); 42 void Polygon3::Split(const Plane3 &partition, 43 Polygon3 &front, 44 Polygon3 &back, 45 VertexContainer &splitPts); 42 46 43 47 /** Returns the area of this polygon. … … 69 73 bool Valid() const; 70 74 75 /** Returns the surface normal. 76 */ 71 77 Vector3 GetNormal() const; 72 78 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r310 r312 27 27 Preprocessor::LoadViewCells(const string filename) 28 28 { 29 return X3dParser().ParseFile(filename, mViewCells); 29 X3dParser parser; 30 environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 31 32 return parser.ParseFile(filename, mViewCells); 30 33 } 31 34 -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h
r311 r312 98 98 99 99 typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap; 100 typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ViewCellPvsMap; 101 typedef PvsData<Intersectable *> ViewCellPvsData; 100 102 typedef PvsData<KdNode *> KdPvsData; 101 102 103 //typedef Pvs<KdNode *> KdPvs; 103 104 typedef Pvs<Intersectable *> ViewCellPvs; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r311 r312 243 243 Intersectable *object = objects[i]; 244 244 245 int pvsSize = object->mKdPvs.GetSize(); 246 245 int pvsSize = 0; 246 if (mViewCellsType == KD_VIEW_CELLS) 247 pvsSize = object->mKdPvs.GetSize(); 248 247 249 if (0 && pvsSize) { 248 250 // mail all nodes from the pvs … … 407 409 exporter->SetExportRayDensity(true); 408 410 exporter->ExportKdTree(*mKdTree); 411 409 412 if (mViewCellsType == BSP_VIEW_CELLS) 410 413 exporter->ExportBspTree(*mBspTree); … … 429 432 430 433 if (1) { 434 435 if (mViewCellsType == BSP_VIEW_CELLS) 436 { 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 453 Material m;//= RandomMaterial(); 454 m.mDiffuseColor = RgbColor(0, 1, 0); 455 exporter->SetForcedMaterial(m); 456 457 exporter->ExportViewCell(mViewCells[k]); 458 459 m.mDiffuseColor = RgbColor(1, 0, 0); 460 exporter->SetForcedMaterial(m); 461 462 Debug << "pvs size: " << mViewCells[k]->GetPvs().GetSize() << " of " << objects.size() << endl; 463 464 for (; it != mViewCells[k]->GetPvs().mEntries.end(); ++ it) 465 { 466 Intersectable *intersect = (*it).first; 467 if (!intersect->Mailed()) 468 { 469 exporter->ExportIntersectable(intersect); 470 intersect->Mail(); 471 } 472 473 } 474 } 475 476 // output rest of the objects 477 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 } 490 431 491 for (int k=0; k < pvsOut; k++) { 432 492 Intersectable *object = objects[k]; … … 436 496 exporter->SetWireframe(); 437 497 438 if (mViewCellsType == BSP_VIEW_CELLS) 498 499 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 500 Intersectable::NewMail(); 501 502 // avoid adding the object to the list 503 object->Mail(); 504 ObjectContainer visibleObjects; 505 506 for (; i != object->mKdPvs.mEntries.end(); i++) 439 507 { 440 508 KdNode *node = (*i).first; 509 exporter->ExportBox(mKdTree->GetBox(node)); 510 mKdTree->CollectObjects(node, visibleObjects); 441 511 } 442 else 443 { 444 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 445 Intersectable::NewMail(); 446 447 // avoid adding the object to the list 448 object->Mail(); 449 ObjectContainer visibleObjects; 450 451 for (; i != object->mKdPvs.mEntries.end(); i++) 452 { 453 KdNode *node = (*i).first; 454 exporter->ExportBox(mKdTree->GetBox(node)); 455 mKdTree->CollectObjects(node, visibleObjects); 456 } 457 458 exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 459 exporter->SetFilled(); 460 461 for (int j = 0; j < visibleObjects.size(); j++) 462 exporter->ExportIntersectable(visibleObjects[j]); 512 513 exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 514 exporter->SetFilled(); 515 516 for (int j = 0; j < visibleObjects.size(); j++) 517 exporter->ExportIntersectable(visibleObjects[j]); 463 518 464 519 465 Material m; 466 m.mDiffuseColor = RgbColor(1, 0, 0); 467 exporter->SetForcedMaterial(m); 468 exporter->ExportIntersectable(object); 469 } 470 471 delete exporter; 520 Material m; 521 m.mDiffuseColor = RgbColor(1, 0, 0); 522 exporter->SetForcedMaterial(m); 523 exporter->ExportIntersectable(object); 524 525 delete exporter; 472 526 } 473 527 } -
trunk/VUT/GtpVisibilityPreprocessor/src/UnigraphicsParser.cpp
r179 r312 117 117 118 118 // add vertices to the mesh vertex list 119 int index = currentMesh->mVertices.size();119 int index = (int)currentMesh->mVertices.size(); 120 120 for (i=0; i < vertices.size(); i++, index++) { 121 121 currentMesh->mVertices.push_back(vertices[i]); -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r308 r312 69 69 // add base vertices and calculate top vertices 70 70 for (int i = 0; i < 3; ++i) 71 { 72 mesh->mVertices.push_back(baseTri.mVertices[i]); 73 topTri.mVertices[i] = baseTri.mVertices[i] + height * triNorm; 74 } 75 71 mesh->mVertices.push_back(baseTri.mVertices[i] + height * 0.5 * triNorm); 72 76 73 // add top vertices 77 74 for (int i = 0; i < 3; ++i) 78 mesh->mVertices.push_back( topTri.mVertices[i]);75 mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm); 79 76 80 77 mesh->Preprocess(); -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r311 r312 173 173 Polygon3 *back_piece = NULL; 174 174 175 VertexContainer splitVertices; 176 175 177 switch (classification) 176 178 { … … 192 194 193 195 //-- split polygon into front and back part 194 poly->Split( &mPlane, front_piece, back_piece);196 poly->Split(mPlane, *front_piece, *back_piece, splitVertices); 195 197 196 198 ++ splits; // increase number of splits … … 365 367 366 368 // extract polygons that guide the split process 367 mStat.polys += AddMesh 2Polygons(viewCell->GetMesh(), *polys, viewCell);369 mStat.polys += AddMeshToPolygons(viewCell->GetMesh(), *polys, viewCell); 368 370 mBox.Include(viewCell->GetBox()); // add to BSP aabb 369 371 … … 399 401 int splits = 0; 400 402 401 // split vie cell polygons with respect to split plane403 // split viewcell polygons with respect to split plane 402 404 interior->SplitPolygons(tData.mPolygons, 403 405 frontPolys, … … 445 447 446 448 dynamic_cast<BspLeaf *>(root)->SetViewCell(viewCell); 447 } 449 } 450 448 451 if (!mRoot) // tree empty => new root 449 452 mRoot = root; … … 452 455 } 453 456 454 int BspTree::AddMesh 2Polygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent)457 int BspTree::AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent) 455 458 { 456 459 FaceContainer::const_iterator fi; … … 481 484 { 482 485 mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 483 AddMesh 2Polygons(viewCells[i]->GetMesh(), polys, viewCells[i]);486 AddMeshToPolygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 484 487 } 485 488 } … … 514 517 { 515 518 mBox.Include(object->GetBox()); // add to BSP tree aabb 516 AddMesh 2Polygons(mesh, polys, mViewCell);519 AddMeshToPolygons(mesh, polys, mViewCell); 517 520 } 518 521 } … … 545 548 mStat.polys = Copy2PolygonSoup(objects, *polys); 546 549 547 bool tmpStorePolys = mStoreSplitPolys;548 mStoreSplitPolys = false;549 550 550 // construct tree from polygon soup 551 551 Construct(polys, viewCells); 552 553 mStoreSplitPolys = tmpStorePolys;554 // filter scene bounding box down the tree in order to store split polygons555 if (mStoreSplitPolys)556 {557 Mesh *polyMesh = new Mesh();558 559 for (int i = 0; i < 6; ++i)560 polyMesh->AddRectangle(mBox.GetFace(i));561 562 PolygonContainer *polys = new PolygonContainer();563 AddMesh2Polygons(polyMesh, *polys, NULL);564 565 InsertPolygons(polys);566 567 delete polyMesh;568 }569 552 } 570 553 … … 579 562 580 563 BspTraversalData tData(new BspLeaf(), polys, 0, mViewCell); 581 582 564 tStack.push(tData); 583 565 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r310 r312 443 443 @returns number of polygons 444 444 */ 445 int AddMesh 2Polygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent);445 int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 446 446 447 447 /** returns next candidate index and reorders polygons so no candidate is chosen two times -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r311 r312 115 115 { 116 116 // $$JB$$ 117 // in the future check whether the mesh was not already exporte t117 // in the future check whether the mesh was not already exported 118 118 // and use a reference to the that mesh instead 119 119 ExportMesh(object->GetMesh()); … … 610 610 return true; 611 611 } 612 613 struct BspSplitData 614 { 615 /// the current node 616 BspNode *mNode; 617 618 PolygonContainer *mPolygons; 619 vector<Plane3 *> mPlanes; 620 vector<bool> mSides; 621 bool mIsFront; 622 623 BspSplitData(BspNode *node, PolygonContainer *polys): 624 mNode(node), mPolygons(polys), mIsFront(false) 625 {}; 626 BspSplitData(BspNode *node, 627 PolygonContainer *polys, 628 vector<Plane3 *> planes, 629 vector<bool> sides, 630 bool isFront): 631 mNode(node), mPolygons(polys), mPlanes(planes), 632 mSides(sides), mIsFront(isFront) 633 {}; 634 }; 635 636 void X3dExporter::ExportBspSplits(const BspTree &tree) 637 { 638 int mask = Random(50000); 639 640 std::stack<BspSplitData> tStack; 641 642 BspSplitData tData(tree.GetRoot(), new PolygonContainer()); 643 tStack.push(tData); 644 645 while (!tStack.empty()) 646 { 647 // filter polygons donw the tree 648 BspSplitData tData = tStack.top(); 649 tStack.pop(); 650 651 if (!tData.mNode->IsLeaf()) 652 { 653 BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode); 654 655 tData.mPlanes.push_back(interior->GetPlane()); 656 tData.mSides.push_back(tData.mIsFront); 657 658 // bounded plane is added to the polygons 659 Polygon3 *planePoly = tree.GetBoundingBox().BoundPlane(*tData.mPlanes.back()); 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 plane 668 interior->SplitPolygons(tData.mPolygons, 669 frontPolys, 670 backPolys, 671 &coincident, 672 splits, 673 false); 674 675 // do all the splits with the previous planes 676 for (int i = 0; i < (int)tData.mPlanes.size(); ++i) 677 { 678 VertexContainer splitPts; 679 Polygon3 *frontPoly = new Polygon3(); 680 Polygon3 *backPoly = new Polygon3(); 681 682 if (planePoly->ClassifyPlane(*tData.mPlanes[i]) == Polygon3::SPLIT) 683 { 684 planePoly->Split(*tData.mPlanes[i], *frontPoly, *backPoly, splitPts); 685 DEL_PTR(planePoly); 686 687 if(tData.mSides[i] == true) 688 { 689 planePoly = frontPoly; 690 DEL_PTR(backPoly); 691 } 692 else 693 { 694 Debug << "take backpoly" << endl; 695 planePoly = backPoly; 696 DEL_PTR(frontPoly); 697 } 698 } 699 } 700 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 } 714 else 715 { 716 next = interior->GetFront(); 717 polys = frontPolys; 718 719 CLEAR_CONTAINER(*backPolys); 720 DEL_PTR(backPolys); 721 side = true; 722 } 723 724 mask = mask >> 1; 725 polys->push_back(planePoly); 726 727 // 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); 737 } 738 else // reached leaf 739 { 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); 747 } 748 } 749 } -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r292 r312 69 69 virtual void 70 70 ExportViewCells(ViewCellContainer *viewCells); 71 static ViewCellContainer foundViewCells; // todo: delete later 71 72 virtual void ExportBspSplits(const BspTree &tree); 73 74 static ViewCellContainer foundViewCells; // todo: remove this 72 75 protected: 73 76 virtual void -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp
r294 r312 385 385 // StdInParseHandlers: Constructors and Destructor 386 386 // --------------------------------------------------------------------------- 387 X3dViewCellsParseHandlers::X3dViewCellsParseHandlers(ViewCellContainer *viewCells) : 387 X3dViewCellsParseHandlers::X3dViewCellsParseHandlers(ViewCellContainer *viewCells, 388 float viewCellHeight) : 388 389 mElementCount(0) 389 390 , mAttrCount(0) … … 391 392 , mSpaceCount(0) 392 393 , mViewCells(viewCells) 394 , mViewCellHeight(viewCellHeight) 393 395 { 394 396 } … … 505 507 506 508 507 for (int i = 0; i < mCurrentVertexIndices.size(); i +=3)509 for (int i = 0; i < mCurrentVertexIndices.size(); i += 3) 508 510 { 509 Triangle3 baseTri(vertices[mCurrentVertexIndices[i ]],510 vertices[mCurrentVertexIndices[i +1]],511 vertices[mCurrentVertexIndices[i +2]]);511 Triangle3 baseTri(vertices[mCurrentVertexIndices[i + 0]], 512 vertices[mCurrentVertexIndices[i + 1]], 513 vertices[mCurrentVertexIndices[i + 2]]); 512 514 513 515 // create view cell from base triangle 514 const float height = 10; 515 mViewCells->push_back(ViewCell::ExtrudeViewCell(baseTri, height)); 516 mViewCells->push_back(ViewCell::ExtrudeViewCell(baseTri, mViewCellHeight)); 516 517 517 518 Mesh *mesh = mViewCells->back()->GetMesh(); … … 640 641 // to do. 641 642 // 642 X3dViewCellsParseHandlers handler(&viewCells );643 X3dViewCellsParseHandlers handler(&viewCells, mViewCellHeight); 643 644 parser->setDocumentHandler(&handler); 644 645 parser->setErrorHandler(&handler); -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.h
r261 r312 10 10 { 11 11 public: 12 X3dParser():Parser() {}12 X3dParser():Parser(), mViewCellHeight(5.0f) {} 13 13 14 14 bool ParseFile(const string filename, SceneGraphNode **root); 15 15 bool ParseFile(const string filename, ViewCellContainer &viewCells); 16 17 float mViewCellHeight; 16 18 }; 17 19 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dParserXerces.h
r261 r312 114 114 // Constructors and Destructor 115 115 // ----------------------------------------------------------------------- 116 X3dViewCellsParseHandlers(ViewCellContainer *mViewCells );116 X3dViewCellsParseHandlers(ViewCellContainer *mViewCells, float viewCellHeight); 117 117 ~X3dViewCellsParseHandlers(); 118 118 … … 152 152 153 153 ViewCellContainer *mViewCells; 154 float mViewCellHeight; 155 154 156 VertexIndexContainer mCurrentVertexIndices; 155 157 -
trunk/VUT/GtpVisibilityPreprocessor/src/common.h
r262 r312 127 127 #define MAX_FLOAT 1e30f 128 128 129 // tolerance value for side relation 130 #define SIDE_TOLERANCE 0.002f // TODO: Test different values 131 #define SIDE_TOLERANCE_SQRD 0.000004f 132 #define AREA_LIMIT 0.0001f 133 129 134 #ifndef DEL_PTR 130 135 #define DEL_PTR(ptr) do {if (ptr) { \ -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r310 r312 58 58 p->BspTreeStatistics(Debug); 59 59 p->Export("vc_bsptree2.x3d", false, false, true); 60 60 // export the bsp splits 61 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 62 63 if (exporter) 64 { 65 Debug << "Exporting bsp splits" << endl; 66 exporter->ExportBspSplits(*p->mBspTree); 67 delete exporter; 68 } 61 69 #if 0 62 70 //-- export the complementary view cells
Note: See TracChangeset
for help on using the changeset viewer.