Changeset 237 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 08/12/05 18:42:20 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h
r225 r237 41 41 float *t = NULL, 42 42 bool *coplanar = NULL 43 ) const {return Vector3(0,0,0);} // TODO 43 ) const 44 { 45 const Vector3 v = b - a; // line from A to B 46 47 float dv = DotProd(mNormal, v); 48 float u = 0; 49 50 if (dv) 51 { 52 u = - Distance(a) / dv; 53 Debug << "t: " << u << ", dv: " << dv << endl; 54 if (coplanar) (*coplanar) = false; 55 } 56 else { 57 Debug << "OHOH: " << u << endl; 58 if (coplanar) (*coplanar) = true; 59 } 60 if (t) (*t) = u; 61 Debug << "A: " << a << ", B: " << b << ", result: " << (a + (u * v)) << endl; 62 63 return a + (u * v); 64 } 44 65 45 66 friend bool -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r235 r237 12 12 VertexIndexContainer::const_iterator it; 13 13 14 Debug << "Creating polygon:\n"; 15 14 16 for (it = face->mVertexIndices.begin(); it != face->mVertexIndices.end(); ++ it) 15 17 { 16 18 mVertices.push_back(parent->mVertices[*it]); 19 Debug << parent->mVertices[*it] << endl; 17 20 } 18 21 } … … 37 40 { 38 41 splits = 0; 39 Vector3 ptA = mVertices[mVertices.size() - 1]; ;42 Vector3 ptA = mVertices[mVertices.size() - 1]; 40 43 41 44 int sideA = partition->Side(ptA); … … 50 53 51 54 // vertices on different sides => split 52 if ((sideA != 0) && (sideB != 0) && (sideA != sideB))55 if (sideB > 0) 53 56 { 54 Vector3 v = ptB - ptA; // line from A to B 55 float dv = DotProd(partition->mNormal, v); 56 float t = 0; 57 if (sideA < 0) 58 { 59 //-- plane - line intersection 60 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 57 61 58 if (dv) 62 // add vertex to both polygons 63 front->mVertices.push_back(splitPt); 64 back->mVertices.push_back(splitPt); 65 66 ++ splits; 67 } 68 front->mVertices.push_back(ptB); 69 } 70 else if (sideB < 0) 71 { 72 if (sideA > 0) 59 73 { 60 t = - partition->Distance(ptA) / dv; 74 //-- plane - line intersection 75 Vector3 splitPt = partition->FindIntersection(ptA, ptB); 76 77 // add vertex to both polygons 78 front->mVertices.push_back(splitPt); 79 back->mVertices.push_back(splitPt); 80 81 ++ splits; 61 82 } 62 63 ++ splits;64 }65 if (sideB >= 0)66 {67 83 back->mVertices.push_back(ptB); 68 84 } 69 else if (sideB <= 0)85 else 70 86 { 87 // vertex on plane => add vertex to both polygons 71 88 front->mVertices.push_back(ptB); 89 back->mVertices.push_back(ptB); 72 90 } 73 91 74 92 ptA = ptB; 75 93 sideA = sideB; -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r236 r237 57 57 }; 58 58 59 // Overload << operator for C++-style output 60 inline ostream& 61 operator<< (ostream &s, const Polygon3 &A) 62 { 63 VertexContainer::const_iterator it; 64 65 s << "Polygon:\n"; 66 67 for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it) 68 s << *it << endl; 69 70 return s; 71 } 59 72 60 73 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r235 r237 69 69 char constructionMethodStr[64]; 70 70 71 environment->GetStringValue("BspTree.constructionMethod", 72 constructionMethodStr); 71 environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr); 73 72 74 73 int constructionMethod = BspTree::VIEWCELLS; 75 74 76 75 if (strcmp(constructionMethodStr, "viewCells") == 0) 77 76 constructionMethod = BspTree::VIEWCELLS; … … 84 83 } 85 84 86 Debug << constructionMethodStr << endl;87 88 85 switch (constructionMethod) 89 86 { 90 87 case BspTree::VIEWCELLS: 88 91 89 mViewcells.clear(); 90 92 91 // derive viewcells from the scene objects 93 92 ViewCell::DeriveViewCells(objects, mViewcells, 1000); 93 94 94 mBspTree->Construct(mViewcells); 95 95 break; … … 102 102 return true; 103 103 } 104 105 104 106 105 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r235 r237 58 58 const int max) 59 59 { 60 // maximal max viewcells 60 61 int n = max > 0 ? std::min((int)objects.size(), max) : (int)objects.size(); 62 61 63 for (int i = 0; i < n; ++i) 62 64 { … … 71 73 viewCells.push_back(viewCell); 72 74 } 75 //TODO: transformed meshes 73 76 } 74 77 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r236 r237 96 96 polys->pop(); 97 97 98 Debug << (*poly); 99 98 100 int result = poly->Side(&mPlane); 99 101 … … 104 106 { 105 107 case Polygon3::COINCIDENT: 106 break;108 //break; //TODO: comment in 107 109 case Polygon3::FRONT_SIDE: 108 110 frontPolys->push(poly); … … 118 120 poly->Split(&mPlane, front_piece, back_piece, splits); 119 121 122 Debug << "SPLIT, plane: " << mPlane << "\norginal: " << (*poly) << "\nback: " << (*back_piece) << "\nfront: " << (*front_piece) << endl; 120 123 backPolys->push(back_piece); 121 124 frontPolys->push(front_piece); … … 123 126 // don't need polygon anymore 124 127 DEL_PTR(poly); 128 125 129 break; 126 130 default: … … 128 132 } 129 133 } 130 // delete old polygons131 // Polygon3::DeletePolygons(polys);132 134 } 133 135 … … 204 206 205 207 app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< 206 maxDepthNodes*100/(double)Leaves()<<endl; 207 208 app << "#N_PMAXDEPTH ( Maximal reached depth )\n"<< 209 maxDepth*100/(double)Leaves()<<endl; 208 maxDepthNodes * 100 / (double)Leaves() << endl; 209 210 app << "#N_PMAXDEPTH ( Maximal reached depth )\n" << maxDepth <<endl; 210 211 211 212 app << "#N_ADDED_RAYREFS (Number of dynamically added ray references )\n"<< … … 334 335 ObjectContainer::const_iterator it, it_end = objects.end(); 335 336 336 for (it = objects.begin(); it != it_end; ++ it) 337 { 338 Intersectable *object = *it; 337 int limit = min((int)objects.size(), 1); 338 339 //for (it = objects.begin(); it != it_end; ++ it) 340 for (int i = 0; i < limit; ++i) 341 { 342 Intersectable *object = objects[i];//*it; 339 343 Mesh *mesh = NULL; 340 344 … … 343 347 { 344 348 case Intersectable::MESH_INSTANCE: 345 346 349 mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 347 350 break; 348 351 case Intersectable::VIEWCELL: 349 352 mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 350 // copy the mesh data to polygons351 CopyMesh2Polygons(mesh, polys);352 353 break; 353 354 default: 354 355 break; 355 356 } 356 } 357 358 if (mesh) // copy the mesh data to polygons 359 { 360 CopyMesh2Polygons(mesh, polys); 361 } 362 } 363 357 364 Debug << "number of polygons: " << polys.size() << endl; 358 365 } … … 360 367 void BspTree::Construct(const ObjectContainer &objects) 361 368 { 369 Debug << "Constructing tree using object container\n"; 370 362 371 mTermMaxPolygons = sTermMaxPolygons; 363 372 mTermMaxDepth = sTermMaxDepth; … … 376 385 while (!tStack.empty()) 377 386 { 378 387 tData = tStack.top(); 379 388 tStack.pop(); 380 389 381 390 Subdivide(tStack, tData); 382 391 } … … 385 394 void BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, ViewCell *viewCell) 386 395 { 396 //Debug << "Subdividing node\n"; 397 387 398 PolygonQueue *backPolys = new PolygonQueue(); 388 399 PolygonQueue *frontPolys = new PolygonQueue(); … … 404 415 tStack.push(BspTraversalData(interior->GetFront(), interior, frontPolys, tData.mDepth + 1)); 405 416 } 406 else 417 else // tree terminates here 418 { 407 419 EvaluateLeafStats(tData); 420 // don't need to store polygon information => delete polygons 421 Polygon3::DeletePolygons(tData.mPolygons); 422 } 408 423 } 409 424 … … 434 449 if ((polys->size() <= mTermMaxPolygons) || (depth >= mTermMaxDepth)) 435 450 { 436 // don't need to store polygon information => delete polygons437 Polygon3::DeletePolygons(polys);438 451 // Debug << polys->size() << ", " << depth << endl; 439 452 return leaf; … … 444 457 // add the new nodes to the tree + select subdivision plane 445 458 BspInterior *node = new BspInterior(SelectPlane(polys)); 446 459 Debug << "new bspinterior: " << (*node) << endl; 447 460 // split polygon according to current plane 448 461 int splits = 0; … … 463 476 node->SetupChildLinks(back, front); 464 477 465 DEL_PTR(leaf); 478 DEL_PTR(leaf); // leaf not member of tree anymore 466 479 467 480 return node; … … 473 486 environment->GetIntValue("BspTree.Termination.maxPolygons", sTermMaxPolygons); 474 487 488 //-- extract strategy to choose the next split plane 475 489 char splitPlaneStrategyStr[60]; 476 490 477 491 environment->GetStringValue("BspTree.splitPlaneStrategy", splitPlaneStrategyStr); 478 // TODO: Extract nodes 492 493 sSplitPlaneStrategy = BspTree::NEXT_POLYGON; 494 495 if (strcmp(splitPlaneStrategyStr, "nextPolygon") == 0) 496 sSplitPlaneStrategy = BspTree::NEXT_POLYGON; 497 else if (strcmp(splitPlaneStrategyStr, "leastSplits") == 0) 498 sSplitPlaneStrategy = BspTree::LEAST_SPLITS; 499 else 500 { 501 cerr << "Wrong BSP split plane strategy " << splitPlaneStrategyStr << endl; 502 exit(1); 503 } 479 504 } 480 505 481 506 void BspTree::EvaluateLeafStats(const BspTraversalData &data) 482 507 { 483 484 508 // the node became a leaf -> evaluate stats for leafs 485 509 BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 486 510 487 if (data.mDepth > mTermMaxDepth) 488 ++ mStat.maxDepthNodes; 511 if (data.mDepth >= mTermMaxDepth) 512 { 513 ++ mStat.maxDepthNodes; 514 } 489 515 490 516 // record maximal depth 491 517 if (data.mDepth > mStat.maxDepth) 492 518 mStat.maxDepth = data.mDepth; 519 520 Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth<< "), #polygons: " << 521 data.mPolygons->size() << " (max: " << mTermMaxPolygons << ")" << endl; 493 522 } 494 523 //} // GtpVisibilityPreprocessor -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r236 r237 145 145 void SplitPolygons(PolygonQueue *polys, PolygonQueue *frontPolys, PolygonQueue *backPolys, int &splits); 146 146 147 friend ostream &operator<<(ostream &s, const BspInterior &A) 148 { 149 return s << A.mPlane; 150 } 151 152 147 153 protected: 148 154 … … 155 161 }; 156 162 157 158 /** BSP leaf node implementation*/163 /** BSP leaf node implementation. 164 */ 159 165 class BspLeaf : public BspNode 160 166 { … … 276 282 /// Pointer to the root of the tree 277 283 BspNode *mRoot; 284 278 285 /// Pointer to the root cell of the viewspace 279 286 // ViewCell *mRootCell; 280 281 287 282 288 BspTreeStatistics mStat; 283 289 … … 286 292 int mTermMaxDepth; 287 293 294 /// Strategies for choosing next split plane. 288 295 enum {NEXT_POLYGON, LEAST_SPLITS}; 289 296 -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r235 r237 48 48 } 49 49 50 if ( 0) {50 if (1) { 51 51 Camera camera; 52 camera.LookAtBox(p->mKdTree->GetBox()); 52 //camera.LookAtBox(p->mKdTree->GetBox()); 53 camera.LookInBox(p->mKdTree->GetBox()); 54 camera.SetPosition(camera.mPosition + Vector3(0,300,0)); 53 55 camera.SnapImage("camera.jpg", p->mKdTree); 54 56
Note: See TracChangeset
for help on using the changeset viewer.