Changeset 1278
- Timestamp:
- 08/24/06 18:05:30 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1264 r1278 48 48 49 49 bool ObjectDirectionBasedDistribution::GenerateSample(SimpleRay &ray) const 50 { 50 { 51 51 Vector3 origin, direction; 52 52 … … 66 66 if (c <= Limits::Small) 67 67 return false; 68 68 69 69 // $$ jb the pdf is yet not correct for all sampling methods! 70 70 const float pdf = 1.0f; … … 78 78 79 79 bool DirectionBasedDistribution::GenerateSample(SimpleRay &ray) const 80 { 80 { 81 81 Vector3 origin, direction; 82 82 mPreprocessor.mViewCellsManager->GetViewPoint(origin); … … 125 125 { 126 126 Vector3 origin, direction; 127 127 128 mPreprocessor.mViewCellsManager->GetViewPoint(origin); 128 129 129 direction = mPreprocessor.mKdTree->GetBox().GetRandomPoint() - origin; 130 130 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
r1233 r1278 13 13 14 14 class ViewCellLeaf; 15 //class BspViewCell;16 15 class Plane3; 17 16 class BspTree; 18 17 class BspInterior; 19 //class Polygon3;20 18 class AxisAlignedBox3; 21 19 class Ray; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1264 r1278 23 23 #include "BvHierarchy.h" 24 24 25 25 26 // should not count origin object for sampling because it disturbs heuristics 26 27 #define SAMPLE_ORIGIN_OBJECTS 0 … … 355 356 // shoot simple ray and add it to importance samples 356 357 mPreprocessor->CastRays(simpleRays, passSamples); 357 358 358 359 Debug << "cast " << mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 359 360 … … 409 410 410 411 //-- construction rays => we use uniform samples for this 412 411 413 CastPassSamples(mInitialSamples, mSamplingType, initialSamples); 412 414 413 415 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 414 415 416 416 417 // construct view cells … … 428 429 Debug << "time needed for initial construction: " 429 430 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 430 431 431 432 432 // take post processing time … … 436 436 ResetViewCells(); 437 437 Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 438 439 438 440 439 if (0) // export initial view cells … … 940 939 941 940 //-- construction rays => we use uniform samples for this 941 942 942 cout << "casting " << samplesPerPass << " samples ... "; 943 943 Debug << "casting " << samplesPerPass << " samples ... "; … … 4803 4803 4804 4804 4805 VspOspViewCellsManager::VspOspViewCellsManager(ViewCellsTree *vcTree, VspTree *vspTree, OspTree *ospTree): 4806 ViewCellsManager(vcTree), mVspTree(vspTree), mOspTree(ospTree) 4807 { 4808 mHierarchyManager = new HierarchyManager(*vspTree, *ospTree); 4805 VspOspViewCellsManager::VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm) 4806 : ViewCellsManager(vcTree), mHierarchyManager(hm) 4807 { 4809 4808 Environment::GetSingleton()->GetIntValue("VspTree.Construction.samples", mInitialSamples); 4810 4809 4811 mVspTree->SetViewCellsManager(this); 4812 mOspTree->SetViewCellsManager(this); 4813 4814 mVspTree->SetViewCellsTree(mViewCellsTree); 4810 mHierarchyManager->SetViewCellsManager(this); 4811 mHierarchyManager->SetViewCellsTree(mViewCellsTree); 4815 4812 } 4816 4813 … … 4818 4815 VspOspViewCellsManager::~VspOspViewCellsManager() 4819 4816 { 4820 DEL_PTR(mHierarchyManager);4821 4817 } 4822 4818 … … 4833 4829 if (!ViewCellsTreeConstructed()) 4834 4830 { 4835 m VspTree->CollectViewCells(mViewCells, false);4831 mHierarchyManager->GetVspTree()->CollectViewCells(mViewCells, false); 4836 4832 } 4837 4833 else … … 4844 4840 bool VspOspViewCellsManager::ViewCellsConstructed() const 4845 4841 { 4846 return m VspTree->GetRoot() != NULL;4842 return mHierarchyManager->GetVspTree()->GetRoot() != NULL; 4847 4843 } 4848 4844 … … 4893 4889 4894 4890 // print subdivision statistics 4895 Debug << mVspTree->GetStatistics() << endl; 4896 Debug << mOspTree->GetStatistics() << endl; 4897 4898 OUT_STREAM stream("osptree.xml.zip"); 4899 mOspTree->Export(stream); 4891 Debug << mHierarchyManager->GetVspTree()->GetStatistics() << endl; 4892 mHierarchyManager->PrintObjectSpaceHierarchyStatistics(Debug); 4893 4894 if (0) 4895 { 4896 OUT_STREAM stream("osptree.xml.zip"); 4897 mHierarchyManager->ExportObjectSpaceHierarchy(stream); 4898 } 4900 4899 4901 4900 // print view cell statistics … … 4985 4984 4986 4985 // compute tree by merging the nodes of the spatial hierarchy 4987 ViewCell *root = ConstructSpatialMergeTree(m VspTree->GetRoot());4986 ViewCell *root = ConstructSpatialMergeTree(mHierarchyManager->GetVspTree()->GetRoot()); 4988 4987 mViewCellsTree->SetRoot(root); 4989 4988 … … 5094 5093 viewPoint = mViewSpaceBox.GetRandomPoint(); 5095 5094 5096 if (m VspTree->ViewPointValid(viewPoint))5095 if (mHierarchyManager->GetVspTree()->ViewPointValid(viewPoint)) 5097 5096 { 5098 5097 return true; … … 5124 5123 VspLeaf *l = vspVc->mLeaf; 5125 5124 5126 const AxisAlignedBox3 box = m VspTree->GetBoundingBox(vspVc->mLeaf);5125 const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaf); 5127 5126 5128 5127 if (clipPlane) … … 5218 5217 } 5219 5218 5220 if (1 && mOspTree->GetRoot()) 5221 { 5222 //-- export final object partition 5223 Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 5224 5225 if (exporter) 5226 { 5227 cout << "exporting object space partition ... "; 5228 5229 if (0 && mExportGeometry) 5230 { 5231 exporter->ExportGeometry(objects); 5232 } 5233 5234 // export rays 5235 if (0 && mExportRays) 5236 { 5237 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 5238 } 5239 5240 exporter->SetWireframe(); 5241 5242 const int savedColorCode = mColorCode; 5243 mColorCode = 0; 5244 const int maxPvs = 200;//mOspTree.GetStatistics().maxPvs; 5245 5246 exporter->ExportOspTree(*mOspTree, mColorCode == 0 ? 0 : maxPvs); 5247 5248 mColorCode = savedColorCode; 5249 5250 delete exporter; 5251 5252 cout << "finished" << endl; 5253 } 5254 } 5255 5219 mHierarchyManager->ExportObjectSpaceHierarchyForViz(objects); 5220 5256 5221 //-- export single view cells 5257 5222 ExportPvs(objects, visRays); … … 5386 5351 exporter->SetFilled(); 5387 5352 5388 if (1) 5353 #if 0 5354 //-- export pvs 5355 5356 Intersectable::NewMail(); 5357 KdLeaf::NewMail(); 5358 5359 vector<KdLeaf *> kdLeaves; 5360 5361 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 5362 5363 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 5389 5364 { 5390 //-- export pvs 5391 5392 Intersectable::NewMail(); 5393 KdLeaf::NewMail(); 5394 5395 vector<KdLeaf *> kdLeaves; 5396 5397 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 5398 5399 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 5400 { 5401 Intersectable *obj = (*oit).first; 5402 5403 if (obj->Type() == Intersectable::KD_INTERSECTABLE) 5404 { 5405 m.mDiffuseColor = RgbColor(1, 1, 1); 5406 exporter->SetForcedMaterial(m); 5407 5408 // export bounding box of node 5409 KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj); 5410 AxisAlignedBox3 box = mOspTree->GetBoundingBox(kdObj->GetItem()); 5411 5412 exporter->SetWireframe(); 5413 exporter->ExportBox(box); 5414 exporter->SetFilled(); 5415 } 5416 5417 m.mDiffuseColor = RgbColor(1, 0, 0); 5365 Intersectable *obj = (*oit).first; 5366 5367 if (obj->Type() == Intersectable::KD_INTERSECTABLE) 5368 { 5369 m.mDiffuseColor = RgbColor(1, 1, 1); 5418 5370 exporter->SetForcedMaterial(m); 5419 5371 5420 // export pvs entry 5421 if (!obj->Mailed()) 5422 { 5423 exporter->ExportIntersectable(obj); 5424 obj->Mail(); 5425 } 5426 } 5427 } 5372 // export bounding box of node 5373 KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj); 5374 AxisAlignedBox3 box = mOspTree->GetBoundingBox(kdObj->GetItem()); 5375 5376 exporter->SetWireframe(); 5377 exporter->ExportBox(box); 5378 exporter->SetFilled(); 5379 } 5380 5381 m.mDiffuseColor = RgbColor(1, 0, 0); 5382 exporter->SetForcedMaterial(m); 5383 5384 // export pvs entry 5385 if (!obj->Mailed()) 5386 { 5387 exporter->ExportIntersectable(obj); 5388 obj->Mail(); 5389 } 5390 } 5391 #endif 5428 5392 5429 5393 DEL_PTR(exporter); … … 5438 5402 ViewCellContainer &viewCells) const 5439 5403 { 5440 return m VspTree->ComputeBoxIntersections(box, viewCells);5404 return mHierarchyManager->GetVspTree()->ComputeBoxIntersections(box, viewCells); 5441 5405 } 5442 5406 … … 5446 5410 ViewCellContainer &viewcells) 5447 5411 { 5448 return m VspTree->CastLineSegment(origin, termination, viewcells);5412 return mHierarchyManager->GetVspTree()->CastLineSegment(origin, termination, viewcells); 5449 5413 } 5450 5414 … … 5503 5467 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl; 5504 5468 5505 m VspTree->Export(stream);5469 mHierarchyManager->GetVspTree()->Export(stream); 5506 5470 stream << endl << "</ViewSpaceHierarchy>" << endl; 5507 5471 … … 5509 5473 //-- export the object space partition 5510 5474 5511 // the type of the view cells hierarchy 5512 if (mHierarchyManager->GetObjectSpaceSubdivisonType() == 5513 HierarchyManager::KD_BASED_OBJ_SUBDIV) 5514 { 5515 stream << "<ObjectSpaceHierarchy type=\"osp\">" << endl; 5516 mOspTree->Export(stream); 5517 stream << endl << "</ObjectSpaceHierarchy>" << endl; 5518 } 5519 else if (mHierarchyManager->GetObjectSpaceSubdivisonType() == 5520 HierarchyManager::BV_BASED_OBJ_SUBDIV) 5521 { 5522 stream << "<ObjectSpaceHierarchy type=\"bvh\">" << endl; 5523 mBvHierarchy->Export(stream); 5524 stream << endl << "</ObjectSpaceHierarchy>" << endl; 5525 } 5526 5475 mHierarchyManager->ExportObjectSpaceHierarchy(stream); 5476 5527 5477 stream << "</VisibilitySolution>" << endl; 5528 5478 stream.close(); … … 5544 5494 return NULL; 5545 5495 5546 return m VspTree->GetViewCell(point, active);5496 return mHierarchyManager->GetVspTree()->GetViewCell(point, active); 5547 5497 } 5548 5498 … … 5561 5511 { 5562 5512 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf; 5563 const AxisAlignedBox3 box = m VspTree->GetBoundingBox(leaf);5513 const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); 5564 5514 5565 5515 IncludeBoxInMesh(box, *mesh); … … 5592 5542 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf; 5593 5543 5594 const AxisAlignedBox3 box = m VspTree->GetBoundingBox(leaf);5544 const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); 5595 5545 5596 5546 const float lVol = box.GetVolume(); … … 5720 5670 float &contribution) const 5721 5671 { 5722 if (!obj) return false; 5723 5724 switch (mHierarchyManager->GetObjectSpaceSubdivisonType()) 5725 { 5726 case HierarchyManager::NO_OBJ_SUBDIV: 5727 // potentially visible objects 5728 return vc->AddPvsSample(obj, pdf, contribution); 5729 5730 case HierarchyManager::KD_BASED_OBJ_SUBDIV: 5731 { 5732 // potentially visible kd cells 5733 KdLeaf *leaf = mOspTree->GetLeaf(hitPoint/*ray->mOriginNode*/); 5734 return mOspTree->AddLeafToPvs(leaf, vc, pdf, contribution); 5735 } 5736 case HierarchyManager::BV_BASED_OBJ_SUBDIV: 5737 { 5738 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 5739 return mBvHierarchy->AddLeafToPvs(leaf, vc, pdf, contribution); 5740 } 5741 default: 5742 return false; 5743 } 5672 return mHierarchyManager->AddSampleToPvs(obj, hitPoint, vc, pdf, contribution); 5744 5673 } 5745 5674 … … 5759 5688 ViewCellsManager *vm = 5760 5689 ViewCellsManager::LoadViewCells(filename, objects, finalizeViewCells, bconverter); 5761 5690 #if 0 5691 // insert scene objects in tree 5762 5692 mOspTree->InsertObjects(mOspTree->GetRoot(), *objects); 5763 5693 #endif 5764 5694 return vm; 5765 5695 } … … 5841 5771 } 5842 5772 5843 Debug << "\nhere295 " << rc / m VspTree->GetBoundingBox().GetVolume() << endl;5773 Debug << "\nhere295 " << rc / mHierarchyManager->GetVspTree()->GetBoundingBox().GetVolume() << endl; 5844 5774 mViewCellsTree->ExportStats(fileName); 5845 5775 cout << "finished" << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1264 r1278 974 974 public: 975 975 976 VspOspViewCellsManager(ViewCellsTree *viewCellsTree, VspTree *tree, OspTree *ospTree); 976 VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm); 977 977 978 ~VspOspViewCellsManager(); 978 979 … … 1068 1069 1069 1070 /// the view space / object partition hierarchies 1070 VspTree *mVspTree;1071 OspTree *mOspTree;1072 BvHierarchy *mBvHierarchy;1071 //VspTree *mVspTree; 1072 //OspTree *mOspTree; 1073 //BvHierarchy *mBvHierarchy; 1073 1074 1074 1075 HierarchyManager *mHierarchyManager; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1264 r1278 34 34 #include "KdTree.h" 35 35 #include "BvHierarchy.h" 36 #include "HierarchyManager.h" 36 37 37 38 … … 91 92 , mObjects(objects) 92 93 , mBoundingBoxConverter(bconverter) 94 , mHierarchyManager(NULL) 93 95 { 94 96 std::stable_sort(mObjects->begin(), mObjects->end(), ilt); … … 354 356 if (element == "ViewCells") 355 357 { 356 cout << " parsing view cells" << endl;358 cout << "\nparsing view cells" << endl; 357 359 358 360 mCurrentState = PARSE_VIEWCELLS; … … 372 374 if (element == "ViewSpaceHierarchy") 373 375 { 374 cout << " parsing view space hierarchy" << endl;376 cout << "\nparsing view space hierarchy" << endl; 375 377 mCurrentState = PARSE_VIEWSPACE_HIERARCHY; 376 378 StartViewSpaceHierarchy(attributes); … … 380 382 if (element == "ObjectSpaceHierarchy") 381 383 { 382 cout << " parsing object space hierarchy" << endl;384 cout << "\nparsing object space hierarchy" << endl; 383 385 mCurrentState = PARSE_OBJECTSPACE_HIERARCHY; 384 386 StartObjectSpaceHierarchy(attributes); … … 565 567 if (attrName == "type") 566 568 { 567 if (strcmp(ptr, " bsp") == 0)569 if (strcmp(ptr, "osp") == 0) 568 570 { 569 Debug << " view space hierarchy: Bsp" << endl;570 m ViewSpaceHierarchyType = BSP;571 Debug << "object space hierarchy: Osp" << endl; 572 mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV); 571 573 } 572 else if (strcmp(ptr, " vsp") == 0)574 else if (strcmp(ptr, "bvh") == 0) 573 575 { 574 Debug << " view space hierarchy: Vsp" << endl;575 m ViewSpaceHierarchyType = VSP;576 Debug << "object space hierarchy: Bvh" << endl; 577 mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::BV_BASED_OBJ_SUBDIV); 576 578 } 577 579 } … … 778 780 779 781 mVspTree = new VspTree(); 782 780 783 // set view space box 781 784 mVspTree->mBoundingBox = mViewSpaceBox; 785 786 // object space hierarchy already constructed 787 if (mHierarchyManager) 788 { 789 mHierarchyManager->mVspTree = mVspTree; 790 mVspTree->mHierarchyManager = mHierarchyManager; 791 } 782 792 } 783 793 784 794 cout << "\nview space box: " << mViewSpaceBox << endl; 785 }786 787 788 void ViewCellsParseHandlers::CreateObjectSpaceHierarchy()789 {790 if (mViewSpaceHierarchyType == OSP)791 {792 Debug << "object hierarchy type: Osp" << endl;793 794 mOspTree = new OspTree();795 }796 else if (mViewSpaceHierarchyType == VSP)797 {798 Debug << "object hierarchy type: Vsp" << endl;799 800 mVspTree = new VspTree();801 }802 795 } 803 796 … … 814 807 else if (mViewSpaceHierarchyType == VSP) 815 808 { 816 Debug << " vcreating view cells manager: VsOspp" << endl;809 Debug << "creating view cells manager: VspOsp" << endl; 817 810 818 811 // hack 819 mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, m VspTree, mOspTree);812 mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mHierarchyManager); 820 813 } 821 814 … … 978 971 else 979 972 { 980 m OspTree->mRoot = interior;973 mHierarchyManager->mOspTree->mRoot = interior; 981 974 } 982 975 … … 996 989 else 997 990 { 998 m OspTree->mRoot = leaf;991 mHierarchyManager->mOspTree->mRoot = leaf; 999 992 } 1000 993 } … … 1002 995 1003 996 void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes) 1004 { 997 {/* 1005 998 KdLeaf * leaf = 1006 999 new KdLeaf(dynamic_cast<KdInterior *>(mCurrentKdNode), NULL); … … 1012 1005 else 1013 1006 { 1014 m OspTree->mRoot = leaf;1015 } 1007 mHierarchyManager->mBvHierarchy->mRoot = leaf; 1008 }*/ 1016 1009 } 1017 1010 1018 1011 1019 1012 void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes) 1020 { 1013 {/* 1021 1014 AxisAlignedPlane plane; 1022 1015 int len = attributes.getLength(); … … 1051 1044 } 1052 1045 1053 mCurrentKdNode = interior; 1046 mCurrentKdNode = interior;*/ 1054 1047 } 1055 1048 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
r1264 r1278 25 25 class VspNode; 26 26 class BvHierarchy; 27 class HierarchyManager; 28 27 29 28 30 class ViewCellsParseHandlers: public HandlerBase … … 73 75 74 76 VspBspTree *mVspBspTree; 75 VspTree *mVspTree; 76 OspTree *mOspTree; 77 HierarchyManager *mHierarchyManager; 77 78 BvHierarchy *mBvHierarchy; 78 79 79 80 BspTree *mBspTree; 80 81 ViewCellsTree *mViewCellsTree; 82 VspTree *mVspTree; 81 83 82 84 BspNode *mCurrentBspNode; … … 142 144 void StartOspInterior(AttributeList& attributes); 143 145 144 void CreateObjectSpaceHierarchy();145 146 void CreateViewSpaceHierarchy(); 146 147 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1262 r1278 2879 2879 2880 2880 SubdivisionCandidate *VspTree::PrepareConstruction(const VssRayContainer &sampleRays, 2881 AxisAlignedBox3 *forcedViewSpace,2882 RayInfoContainer &rays)2883 { 2881 AxisAlignedBox3 *forcedViewSpace, 2882 RayInfoContainer &rays) 2883 { 2884 2884 // store pointer to this tree 2885 2885 VspSubdivisionCandidate::sVspTree = this;
Note: See TracChangeset
for help on using the changeset viewer.