Changeset 1695 for GTP/trunk/Lib/Vis
- Timestamp:
- 10/29/06 15:20:18 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1686 r1695 421 421 void EvalCandidate(bool computeSplitplane = true) 422 422 { 423 mDirty = false; 423 424 sBvHierarchy->EvalSubdivisionCandidate(*this, computeSplitplane); 424 425 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1684 r1695 1392 1392 "300000"); 1393 1393 1394 RegisterOption("ViewCells.Evaluation.samplesForStats", 1395 optInt, 1396 "view_cells_evaluation_samples_for_stats=", 1397 "300000"); 1398 1394 1399 RegisterOption("ViewCells.exportToFile", 1395 1400 optBool, … … 1804 1809 "preprocessor_kd_tree_filename=", 1805 1810 "vienna_kdtree.bin.gz"); 1806 1811 1812 RegisterOption("Preprocessor.exportObj", 1813 optBool, 1814 "preprocessor_export_obj=", 1815 "false"); 1816 1807 1817 1808 1818 /*************************************************************************/ -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1694 r1695 1328 1328 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1329 1329 1330 1331 1330 /////////////////////////// 1332 1331 //-- compute bounding box of object space -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
r1655 r1695 204 204 sscanf(str + 1, "%f %f %f", &x, &y, &z); 205 205 vertices.push_back(Vector3(x,y,z)); 206 // Debug<< "vertex: " << vertices.back() << endl;206 //cout << "vertex: " << vertices.back() << endl; 207 207 break; 208 208 } -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h
r1667 r1695 254 254 void EvalCandidate(bool computeSplitplane = true) 255 255 { 256 //if (computeSplitplane) TODO 256 mDirty = false; 257 // todo: avoid computing split plane 257 258 sOspTree->EvalSubdivisionCandidate(*this); 258 259 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1664 r1695 158 158 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", mApplyVisibilityFilter ); 159 159 Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", 160 mApplyVisibilitySpatialFilter );160 mApplyVisibilitySpatialFilter ); 161 161 Environment::GetSingleton()->GetFloatValue("Preprocessor.visibilityFilterWidth", mVisibilityFilterWidth); 162 162 163 Environment::GetSingleton()->GetBoolValue("Preprocessor.exportObj", mExportObj); 164 165 Debug << "******* Preprocessor Options **********" << endl; 163 166 Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl; 164 167 Debug << "load meshes: " << mLoadMeshes << endl; 168 Debug << "load meshes: " << mLoadMeshes << endl; 169 Debug << "export obj: " << mExportObj << endl; 165 170 } 166 171 … … 298 303 299 304 return true; 305 } 306 307 308 bool Preprocessor::ExportObj(const string filename, const ObjectContainer &objects) 309 { 310 ofstream samplesOut(filename.c_str()); 311 312 if (!samplesOut.is_open()) 313 return false; 314 315 ObjectContainer::const_iterator oit, oit_end = objects.end(); 316 317 for (oit = objects.begin(); oit != oit_end; ++ oit) 318 { 319 Intersectable *obj = *oit; 320 321 if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 322 { 323 Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 324 325 samplesOut << "v " << tri.mVertices[0].x << " " << tri.mVertices[0].y << " " << tri.mVertices[0].z << endl; 326 samplesOut << "v " << tri.mVertices[1].x << " " << tri.mVertices[1].y << " " << tri.mVertices[1].z << endl; 327 samplesOut << "v " << tri.mVertices[2].x << " " << tri.mVertices[2].y << " " << tri.mVertices[2].z << endl; 328 } 329 else 330 { 331 cout << "not implemented intersectable type " << obj->Type() << endl; 332 } 333 } 334 335 // write faces 336 int i = 1; 337 for (oit = objects.begin(); oit != oit_end; ++ oit, i += 3) 338 { 339 Intersectable *obj = *oit; 340 if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE) 341 { 342 Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem(); 343 samplesOut << "f " << i << " " << i + 1 << " " << i + 2 << endl; 344 } 345 else 346 { 347 cout << "not implemented intersectable type " << obj->Type() << endl; 348 } 349 } 350 351 return true; 352 300 353 } 301 354 … … 323 376 cout << "number of input files: " << files << endl; 324 377 bool result = false; 378 bool isObj = false; 325 379 326 380 // root for different files … … 357 411 else if (strstr(filename.c_str(), ".obj")) 358 412 { 413 isObj = true; 414 359 415 // hack: load binary dump 360 416 string binFile = ReplaceSuffix(filename, ".obj", ".bin"); … … 417 473 418 474 SceneGraphNode *node = new SceneGraphNode(); 419 const bool success = parser->ParseFile( 420 filename, 421 node, 422 mLoadMeshes, 423 fi); 475 const bool success = 476 parser->ParseFile(filename, node, mLoadMeshes, fi); 424 477 425 478 if (success) … … 943 996 case SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION: 944 997 return new SpatialBoxBasedDistribution(*this); 998 case SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION: 999 return new ReverseObjectBasedDistribution(*this); 945 1000 //case OBJECTS_INTERIOR_DISTRIBUTION: 946 1001 // return new ObjectsInteriorDistribution(*this); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1658 r1695 100 100 /** Export preprocessor data. 101 101 */ 102 bool Export( 103 const string filename, 104 const bool scene, 105 const bool kdtree); 102 bool Export(const string filename, const bool scene, const bool kdtree); 106 103 107 104 virtual void KdTreeStatistics(ostream &s); … … 114 111 */ 115 112 bool LoadSamples(VssRayContainer &samples, 116 ObjectContainer &objects) const;113 ObjectContainer &objects) const; 117 114 118 115 /** Exports samples to file. … … 124 121 bool ExportKdTree(const string filename); 125 122 126 virtual bool 127 GenerateRays( 128 const int number, 129 const int raysType, 130 SimpleRayContainer &rays 131 ); 132 133 bool GenerateRayBundle( 134 SimpleRayContainer &rayBundle, 135 const SimpleRay &mainRay, 136 const int number, 137 const int shuffleType) const; 123 virtual bool GenerateRays(const int number, 124 const int raysType, 125 SimpleRayContainer &rays); 126 127 bool GenerateRayBundle(SimpleRayContainer &rayBundle, 128 const SimpleRay &mainRay, 129 const int number, 130 const int shuffleType) const; 138 131 139 132 virtual void CastRays(SimpleRayContainer &rays, 140 VssRayContainer &vssRays,141 const bool castDoubleRays,142 const bool pruneInvalidRays = true);133 VssRayContainer &vssRays, 134 const bool castDoubleRays, 135 const bool pruneInvalidRays = true); 143 136 144 137 /** Returns a view cells manager of the given name. … … 153 146 bool InitRayCast(const string externKdTree, const string internKdTree); 154 147 148 bool ExportObj(const string filename, const ObjectContainer &objects); 155 149 156 150 //////////////////////////////////////////////// … … 206 200 bool mStopComputation; 207 201 202 bool mExportObj; 203 204 208 205 protected: 209 206 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1692 r1695 151 151 } 152 152 153 154 bool ReverseObjectBasedDistribution::GenerateSample(SimpleRay &ray) const 155 { 156 Vector3 origin, direction; 157 158 mPreprocessor.mViewCellsManager->GetViewPoint(origin); 159 160 Vector3 point; 161 Vector3 normal; 162 //cout << "y"; 163 const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 164 165 Intersectable *object = mPreprocessor.mObjects[i]; 166 167 object->GetRandomSurfacePoint(point, normal); 168 direction = origin - point; 169 170 // $$ jb the pdf is yet not correct for all sampling methods! 171 const float c = Magnitude(direction); 172 173 if (c <= Limits::Small) 174 return false; 175 176 // $$ jb the pdf is yet not correct for all sampling methods! 177 const float pdf = 1.0f; 178 //cout << "p: " << point << " "; 179 direction *= 1.0f / c; 180 ray = SimpleRay(point, direction, pdf); 181 182 return true; 183 } 184 153 185 #if 0 154 186 bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray) const -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1520 r1695 27 27 VSS_BASED_DISTRIBUTION, 28 28 OBJECT_DIRECTION_BASED_DISTRIBUTION, 29 OBJECTS_INTERIOR_DISTRIBUTION 29 OBJECTS_INTERIOR_DISTRIBUTION, 30 REVERSE_OBJECT_BASED_DISTRIBUTION 30 31 }; 31 32 … … 53 54 54 55 ObjectBasedDistribution(const Preprocessor &preprocessor): 56 SamplingStrategy(preprocessor) {} 57 58 virtual bool GenerateSample(SimpleRay &ray) const; 59 }; 60 61 62 class ReverseObjectBasedDistribution: public SamplingStrategy 63 { 64 public: 65 66 ReverseObjectBasedDistribution(const Preprocessor &preprocessor): 55 67 SamplingStrategy(preprocessor) {} 56 68 -
GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h
r1684 r1695 22 22 enum {OBJECT_SPACE, VIEW_SPACE}; 23 23 24 SubdivisionCandidate(): mRenderCostDecrease(0) {};24 SubdivisionCandidate(): mRenderCostDecrease(0), mDirty(true) {}; 25 25 26 26 virtual ~SubdivisionCandidate() {}; … … 130 130 131 131 int mMailbox; 132 133 bool mDirty; 132 134 }; 133 135 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1667 r1695 1527 1527 tqueue.push(mRoot); 1528 1528 1529 //cout << "exporting stats ... " << endl; 1529 1530 int numViewCells = 1; 1530 1531 … … 1534 1535 const int rootPvs = GetPvsSize(mRoot); 1535 1536 const int rootEntries = GetPvsEntries(mRoot); 1536 1537 cout << "exporting stats ... " << endl;1538 1539 1537 float totalRenderCost, avgRenderCost, expectedCost; 1540 1538 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1694 r1695 38 38 // HACK 39 39 const static bool SAMPLE_AFTER_SUBDIVISION = true; 40 const static bool CLAMP_TO_BOX = false;40 const static bool CLAMP_TO_BOX = true; 41 41 42 42 template <typename T> class myless … … 72 72 73 73 mViewCellsTree->SetViewCellsManager(this); 74 //mViewCellsTree = new ViewCellsTree(this);75 74 } 76 75 … … 112 111 113 112 // sampling type for view cells construction samples 114 if (strcmp(buf, "box") == 0) 113 if (strcmp(buf, "object") == 0) 114 { 115 mSamplingType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 116 } 117 else if (strcmp(buf, "box") == 0) 115 118 { 116 119 mSamplingType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; … … 123 126 { 124 127 mSamplingType = SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION; 128 } 129 else if (strcmp(buf, "reverse_object") == 0) 130 { 131 mSamplingType = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION; 125 132 } 126 133 /*else if (strcmp(buf, "interior") == 0) … … 137 144 Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.samplingType", buf); 138 145 139 if (strcmp(buf, "box") == 0) 146 if (strcmp(buf, "object") == 0) 147 { 148 mEvaluationSamplingType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 149 } 150 else if (strcmp(buf, "box") == 0) 140 151 { 141 152 mEvaluationSamplingType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; … … 148 159 { 149 160 mEvaluationSamplingType = SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION; 161 } 162 else if (strcmp(buf, "reverse_object") == 0) 163 { 164 mEvaluationSamplingType = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION; 150 165 } 151 166 /*else if (strcmp(buf, "interior") == 0) … … 155 170 else 156 171 { 172 mEvaluationSamplingType = -1; 157 173 Debug << "error! wrong sampling type" << endl; 158 174 exit(0); … … 868 884 int castSamples = 0; 869 885 char str[64]; 886 int oldSamples = 0; 887 888 int samplesForStats; 870 889 871 890 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", samplesPerPass); 891 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesForStats", samplesForStats); 872 892 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samples", numSamples); 873 893 … … 924 944 925 945 Real timeDiff = TimeDiff(startTime, GetTime()); 926 Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 927 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 928 946 947 cout << "finished in " << timeDiff * 1e-3f << " secs" << endl; 929 948 cout << "computing sample contributions of " << (int)evaluationSamples.size() << " samples ... "; 949 950 Debug << "finished in " << timeDiff * 1e-3f << " secs" << endl; 930 951 Debug << "computing sample contributions of " << (int)evaluationSamples.size() << " samples ... "; 931 952 … … 938 959 Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl; 939 960 940 startTime = GetTime(); 941 cout << "compute new statistics ... " << endl; 942 943 /////////// 944 //-- output stats 945 946 sprintf(str, "-%09d-eval.log", castSamples); 947 string fileName = string(statsPrefix) + string(str); 948 949 /////////////// 950 //-- propagate pvs or pvs size information 951 952 ObjectPvs pvs; 953 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 954 955 ExportStats(fileName); 956 957 timeDiff = TimeDiff(startTime, GetTime()); 958 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 959 Debug << "statistis compted in " << timeDiff * 1e-3 << " secs" << endl; 960 961 if ((castSamples >= samplesForStats + oldSamples) || (castSamples >= numSamples)) 962 { 963 oldSamples += samplesForStats; 964 965 /////////// 966 //-- output stats 967 968 sprintf(str, "-%09d-eval.log", castSamples); 969 string fileName = string(statsPrefix) + string(str); 970 971 /////////////// 972 //-- propagate pvs or pvs size information 973 974 startTime = GetTime(); 975 ObjectPvs pvs; 976 977 cout << "updating pvs for contribution ... " << endl; 978 979 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 980 981 timeDiff = TimeDiff(startTime, GetTime()); 982 cout << "finished updating the pvs in " << timeDiff * 1e-3 << " secs" << endl; 983 Debug << "pvs evaluated in " << timeDiff * 1e-3 << " secs" << endl; 984 985 startTime = GetTime(); 986 cout << "compute new statistics ... " << endl; 987 988 ExportStats(fileName); 989 990 timeDiff = TimeDiff(startTime, GetTime()); 991 cout << "finished in " << timeDiff * 1e-3 << " secs" << endl; 992 Debug << "statistis computed in " << timeDiff * 1e-3 << " secs" << endl; 993 } 994 961 995 disposeRays(evaluationSamples, NULL); 962 996 } … … 966 1000 //-- histogram 967 1001 1002 const int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot()); 968 1003 bool useHisto; 969 1004 int histoStepSize; … … 971 1006 Environment::GetSingleton()->GetBoolValue("ViewCells.Evaluation.histogram", useHisto); 972 1007 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.histoStepSize", histoStepSize); 973 974 const int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot());975 976 1008 977 1009 if (useHisto) … … 2529 2561 // reset recursive pvs 2530 2562 pvs.Clear(); 2563 2564 // pvss of child nodes 2531 2565 vector<ObjectPvs> pvsList; 2532 2566 2533 2567 ViewCellContainer::const_iterator vit, vit_end = interior->mChildren.end(); 2534 2535 for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit) 2536 { 2537 ObjectPvs objPvs; 2568 pvsList.resize((int)interior->mChildren.size()); 2569 int i = 0; 2570 for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ i) 2571 { 2572 //ObjectPvs objPvs; 2538 2573 2539 2574 ////////////////// 2540 2575 //-- recursivly compute child pvss 2541 2576 2542 UpdatePvsForEvaluation(*vit, objPvs);2577 UpdatePvsForEvaluation(*vit, pvsList[i]/*objPvs*/); 2543 2578 2544 2579 // store pvs in vector 2545 pvsList.push_back(objPvs);2580 //pvsList.push_back(objPvs); 2546 2581 } 2547 2582 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r1686 r1695 480 480 void EvalCandidate(bool computeSplitplane = true) 481 481 { 482 mDirty = false; 482 483 sVspTree->EvalSubdivisionCandidate(*this, computeSplitplane); 483 484 } -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1694 r1695 94 94 95 95 96 static string GetIntern KdTreeName(const string &filename)96 static string GetInternFilename(const string &filename, const string newSuffix) 97 97 { 98 98 vector<string> filenames; … … 118 118 strippedFilename = string(str); 119 119 120 delete [] str;120 delete [] str; 121 121 } 122 122 … … 125 125 if (i == (int)filenames.size() - 1) 126 126 { 127 if (preprocessor->mLoadMeshes) 128 { 129 suffix = ".kdm"; 130 } 131 else 132 { 133 suffix = ".kdt"; 134 } 127 suffix = newSuffix; 135 128 } 136 129 … … 200 193 Environment::GetSingleton()->GetStringValue("Scene.filename", buff); 201 194 string filename(buff); 202 const string dummyname = GetInternKdTreeName(filename);195 203 196 204 197 if (!preprocessor->LoadScene(filename)) … … 218 211 219 212 const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf"); 220 const string internKdTree = GetIntern KdTreeName(filename);213 const string internKdTree = GetInternFilename(filename, preprocessor->mLoadMeshes ? ".kdm" : ".kdt"); 221 214 222 215 //-- initialize external ray casters 216 223 217 if (preprocessor->InitRayCast(externKdTree, internKdTree)) 224 218 { … … 230 224 Cleanup(); 231 225 exit(1); 226 } 227 228 229 // export objects as obj 230 if (preprocessor->mExportObj) 231 { 232 if (strstr(filename.c_str(), ".obj")) 233 { 234 cerr << "already in obj format" << endl; 235 if (1) 236 preprocessor->ExportObj("test.obj", preprocessor->mObjects); 237 } 238 else 239 { 240 const string objname = GetInternFilename(filename, ".obj"); 241 242 //cout << "exporting scene to " << objname << endl; 243 bool success = preprocessor->ExportObj(objname, preprocessor->mObjects); 244 245 if (success) 246 { 247 cout << "finished exporting obj" << endl; 248 } 249 else 250 { 251 cerr << "error exporting " << objname << endl; 252 } 253 } 232 254 } 233 255
Note: See TracChangeset
for help on using the changeset viewer.