Changeset 1764 for GTP/trunk/Lib/Vis
- Timestamp:
- 11/17/06 10:10:41 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
r1758 r1764 106 106 bool Exporter::ExportBvHierarchy(const BvHierarchy &bvHierarchy, 107 107 const int maxPvs, 108 constAxisAlignedBox3 *box,108 AxisAlignedBox3 *box, 109 109 const bool exportBoundingBoxes) 110 110 { … … 149 149 150 150 SetFilled(); 151 ExportGeometry(leaf->mObjects, true );151 ExportGeometry(leaf->mObjects, true, box); 152 152 } 153 153 … … 177 177 case Intersectable::TRIANGLE_INTERSECTABLE: 178 178 { 179 const Triangle3 triangle = dynamic_cast<TriangleIntersectable *>(object)->GetItem(); 180 Polygon3 poly(triangle); 181 ExportPolygon(&poly); 182 break; 179 // if (mClampToBox && !Overlap(mBoundingBox, object->GetBox())) return; 180 const Triangle3 triangle = dynamic_cast<TriangleIntersectable *>(object)->GetItem(); 181 182 Polygon3 poly(triangle); 183 ExportPolygon(&poly); 184 break; 183 185 } 184 186 case Intersectable::BVH_INTERSECTABLE: 185 187 { 186 188 BvhNode *node = dynamic_cast<BvhNode *>(object); 189 187 190 if (node->IsLeaf()) 191 { 188 192 ExportGeometry(dynamic_cast<BvhLeaf *>(node)->mObjects, true); 193 } 194 189 195 break; 190 196 } … … 247 253 } 248 254 249 250 255 /////////////////////// 251 256 //-- all objects exported as one mesh … … 260 265 if (bbox && !Overlap(*bbox, obj->GetBox())) 261 266 { 262 //cout << *bbox << " " << obj->GetBox() << endl;263 267 continue; 264 268 } 265 266 269 switch (obj->Type()) 267 270 { … … 293 296 } 294 297 295 //cout << "describe:\n" << dummyMesh << endl;296 //dummyMesh.CheckMesh();297 298 298 ExportMesh(&dummyMesh); 299 299 CLEAR_CONTAINER(polys); -
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h
r1418 r1764 11 11 #include "Containers.h" 12 12 #include "VssRay.h" 13 #include "AxisAlignedBox3.h" 13 14 14 15 namespace GtpVisibilityPreprocessor { … … 18 19 class SceneGraphNode; 19 20 class Ray; 20 class AxisAlignedBox3;21 21 class Intersectable; 22 22 class BspLeaf; … … 48 48 mWireframe(false), 49 49 mUseForcedMaterial(false), 50 mExportRayDensity(false) 50 mExportRayDensity(false), 51 mClampToBox(false) 51 52 {} 52 53 … … 154 155 const BvHierarchy &bvHierarchy, 155 156 const int maxPvs, 156 constAxisAlignedBox3 *box = NULL,157 AxisAlignedBox3 *box = NULL, 157 158 const bool exportBoundingBoxes = true); 158 159 … … 163 164 164 165 virtual void ExportPolygon(Polygon3 *poly) = 0; 166 167 bool mClampToBox; 168 AxisAlignedBox3 mBoundingBox; 165 169 }; 166 170 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1763 r1764 1428 1428 1429 1429 1430 bool HierarchyManager::AddSampleToPvs(Intersectable *obj,1431 const Vector3 &hitPoint,1432 ViewCell *vc,1433 const float pdf,1434 float &contribution) const1435 {1436 if (!obj) return false;1437 1438 switch (mObjectSpaceSubdivisionType)1439 {1440 case NO_OBJ_SUBDIV:1441 {1442 // potentially visible objects1443 return vc->AddPvsSample(obj, pdf, contribution);1444 }1445 case KD_BASED_OBJ_SUBDIV:1446 {1447 // potentially visible kd cells1448 KdLeaf *leaf = mOspTree->GetLeaf(hitPoint/*ray->mOriginNode*/);1449 return mOspTree->AddLeafToPvs(leaf, vc, pdf, contribution);1450 }1451 case BV_BASED_OBJ_SUBDIV:1452 {1453 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj);1454 1455 return vc->AddPvsSample(leaf, pdf, contribution);1456 }1457 default:1458 return false;1459 }1460 }1461 1462 1463 1430 void HierarchyManager::PrintHierarchyStatistics(ostream &stream) const 1464 1431 { … … 1488 1455 void HierarchyManager::ExportObjectSpaceHierarchy(Exporter *exporter, 1489 1456 const ObjectContainer &objects, 1490 constAxisAlignedBox3 *bbox,1457 AxisAlignedBox3 *bbox, 1491 1458 const bool exportBounds) const 1492 1459 { … … 1570 1537 break; 1571 1538 } 1539 1572 1540 return obj; 1573 1541 } … … 1972 1940 mOldViewCells = viewCells; 1973 1941 1974 return viewCells.size() + bvhNodes.size();1942 return (int)(viewCells.size() + bvhNodes.size()); 1975 1943 } 1976 1944 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1750 r1764 236 236 */ 237 237 void ExportObjectSpaceHierarchy(OUT_STREAM &stream); 238 /** Adds a sample to the pvs of the specified view cell. 239 */ 240 bool AddSampleToPvs( 241 Intersectable *obj, 242 const Vector3 &hitPoint, 243 ViewCell *vc, 244 const float pdf, 245 float &contribution) const; 246 238 247 239 /** Print out statistics. 248 240 */ … … 265 257 void ExportObjectSpaceHierarchy(Exporter *exporter, 266 258 const ObjectContainer &objects, 267 constAxisAlignedBox3 *bbox,259 AxisAlignedBox3 *bbox, 268 260 const bool exportBounds = true) const; 269 261 … … 391 383 const float renderCostPerStorage, 392 384 const float vspOspRatio); 393 394 bool AddSampleToPvs(Intersectable *obj,395 const float pdf,396 float &contribution) const;397 385 398 386 /** Collect affected view space candidates. -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1757 r1764 407 407 void Pvs<T, S>::MergeInPlace(const Pvs<T, S> &a) 408 408 { 409 //const int samples = mSamples + a.mSamples;410 409 ObjectPvs interPvs; 411 410 … … 415 414 mEntries = interPvs.mEntries; 416 415 mSamples = interPvs.mSamples; 417 //mSamples = samples;418 416 } 419 417 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1763 r1764 262 262 const float pdf, 263 263 float &contribution) 264 { 264 { cout << "here15" << endl; 265 265 const bool result = mPvs.AddSample(sample, pdf, contribution); 266 266 // have to recompute pvs size -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1763 r1764 28 28 #define ABS_CONTRIBUTION_WEIGHT 1.0f 29 29 30 // warning: Should not count origin object for sampling because it disturbs heuristics 30 // warning: Should not count origin object for sampling 31 // because it disturbs heuristics 31 32 #define SAMPLE_ORIGIN_OBJECTS 0 // matt temp 32 33 33 34 // $$JB HACK 34 #define USE_KD_PVS 135 #define USE_KD_PVS 0 35 36 #define KD_PVS_AREA (1e-4f) 36 37 … … 42 43 // HACK 43 44 const static bool SAMPLE_AFTER_SUBDIVISION = true; 44 const static bool CLAMP_TO_BOX = false;45 //const static bool CLAMP_TO_BOX = true;45 //const static bool CLAMP_TO_BOX = false; 46 const static bool CLAMP_TO_BOX = true; 46 47 47 48 … … 118 119 Environment::GetSingleton()->GetStringValue("ViewCells.samplingType", buf); 119 120 120 121 /*ObjectPvs pvs1, pvs2, mergedPvs;122 123 pvs1.AddSample((Intersectable *)1, 1);124 pvs1.AddSample((Intersectable *)3, 1);125 pvs1.AddSample((Intersectable *)6, 1);126 pvs1.AddSample((Intersectable *)7, 1);127 pvs1.AddSample((Intersectable *)9, 1);128 pvs1.AddSample((Intersectable *)12, 1);129 pvs1.AddSample((Intersectable *)15, 1);130 pvs1.AddSample((Intersectable *)7, 1);131 pvs2.AddSample((Intersectable *)3, 1);132 pvs2.AddSample((Intersectable *)4, 1);133 pvs2.AddSample((Intersectable *)6, 1);134 pvs2.AddSample((Intersectable *)8, 1);135 pvs2.AddSample((Intersectable *)9, 1);136 pvs2.AddSample((Intersectable *)14, 1);137 138 ObjectPvs::Merge(mergedPvs, pvs1, pvs2);139 140 Debug << "\npvs1\n";141 cout << "\npvs1\n";142 ObjectPvsIterator pvs1It = pvs1.GetIterator();143 144 while (pvs1It.HasMoreEntries())145 {146 ObjectPvsEntry entry = pvs1It.Next();147 148 Debug << (int)entry.mObject << " ";149 cout << (int)entry.mObject << " ";150 }151 152 Debug << "\npvs2\n";153 cout << "\npvs2\n";154 ObjectPvsIterator pvs2It = pvs2.GetIterator();155 156 while (pvs2It.HasMoreEntries())157 {158 ObjectPvsEntry entry = pvs2It.Next();159 160 Debug << (int)entry.mObject << " ";161 cout << (int)entry.mObject << " ";162 }163 164 Debug << "\nmerged\n";165 cout << "\nmerged\n";166 ObjectPvsIterator mergedIt = mergedPvs.GetIterator();167 168 while (mergedIt.HasMoreEntries())169 {170 ObjectPvsEntry entry = mergedIt.Next();171 Debug << (int)entry.mObject << " " << entry.mData.mSumPdf << " x ";172 cout << (int)entry.mObject << " " << entry.mData.mSumPdf << " x ";173 }174 */175 121 // sampling type for view cells construction samples 176 122 if (strcmp(buf, "object") == 0) … … 956 902 { 957 903 return mExportPvs; 958 }959 960 961 bool ViewCellsManager::AddSampleToPvs(Intersectable *obj,962 const Vector3 &hitPoint,963 ViewCell *vc,964 const float pdf,965 float &contribution) const966 {967 if (!obj)968 return false;969 970 // potentially visible objects971 return vc->AddPvsSample(obj, pdf, contribution);972 904 } 973 905 … … 2008 1940 ViewCellsManager::AddSampleContributions(VssRay &ray) 2009 1941 { 2010 // assumes viewcells have been stored... 2011 ViewCellContainer *viewcells = &ray.mViewCells; 2012 ViewCellContainer::const_iterator it; 2013 2014 if (!ray.mTerminationObject) 2015 return; 2016 2017 Intersectable *obj = GetIntersectable(ray, true); 2018 2019 for (it = viewcells->begin(); it != viewcells->end(); ++it) { 2020 ViewCell *viewcell = *it; 2021 if (viewcell->GetValid()) { 2022 // if ray not outside of view space 2023 viewcell->GetPvs().AddSample(obj, ray.mPdf); 2024 } 2025 } 1942 // assumes viewcells have been stored... 1943 ViewCellContainer *viewcells = &ray.mViewCells; 1944 ViewCellContainer::const_iterator it; 1945 1946 if (!ray.mTerminationObject) 1947 return; 1948 1949 Intersectable *obj = GetIntersectable(ray, true); 1950 1951 for (it = viewcells->begin(); it != viewcells->end(); ++it) 1952 { 1953 ViewCell *viewcell = *it; 1954 if (viewcell->GetValid()) 1955 { 1956 Intersectable *entry = GetIntersectable(ray, true); 1957 if (entry) 1958 // if ray not outside of view space 1959 viewcell->GetPvs().AddSample(entry, ray.mPdf); 1960 } 1961 } 2026 1962 } 2027 1963 … … 2061 1997 2062 1998 Intersectable *obj = GetIntersectable(ray, true); 2063 2064 1999 2065 2000 ViewCellContainer::const_iterator it = viewcells.begin(); 2066 2001 … … 2068 2003 { 2069 2004 ViewCell *viewcell = *it; 2070 2071 if (viewcell->GetValid()) // tests if view cell is in valid view space2005 // tests if view cell is in valid view space 2006 if (viewcell->GetValid()) 2072 2007 { 2073 2008 float contribution; … … 2113 2048 // if view point is valid, add new object to the pvs 2114 2049 if (ray.mTerminationObject) 2115 { 2050 { 2116 2051 viewcell->GetPvs().AddSample(obj, ray.mPdf); 2117 2052 } 2118 2053 #if SAMPLE_ORIGIN_OBJECTS 2119 2054 if (ray.mOriginObject) 2120 { 2055 { 2121 2056 viewcell->GetPvs().AddSample(ray.mOriginObject, ray.mPdf); 2122 2057 } … … 2593 2528 { 2594 2529 Intersectable *o = *noi; 2530 2595 2531 // $$ JB warning: pdfs are not correct at this point! 2596 2532 nPvs.AddSample(o, Limits::Small); … … 2598 2534 } 2599 2535 } 2600 // cout<<"nPvs size = "<<nPvsSize<<endl; 2601 2536 2537 // cout<<"nPvs size = "<<nPvsSize<<endl; 2602 2538 pvs.MergeInPlace(nPvs); 2603 2539 } … … 2850 2786 } 2851 2787 2852 //cout << "recursivly updating pvs" << endl;2853 2854 2788 //////////////// 2855 2789 //-- interior node => propagate pvs up the tree … … 2899 2833 2900 2834 if (!intersect->Mailed()) 2901 { 2835 { 2902 2836 pvs.AddSample(intersect, entry.mData.mSumPdf); 2903 2837 intersect->Mail(); … … 5504 5438 if (exporter) 5505 5439 { 5440 if (CLAMP_TO_BOX) 5441 { 5442 exporter->mClampToBox = true; 5443 } 5444 5506 5445 EvaluateViewCellsStats(); 5507 5446 5447 const long starttime = GetTime(); 5448 cout << "exporting final view cells (after initial construction + post process) ... "; 5449 5450 // matt: hack for clamping scene 5451 AxisAlignedBox3 bbox = mViewSpaceBox; 5452 bbox.Scale(scale); 5453 5454 if (1 && mExportRays) 5455 { 5456 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 5457 } 5458 5459 mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, 5460 CLAMP_TO_BOX ? &bbox : NULL, false); 5461 5508 5462 // hack color code (show pvs size) 5509 5463 const int savedColorCode = mColorCode; 5510 5464 mColorCode = 1; // export pvs 5511 5465 5512 const long starttime = GetTime(); 5513 cout << "exporting final view cells (after initial construction + post process) ... "; 5514 5515 // matt: hack for clamping scene 5516 AxisAlignedBox3 bbox = mViewSpaceBox; 5517 bbox.Scale(scale); 5518 5466 //ExportViewCellsForViz(exporter, CLAMP_TO_BOX ? &bbox : NULL, mColorCode, GetClipPlane()); 5467 ExportViewCellsForViz(exporter, NULL, mColorCode, GetClipPlane()); 5468 5469 delete exporter; 5470 5471 cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl; 5472 mColorCode = savedColorCode; 5473 } 5474 5475 // export final object partition 5476 exporter = Exporter::GetExporter("final_object_partition.wrl"); 5477 5478 if (exporter) 5479 { 5519 5480 if (CLAMP_TO_BOX) 5520 5481 { 5521 exporter->SetWireframe(); 5522 exporter->ExportBox(bbox); 5523 exporter->SetFilled(); 5524 } 5525 5526 if (0 && mExportGeometry) 5527 { 5528 exporter->ExportGeometry(objects, true, CLAMP_TO_BOX ? &bbox : NULL); 5529 } 5530 5531 if (1 && mExportRays) 5532 { 5533 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 5534 } 5535 5536 mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, 5537 CLAMP_TO_BOX ? &bbox : NULL, false); 5538 5539 //ExportViewCellsForViz(exporter, CLAMP_TO_BOX ? &bbox : NULL, mColorCode, GetClipPlane()); 5540 ExportViewCellsForViz(exporter, NULL, mColorCode, GetClipPlane()); 5541 5542 delete exporter; 5543 5544 cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl; 5545 mColorCode = savedColorCode; 5546 } 5547 5548 // export final object partition 5549 exporter = Exporter::GetExporter("final_object_partition.wrl"); 5550 5551 if (exporter) 5552 { 5482 exporter->mClampToBox = true; 5483 } 5484 5553 5485 const long starttime = GetTime(); 5554 5486 … … 5904 5836 { 5905 5837 // todo: maybe not correct for kd node pvs 5906 5907 if (viewcell->GetPvs().GetSampleContribution(terminationObj, 5908 ray.mPdf, 5909 contribution)) 5838 if (viewcell->GetPvs().GetSampleContribution( 5839 terminationObj, ray.mPdf, contribution)) 5910 5840 { 5911 5841 ++ ray.mPvsContribution; 5912 5842 } 5913 5914 5843 5844 ray.mRelativePvsContribution += contribution; 5915 5845 } 5916 5846 5917 5847 //////////////// 5918 //-- for directional sampling it is important to count only contributions5919 //-- made in one direction!5848 //-- for directional sampling it is important to count 5849 //-- only contributions made in one direction! 5920 5850 //-- the other contributions of this sample will be counted for the opposite ray! 5851 5921 5852 #if SAMPLE_ORIGIN_OBJECTS 5853 5922 5854 if (originObj && 5923 5855 viewcell->GetPvs().GetSampleContribution(originObj, … … 5946 5878 5947 5879 //$$JB hack 5948 #if !USE_KD_PVS5949 AddSampleToPvs(5950 terminationObj,5951 ray.mTermination,5952 viewCell,5953 ray.mPdf,5954 ray.mRelativePvsContribution);5955 #else5956 5880 viewCell->GetPvs().AddSample(terminationObj, ray.mPdf); 5957 #endif5958 5881 5959 5882 #if SAMPLE_ORIGIN_OBJECTS 5960 AddSampleToPvs( 5961 originObj, 5962 ray.mOrigin, 5963 viewCell, 5964 ray.mPdf, 5965 ray.mRelativePvsContribution); 5883 viewCell->GetPvs().AddSample(originObj, ray.mPdf); 5966 5884 #endif 5967 5885 } 5968 5886 5969 5970 5971 5887 return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 5972 5888 (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 5973 }5974 5975 5976 bool VspOspViewCellsManager::AddSampleToPvs(Intersectable *obj,5977 const Vector3 &hitPoint,5978 ViewCell *vc,5979 const float pdf,5980 float &contribution) const5981 {5982 // The hierarchy manager decides about the type of sample cast5983 return mHierarchyManager->AddSampleToPvs(obj, hitPoint, vc, pdf, contribution);5984 5889 } 5985 5890 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1761 r1764 516 516 bool GetStoreKdPVs() const; 517 517 518 /** Adds a sample to the pvs of the specified view cell.519 @param obj the hit object520 @param hitPoint the point where the object is hit.521 @param vc the sanpled view cell522 @param pdf probability of the ray523 @param contribution the relative pvs contribution524 @returns true if the sample gives a contribution to the pvs.525 */526 virtual bool AddSampleToPvs(Intersectable *obj,527 const Vector3 &hitPoint,528 ViewCell *vc,529 const float pdf,530 float &contribution) const;531 532 518 /** Exports single view cells for visualization. 533 519 @param objects the scene objects … … 1121 1107 BoundingBoxConverter *bconverter); 1122 1108 1123 bool AddSampleToPvs(Intersectable *obj,1124 const Vector3 &hitPoint,1125 ViewCell *vc,1126 const float pdf,1127 float &contribution) const;1128 1129 1109 void ExportSingleViewCells(const ObjectContainer &objects, 1130 1110 const int maxViewCells, -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1763 r1764 1033 1033 1034 1034 bool madeContrib = false; 1035 float contribution; 1036 1037 Intersectable *obj = ray->mTerminationObject; 1038 1039 if (obj) 1035 float contribution = 1; 1036 1037 Intersectable *entry = 1038 mHierarchyManager->GetIntersectable(ray->mTerminationObject, true); 1039 1040 if (entry) 1040 1041 { 1041 1042 madeContrib = 1042 mViewCellsManager->AddSampleToPvs( 1043 obj, 1044 ray->mTermination, 1045 vc, 1046 ray->mPdf, 1047 contribution); 1043 vc->GetPvs().AddSample(entry, ray->mPdf); 1048 1044 1049 1045 sc += contribution; 1050 1046 } 1051 1047 #if COUNT_ORIGIN_OBJECTS 1052 obj = ray->mOriginObject;1053 1054 if ( obj)1048 entry = mHierarchyManager->GetIntersectable(ray->mOriginObject, true); 1049 1050 if (entry) 1055 1051 { 1056 1052 madeContrib = 1057 mViewCellsManager->AddSampleToPvs( 1058 obj, 1059 ray->mOrigin, 1060 vc, 1061 ray->mPdf, 1062 contribution); 1053 vc->GetPvs().AddSample(entry, ray->mPdf); 1063 1054 1064 1055 sc += contribution; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r1732 r1764 38 38 class KdTreeStatistics; 39 39 40 41 #define WORK_WITH_VIEWCELLS 0 40 42 41 43 /** View space partition statistics.
Note: See TracChangeset
for help on using the changeset viewer.