Changeset 1528 for GTP/trunk/Lib
- Timestamp:
- 09/28/06 18:51:43 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1524 r1528 23 23 static vector<VizStruct> vizContainer; 24 24 25 GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0) 25 GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0), mCastPassSamples(0), mCastTotalSamples(0) 26 26 { 27 27 Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples); … … 57 57 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 58 58 if (!HandleRay(newRay)) 59 { 59 60 delete newRay; 61 } 60 62 61 63 return true; … … 68 70 bool GvsPreprocessor::HandleRay(VssRay *vssRay) 69 71 { 70 const int oldContri = vssRay->mPvsContribution;71 72 mViewCellsManager->ComputeSampleContribution(*vssRay, true, false); 72 73 // some pvs contribution for this ray? 74 if ((vssRay->mPvsContribution - oldContri) > 0) 75 { 76 //cout << "h"; 73 74 // some pvs contribution for this ray? 75 if (vssRay->mPvsContribution > 0) 76 { 77 cout << " h " << mCastPassSamples << " " << mSamplesPerPass << " " << mTotalSamples << " q: " << mRayQueue.size() << endl; 78 79 cout << "error!!! " << vssRay->mPvsContribution << " " << vssRay->mTerminationObject << endl; 80 77 81 mRayQueue.push(vssRay); 78 82 mVssRays.push_back(new VssRay(*vssRay)); 83 ++ mCastPassSamples; 79 84 return true; 80 85 } … … 99 104 const Vector3 c = hitTriangle.mVertices[index] - hitTriangle.mVertices[indexL]; 100 105 101 const float len = Magnitude(a);106 const float len = 1;//Magnitude(a); 102 107 103 108 const Vector3 dir1 = Normalize(CrossProd(a, b)); //N((pi-xp)×(pi+1- pi)); … … 172 177 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin); 173 178 174 VssRay *newRay = mRayCaster->CastSingleRay(sray .mOrigin, sray.mDirection, 1, mViewSpaceBox);179 VssRay *newRay = mRayCaster->CastSingleRay(sray, mViewSpaceBox); 175 180 176 181 if (!newRay) return 0; … … 217 222 { 218 223 const Vector3 rayDir = (*vit) - currentRay.GetOrigin(); 219 simpleRays.push_back(SimpleRay(currentRay.GetOrigin(), rayDir)); 224 SimpleRay sr(currentRay.GetOrigin(), rayDir); 225 simpleRays.AddRay(sr); 226 227 //cout << "here244 " << (*vit) << " " << currentRay.GetOrigin() << endl; 228 //cout << " sr" << sr.mOrigin << sr.mDirection << endl; 220 229 } 221 230 … … 228 237 // cast rays to triangle vertices and determine visibility 229 238 VssRayContainer vssRays; 230 CastRays(simpleRays, vssRays, false); 231 cout << "here211 " << simpleRays.size() << " " << vssRays.size() << endl; 239 CastRays(simpleRays, vssRays, false, false); 240 //CastRays(simpleRays, vssRays, true, true); 241 //cout << "here211 " << simpleRays.size() << " " << vssRays.size() << endl; 232 242 // add to ray queue 233 243 EnqueueRays(vssRays); 244 234 245 const int n = (int)enlargedTriangle.size(); 235 246 236 #if 1247 #if 0 237 248 // recursivly subdivide each edge 238 249 for (int i = 0; i < n; ++ i) … … 303 314 SimpleRayContainer simpleRays; 304 315 GenerateRays(numSamples, sampleType, simpleRays); 305 316 317 //cout << "here909 " << simpleRays.size() << endl; 318 //for (int i = 0; i < simpleRays.size(); ++ i) 319 // cout << "here544 " << simpleRays[i].mOrigin << endl; 306 320 // generate vss rays 307 321 VssRayContainer samples; … … 310 324 // add to ray queue 311 325 EnqueueRays(samples); 312 326 //for (int i = 0; i < samples.size(); ++ i) 327 // cout << "here1544 " << samples[i]->mOrigin << endl; 313 328 Debug << "generated " << numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 314 329 … … 331 346 int GvsPreprocessor::Pass() 332 347 { 333 int castSamples = 0;334 348 const int mSampleType = 0; 335 while (castSamples < mSamplesPerPass) 336 { 349 // reset samples 350 mCastPassSamples = 0; 351 352 while (mCastPassSamples < mSamplesPerPass) 353 { 337 354 // Ray queue empty => 338 355 // cast a number of uniform samples to fill ray Queue 339 356 CastInitialSamples(mInitialSamples, mSampleType); 340 341 const int gvsSamples = ProcessQueue(); 342 #if 0 343 castSamples += gvsSamples; 344 #else 345 castSamples += mInitialSamples; 346 #endif 347 cout << "\nround finished, cast " << castSamples << " of " << mSamplesPerPass << endl; 348 } 349 350 return castSamples; 357 ProcessQueue(); 358 359 cout << "\nround finished, cast " << mCastPassSamples << " of " << mSamplesPerPass << endl; 360 } 361 362 mCastTotalSamples += mCastPassSamples; 363 364 return mCastPassSamples; 351 365 } 352 366 … … 361 375 VssRay *ray = mRayQueue.top(); 362 376 mRayQueue.pop(); 363 377 364 378 castSamples += AdaptiveBorderSampling(*ray); 365 366 379 delete ray; 367 380 } 368 381 369 382 return castSamples; 370 383 } … … 385 398 } 386 399 387 int castSamples = 0; 388 389 while (castSamples < mTotalSamples) 390 { 391 const int passSamples = Pass(); 392 castSamples += passSamples; 393 400 while (mCastTotalSamples < mTotalSamples) 401 { 402 Pass(); 403 394 404 //////// 395 405 //-- stats 396 406 cout << "+"; 397 cout << "\nsamples cast " << passSamples << " (=" << castSamples << " of " << mTotalSamples << ")" << endl;407 cout << "\nsamples cast " << mCastPassSamples << " (=" << mCastTotalSamples << " of " << mTotalSamples << ")" << endl; 398 408 //mVssRays.PrintStatistics(mStats); 399 409 mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl 400 << "#TotalSamples\n" << castSamples << endl;410 << "#TotalSamples\n" << mCastTotalSamples << endl; 401 411 402 412 mViewCellsManager->PrintPvsStatistics(mStats); -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r1522 r1528 129 129 float mThreshold; 130 130 VssRayContainer mVssRays; 131 int mCastPassSamples; 132 int mCastTotalSamples; 131 133 }; 132 134 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
r1521 r1528 32 32 33 33 int IntelRayCaster::CastRay( 34 const Vector3 &viewPoint, 35 const Vector3 &direction, 36 const float probability, 34 const SimpleRay &simpleRay, 37 35 VssRayContainer &vssRays, 38 36 const AxisAlignedBox3 &box, 39 const bool castDoubleRay 37 const bool castDoubleRay, 38 const bool pruneInvalidRays 40 39 ) 41 40 { … … 44 43 int hits = 0; 45 44 int hittriangle; 46 Vector3 pointA, pointB; 47 Vector3 normalA, normalB; 48 Intersectable *objectA = NULL, *objectB = NULL; 45 Intersection hitA, hitB; 46 49 47 float dist; 50 48 double normal[3]; 51 49 52 50 hittriangle = mlrtaIntersectAS( 53 & viewPoint.x,54 & direction.x,51 &simpleRay.mOrigin.x, 52 &simpleRay.mDirection.x, 55 53 normal, 56 54 dist); … … 60 58 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 61 59 else { 62 objectA= mPreprocessor.mFaceParents[hittriangle].mObject;63 normalA= Vector3(normal[0], normal[1], normal[2]);60 hitA.mObject = mPreprocessor.mFaceParents[hittriangle].mObject; 61 hitA.mNormal = Vector3(normal[0], normal[1], normal[2]); 64 62 // Get the normal of that face 65 63 // Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 66 64 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 67 65 //-rays[index+i].mDirection; // $$ temporary 68 pointA = viewPoint + direction*dist;66 hitA.mPoint = simpleRay.Extrap(dist); 69 67 } 70 68 } … … 72 70 if (castDoubleRay) 73 71 { 74 Vector3 dir = - direction;72 Vector3 dir = -simpleRay.mDirection; 75 73 hittriangle = mlrtaIntersectAS( 76 & viewPoint.x,74 &simpleRay.mOrigin.x, 77 75 &dir.x, 78 76 normal, … … 84 82 else 85 83 { 86 objectB= mPreprocessor.mFaceParents[hittriangle].mObject;87 normalB= Vector3(normal[0], normal[1], normal[2]);84 hitB.mObject = mPreprocessor.mFaceParents[hittriangle].mObject; 85 hitB.mNormal = Vector3(normal[0], normal[1], normal[2]); 88 86 // Get the normal of that face 89 87 // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 90 88 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 91 89 //-rays[index+i].mDirection; // $$ temporary 92 pointB = viewPoint + dir * dist;90 hitB.mPoint = simpleRay.Extrap(dist); 93 91 } 94 92 } … … 96 94 97 95 return ProcessRay( 98 viewPoint, 99 direction, 100 objectA, pointA, normalA, 101 objectB, pointB, normalB, 102 probability, 96 simpleRay, 97 hitA, 98 hitB, 103 99 vssRays, 104 box 100 box, 101 castDoubleRay, 102 pruneInvalidRays 105 103 ); 106 104 } … … 112 110 VssRayContainer &vssRays, 113 111 const AxisAlignedBox3 &sbox, 114 const bool castDoubleRay) 112 const bool castDoubleRay, 113 const bool pruneInvalidRays) 115 114 { 116 115 int i; … … 160 159 for (i=0; i < num; i++) 161 160 { 162 Intersectable *objectA = NULL, *objectB = NULL; 163 Vector3 pointA, pointB; 164 Vector3 normalA, normalB; 165 161 Intersection hitA, hitB; 162 166 163 if (forward_hit_triangles[i] != -1 ) { 167 164 if (forward_hit_triangles[i] >= mPreprocessor.mFaceParents.size()) 168 165 cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl; 169 166 else { 170 objectA= mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject;167 hitA.mObject = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject; 171 168 // Get the normal of that face 172 normalA = objectA->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);169 hitA.mNormal = hitA.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex); 173 170 //-rays[index+i].mDirection; // $$ temporary 174 pointA= rays[index+i].Extrap(forward_dist[i]);171 hitA.mPoint = rays[index+i].Extrap(forward_dist[i]); 175 172 } 176 173 } … … 180 177 cerr<<"Warning: triangle index out of range! "<<backward_hit_triangles[i]<<endl; 181 178 else { 182 objectB= mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject;183 normalB = objectB->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);179 hitB.mObject = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject; 180 hitB.mNormal = hitB.mObject->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex); 184 181 185 182 // normalB = rays[index+i].mDirection; // $$ temporary 186 pointB= rays[index+i].Extrap(-backward_dist[i]);183 hitB.mPoint = rays[index+i].Extrap(-backward_dist[i]); 187 184 } 188 185 } 189 186 190 187 ProcessRay( 191 rays[index+i].mOrigin, 192 rays[index+i].mDirection, 193 objectA, pointA, normalA, 194 objectB, pointB, normalB, 195 rays[index+i].mPdf, 188 rays[index + i], 189 hitA, 190 hitB, 196 191 vssRays, 197 sbox 192 sbox, 193 castDoubleRay, 194 pruneInvalidRays 198 195 ); 199 196 } -
GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h
r1520 r1528 18 18 struct VssRayContainer; 19 19 class Preprocessor; 20 20 struct SimpleRay; 21 21 22 22 /** This class provides an interface for ray casting. … … 36 36 37 37 virtual int CastRay( 38 const Vector3 &viewPoint, 39 const Vector3 &direction, 40 const float probability, 38 const SimpleRay &simpleRay, 41 39 VssRayContainer &vssRays, 42 40 const AxisAlignedBox3 &box, 43 const bool castDoubleRay 41 const bool castDoubleRay, 42 const bool pruneInvalidRays = true 44 43 ); 45 44 … … 49 48 VssRayContainer &vssRays, 50 49 const AxisAlignedBox3 &sbox, 51 const bool castDoubleRay 50 const bool castDoubleRay, 51 const bool pruneInvalidRays = true 52 52 ); 53 53 -
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
r1521 r1528 21 21 22 22 23 int InternalRayCaster::CastRay(const Vector3 &viewPoint, 24 const Vector3 &direction, 25 const float probability, 23 int InternalRayCaster::CastRay(const SimpleRay &simpleRay, 26 24 VssRayContainer &vssRays, 27 25 const AxisAlignedBox3 &box, 28 const bool castDoubleRay 26 const bool castDoubleRay, 27 const bool pruneInvalidRays 29 28 ) 30 29 { … … 32 31 int hits = 0; 33 32 static Ray ray; 34 Intersectable *objectA = NULL, *objectB = NULL; 35 Vector3 pointA, pointB; 36 Vector3 normalA, normalB; 37 38 #if 0 39 AxisAlignedBox3 sbox = box; 40 sbox.Enlarge(Vector3(-Limits::Small)); 41 if (!sbox.IsInside(viewPoint)) 42 return 0; 43 #endif 44 45 mPreprocessor.SetupRay(ray, viewPoint, direction); 33 Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin); 34 35 mPreprocessor.SetupRay(ray, simpleRay.mOrigin, simpleRay.mDirection); 46 36 ray.mFlags &= ~Ray::CULL_BACKFACES; 47 37 48 38 if (mKdTree->CastRay(ray)) 49 39 { 50 objectA = ray.intersections[0].mObject; 51 pointA = ray.Extrap(ray.intersections[0].mT); 52 normalA = ray.intersections[0].mNormal; 40 hitA.mObject = ray.intersections[0].mObject; 41 hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 42 hitA.mNormal = ray.intersections[0].mNormal; 43 // cout << "here91 " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 53 44 } 54 45 55 mPreprocessor.SetupRay(ray, viewPoint, -direction);46 mPreprocessor.SetupRay(ray, simpleRay.mOrigin, -simpleRay.mDirection); 56 47 ray.mFlags &= ~Ray::CULL_BACKFACES; 57 48 58 49 if (castDoubleRay && mKdTree->CastRay(ray)) 59 50 { 60 objectB= ray.intersections[0].mObject;61 pointB= ray.Extrap(ray.intersections[0].mT);62 normalB= ray.intersections[0].mNormal;51 hitB.mObject = ray.intersections[0].mObject; 52 hitB.mPoint = ray.Extrap(ray.intersections[0].mT); 53 hitB.mNormal = ray.intersections[0].mNormal; 63 54 } 64 55 65 56 return ProcessRay( 66 viewPoint,67 direction,68 objectA, pointA, normalA,69 objectB, pointB, normalB,70 probability,71 vssRays,72 box57 simpleRay, 58 hitA, 59 hitB, 60 vssRays, 61 box, 62 castDoubleRay, 63 pruneInvalidRays 73 64 ); 74 65 } … … 79 70 VssRayContainer &vssRays, 80 71 const AxisAlignedBox3 &sbox, 81 const bool castDoubleRays) 72 const bool castDoubleRays, 73 const bool pruneInvalidRays) 82 74 { 83 75 const int num = 16; … … 90 82 for (int i=index; i < index + num; i++) 91 83 { 92 CastRay(rays[i].mOrigin, 93 rays[i].mDirection, 94 rays[i].mPdf, 95 vssRays, 96 sbox, 97 castDoubleRays); 84 CastRay(rays[i], vssRays, sbox, castDoubleRays, pruneInvalidRays); 98 85 } 99 86 -
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h
r1520 r1528 20 20 struct VssRayContainer; 21 21 class Preprocessor; 22 22 struct SimpleRay; 23 23 24 24 … … 36 36 37 37 virtual int CastRay( 38 const Vector3 &viewPoint, 39 const Vector3 &direction, 40 const float probability, 38 const SimpleRay &simpleRay, 41 39 VssRayContainer &vssRays, 42 40 const AxisAlignedBox3 &box, 43 const bool castDoubleRay 41 const bool castDoubleRay, 42 const bool pruneInvalidRays = true 44 43 ); 45 44 … … 49 48 VssRayContainer &vssRays, 50 49 const AxisAlignedBox3 &sbox, 51 const bool castDoubleRay 50 const bool castDoubleRay, 51 const bool pruneInvalidRays = true 52 52 ); 53 53 -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
r1444 r1528 1386 1386 if (!vdata) 1387 1387 { 1388 Debug << "error! !" << endl;1388 Debug << "error! should not come here" << endl; 1389 1389 continue; 1390 1390 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1524 r1528 846 846 SimpleRayContainer &rays, 847 847 VssRayContainer &vssRays, 848 const bool castDoubleRays 848 const bool castDoubleRays, 849 const bool pruneInvalidRays 849 850 ) 850 851 { … … 860 861 vssRays, 861 862 mViewCellsManager->GetViewSpaceBox(), 862 castDoubleRays); 863 castDoubleRays, 864 pruneInvalidRays); 863 865 i += 16; 864 866 } … … 866 868 { 867 869 mRayCaster->CastRay( 868 rays[i].mOrigin, 869 rays[i].mDirection, 870 rays[i].mPdf, 870 rays[i], 871 871 vssRays, 872 872 mViewCellsManager->GetViewSpaceBox(), 873 castDoubleRays); 873 castDoubleRays, 874 pruneInvalidRays); 874 875 i ++; 875 876 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1521 r1528 138 138 virtual void CastRays(SimpleRayContainer &rays, 139 139 VssRayContainer &vssRays, 140 const bool castDoubleRays); 140 const bool castDoubleRays, 141 const bool pruneInvalidRays = true); 141 142 142 143 /** Returns a view cells manager of the given name. -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r1189 r1528 392 392 bool 393 393 Pvs<T, S>::GetSampleContribution(T sample, 394 395 394 const float pdf, 395 float &contribution) 396 396 { 397 397 S *data = Find(sample); -
GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
r1473 r1528 35 35 enum {FRONT, BACK, BACK_FRONT, FRONT_BACK, COINCIDENT}; 36 36 37 struct Intersection { 38 // the point of intersection 39 float mT; 40 41 // the normal of the intersection 42 Vector3 mNormal; 43 44 // can be either mesh or a viewcell 45 Intersectable *mObject; 46 47 // the face of the intersectable 48 int mFace; 49 50 Intersection(const float t, 51 const Vector3 &normal, 52 Intersectable *object, 53 const int face):mT(t), 54 mNormal(normal), 55 mObject(object), mFace(face) {} 56 57 Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0) {} 58 59 bool operator<( 60 const Intersection &b) const { 61 62 return 63 mT 64 < 65 b.mT; 66 } 67 37 struct Intersection 38 { 39 /// the point of intersection 40 float mT; 41 42 /// the normal of the intersection 43 Vector3 mNormal; 44 45 /// can be either mesh or a viewcell 46 Intersectable *mObject; 47 48 /// the face of the intersectable 49 int mFace; 50 51 Intersection(const float t, 52 const Vector3 &normal, 53 Intersectable *object, 54 const int face): 55 mT(t), mNormal(normal), mObject(object), mFace(face) 56 {} 57 58 Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0) 59 {} 60 61 bool operator<(const Intersection &b) const 62 { 63 return mT < b.mT; 64 } 68 65 }; 69 66 … … 318 315 mOrigin(o), mDirection(d), mPdf(p) {} 319 316 320 Vector3 Extrap(const float t) {317 Vector3 Extrap(const float t) const { 321 318 return mOrigin + mDirection * t; 322 319 } … … 326 323 { 327 324 public: 328 329 325 330 326 SimpleRayContainer():vector<SimpleRay>() {} 331 327 -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1522 r1528 22 22 23 23 24 VssRay *RayCaster::CastSingleRay(const Vector3 &viewPoint, 25 const Vector3 &direction, 26 const float probability, 24 VssRay *RayCaster::CastSingleRay(const SimpleRay &simpleRay, 27 25 const AxisAlignedBox3 &box) 28 26 { 29 27 VssRayContainer rays; 30 CastRay( viewPoint, direction, probability, rays, box, false);28 CastRay(simpleRay, rays, box, false); 31 29 32 30 if (!rays.empty()) … … 37 35 38 36 39 int RayCaster::ProcessRay(const Vector3 &viewPoint, 40 const Vector3 &direction, 41 Intersectable *objectA, 42 Vector3 &pointA, 43 const Vector3 &normalA, 44 Intersectable *objectB, 45 Vector3 &pointB, 46 const Vector3 &normalB, 47 const float probability, 37 /** Checks if ray is valid, (e.g., not in empty view space or outside the view space) 38 */ 39 bool RayCaster::ValidateRay(const Vector3 &origin, 40 const Vector3 &direction, 41 const AxisAlignedBox3 &box, 42 Intersection &hit) 43 { 44 if (!hit.mObject) 45 { 46 // compute intersection with the scene bounding box 47 static Ray ray; 48 mPreprocessor.SetupRay(ray, origin, direction); 49 50 float tmin, tmax; 51 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) 52 { 53 hit.mPoint = ray.Extrap(tmax); 54 } 55 else 56 { 57 return false; 58 } 59 } 60 else if (mPreprocessor.mDetectEmptyViewSpace) 61 { 62 if (DotProd(hit.mNormal, direction) >= 0) 63 { 64 hit.mObject = NULL; 65 return false; 66 } 67 } 68 69 return true; 70 } 71 72 73 int RayCaster::ProcessRay(const SimpleRay &simpleRay, 74 Intersection &hitA, 75 Intersection &hitB, 48 76 VssRayContainer &vssRays, 49 const AxisAlignedBox3 &box 50 ) 77 const AxisAlignedBox3 &box, 78 const bool castDoubleRay, 79 const bool pruneInvalidRays) 51 80 { 52 81 int hits = 0; 82 53 83 #if DEBUG_RAYCAST 54 84 Debug<<"PR "; 55 85 #endif 56 if (objectA == NULL && objectB == NULL) 86 87 if (pruneInvalidRays) 88 { 89 if (!hitA.mObject && !hitB.mObject) 90 { 91 return 0; 92 } 93 94 // inside test for bounding box 95 // enlarge box slightly so the view point fits for sure 96 AxisAlignedBox3 sbox = box; 97 sbox.Enlarge(Vector3(-Limits::Small)); 98 99 if (!sbox.IsInside(simpleRay.mOrigin)) 100 { 101 return 0; 102 } 103 } 104 // cout << "here81 " << hitA.mObject << endl; 105 const bool validA = 106 ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 107 if (!validA && pruneInvalidRays) 108 { 57 109 return 0; 58 59 AxisAlignedBox3 sbox = box;60 sbox.Enlarge(Vector3(-Limits::Small));61 62 if (!sbox.IsInside(viewPoint))63 return 0;64 65 if (objectA == NULL) {66 // compute intersection with the scene bounding box67 static Ray ray;68 mPreprocessor.SetupRay(ray, viewPoint, direction);69 70 float tmin, tmax;71 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)72 pointA = ray.Extrap(tmax);73 else74 return 0;75 } else {76 if (mPreprocessor.mDetectEmptyViewSpace)77 if (DotProd(normalA, direction) >= 0) {78 // discard the sample79 return 0;80 }81 110 } 82 111 83 if (objectB == NULL) { 84 // compute intersection with the scene bounding box 85 static Ray ray; 86 mPreprocessor.SetupRay(ray, viewPoint, -direction); 112 const bool validB = castDoubleRay && 113 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 87 114 88 float tmin, tmax; 89 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 90 pointB = ray.Extrap(tmax); 91 else 92 return 0; 93 } else { 94 if (mPreprocessor.mDetectEmptyViewSpace) 95 if (DotProd(normalB, direction) <= 0) { 96 // discard the sample 97 return 0; 98 } 115 if (!validB && pruneInvalidRays) 116 { 117 return 0; 99 118 } 100 119 101 VssRay *vssRay = NULL; 102 bool validSample = (objectA != objectB); 103 if (validSample) { 104 if (objectA) { 105 vssRay = new VssRay( 106 pointB, 107 pointA, 108 objectB, 109 objectA, 120 const bool validSample = !pruneInvalidRays || (hitA.mObject != hitB.mObject); 121 122 if (validSample) 123 { 124 if (!pruneInvalidRays || hitA.mObject) 125 { 126 VssRay *vssRay = new VssRay( 127 hitB.mPoint, 128 hitA.mPoint, 129 hitB.mObject, 130 hitA.mObject, 110 131 mPreprocessor.mPass, 111 probability132 simpleRay.mPdf 112 133 ); 113 134 114 135 vssRays.push_back(vssRay); 115 hits ++; 136 ++ hits; 137 //cout << "here70 vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 116 138 } 117 139 118 if (objectB) { 119 vssRay = new VssRay( 120 pointA, 121 pointB, 122 objectA, 123 objectB, 140 if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 141 { 142 VssRay *vssRay = new VssRay( 143 hitA.mPoint, 144 hitB.mPoint, 145 hitA.mObject, 146 hitB.mObject, 124 147 mPreprocessor.mPass, 125 probability148 simpleRay.mPdf 126 149 ); 127 150 128 151 vssRays.push_back(vssRay); 129 hits ++; 152 ++ hits; 153 //cout << "here71 vssray 2: " << *vssRay << endl; 130 154 } 131 155 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r1521 r1528 4 4 #include "Containers.h" 5 5 #include <string> 6 #include "Vector3.h" 7 6 8 using namespace std; 7 9 … … 14 16 class SimpleRayContainer; 15 17 class AxisAlignedBox3; 16 class Vector3;18 //class Vector3; 17 19 struct VssRayContainer; 18 20 class Preprocessor; 21 struct SimpleRay; 22 19 23 20 24 /** This class provides an interface for ray casting. … … 22 26 class RayCaster 23 27 { 28 24 29 public: 25 30 … … 38 43 */ 39 44 VssRay *CastSingleRay( 40 const Vector3 &viewPoint, 41 const Vector3 &direction, 42 const float probability, 43 const AxisAlignedBox3 &box 45 const SimpleRay &simpleRay, 46 const AxisAlignedBox3 &box 44 47 ); 45 48 46 49 virtual int CastRay( 47 const Vector3 &viewPoint, 48 const Vector3 &direction, 49 const float probability, 50 const SimpleRay &simpleRay, 50 51 VssRayContainer &vssRays, 51 52 const AxisAlignedBox3 &box, 52 const bool castDoubleRay 53 const bool castDoubleRay, 54 const bool pruneInvalidRays = true 53 55 ) = 0; 54 56 … … 58 60 VssRayContainer &vssRays, 59 61 const AxisAlignedBox3 &sbox, 60 const bool castDoubleRay 62 const bool castDoubleRay, 63 const bool pruneInvalidRays = true 61 64 ) = 0; 62 65 63 66 64 67 protected: 68 struct Intersection 69 { 70 Intersection(): mObject(NULL), mFaceId(0) 71 {} 72 73 Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f): 74 mPoint(p), mNormal(n), mObject(o), mFaceId(f) 75 {} 76 77 Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0) 78 {} 79 Vector3 mPoint; 80 Vector3 mNormal; 81 Intersectable *mObject; 82 int mFaceId; 83 }; 65 84 66 85 int ProcessRay( 67 const Vector3 &viewPoint, 68 const Vector3 &direction, 69 Intersectable *objectA, 70 Vector3 &pointA, 71 const Vector3 &normalA, 72 Intersectable *objectB, 73 Vector3 &pointB, 74 const Vector3 &normalB, 75 const float probability, 86 const SimpleRay &ray, 87 Intersection &hitA, 88 Intersection &hitB, 76 89 VssRayContainer &vssRays, 77 const AxisAlignedBox3 &box 90 const AxisAlignedBox3 &box, 91 const bool castDoubleRay, 92 const bool pruneInvalidRays = true 78 93 ); 79 94 95 /** Checks if ray is valid. 96 I.e., the ray is in valid view space. 97 @note: clamps the ray to valid view space. 98 */ 99 bool ValidateRay(const Vector3 &origin, 100 const Vector3 &direction, 101 const AxisAlignedBox3 &box, 102 Intersection &hit); 80 103 81 104 const Preprocessor &mPreprocessor; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1522 r1528 1318 1318 1319 1319 float sum = 0.0f; 1320 1321 1320 VssRayContainer::const_iterator it, it_end = rays.end(); 1322 1321 … … 1831 1830 ViewCell *viewcell = *it; 1832 1831 1833 if (viewcell->GetValid()) // tests if view cell is in valid view space1832 if (viewcell->GetValid()) // tests if view cell is in valid view space 1834 1833 { 1835 1834 float contribution; … … 1838 1837 { 1839 1838 if (viewcell->GetPvs().GetSampleContribution( 1840 ray.mTerminationObject,1841 ray.mPdf,1842 contribution))1839 ray.mTerminationObject, 1840 ray.mPdf, 1841 contribution)) 1843 1842 { 1844 1843 ++ ray.mPvsContribution; … … 1865 1864 } 1866 1865 1867 // if addrays is true,sampled entities are stored in the pvs1866 // if true, the sampled entities are stored in the pvs 1868 1867 if (addRays) 1869 1868 { … … 1876 1875 // if view point is valid, add new object to the pvs 1877 1876 if (ray.mTerminationObject) 1878 { 1877 {cout <<"here22" << endl; 1879 1878 viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf); 1880 1879 } … … 5483 5482 { 5484 5483 // todo: maybe not correct for kd node pvs 5485 if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 5486 ray.mPdf, contribution)) 5484 Intersectable *obj = mHierarchyManager->GetIntersectable(ray, true); 5485 if (viewcell->GetPvs().GetSampleContribution(obj, 5486 ray.mPdf, 5487 contribution)) 5487 5488 { 5488 5489 ++ ray.mPvsContribution; -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
r1420 r1528 97 97 98 98 if (rays.empty()) 99 { 99 100 return false; 100 101 stream << "Shape {" << endl; 102 stream << "appearance Appearance {" << endl; 103 stream << "material Material {" << endl; 104 stream << "diffuseColor " << color.r << " " << color.g << " " << color.b << endl; 105 stream << "}" << endl; // end material 106 stream << "}" << endl; // end appearance 107 108 stream << "geometry IndexedLineSet { coordIndex [" << endl; 109 110 int index = 0; 111 VssRayContainer::const_iterator ri = rays.begin(); 112 113 for (; ri != rays.end(); ++ ri) 114 { 115 stream << index << " " << index + 1 << " -1\n"; 116 index += 2 ; 117 } 118 119 stream << "]" << endl; 120 121 stream << "coord Coordinate { point [" << endl; 122 123 for (ri = rays.begin(); ri != rays.end(); ++ ri) 124 { 125 const Vector3 a = (*ri)->GetOrigin(); 126 const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir()); 127 101 } 102 103 stream << "Shape {" << endl; 104 stream << "appearance Appearance {" << endl; 105 stream << "material Material {" << endl; 106 stream << "diffuseColor " << color.r << " " << color.g << " " << color.b << endl; 107 stream << "}" << endl; // end material 108 stream << "}" << endl; // end appearance 109 110 stream << "geometry IndexedLineSet { coordIndex [" << endl; 111 112 int index = 0; 113 VssRayContainer::const_iterator ri = rays.begin(); 114 115 for (; ri != rays.end(); ++ ri) 116 { 117 stream << index << " " << index + 1 << " -1\n"; 118 index += 2 ; 119 } 120 121 stream << "]" << endl; 122 123 stream << "coord Coordinate { point [" << endl; 124 125 for (ri = rays.begin(); ri != rays.end(); ++ ri) 126 { 127 const Vector3 a = (*ri)->GetOrigin(); 128 const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir()); 129 130 // cout << "here45 origin " << a << " termination: " << b << endl; 128 131 #if _DEBUG 129 130 131 132 133 134 135 136 137 138 139 140 141 142 132 bool isnan = false; 133 if (!a.CheckValidity()) 134 { 135 cout << "error a"<<endl; 136 isnan = true; 137 } 138 139 if (!b.CheckValidity()) 140 { 141 cout << "error b"<<endl; 142 isnan = true; 143 } 144 if (isnan) 145 continue; 143 146 #endif 144 145 146 147 148 149 150 151 152 153 154 147 stream << a.x << " " << a.y << " " << a.z << " ,"; 148 stream << b.x << " " << b.y << " " << b.z << " ,\n"; 149 } 150 151 stream << "]" << endl; 152 stream << "}" << endl; 153 stream << "}" << endl; 154 stream << "}" << endl; 155 //stream << "}" << endl; 156 157 return true; 155 158 } 156 159 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1521 r1528 485 485 486 486 mViewCellsManager->GetViewPoint(viewpoint); 487 Vector3 direction = GetDirection(viewpoint, &mViewSpaceBox); 488 489 sampleContributions = mRayCaster->CastRay(viewpoint, direction, 1, mVssRays, mViewSpaceBox, true); 487 const Vector3 direction = GetDirection(viewpoint, &mViewSpaceBox); 488 489 const SimpleRay sray(viewpoint, direction); 490 sampleContributions = mRayCaster->CastRay(sray, mVssRays, mViewSpaceBox, true); 490 491 491 492 if (sampleContributions) { … … 615 616 } 616 617 617 for (int i=0; i < rays.size(); i++) 618 { 619 mRayCaster->CastRay(rays[i].mOrigin, rays[i].mDirection, 1, vssRays, mViewSpaceBox, true); 620 } 621 618 CastRays(rays, vssRays, true); 622 619 vssTree->AddRays(vssRays); 623 620 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp
r1259 r1528 7 7 int 8 8 VssRay::mailID = 0; 9 10 11 VssRay::VssRay( 12 const Vector3 &origin, 13 const Vector3 &termination, 14 Intersectable *originObject, 15 Intersectable *terminationObject, 16 const int pass, 17 const float pdf 18 ): 19 mMailbox(-1), 20 mOrigin(origin), 21 mTermination(termination), 22 mOriginObject(originObject), 23 mTerminationObject(terminationObject), 24 mRefCount(0), 25 mFlags(0), 26 mPass(pass), 27 mViewCells(0), 28 mWeightedPvsContribution(0), 29 mPdf(pdf), 30 mTerminationNode(NULL), 31 mOriginNode(NULL), 32 mPvsContribution(0) 33 { 34 Precompute(); 35 } 36 37 38 VssRay::VssRay(const Ray &ray): 39 mRefCount(0), 40 mFlags(0), 41 mMailbox(-1), 42 mOriginObject(ray.sourceObject.mObject), 43 mPass(0), 44 mViewCells(0), 45 mPdf(1.0f), 46 mTerminationNode(NULL), 47 mOriginNode(NULL), 48 mPvsContribution(0) 49 { 50 if (ray.sourceObject.mObject) 51 mOrigin = ray.Extrap(ray.sourceObject.mT); 52 else 53 mOrigin = ray.GetLoc(); 54 55 //Debug << "origin: " << mOrigin << endl; 56 if (!ray.intersections.empty()) 57 { 58 mTermination = ray.Extrap(ray.intersections[0].mT); 59 mTerminationObject = ray.intersections[0].mObject; 60 } 61 else 62 { 63 mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity 64 mTerminationObject = NULL; 65 } 66 67 Precompute(); 68 } 69 70 71 void VssRay::Precompute() 72 { 73 mFlags = 0; 74 Vector3 dir = GetDir(); 75 76 #define BIDIRECTIONAL_RAY 0 77 #if BIDIRECTIONAL_RAY 78 if (dir.y < 0) { 79 // swap objects and poits 80 swap(mOriginObject, mTerminationObject); 81 swap(mOrigin, mTermination); 82 dir = -dir; 83 } 84 #endif 85 if (dir.x > 0.0f) mFlags |= FPosDirX; 86 if (dir.y > 0.0f) mFlags |= FPosDirY; 87 if (dir.z > 0.0f) mFlags |= FPosDirZ; 88 89 mInvSize = 1.0f/Magnitude(GetDir()); 90 } 9 91 10 92 … … 265 347 266 348 267 void VssRay::GetSampleData(const bool isTermination, 268 Vector3 &pt, 269 Intersectable **obj, 270 KdNode **node) const 271 { 272 if (isTermination) 273 { 274 pt = mTermination; 275 *obj = mTerminationObject; 276 *node = mTerminationNode; 277 } 278 else 279 { 280 pt = mOrigin; 281 *obj = mOriginObject; 282 *node = mOriginNode; 283 } 284 } 285 286 287 } 349 350 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
r1259 r1528 14 14 class KdNode; 15 15 16 16 17 class VssRay { 17 18 public: 18 // various flags 19 20 // various flags 19 21 enum { 20 22 FPosDirX = 1, // the direction of ray in X-axis is positive … … 87 89 const int pass = 0, 88 90 const float pdf = 1.0f 89 ): 90 mMailbox(-1), 91 mOrigin(origin), 92 mTermination(termination), 93 mOriginObject(originObject), 94 mTerminationObject(terminationObject), 95 mRefCount(0), 96 mFlags(0), 97 mPass(pass), 98 mViewCells(0), 99 mWeightedPvsContribution(0), 100 mPdf(pdf), 101 mTerminationNode(NULL), 102 mOriginNode(NULL) 103 { 104 Precompute(); 105 } 106 107 VssRay(const Ray &ray): 108 mRefCount(0), 109 mFlags(0), 110 mMailbox(-1), 111 mOriginObject(ray.sourceObject.mObject), 112 mPass(0), 113 mViewCells(0), 114 mPdf(1.0f), 115 mTerminationNode(NULL), 116 mOriginNode(NULL) 117 { 118 if (ray.sourceObject.mObject) 119 mOrigin = ray.Extrap(ray.sourceObject.mT); 120 else 121 mOrigin = ray.GetLoc(); 122 123 //Debug << "origin: " << mOrigin << endl; 124 if (!ray.intersections.empty()) 125 { 126 mTermination = ray.Extrap(ray.intersections[0].mT); 127 mTerminationObject = ray.intersections[0].mObject; 128 } 129 else 130 { 131 mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity 132 mTerminationObject = NULL; 133 } 134 135 Precompute(); 136 } 137 138 void Precompute() { 139 mFlags = 0; 140 Vector3 dir = GetDir(); 141 142 #define BIDIRECTIONAL_RAY 0 143 #if BIDIRECTIONAL_RAY 144 if (dir.y < 0) { 145 // swap objects and poits 146 swap(mOriginObject, mTerminationObject); 147 swap(mOrigin, mTermination); 148 dir = -dir; 149 } 150 #endif 151 if (dir.x > 0.0f) mFlags |= FPosDirX; 152 if (dir.y > 0.0f) mFlags |= FPosDirY; 153 if (dir.z > 0.0f) mFlags |= FPosDirZ; 154 155 mInvSize = 1.0f/Magnitude(GetDir()); 156 } 91 ); 92 93 VssRay(const Ray &ray); 94 95 96 void Precompute(); 157 97 158 98 void Mail() { mMailbox = mailID; } … … 283 223 } 284 224 225 /** Returns the data sampled on either the ray origin or termination. 226 */ 285 227 void GetSampleData( 286 228 const bool isTerminaton, … … 292 234 293 235 }; 236 237 inline void VssRay::GetSampleData(const bool isTermination, 238 Vector3 &pt, 239 Intersectable **obj, 240 KdNode **node) const 241 { 242 if (isTermination) 243 { 244 pt = mTermination; 245 *obj = mTerminationObject; 246 *node = mTerminationNode; 247 } 248 else 249 { 250 pt = mOrigin; 251 *obj = mOriginObject; 252 *node = mOriginNode; 253 } 254 } 294 255 295 256 void … … 318 279 // For sorting rays 319 280 // -------------------------------------------------------------- 320 struct 281 struct SortableEntry 321 282 { 322 283 enum EType {
Note: See TracChangeset
for help on using the changeset viewer.