Changeset 354
- Timestamp:
- 10/28/05 14:46:59 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
r349 r354 43 43 virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 44 44 45 virtual int 46 GetRandomVisibleSurfacePoint(Vector3 &point, 47 Vector3 &normal, 48 const Vector3 &viewpoint, 49 const int maxTries 50 ) = 0; 51 45 52 virtual ostream &Describe(ostream &s) = 0; 46 53 -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
r333 r354 641 641 KdNode * 642 642 KdTree::FindRandomNeighbor(KdNode *n, 643 644 643 bool onlyUnmailed 644 ) 645 645 { 646 646 stack<KdNode *> nodeStack; … … 811 811 return totalPvsSize; 812 812 } 813 814 815 KdNode * 816 KdTree::GetRandomLeaf(const bool onlyUnmailed) 817 { 818 stack<KdNode *> nodeStack; 819 nodeStack.push(mRoot); 820 821 int mask = rand(); 822 823 while (!nodeStack.empty()) { 824 KdNode *node = nodeStack.top(); 825 nodeStack.pop(); 826 if (node->IsLeaf()) { 827 if ( (!onlyUnmailed || !node->Mailed()) ) 828 return node; 829 } else { 830 KdInterior *interior = (KdInterior *)node; 831 // random decision 832 if (mask&1) 833 nodeStack.push(interior->mBack); 834 else 835 nodeStack.push(interior->mFront); 836 mask = mask>>1; 837 } 838 } 839 return NULL; 840 } -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h
r329 r354 305 305 KdNode * 306 306 FindRandomNeighbor(KdNode *n, 307 308 309 307 bool onlyUnmailed 308 ); 309 310 310 311 311 KdNode * 312 312 KdTree::GetRandomLeaf(const Plane3 &halfspace); 313 313 314 KdNode * 315 GetRandomLeaf(const bool onlyUnmailed = false); 316 314 317 int 315 318 FindNeighbors(KdNode *n, -
trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
r340 r354 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (1.07a) (Qt 3.3.2) on: Tue Oct 18 16:48:3320053 # Generated by qmake (1.07a) (Qt 3.3.2) on: Wed Oct 26 17:55:30 2005 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 39 39 ####### Files 40 40 41 HEADERS = 41 HEADERS = Halton.h 42 42 SOURCES = Preprocessor.cpp \ 43 43 SamplingPreprocessor.cpp \ … … 68 68 Polygon3.cpp \ 69 69 ViewCell.cpp \ 70 ViewCellBsp.cpp 70 ViewCellBsp.cpp \ 71 Halton.cpp 71 72 OBJECTS = Preprocessor.obj \ 72 73 SamplingPreprocessor.obj \ … … 97 98 Polygon3.obj \ 98 99 ViewCell.obj \ 99 ViewCellBsp.obj 100 ViewCellBsp.obj \ 101 Halton.obj 100 102 FORMS = 101 103 UICDECLS = … … 188 190 -$(DEL_FILE) ViewCell.obj 189 191 -$(DEL_FILE) ViewCellBsp.obj 192 -$(DEL_FILE) Halton.obj 190 193 191 194 … … 371 374 Matrix4x4.h \ 372 375 Vector3.h \ 376 Halton.h \ 373 377 common.h \ 374 378 … … 606 610 607 611 612 Halton.obj: Halton.cpp \ 613 Halton.h \ 614 615 608 616 ####### Install 609 617 -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
r350 r354 289 289 290 290 int 291 Mesh::GetRandomVisibleSurfacePoint(Vector3 &point, 292 Vector3 &normal, 293 const Vector3 &viewpoint, 294 const int maxTries 295 ) 296 { 297 Plane3 plane; 298 int faceIndex = RandomValue(0, mFaces.size()-1); 299 for (int tries = 0; tries < maxTries; tries++) { 300 Face *face = mFaces[faceIndex]; 301 plane = GetFacePlane(faceIndex); 302 303 if (plane.Side(viewpoint) > 0) { 304 point = Vector3(0,0,0); 305 float sum = 0.0f; 306 // pickup a point inside this triangle 307 for (int i = 0; i < face->mVertexIndices.size(); i++) { 308 float r = RandomValue(0,1); 309 sum += r; 310 point += mVertices[face->mVertexIndices[i]]*r; 311 } 312 point *= 1.0f/sum; 313 break; 314 } 315 } 316 317 normal = plane.mNormal; 318 return (tries < maxTries) ? faceIndex + 1 : 0; 319 } 320 321 322 int 291 323 MeshInstance::CastRay( 292 324 Ray &ray … … 313 345 return mMesh->GetRandomSurfacePoint(point, normal); 314 346 } 347 348 int 349 MeshInstance::GetRandomVisibleSurfacePoint(Vector3 &point, 350 Vector3 &normal, 351 const Vector3 &viewpoint, 352 const int maxTries 353 ) 354 { 355 return mMesh->GetRandomVisibleSurfacePoint(point, normal, viewpoint, maxTries); 356 } 357 315 358 316 359 int -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r349 r354 145 145 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 146 146 147 int 148 GetRandomVisibleSurfacePoint(Vector3 &point, 149 Vector3 &normal, 150 const Vector3 &viewpoint, 151 const int maxTries 152 ); 153 147 154 virtual ostream &Describe(ostream &s) { 148 155 return s<<"Mesh #vertices="<<mVertices.size()<<" #faces="<<mFaces.size(); … … 161 168 162 169 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 170 171 int 172 GetRandomVisibleSurfacePoint(Vector3 &point, 173 Vector3 &normal, 174 const Vector3 &viewpoint, 175 const int maxTries 176 ); 163 177 164 178 -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r352 r354 148 148 int 149 149 SamplingPreprocessor::CastRay(Intersectable *object, 150 Ray &ray) 150 Ray &ray, 151 const bool reverseRay 152 ) 151 153 { 152 154 int sampleContributions = 0; … … 168 170 { 169 171 mBspTree->CastRay(ray); 170 171 sampleContributions += AddObjectSamples(object, ray); 172 172 173 if (!reverseRay) 174 sampleContributions += AddObjectSamples(object, ray); 175 173 176 if (!ray.intersections.empty()) // second intersection found 174 {175 sampleContributions +=176 AddObjectSamples(ray.intersections[0].mObject, ray);177 }177 { 178 sampleContributions += 179 AddObjectSamples(ray.intersections[0].mObject, ray); 180 } 178 181 } 179 182 } … … 181 184 { 182 185 if (ray.leaves.size()) { 183 sampleContributions += AddNodeSamples(object, ray); 186 if (!reverseRay) 187 sampleContributions += AddNodeSamples(object, ray); 184 188 185 189 if (ray.intersections.size()) { … … 274 278 // to the mesh 275 279 rays++; 276 edgeSamplesContributions += CastRay(object, ray );280 edgeSamplesContributions += CastRay(object, ray, false); 277 281 } 278 282 } 279 283 return edgeSamplesContributions; 284 } 285 286 KdNode * 287 SamplingPreprocessor::GetNodeToSample(Intersectable *object) 288 { 289 int pvsSize = object->mKdPvs.GetSize(); 290 KdNode *nodeToSample = NULL; 291 292 bool samplePvsBoundary = false; 293 if (pvsSize && samplePvsBoundary) { 294 // this samples the nodes from the boundary of the current PVS 295 // mail all nodes from the pvs 296 Intersectable::NewMail(); 297 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 298 299 for (; i != object->mKdPvs.mEntries.end(); i++) { 300 KdNode *node = (*i).first; 301 node->Mail(); 302 } 303 304 int maxTries = 2*pvsSize; 305 Debug << "Finding random neighbour" << endl; 306 for (int tries = 0; tries < 10; tries++) { 307 int index = RandomValue(0, pvsSize - 1); 308 KdPvsData data; 309 KdNode *node; 310 object->mKdPvs.GetData(index, node, data); 311 nodeToSample = mKdTree->FindRandomNeighbor(node, true); 312 if (nodeToSample) 313 break; 314 } 315 } else { 316 // just pickup a random node 317 // nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point)); 318 nodeToSample = mKdTree->GetRandomLeaf(); 319 } 320 return nodeToSample; 321 } 322 323 void 324 SamplingPreprocessor::VerifyVisibility(Intersectable *object) 325 { 326 // mail all nodes from the pvs 327 Intersectable::NewMail(); 328 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 329 for (; i != object->mKdPvs.mEntries.end(); i++) { 330 KdNode *node = (*i).first; 331 node->Mail(); 332 } 333 Debug << "Get all neighbours from PVS" << endl; 334 vector<KdNode *> invisibleNeighbors; 335 // get all neighbors of all PVS nodes 336 i = object->mKdPvs.mEntries.begin(); 337 for (; i != object->mKdPvs.mEntries.end(); i++) { 338 KdNode *node = (*i).first; 339 mKdTree->FindNeighbors(node, invisibleNeighbors, true); 340 AxisAlignedBox3 box = object->GetBox(); 341 for (int j=0; j < invisibleNeighbors.size(); j++) { 342 int visibility = ComputeBoxVisibility(mSceneGraph, 343 mKdTree, 344 box, 345 mKdTree->GetBox(invisibleNeighbors[j]), 346 1e-6f); 347 // exit(0); 348 } 349 // now rank all the neighbors according to probability that a new 350 // sample creates some contribution 351 } 280 352 } 281 353 … … 312 384 Real maxTime = 0; 313 385 int maxTimeIdx = 0; 314 386 int reverseSamples = 0; 315 387 bool collectSamplesForBsp = 316 388 (mViewCellsType == BSP_VIEW_CELLS) && … … 329 401 pvsSize = object->mKdPvs.GetSize(); 330 402 331 if (0 && pvsSize) {332 // mail all nodes from the pvs333 Intersectable::NewMail();334 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin();335 336 for (; i != object->mKdPvs.mEntries.end(); i++) {337 KdNode *node = (*i).first;338 node->Mail();339 }340 341 int maxTries = 2*pvsSize;342 Debug << "Finding random neighbour" << endl;343 for (int tries = 0; tries < 10; tries++) {344 index = RandomValue(0, pvsSize - 1);345 KdPvsData data;346 KdNode *node;347 object->mKdPvs.GetData(index, node, data);348 nodeToSample = mKdTree->FindRandomNeighbor(node, true);349 if (nodeToSample)350 break;351 }352 }353 403 354 404 if (0 && pvsSize && mPass == 1000 ) { 355 // mail all nodes from the pvs 356 Intersectable::NewMail(); 357 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 358 for (; i != object->mKdPvs.mEntries.end(); i++) { 359 KdNode *node = (*i).first; 360 node->Mail(); 361 } 362 Debug << "Get all neighbours from PVS" << endl; 363 vector<KdNode *> invisibleNeighbors; 364 // get all neighbors of all PVS nodes 365 i = object->mKdPvs.mEntries.begin(); 366 for (; i != object->mKdPvs.mEntries.end(); i++) { 367 KdNode *node = (*i).first; 368 mKdTree->FindNeighbors(node, invisibleNeighbors, true); 369 AxisAlignedBox3 box = object->GetBox(); 370 for (int j=0; j < invisibleNeighbors.size(); j++) { 371 int visibility = ComputeBoxVisibility(mSceneGraph, 372 mKdTree, 373 box, 374 mKdTree->GetBox(invisibleNeighbors[j]), 375 1e-6f); 376 // exit(0); 377 } 378 // now rank all the neighbors according to probability that a new 379 // sample creates some contribution 380 } 405 VerifyVisibility(object); 381 406 } 382 407 … … 389 414 bool debug = false; //(object->GetId() >= 2199); 390 415 if (viewcellSample) { 391 nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point)); 416 //mKdTree->GetRandomLeaf(Plane3(normal, point)); 417 418 for (int k=0; k < mSamplesPerPass; k++) { 419 bool reverseSample = false; 392 420 393 for (int k=0; k < mSamplesPerPass; k++) { 421 nodeToSample = GetNodeToSample(object); 422 394 423 if (nodeToSample) { 395 int maxTries = 5; 396 397 for (int tries = 0; tries < maxTries; tries++) { 398 direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 399 400 if (DotProd(direction, normal) > Limits::Small) 401 break; 424 Vector3 pointToSample = mKdTree->GetBox(nodeToSample).GetRandomPoint(); 425 if (object->GetRandomVisibleSurfacePoint( point, normal, pointToSample, 5 )) { 426 direction = pointToSample - point; 427 } else { 428 reverseSamples++; 429 reverseSample = true; 430 direction = point - pointToSample; 431 point = pointToSample; 402 432 } 403 if (tries == maxTries)404 direction = UniformRandomVector(normal);405 406 if (debug) {407 cout<<408 "normal "<<normal<<endl<<409 "tries "<<tries<<endl<<410 "dir="<<direction<<endl;411 }412 413 433 } 414 434 else { … … 418 438 // construct a ray 419 439 SetupRay(ray, point, direction, Ray::LOCAL_RAY); 420 421 sampleContributions = CastRay(object, ray );440 441 sampleContributions = CastRay(object, ray, reverseSample); 422 442 423 443 //-- CORR matt: put block inside loop … … 541 561 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 542 562 << pvsSize/(float)objects.size() << endl 543 << "avg ray contrib=" << avgRayContrib << endl; 544 563 << "avg ray contrib=" << avgRayContrib << endl 564 << "reverse samples [%]" << reverseSamples/(float)passSamples*100.0f << endl; 565 545 566 mStats << 546 567 "#Pass\n" <<mPass<<endl<< -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r349 r354 49 49 50 50 int 51 CastRay(Intersectable *object, Ray &ray); 51 CastRay(Intersectable *object, Ray &ray, const bool reverseSample); 52 53 KdNode * 54 GetNodeToSample(Intersectable *object); 55 void 56 VerifyVisibility(Intersectable *object); 52 57 53 58 int -
trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.cpp
r349 r354 1 1 #include "Matrix4x4.h" 2 2 #include "Vector3.h" 3 #include "Halton.h" 3 4 4 5 float Vector3::sDistTolerance = 0.002f; … … 195 196 UniformRandomVector(const Vector3 &normal) 196 197 { 197 float r1 = RandomValue(0.0f, 1.0f); 198 float r2 = RandomValue(0.0f, 1.0f); 199 float cosTheta = 1.0f - r1; 198 // float r1 = RandomValue(0.0f, 1.0f); 199 // float r2 = RandomValue(0.0f, 1.0f); 200 float r1, r2; 201 202 halton2.GetNext(r1, r2); 203 204 205 float cosTheta = 1.0f - r1; 200 206 float sinTheta = sqrt(1 - sqr(cosTheta)); 201 207 float fi = 2.0f*M_PI*r2; -
trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
r340 r354 23 23 24 24 # Input 25 HEADERS += 25 HEADERS += Halton.h 26 26 27 27 … … 33 33 Exporter.cpp Camera.cpp X3dParser.cpp MeshKdTree.cpp Pvs.cpp \ 34 34 MutualVisibility.cpp Triangle3.cpp Rectangle3.cpp Plane3.cpp Polygon3.cpp \ 35 ViewCell.cpp ViewCellBsp.cpp 35 ViewCell.cpp ViewCellBsp.cpp Halton.cpp 36 36 37 37
Note: See TracChangeset
for help on using the changeset viewer.