Changeset 322 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 10/13/05 01:53:40 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r321 r322 101 101 #splitPlaneStrategy 72 102 102 103 splitPlaneStrategy 72103 splitPlaneStrategy 1 104 104 105 105 maxCandidates 50 106 106 107 107 Termination { 108 maxPolysForAxisAligned 100 109 maxPolygons 30108 maxPolysForAxisAligned 1000 109 maxPolygons 50 110 110 maxDepth 100 111 111 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r321 r322 165 165 // 3 vertices enough to decide coincident 166 166 else if (((++ count) >= 3) && !onFrontSide && !onBackSide) 167 // && (DotProd(GetSupportingPlane().mNormal, plane.mNormal) > 0))168 167 { 169 168 return COINCIDENT; … … 179 178 return FRONT_SIDE; 180 179 } 181 //if (DotProd(GetNormal(), plane.mNormal) < 0) return FRONT_SIDE; 180 182 181 return COINCIDENT; // plane and polygon are coincident 183 182 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r321 r322 254 254 int index = 0; 255 255 256 Debug << "starting new loop " << totalSamples << endl;257 258 256 // construct Bsp tree if not 259 257 if ((mViewCellsType == Preprocessor::BSP_VIEW_CELLS) && … … 262 260 BuildBspTree(); 263 261 } 264 Debug << "here" << totalSamples << endl; 262 265 263 for (i = 0; i < objects.size(); i++) { 266 264 KdNode *nodeToSample = NULL; … … 471 469 delete exporter; 472 470 } 473 474 471 if (1) { 475 476 if (mViewCellsType == BSP_VIEW_CELLS) 477 { 478 for (int j = 0; j < pvsViewCells.size(); ++ j) 479 { 480 ViewCell *vc = pvsViewCells[j]; 481 482 Intersectable::NewMail(); 483 484 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", j); 485 Exporter *exporter = Exporter::GetExporter(s); 486 exporter->SetFilled(); 487 488 ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 489 490 Material m;//= RandomMaterial(); 491 m.mDiffuseColor = RgbColor(0, 1, 0); 492 exporter->SetForcedMaterial(m); 493 494 exporter->ExportViewCell(vc); 495 496 Debug << "pvs size: " << (int)vc->GetPvs().GetSize() << " of " << (int)objects.size(); 497 Debug << " exporting rays: " << (int)vcRays[j].size() << endl; 498 499 exporter->SetWireframe(); 500 501 m.mDiffuseColor = RgbColor(1, 0, 1); 502 exporter->SetForcedMaterial(m); 503 504 if (1) 505 { 506 exporter->ExportViewCells(mViewCells); 507 } 508 509 // export rays piercing this view cell 510 exporter->ExportRays(vcRays[j], 1000, RgbColor(0, 1, 0)); 511 512 m.mDiffuseColor = RgbColor(1, 0, 0); 513 exporter->SetForcedMaterial(m); 514 515 // output pvs of view cell 516 for (; it != vc->GetPvs().mEntries.end(); ++ it) 517 { 518 Intersectable *intersect = (*it).first; 519 if (!intersect->Mailed()) 520 { 521 exporter->ExportIntersectable(intersect); 522 intersect->Mail(); 523 } 524 } 525 526 // output rest of the objects 527 if (1) 528 { 529 Material m;//= RandomMaterial(); 530 m.mDiffuseColor = RgbColor(0, 0, 1); 531 exporter->SetForcedMaterial(m); 532 533 for (int j = 0; j < objects.size(); ++ j) 534 if (!objects[j]->Mailed()) 535 { 536 exporter->ExportIntersectable(objects[j]); 537 objects[j]->Mail(); 538 } 539 } 540 DEL_PTR(exporter); 541 } 542 } 543 544 for (int k=0; k < pvsOut; k++) { 472 if (mViewCellsType == BSP_VIEW_CELLS) 473 { 474 for (int j = 0; j < pvsViewCells.size(); ++ j) 475 { 476 ViewCell *vc = pvsViewCells[j]; 477 478 Intersectable::NewMail(); 479 480 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", j); 481 Exporter *exporter = Exporter::GetExporter(s); 482 exporter->SetFilled(); 483 484 ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 485 486 Material m;//= RandomMaterial(); 487 m.mDiffuseColor = RgbColor(0, 1, 0); 488 exporter->SetForcedMaterial(m); 489 490 exporter->ExportViewCell(vc); 491 492 Debug << "pvs size: " << (int)vc->GetPvs().GetSize() << " of " << (int)objects.size(); 493 Debug << " exporting rays: " << (int)vcRays[j].size() << endl; 494 495 exporter->SetWireframe(); 496 497 // export view cells 498 m.mDiffuseColor = RgbColor(1, 0, 1); 499 exporter->SetForcedMaterial(m); 500 exporter->ExportViewCells(mViewCells); 501 502 // export rays piercing this view cell 503 exporter->ExportRays(vcRays[j], 1000, RgbColor(0, 1, 0)); 504 505 m.mDiffuseColor = RgbColor(1, 0, 0); 506 exporter->SetForcedMaterial(m); 507 508 // output pvs of view cell 509 for (; it != vc->GetPvs().mEntries.end(); ++ it) 510 { 511 Intersectable *intersect = (*it).first; 512 if (!intersect->Mailed()) 513 { 514 exporter->ExportIntersectable(intersect); 515 intersect->Mail(); 516 } 517 } 518 519 // output rest of the objects 520 if (1) 521 { 522 Material m;//= RandomMaterial(); 523 m.mDiffuseColor = RgbColor(0, 0, 1); 524 exporter->SetForcedMaterial(m); 525 526 for (int j = 0; j < objects.size(); ++ j) 527 if (!objects[j]->Mailed()) 528 { 529 exporter->ExportIntersectable(objects[j]); 530 objects[j]->Mail(); 531 } 532 } 533 DEL_PTR(exporter); 534 } 535 } 536 537 for (int k=0; k < pvsOut; k++) { 545 538 Intersectable *object = objects[k]; 546 539 char s[64]; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r319 r322 25 25 26 26 //-- factors for bsp tree split plane heuristics 27 27 28 float BspTree::sLeastSplitsFactor = 1.0f; 28 float BspTree::sBalancedPolysFactor = 2.0f; 29 float BspTree::sBalancedViewCellsFactor = 2.0f; 30 float BspTree::sVerticalSplitsFactor = 1.0f; // very important criterium for 2.5d scenes 29 float BspTree::sBalancedPolysFactor = 1.0f; 30 float BspTree::sBalancedViewCellsFactor = 1.0f; 31 // NOTE: very important criterium for 2.5d scenes 32 float BspTree::sVerticalSplitsFactor = 1.0f; 31 33 float BspTree::sLargestPolyAreaFactor = 1.0f; 32 34 float BspTree::sBlockedRaysFactor = 1.0f; 35 36 bool BspTree::sStoreSplitPolys = false; 33 37 34 38 /** Evaluates split plane classification with respect to the plane's … … 41 45 float BspTree::sBalancedPolysTable[] = {-1, 1, 0, 0}; 42 46 43 //int counter = 0;44 45 47 /****************************************************************/ 46 48 /* class BspNode implementation */ … … 179 181 { 180 182 case Polygon3::COINCIDENT: 181 //Debug << "coincident" << endl;182 183 coincident.push_back(poly); 183 184 break; 184 185 case Polygon3::FRONT_SIDE: 185 //Debug << "front" << endl;186 186 frontPolys.push_back(poly); 187 187 break; 188 188 case Polygon3::BACK_SIDE: 189 //Debug << "back" << endl;190 189 backPolys.push_back(poly); 191 190 break; … … 262 261 BspTree::BspTree(ViewCell *viewCell): 263 262 mRoot(NULL), 264 mRootCell(viewCell), 265 //mStoreSplitPolys(true) 266 mStoreSplitPolys(false) 263 mRootCell(viewCell) 267 264 { 268 265 Randomize(); // initialise random generator for heuristics … … 280 277 app << setprecision(4); 281 278 282 app << "#N_RAYS Number of rays )\n"283 << rays << endl;284 app << "#N_DOMAINS ( Number of query domains )\n"285 << queryDomains <<endl;286 287 279 app << "#N_NODES ( Number of nodes )\n" << nodes << "\n"; 288 280 … … 292 284 293 285 app << "#N_SPLITS ( Number of splits )\n" << splits << "\n"; 294 295 app << "#N_RAYREFS ( Number of rayRefs )\n" <<296 rayRefs << "\n";297 298 app << "#N_RAYRAYREFS ( Number of rayRefs / ray )\n" <<299 rayRefs/(double)rays << "\n";300 301 app << "#N_LEAFRAYREFS ( Number of rayRefs / leaf )\n" <<302 rayRefs/(double)Leaves() << "\n";303 304 app << "#N_MAXOBJECTREFS ( Max number of rayRefs / leaf )\n" <<305 maxObjectRefs << "\n";306 307 app << "#N_NONEMPTYRAYREFS ( Number of rayRefs in nonEmpty leaves / non empty leaf )\n" <<308 rayRefsNonZeroQuery/(double)(Leaves() - zeroQueryNodes) << "\n";309 310 app << "#N_LEAFDOMAINREFS ( Number of query domain Refs / leaf )\n" <<311 objectRefs/(double)Leaves() << "\n";312 313 app << "#N_PEMPTYLEAVES ( Percentage of leaves with zero query domains )\n"<<314 zeroQueryNodes*100/(double)Leaves() << endl;315 286 316 287 app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< … … 323 294 app << "#AVGDEPTH ( average depth )\n" << AvgDepth() << endl; 324 295 325 app << "#N_ADDED_RAYREFS ( Number of dynamically added ray references )\n"<< 326 addedRayRefs << endl; 327 328 app << "#N_REMOVED_RAYREFS ( Number of dynamically removed ray references )\n" << 329 removedRayRefs << endl; 330 331 app << "#N_INPUT_POLYGONS (number of input polygons )\n" << 332 polys << endl; 296 app << "#N_INPUT_POLYGONS (number of input polygons )\n" << polys << endl; 333 297 334 298 app << "#N_ROUTPUT_INPUT_POLYGONS ( ratio polygons after subdivision / input polygons )\n" << … … 394 358 395 359 //-- filter view cell polygons down the tree until a leaf is reached 396 if ( (int)tData.mPolygons->size() > 0)360 if (!tData.mPolygons->empty()) 397 361 { 398 362 PolygonContainer *frontPolys = new PolygonContainer(); … … 408 372 coincident, 409 373 splits, 410 mStoreSplitPolys);374 sStoreSplitPolys); 411 375 412 376 // extract view cells associated with the split polygons … … 425 389 426 390 // don't need coincident polygons anymore 427 interior->ProcessPolygons(&coincident, mStoreSplitPolys);391 interior->ProcessPolygons(&coincident, sStoreSplitPolys); 428 392 429 393 mStat.splits += splits; 430 394 431 395 // push the children on the stack 432 tStack.push(BspTraversalData(interior->GetFront(), frontPolys, tData.mDepth + 1, frontViewCell)); 433 tStack.push(BspTraversalData(interior->GetBack(), backPolys, tData.mDepth + 1, backViewCell)); 396 tStack.push(BspTraversalData(interior->GetFront(), 397 frontPolys, 398 tData.mDepth + 1, 399 frontViewCell)); 400 401 tStack.push(BspTraversalData(interior->GetBack(), 402 backPolys, 403 tData.mDepth + 1, 404 backViewCell)); 434 405 } 435 406 … … 439 410 else // reached leaf => subdivide current viewcell 440 411 { 441 //if (tData.mPolygons->size() > 0) Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl;442 412 BspNode *root = Subdivide(tStack, tData); 443 413 444 414 if (viewCells && root->IsLeaf()) 445 { // generate new view cell for each leaf 415 { 416 // generate new view cell for each leaf 446 417 ViewCell *viewCell = new ViewCell(); 447 418 viewCells->push_back(viewCell); … … 459 430 { 460 431 FaceContainer::const_iterator fi; 461 int polysNum = 0; 462 432 463 433 // copy the face data to polygons 464 434 for (fi = mesh->mFaces.begin(); fi != mesh->mFaces.end(); ++ fi) … … 467 437 poly->mParent = parent; // set parent intersectable 468 438 polys.push_back(poly); 469 470 //if (!poly->Valid()) 471 // Debug << "Input polygon not valid: " << *poly << endl << "Area: " << poly->GetArea() << endl; 472 473 ++ polysNum; 474 } 475 return polysNum; 476 } 477 478 int BspTree::AddToPolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects) 479 { 480 int limit = (maxObjects > 0) ? Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 439 } 440 return (int)mesh->mFaces.size(); 441 } 442 443 int BspTree::AddToPolygonSoup(const ViewCellContainer &viewCells, 444 PolygonContainer &polys, 445 int maxObjects) 446 { 447 int limit = (maxObjects > 0) ? 448 Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 481 449 482 for (int i = 0; i < limit; ++i) 483 {//if ((i == 12) ||(i==14)) 450 int polysSize = 0; 451 452 for (int i = 0; i < limit; ++ i) 453 { 484 454 if (viewCells[i]->GetMesh()) // copy the mesh data to polygons 485 455 { 486 456 mBox.Include(viewCells[i]->GetBox()); // add to BSP tree aabb 487 AddMeshToPolygons(viewCells[i]->GetMesh(), polys, viewCells[i]); 488 } 489 } 490 491 return (int)polys.size(); 457 polysSize += AddMeshToPolygons(viewCells[i]->GetMesh(), 458 polys, viewCells[i]); 459 } 460 } 461 462 return polysSize; 492 463 } 493 464 … … 644 615 // clean up 645 616 // remaining polygons are discarded or added to node 646 leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys);617 leaf->ProcessPolygons(tData.mPolygons, sStoreSplitPolys); 647 618 DEL_PTR(tData.mPolygons); 648 619 … … 682 653 683 654 // don't need coincident polygons anymore 684 interior->ProcessPolygons(&coincident, mStoreSplitPolys);655 interior->ProcessPolygons(&coincident, sStoreSplitPolys); 685 656 686 657 // push the children on the stack … … 753 724 coincident, 754 725 splits, 755 mStoreSplitPolys);726 sStoreSplitPolys); 756 727 757 728 mStat.splits += splits; … … 916 887 return Plane3(norm, position); 917 888 } 918 /*int axis = box.Size().DrivingAxis();919 Vector3 norm(0,0,0); norm[axis] = 1;920 Vector3 position = (box.Min()[axis] + box.Max()[axis]) * 0.5f;921 return Plane3(norm, position);*/922 889 } 923 890 924 891 // simplest strategy: just take next polygon 925 if (sSplitPlaneStrategy & NEXT_POLYGON)926 { 927 return polys .front()->GetSupportingPlane();892 if (sSplitPlaneStrategy & RANDOM_POLYGON) 893 { 894 return polys[Random((int)polys.size())]->GetSupportingPlane(); 928 895 } 929 896 … … 949 916 950 917 // evaluate current candidate 951 float candidateCost = EvalSplitPlane(polys, candidatePlane);918 float candidateCost = SplitPlaneCost(polys, candidatePlane); 952 919 953 920 if (candidateCost < lowestCost) … … 964 931 int BspTree::GetNextCandidateIdx(int currentIdx, PolygonContainer &polys) 965 932 { 966 int candidateIdx = Random(currentIdx--); 967 933 int candidateIdx = Random(currentIdx --); 968 934 //Debug << "new candidate " << candidateIdx << endl; 969 935 … … 976 942 } 977 943 978 float BspTree:: EvalSplitPlane(PolygonContainer &polys,944 float BspTree::SplitPlaneCost(PolygonContainer &polys, 979 945 const Plane3 &candidatePlane) 980 946 { … … 1029 995 { 1030 996 if (classification == Polygon3::COINCIDENT) 1031 { 1032 float area = (*it)->GetArea(); 1033 //Debug << "polygon area: " << area << " "; 1034 sumPolyArea += area; 1035 } 997 sumPolyArea += (*it)->GetArea(); 1036 998 //totalArea += area; 1037 999 } … … 1150 1112 environment->GetFloatValue("MeshKdTree.splitBorder", sSplitBorder); 1151 1113 environment->GetFloatValue("MeshKdTree.Termination.maxCostRatio", sMaxCostRatio); 1114 environment->GetBoolValue("BspTree.storeSplitPolys", sStoreSplitPolys); 1152 1115 1153 1116 Debug << "BSP max depth: " << sTermMaxDepth << endl; … … 1156 1119 1157 1120 Debug << "Split plane strategy: "; 1158 if (sSplitPlaneStrategy & NEXT_POLYGON)1159 Debug << " nextpolygon ";1121 if (sSplitPlaneStrategy & RANDOM_POLYGON) 1122 Debug << "random polygon "; 1160 1123 if (sSplitPlaneStrategy & AXIS_ALIGNED) 1161 1124 Debug << "axis aligned "; … … 1211 1174 } 1212 1175 1213 bool BspTree::StorePolys() const1214 {1215 return mStoreSplitPolys;1216 }1217 1218 1176 void BspTree::EvaluateLeafStats(const BspTraversalData &data) 1219 1177 { … … 1222 1180 1223 1181 if (data.mDepth >= sTermMaxDepth) 1224 {1225 1182 ++ mStat.maxDepthNodes; 1226 }1227 1228 1183 // store maximal and minimal depth 1229 1184 if (data.mDepth > mStat.maxDepth) … … 1235 1190 mStat.accumDepth += data.mDepth; 1236 1191 1237 if (leaf->mViewCell )1238 ++ mStat.viewCell Leaves;1192 if (leaf->mViewCell != mRootCell) 1193 ++ mStat.viewCells; 1239 1194 1240 1195 #ifdef _DEBUG 1241 Debug << "BSP Traversal data. Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), #polygons: " << 1242 data.mPolygons->size() << " (max: " << sTermMaxPolygons << ")" << endl; 1196 Debug << "BSP Traversal data. Depth: " << data.mDepth 1197 << " (max: " << mTermMaxDepth << "), #polygons: " 1198 << data.mPolygons->size() << " (max: " 1199 << sTermMaxPolygons << ")" << endl; 1243 1200 #endif 1244 1201 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r321 r322 27 27 }; 28 28 29 class BspTreeStatistics // TODO: should have common superclass with KdTreeStatistics29 class BspTreeStatistics 30 30 { 31 31 public: … … 40 40 // minimal depth 41 41 int minDepth; 42 // total number of query domains43 int queryDomains;44 // total number of ray references45 int rayRefs;46 // refs in non empty leafs47 int rayRefsNonZeroQuery;48 // total number of query references49 int objectRefs;50 // nodes with zero queries51 int zeroQueryNodes;52 42 // max depth nodes 53 43 int maxDepthNodes; 54 44 // max number of rays per node 55 45 int maxObjectRefs; 56 // number of dynamically added ray refs 57 int addedRayRefs; 58 // number of dynamically removed ray refs 59 int removedRayRefs; 60 // accumulated depth (used to compute average) 46 // accumulated depth (used to compute average) 61 47 int accumDepth; 62 48 // number of initial polygons 63 49 int polys; 64 /// number of view cells in leaf65 int viewCell Leaves;50 /// number of view cells different to the view cell representing unbounded space. 51 int viewCells; 66 52 67 53 // Constructor … … 80 66 nodes = 0; 81 67 splits = 0; 82 rays = queryDomains = 0;83 rayRefs = rayRefsNonZeroQuery = objectRefs = 0;84 zeroQueryNodes = 0;85 68 maxDepthNodes = 0; 86 87 maxObjectRefs = 0;88 addedRayRefs = removedRayRefs = 0;89 69 maxDepth = 0; 90 70 minDepth = 99999; 91 71 polys = 0; 92 72 accumDepth = 0; 93 viewCell Leaves = 0;73 viewCells = 0; 94 74 } 95 75 … … 331 311 BspNode *GetRoot() const; 332 312 333 /** If the view cell polygons are stored in the nodes.334 */335 bool StorePolys() const;336 337 313 /** Exports Bsp tree to file. 338 314 */ … … 376 352 @returns the cost of the candidate split plane 377 353 */ 378 float EvalSplitPlane(PolygonContainer &polys,354 float SplitPlaneCost(PolygonContainer &polys, 379 355 const Plane3 &candidatePlane); 380 356 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r318 r322 403 403 //ViewCellContainer foundViewCells; 404 404 405 if ( tree.StorePolys())405 if (BspTree::sStoreSplitPolys) 406 406 { 407 407 while (!tStack.empty()) … … 411 411 tStack.pop(); 412 412 413 if (tree.StorePolys()) // extract the polygons 414 { 415 PolygonContainer::const_iterator it; 416 PolygonContainer::const_iterator it_end = node->GetPolygons()->end(); 417 418 for (it = node->GetPolygons()->begin(); it != it_end; ++ it) 419 ExportPolygon(*it); 420 } 421 413 PolygonContainer::const_iterator it; 414 PolygonContainer::const_iterator it_end = node->GetPolygons()->end(); 415 416 for (it = node->GetPolygons()->begin(); it != it_end; ++ it) 417 ExportPolygon(*it); 418 422 419 if (!node->IsLeaf()) 423 420 { -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r321 r322 57 57 58 58 p->BuildBspTree(); 59 59 p->Export("vc_bsptree.x3d", false, false, true); 60 60 p->BspTreeStatistics(Debug); 61 p->Export("vc_bsptree2.x3d", false, false, true); 62 61 63 62 bool exportSplits = false; 64 63 environment->GetBoolValue("BspTree.exportSplits", exportSplits);
Note: See TracChangeset
for help on using the changeset viewer.