Changeset 1772 for GTP/trunk/Lib/Vis
- Timestamp:
- 11/20/06 18:44:29 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r1768 r1772 2286 2286 } 2287 2287 2288 } 2289 2288 2289 Vector3 AxisAlignedBox3::GetRandomSurfacePoint() const 2290 { 2291 const int idx = Random(6); 2292 2293 const Rectangle3 face = GetFace(idx); 2294 2295 Vector3 point = Vector3(0,0,0); 2296 float sum = 0.0f; 2297 2298 for (int i = 0; i < 4; ++ i) 2299 { 2300 const float r = RandomValue(0, 1); 2301 sum += r; 2302 point += face.mVertices[i] * r; 2303 } 2304 2305 point *= 1.0f / sum; 2306 2307 //normal = face.GetNormal(); 2308 2309 return point; 2310 } 2311 2312 2313 } 2314 -
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
r1768 r1772 182 182 183 183 Vector3 GetRandomPoint() const; 184 184 Vector3 GetRandomSurfacePoint() const; 185 185 186 186 Vector3 GetPoint(const Vector3 &p) const { -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
r1769 r1772 422 422 Mesh::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) 423 423 { 424 424 //const int faceIndex = (int)RandomValue(0, (Real)((int)mFaces.size()-1)); 425 425 const int faceIndex = (int)RandomValue(0, (Real)mFaces.size() - 0.5f); 426 426 427 // assume the face is convex and generate a convex combination 428 // 429 Face *face = mFaces[faceIndex]; 430 431 point = Vector3(0,0,0); 432 float sum = 0.0f; 433 434 for (int i = 0; i < face->mVertexIndices.size(); i++) { 435 float r = RandomValue(0,1); 436 sum += r; 437 point += mVertices[face->mVertexIndices[i]]*r; 438 } 439 point *= 1.0f/sum; 440 427 // assume the face is convex and generate a convex combination 428 Face *face = mFaces[faceIndex]; 429 430 point = Vector3(0,0,0); 431 float sum = 0.0f; 432 433 for (int i = 0; i < face->mVertexIndices.size(); i++) { 434 float r = RandomValue(0,1); 435 sum += r; 436 point += mVertices[face->mVertexIndices[i]]*r; 437 } 438 point *= 1.0f/sum; 439 441 440 normal = GetFacePlane(faceIndex).mNormal; 442 441 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1771 r1772 945 945 SimpleRayContainer &rays) 946 946 { 947 947 return strategy.GenerateSamples(number, rays); 948 948 } 949 949 … … 953 953 SimpleRayContainer &rays) 954 954 { 955 956 957 958 959 960 { 961 962 } 963 955 const int startSize = (int)rays.size(); 956 SamplingStrategy *strategy = GenerateSamplingStrategy(sampleType); 957 int castRays = 0; 958 959 if (!strategy) 960 { 961 return 0; 962 } 963 964 964 #if 1 965 if (!strategy->GenerateSamples(number, rays)) 966 return false; 967 ++ castRays; 965 castRays = strategy->GenerateSamples(number, rays); 968 966 #else 969 970 967 GenerateRayBundle(rays, newRay, 16, 0); 968 castRays += 16; 971 969 #endif 972 973 974 970 971 delete strategy; 972 return castRays; 975 973 } 976 974 … … 994 992 case SamplingStrategy::VIEWCELL_BORDER_BASED_DISTRIBUTION: 995 993 return new ViewCellBorderBasedDistribution(*this); 994 case SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION: 995 return new ViewSpaceBorderBasedDistribution(*this); 996 case SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION: 997 return new ReverseViewSpaceBorderBasedDistribution(*this); 996 998 //case OBJECTS_INTERIOR_DISTRIBUTION: 997 999 // return new ObjectsInteriorDistribution(*this); -
GTP/trunk/Lib/Vis/Preprocessing/src/Rectangle3.h
r863 r1772 15 15 Vector3 mVertices[4]; 16 16 17 Vector3 GetVertex(const int i) const { return mVertices[i]; }17 inline Vector3 GetVertex(const int i) const { return mVertices[i]; } 18 18 Rectangle3() {} 19 19 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1771 r1772 24 24 SimpleRayContainer &rays) const 25 25 { 26 SimpleRay ray; 27 int i = 0; 28 for (; i < number; i++) { 29 if (!GenerateSample(ray)) 30 return i; 31 rays.push_back(ray); 32 } 33 34 return i; 26 SimpleRay ray; 27 int samples = 0; 28 int i = 0; 29 const int maxTries = 20; 30 // tmp changed matt. Q: should one rejected sample 31 // terminate the whole method? 32 if (0) 33 { 34 for (; i < number; i++) { 35 if (!GenerateSample(ray)) 36 return i; 37 rays.push_back(ray); 38 } 39 } 40 else 41 { 42 for (; i < number; i++) 43 { 44 int j = 0; 45 bool sampleGenerated = false; 46 47 for (j = 0; !sampleGenerated && (j < maxTries); ++ j) 48 { 49 sampleGenerated = GenerateSample(ray); 50 51 if (sampleGenerated) 52 { 53 ++ samples; 54 rays.push_back(ray); 55 } 56 } 57 } 58 } 59 60 return samples; 35 61 } 36 62 … … 196 222 direction *= 1.0f / c; 197 223 // a little offset 198 point += direction * 0.0 1f;224 point += direction * 0.001f; 199 225 200 226 ray = SimpleRay(point, direction, pdf); … … 279 305 #endif 280 306 307 308 bool ReverseViewSpaceBorderBasedDistribution::GenerateSample(SimpleRay &ray) const 309 { 310 Vector3 origin, direction; 311 312 origin = mPreprocessor.mViewCellsManager->GetViewSpaceBox().GetRandomSurfacePoint(); 313 314 Vector3 point; 315 Vector3 normal; 316 //cout << "y"; 317 const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 318 319 Intersectable *object = mPreprocessor.mObjects[i]; 320 321 object->GetRandomSurfacePoint(point, normal); 322 323 direction = origin - point; 324 325 // $$ jb the pdf is yet not correct for all sampling methods! 326 const float c = Magnitude(direction); 327 328 if ((c <= Limits::Small) || (DotProd(direction, normal) < 0)) 329 { 330 return false; 331 } 332 333 // $$ jb the pdf is yet not correct for all sampling methods! 334 const float pdf = 1.0f; 335 //cout << "p: " << point << " "; 336 direction *= 1.0f / c; 337 // a little offset 338 point += direction * 0.001f; 339 340 ray = SimpleRay(point, direction, pdf); 341 342 return true; 343 } 344 345 346 bool ViewSpaceBorderBasedDistribution::GenerateSample(SimpleRay &ray) const 347 { 348 Vector3 origin, direction; 349 350 origin = mPreprocessor.mViewCellsManager->GetViewSpaceBox().GetRandomSurfacePoint(); 351 352 Vector3 point; 353 Vector3 normal; 354 //cout << "w"; 355 const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 356 357 Intersectable *object = mPreprocessor.mObjects[i]; 358 359 object->GetRandomSurfacePoint(point, normal); 360 direction = point - origin; 361 362 // $$ jb the pdf is yet not correct for all sampling methods! 363 const float c = Magnitude(direction); 364 365 if (c <= Limits::Small) 366 return false; 367 368 // $$ jb the pdf is yet not correct for all sampling methods! 369 const float pdf = 1.0f; 370 371 direction *= 1.0f / c; 372 373 // a little offset 374 origin += direction * 0.001f; 375 376 ray = SimpleRay(origin, direction, pdf); 377 378 return true; 379 } 380 381 281 382 bool 282 383 RssBasedDistribution::GenerateSample(SimpleRay &ray) const -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
r1771 r1772 14 14 class SamplingStrategy 15 15 { 16 public:17 18 /** Sample rays of particular type19 */20 enum21 {22 OBJECT_BASED_DISTRIBUTION,23 DIRECTION_BASED_DISTRIBUTION,24 DIRECTION_BOX_BASED_DISTRIBUTION,25 SPATIAL_BOX_BASED_DISTRIBUTION,26 RSS_BASED_DISTRIBUTION,27 RSS_SILHOUETTE_BASED_DISTRIBUTION,28 VSS_BASED_DISTRIBUTION,29 OBJECT_DIRECTION_BASED_DISTRIBUTION,30 OBJECTS_INTERIOR_DISTRIBUTION,31 REVERSE_OBJECT_BASED_DISTRIBUTION,32 VIEWCELL_BORDER_BASED_DISTRIBUTION33 };34 35 /** Default constructor36 */37 SamplingStrategy(const Preprocessor &preprocessor);38 39 virtual ~SamplingStrategy();40 41 /** Each strategy has to implement this function.42 @returns true if generated valid sample.43 */44 45 virtual int GenerateSamples(const int number, SimpleRayContainer &rays) const;46 47 private:48 49 virtual bool GenerateSample(SimpleRay &ray) const = 0;50 51 16 public: 52 /// variables usefull for mixed distribution sampling 53 int mType; 54 int mRays; 55 float mContribution; 56 float mTime; 57 float mRatio; 58 17 18 /** Sample rays of particular type 19 */ 20 enum 21 { 22 OBJECT_BASED_DISTRIBUTION, 23 DIRECTION_BASED_DISTRIBUTION, 24 DIRECTION_BOX_BASED_DISTRIBUTION, 25 SPATIAL_BOX_BASED_DISTRIBUTION, 26 RSS_BASED_DISTRIBUTION, 27 RSS_SILHOUETTE_BASED_DISTRIBUTION, 28 VSS_BASED_DISTRIBUTION, 29 OBJECT_DIRECTION_BASED_DISTRIBUTION, 30 OBJECTS_INTERIOR_DISTRIBUTION, 31 REVERSE_OBJECT_BASED_DISTRIBUTION, 32 VIEWCELL_BORDER_BASED_DISTRIBUTION, 33 VIEWSPACE_BORDER_BASED_DISTRIBUTION, 34 REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION 35 }; 36 37 /** Default constructor 38 */ 39 SamplingStrategy(const Preprocessor &preprocessor); 40 41 virtual ~SamplingStrategy(); 42 43 /** Each strategy has to implement this function. 44 @returns true if generated valid sample. 45 */ 46 47 virtual int GenerateSamples(const int number, SimpleRayContainer &rays) const; 48 49 private: 50 51 virtual bool GenerateSample(SimpleRay &ray) const = 0; 52 53 public: 54 /// variables usefull for mixed distribution sampling 55 int mType; 56 int mRays; 57 float mContribution; 58 float mTime; 59 float mRatio; 60 59 61 protected: 60 61 62 62 63 const Preprocessor &mPreprocessor; 64 63 65 }; 64 66 … … 134 136 SpatialBoxBasedDistribution(const Preprocessor &preprocessor): 135 137 SamplingStrategy(preprocessor){ 138 mType = DIRECTION_BOX_BASED_DISTRIBUTION; 139 } 140 141 private: 142 virtual bool GenerateSample(SimpleRay &ray) const; 143 }; 144 145 146 class ViewSpaceBorderBasedDistribution: public SamplingStrategy 147 { 148 public: 149 ViewSpaceBorderBasedDistribution(const Preprocessor &preprocessor): 150 SamplingStrategy(preprocessor){ 136 151 mType = SPATIAL_BOX_BASED_DISTRIBUTION; 137 152 } … … 140 155 virtual bool GenerateSample(SimpleRay &ray) const; 141 156 }; 157 158 159 class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy 160 { 161 public: 162 ReverseViewSpaceBorderBasedDistribution(const Preprocessor &preprocessor): 163 SamplingStrategy(preprocessor){ 164 mType = SPATIAL_BOX_BASED_DISTRIBUTION; 165 } 166 167 private: 168 virtual bool GenerateSample(SimpleRay &ray) const; 169 }; 170 142 171 143 172 class RssBasedDistribution: public SamplingStrategy … … 159 188 160 189 }; 190 161 191 162 192 class ViewCellBorderBasedDistribution: public SamplingStrategy -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r1770 r1772 206 206 Name="VCLinkerTool" 207 207 AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib QtCore4.lib qtmain.lib QtOpenGL4.lib Qt3Support4.lib QtTest4.lib QtGui4.lib QtGlRenderer.lib" 208 OutputFile="../bin/release/Preprocessor .exe"208 OutputFile="../bin/release/Preprocessor2.exe" 209 209 LinkIncremental="1" 210 210 AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;"$(QTDIR)\lib";.\QtGlRenderer\Release" -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1764 r1772 262 262 const float pdf, 263 263 float &contribution) 264 { cout << "here15" << endl;264 { 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
r1771 r1772 320 320 321 321 const int numRaysPerPass = samplesPerPass / (int)strategies.size(); 322 323 322 vector<int>::const_iterator iit, iit_end = strategies.end(); 324 323 325 324 for (iit = strategies.begin(); iit != iit_end; ++ iit) 326 325 { 327 int stype = *iit;326 const int stype = *iit; 328 327 const int newRays = 329 328 mPreprocessor->GenerateRays(numRaysPerPass, stype, simpleRays); 330 329 331 330 cout << "cast " << newRays << " rays of strategy " << stype << endl; 332 331 castRays += newRays; … … 394 393 // mix of sampling strategies 395 394 vector<int> strategies; 396 strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 397 strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 398 strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 395 396 if (0) 397 { 398 strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 399 strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 400 strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 401 } 402 else 403 { 404 strategies.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION); 405 //strategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 406 } 399 407 400 408 // cast initial samples … … 838 846 for (; it != it_end; ++it) { 839 847 //(*it)->UpdatePvsCost(); 840 (*it)->SetPvsCost((*it)->GetFilteredPvsSize()); 841 } 842 848 (*it)->SetPvsCost((float)(*it)->GetFilteredPvsSize()); 849 } 843 850 844 851 float maxPvs, maxVal, minVal; … … 989 996 // mix of sampling strategies 990 997 vector<int> strategies; 991 strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 992 strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 993 strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 998 999 if (0) 1000 { 1001 strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 1002 strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 1003 strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 1004 } 1005 else 1006 { 1007 strategies.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION); 1008 strategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 1009 } 994 1010 995 1011 cout << "finished" << endl; … … 5980 5996 // mix of sampling strategies 5981 5997 vector<int> strategies; 5982 strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 5983 strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 5984 strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 5985 //strategies.push_back(SamplingStrategy::VIEWCELL_BORDER_BASED_DISTRIBUTION); 5998 5999 if (0) 6000 { 6001 strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION); 6002 strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION); 6003 strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION); 6004 } 6005 else 6006 { 6007 strategies.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION); 6008 strategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION); 6009 } 6010 5986 6011 cout << "reseting pvs ... "; 5987 6012 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1767 r1772 1496 1496 //-- compute cost 1497 1497 1498 const int lowerPvsLimit =mViewCellsManager->GetMinPvsSize();1499 const int upperPvsLimit =mViewCellsManager->GetMaxPvsSize();1498 const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize(); 1499 const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize(); 1500 1500 1501 1501 const float pOverall = sizeBox; … … 2018 2018 2019 2019 // upper and lower bounds 2020 const int lowerPvsLimit =mViewCellsManager->GetMinPvsSize();2021 const int upperPvsLimit =mViewCellsManager->GetMaxPvsSize();2022 2023 const float penaltyOld = EvalPvsPenalty( (int)totalPvs, lowerPvsLimit, upperPvsLimit);2024 const float penaltyFront = EvalPvsPenalty( (int)pvsFront, lowerPvsLimit, upperPvsLimit);2025 const float penaltyBack = EvalPvsPenalty( (int)pvsBack, lowerPvsLimit, upperPvsLimit);2020 const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize(); 2021 const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize(); 2022 2023 const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit); 2024 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 2025 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 2026 2026 2027 2027 const float oldRenderCost = pOverall * penaltyOld; … … 2125 2125 } 2126 2126 2127 2128 // -- pvs rendering heuristics 2127 //////// 2128 //-- pvs rendering heuristics 2129 2129 2130 const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 2130 2131 const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 2131 2132 2132 2133 // only render cost heuristics or combined with standard deviation 2133 const float penaltyOld = EvalPvsPenalty( (int)totalPvs, lowerPvsLimit, upperPvsLimit);2134 const float penaltyFront = EvalPvsPenalty( (int)pvsFront, lowerPvsLimit, upperPvsLimit);2135 const float penaltyBack = EvalPvsPenalty( (int)pvsBack, lowerPvsLimit, upperPvsLimit);2134 const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit); 2135 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 2136 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 2136 2137 2137 2138 const float oldRenderCost = pOverall * penaltyOld; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1765 r1772 1411 1411 } 1412 1412 1413 //#ifdef GTP_DEBUG1413 #ifdef GTP_DEBUG 1414 1414 cout << "\n((((( eval local cost )))))" << endl 1415 1415 << "back pvs: " << penaltyBack << " front pvs: " << penaltyFront << " total pvs: " << penaltyOld << endl … … 1417 1417 << "old rc: " << oldRenderCost * volRatio << " new rc: " << newRenderCost * volRatio << endl 1418 1418 << "render cost decrease: " << oldRenderCost * volRatio - newRenderCost * volRatio << endl; 1419 //#endif1419 #endif 1420 1420 return ratio; 1421 1421 }
Note: See TracChangeset
for help on using the changeset viewer.