- Timestamp:
- 01/03/07 01:36:35 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1928 r1932 46 46 Debug << "eps: " << mEps << endl; 47 47 48 m Stats.open("gvspreprocessor.log");48 mGvsStats.open("gvspreprocessor.log"); 49 49 } 50 50 … … 54 54 const VssRay &oldRay) 55 55 { 56 const float dist = Magnitude(oldRay.GetDir());57 const float newDist = Magnitude(currentRay.GetDir());58 59 #if 0 60 if ((dist - newDist) > mThresHold)61 #else 62 // rather take relative distance63 if (( dist / newDist) > mThreshold)64 #endif 65 {56 // the predicted hitpoint: we expect to hit the same mesh again 57 const Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 58 59 const float predictedLen = Magnitude(predictedHit - currentRay.mOrigin); 60 const float len = Magnitude(currentRay.mTermination - currentRay.mOrigin); 61 62 // distance large => this is likely to be a discontinuity 63 if ((predictedLen - len) > mThreshold) 64 { 65 cout << "d"; 66 66 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 67 67 68 // set flag for visualization 68 69 newRay->mFlags |= VssRay::ReverseSample; 69 70 70 // ray is not pushed into the queue=> can delete ray71 // if ray is not further processed => can delete ray 71 72 if (!HandleRay(newRay)) 72 73 delete newRay; … … 81 82 bool GvsPreprocessor::HandleRay(VssRay *vssRay) 82 83 { 84 // compute the contribution to the view cells 83 85 const bool storeRaysForViz = true; 84 mViewCellsManager->ComputeSampleContribution(*vssRay, true, storeRaysForViz); 85 86 mViewCellsManager->ComputeSampleContribution(*vssRay, 87 true, 88 storeRaysForViz); 89 86 90 // some pvs contribution for this ray? 87 91 if (vssRay->mPvsContribution > 0) … … 92 96 if (storeRaysForViz) 93 97 { 98 VssRay *nray = new VssRay(*vssRay); 99 nray->mFlags = vssRay->mFlags; 100 101 // store ray in contributing view cell 94 102 ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end(); 95 103 for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit) 96 { 97 VssRay *nray = new VssRay(*vssRay); 104 { 98 105 (*vit)->GetOrCreateRays()->push_back(nray); 99 106 } 100 107 } 108 101 109 //mVssRays.push_back(new VssRay(*vssRay)); 102 110 ++ mSampleContriPerPass; … … 111 119 /** Creates 3 new vertices for triangle vertex with specified index. 112 120 */ 113 static void CreateNewVertices(VertexContainer &vertices, 114 const Triangle3 &hitTriangle, 115 const VssRay &ray, 116 const int index, 117 const float eps) 121 void GvsPreprocessor::CreateDisplacedVertices(VertexContainer &vertices, 122 const Triangle3 &hitTriangle, 123 const VssRay &ray, 124 const int index) const 118 125 { 119 126 const int indexU = (index + 1) % 3; … … 125 132 126 133 const float len = Magnitude(a); 127 134 128 135 const Vector3 dir1 = Normalize(CrossProd(a, b)); //N((pi-xp)×(pi+1- pi)); 129 136 const Vector3 dir2 = Normalize(CrossProd(a, c)); // N((pi-xp)×(pi- pi-1)) … … 133 140 // compute the new three hit points 134 141 // pi, i + 1: pi+ e·|pi-xp|·di, j 135 const Vector3 pt1 = hitTriangle.mVertices[index] + eps * len * dir1;142 const Vector3 pt1 = hitTriangle.mVertices[index] + mEps * len * dir1; 136 143 // pi, i - 1: pi+ e·|pi-xp|·di, j 137 const Vector3 pt2 = hitTriangle.mVertices[index] + eps * len * dir2;144 const Vector3 pt2 = hitTriangle.mVertices[index] + mEps * len * dir2; 138 145 // pi, i: pi+ e·|pi-xp|·di, j 139 const Vector3 pt3 = hitTriangle.mVertices[index] + eps * len * dir3;146 const Vector3 pt3 = hitTriangle.mVertices[index] + mEps * len * dir3; 140 147 141 148 vertices.push_back(pt2); … … 147 154 void GvsPreprocessor::EnlargeTriangle(VertexContainer &vertices, 148 155 const Triangle3 &hitTriangle, 149 const VssRay &ray) 150 { 151 CreateNewVertices(vertices, hitTriangle, ray, 0, mEps); 152 CreateNewVertices(vertices, hitTriangle, ray, 1, mEps); 153 CreateNewVertices(vertices, hitTriangle, ray, 2, mEps); 154 } 155 156 157 static Vector3 CalcPredictedHitPoint(const VssRay &newRay, 158 const Triangle3 &hitTriangle, 159 const VssRay &oldRay) 160 { 156 const VssRay &ray) const 157 { 158 CreateDisplacedVertices(vertices, hitTriangle, ray, 0); 159 CreateDisplacedVertices(vertices, hitTriangle, ray, 1); 160 CreateDisplacedVertices(vertices, hitTriangle, ray, 2); 161 } 162 163 164 Vector3 GvsPreprocessor::CalcPredictedHitPoint(const VssRay &newRay, 165 const Triangle3 &hitTriangle, 166 const VssRay &oldRay) const 167 { 168 // find the intersection of the plane induced by the 169 // hit triangle with the new ray 161 170 Plane3 plane(hitTriangle.GetNormal(), hitTriangle.mVertices[0]); 162 171 … … 177 186 const Vector3 &p1, 178 187 const Vector3 &p2, 179 const VssRay & x,180 const VssRay & y,188 const VssRay &ray1, 189 const VssRay &ray2, 181 190 const VssRay &oldRay) 182 191 { 183 // the predicted hitpoint expects to hit the same mesh again 184 const Vector3 predictedHitX = CalcPredictedHitPoint(x, hitTriangle, oldRay); 185 const Vector3 predictedHitY = CalcPredictedHitPoint(y, hitTriangle, oldRay); 186 187 CheckDiscontinuity(x, hitTriangle, oldRay); 188 CheckDiscontinuity(y, hitTriangle, oldRay); 189 190 if (EqualVisibility(x, y)) 192 CheckDiscontinuity(ray1, hitTriangle, oldRay); 193 CheckDiscontinuity(ray2, hitTriangle, oldRay); 194 195 if (EqualVisibility(ray1, ray2) || (Magnitude(p1 - p2) <= mEps)) 191 196 { 192 197 return 0; … … 194 199 else 195 200 { 196 cout << "s";201 // the new subdivision point 197 202 const Vector3 p = (p1 + p2) * 0.5f; 203 204 //cout << "tobj " << ray1.mTerminationObject << " " << ray2.mTerminationObject << " " << p1 << " " << p2 << endl; 205 //cout << "term " << ray1.mTermination << " " << ray2.mTermination << endl; 206 207 // cast ray into the new point 198 208 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f); 199 209 200 // cast ray into the new subdivision point 201 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), false); 202 210 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox()); 211 203 212 if (!newRay) return 0; 204 213 … … 209 218 210 219 // subdivide further 211 const int s1 = SubdivideEdge(hitTriangle, p1, p, x, *newRay, oldRay); 212 const int s2 = SubdivideEdge(hitTriangle, p, p2, *newRay, y, oldRay); 213 220 const int samples1 = SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay); 221 const int samples2 = SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay); 222 223 // this ray will not be further processed 214 224 if (!enqueued) 215 225 delete newRay; 216 226 217 return s 1 +s2 + 1;227 return samples1 + samples2 + 1; 218 228 } 219 229 } … … 222 232 int GvsPreprocessor::AdaptiveBorderSampling(const VssRay ¤tRay) 223 233 { 224 cout << "a";225 234 Intersectable *tObj = currentRay.mTerminationObject; 226 235 Triangle3 hitTriangle; … … 245 254 simpleRays.reserve(9); 246 255 256 //cout << "currentRay: " << currentRay.mOrigin << " dir: " << currentRay.GetDir() << endl; 257 247 258 VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end(); 248 259 … … 252 263 SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f); 253 264 simpleRays.AddRay(sr); 254 } 255 256 // visualize enlarged triangles 265 266 //cout << "new: " << sr.mOrigin << " dist: " << sr.mDirection << endl; 267 } 268 257 269 if (0) 258 270 { 271 // visualize enlarged triangles 259 272 VizStruct dummy; 260 273 dummy.enlargedTriangle = new Polygon3(enlargedTriangle); 261 274 dummy.originalTriangle = hitTriangle; 262 //dummy.ray = new VssRay(currentRay);263 275 vizContainer.push_back(dummy); 264 276 } … … 266 278 // cast rays to triangle vertices and determine visibility 267 279 VssRayContainer vssRays; 268 CastRays(simpleRays, vssRays, false, false); 280 281 // don't cast double rays as we need only the forward rays 282 const bool castDoubleRays = false; 283 // cannot prune invalid rays because we have to 284 // compare adjacent rays. 285 const bool pruneInvalidRays = false; 286 287 CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays); 269 288 270 289 // set flags … … 275 294 } 276 295 277 // add to ray queue296 // handle rays 278 297 EnqueueRays(vssRays); 279 298 … … 282 301 283 302 // recursivly subdivide each edge 284 for (int i = 0; 1 && (i < n); ++ i) 285 { 286 castRays += SubdivideEdge( 287 hitTriangle, 288 enlargedTriangle[i], 289 enlargedTriangle[(i + 1) % n], 290 *vssRays[i], 291 *vssRays[(i + 1) % n], 292 currentRay); 303 for (int i = 0; i < n; ++ i) 304 { 305 castRays += SubdivideEdge(hitTriangle, 306 enlargedTriangle[i], 307 enlargedTriangle[(i + 1) % n], 308 *vssRays[i], 309 *vssRays[(i + 1) % n], 310 currentRay); 293 311 } 294 312 295 313 mBorderSamples += castRays; 314 296 315 return castRays; 297 316 } 298 317 299 318 300 static Vector3GetPassingPoint(const VssRay ¤tRay,301 302 const VssRay &oldRay)303 { 304 // intersect triangle plane with plane spanned by current samples319 Vector3 GvsPreprocessor::GetPassingPoint(const VssRay ¤tRay, 320 const Triangle3 &hitTriangle, 321 const VssRay &oldRay) const 322 { 323 //-- intersect triangle plane with plane spanned by current samples 305 324 Plane3 plane(currentRay.GetOrigin(), currentRay.GetTermination(), oldRay.GetTermination()); 306 325 Plane3 triPlane(hitTriangle.GetNormal(), hitTriangle.mVertices[0]); … … 310 329 // Evaluate new hitpoint just outside the triangle 311 330 const float factor = 0.95f; 312 float t = triPlane.FindT(intersectLine);331 const float t = triPlane.FindT(intersectLine); 313 332 const Vector3 newPoint = intersectLine.mOrigin + t * factor * intersectLine.mDirection; 314 333 … … 329 348 const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay); 330 349 331 //-- Construct the mutated ray with xnew, dir = predicted(x)- pnew332 //-- as direction vector350 //-- Construct the mutated ray with xnew, 351 //-- dir = predicted(x)- pnew as direction vector 333 352 const Vector3 newDir = predicted - newPoint ; 353 334 354 // take xnew,p = intersect(viewcell, line(pnew, predicted(x)) as origin ? 335 355 // difficult to say!! … … 438 458 else if (0) 439 459 { 440 //-- load view cells from file441 460 //-- test successful view cells loading by exporting them again 442 461 VssRayContainer dummies; … … 451 470 //////// 452 471 //-- stats 472 453 473 cout << "\nPass " << mPass << " #samples: " << castSamples << " of " << mTotalSamples << endl; 454 455 //mVssRays.PrintStatistics(mStats); 456 mStats 474 //mVssRays.PrintStatistics(mGvsStats); 475 mGvsStats 457 476 << "#Pass\n" << mPass << endl 458 477 << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl … … 464 483 << "#GvsRuns\n" << mGvsPass << endl; 465 484 466 mViewCellsManager->PrintPvsStatistics(m Stats);485 mViewCellsManager->PrintPvsStatistics(mGvsStats); 467 486 468 487 char str[64]; sprintf(str, "tmp/pass%04d-", mPass); … … 489 508 } 490 509 491 cout << 2 * castSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl;510 cout << "cast " << 2 * castSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl; 492 511 Visualize(); 493 512 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r1771 r1932 105 105 void EnlargeTriangle(VertexContainer &vertices, 106 106 const Triangle3 &hitTriangle, 107 const VssRay &ray) ;107 const VssRay &ray) const; 108 108 109 int SubdivideEdge( 110 const Triangle3 &hitTriangle, 111 const Vector3 &p1, 112 const Vector3 &p2, 113 const VssRay &x, 114 const VssRay &y, 115 const VssRay &oldRay); 109 int SubdivideEdge(const Triangle3 &hitTriangle, 110 const Vector3 &p1, 111 const Vector3 &p2, 112 const VssRay &ray1, 113 const VssRay &ray2, 114 const VssRay &oldRay); 116 115 117 116 void Visualize(); 117 118 void CreateDisplacedVertices(VertexContainer &vertices, 119 const Triangle3 &hitTriangle, 120 const VssRay &ray, 121 const int index) const; 122 123 Vector3 CalcPredictedHitPoint(const VssRay &newRay, 124 const Triangle3 &hitTriangle, 125 const VssRay &oldRay) const; 126 127 128 Vector3 GetPassingPoint(const VssRay ¤tRay, 129 const Triangle3 &hitTriangle, 130 const VssRay &oldRay) const; 118 131 119 132 ////////////////////// … … 134 147 /////////// 135 148 // stats 149 136 150 int mSampleContriPerPass; 137 151 int mTotalSampleContri; … … 139 153 int mBorderSamples; 140 154 int mGvsPass; 155 156 ofstream mGvsStats; 141 157 }; 142 158 -
GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h
r1842 r1932 21 21 const Vector3 &b, 22 22 const Vector3 &c 23 );23 ); 24 24 25 25 Plane3(const Vector3 &normal, … … 33 33 } 34 34 35 float Distance(const Vector3 &v) const { 36 return DotProd(v, mNormal) + mD; 35 float Distance(const Vector3 &v) const 36 { 37 return DotProd(v, mNormal) + mD; 37 38 } 38 39 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1931 r1932 1133 1133 ) 1134 1134 { 1135 1135 const long t1 = GetTime(); 1136 1136 1137 1137 for (int i = 0; i < (int)rays.size();) … … 1149 1149 } 1150 1150 else 1151 1151 { 1152 1152 mRayCaster->CastRay( 1153 1153 rays[i], … … 1156 1156 castDoubleRays, 1157 1157 pruneInvalidRays); 1158 i ++;1159 1158 ++ i; 1159 } 1160 1160 1161 1161 if (rays.size() > 10000 && i % 10000 == 0) … … 1163 1163 } 1164 1164 1165 if (rays.size() > 10000) { 1165 if (rays.size() > 10000) 1166 { 1166 1167 cout<<endl; 1167 1168 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1931 r1932 142 142 143 143 virtual void CastRays(SimpleRayContainer &rays, 144 VssRayContainer &vssRays,145 const bool castDoubleRays,146 const bool pruneInvalidRays = true);144 VssRayContainer &vssRays, 145 const bool castDoubleRays, 146 const bool pruneInvalidRays = true); 147 147 148 148 /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */ -
GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer/QtGlRenderer.h
r1926 r1932 100 100 void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays); 101 101 102 float 103 GetPixelError(int &pvsSize); 102 float GetPixelError(int &pvsSize); 104 103 105 104 int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const; … … 109 108 110 109 void SetupProjectionForViewPoint(const Vector3 &viewPoint, 111 const Beam &beam,112 Intersectable *sourceObject);110 const Beam &beam, 111 Intersectable *sourceObject); 113 112 114 113 … … 296 295 } 297 296 298 // matt: dummy f ile297 // matt: dummy function, must be provided by bittner 299 298 void RenderRenderCost() {} 300 299 -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1900 r1932 24 24 25 25 VssRay *RayCaster::CastRay(const SimpleRay &simpleRay, 26 const AxisAlignedBox3 &box ,27 const bool castDoubleRay)26 const AxisAlignedBox3 &box) 27 //const bool castDoubleRay) 28 28 { 29 VssRayContainer rays; 30 CastRay(simpleRay, rays, box, castDoubleRay); 31 32 if (!rays.empty()) 33 return rays.back(); 34 else 35 return NULL; 29 // note: make no sense otherwise 30 const bool castDoubleRay = false; 31 VssRayContainer rays; 32 CastRay(simpleRay, rays, box, castDoubleRay); 33 34 if (!rays.empty()) 35 return rays.back(); 36 else 37 return NULL; 36 38 } 37 39 … … 45 47 Intersection &hit) 46 48 { 47 if (!hit.mObject) { 48 // compute intersection with the scene bounding box 49 if (!hit.mObject) 50 { 51 // compute intersection with the scene bounding box 49 52 #if EXACT_BOX_CLIPPING 50 static Ray ray; 51 mPreprocessor.SetupRay(ray, origin, direction); 52 53 float tmin, tmax; 54 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) { 55 hit.mPoint = ray.Extrap(tmax); 53 static Ray ray; 54 mPreprocessor.SetupRay(ray, origin, direction); 55 56 float tmin, tmax; 57 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax)) 58 { 59 hit.mPoint = ray.Extrap(tmax); 60 } 61 else 62 { 63 // cout<<" invalid hp "<<tmin<<" "<<tmax<<endl; 64 // cout<<" box "<<box<<endl; 65 // cout<<" origin "<<origin<<endl; 66 // cout<<" direction "<<direction<<endl; 67 // cout<< "inv dir"<<ray.GetInvDir()<<endl; 68 return false; 69 } 70 #else 71 hit.mPoint = origin + direction * Magnitude(box.Diagonal()); 72 #endif 56 73 } 57 else { 58 // cout<<" invalid hp "<<tmin<<" "<<tmax<<endl; 59 // cout<<" box "<<box<<endl; 60 // cout<<" origin "<<origin<<endl; 61 // cout<<" direction "<<direction<<endl; 62 // cout<< "inv dir"<<ray.GetInvDir()<<endl; 63 return false; 74 else 75 { 76 if (mPreprocessor.mDetectEmptyViewSpace) 77 { 78 if (DotProd(hit.mNormal, direction) >= -Limits::Small) 79 { 80 hit.mObject = NULL; 81 return false; 82 } 83 } 64 84 } 65 #else 66 hit.mPoint = origin + direction*Magnitude(box.Diagonal()); 67 #endif 68 } 69 else 70 if (mPreprocessor.mDetectEmptyViewSpace) { 71 if (DotProd(hit.mNormal, direction) >= -Limits::Small) { 72 hit.mObject = NULL; 73 return false; 74 } 75 } 76 77 return true; 85 86 return true; 78 87 } 79 88 … … 98 107 // return 0; 99 108 100 if (pruneInvalidRays) { 101 if (!hitA.mObject && !hitB.mObject) { 102 return 0; 103 } 109 if (pruneInvalidRays) 110 { 111 if (!hitA.mObject && !hitB.mObject) 112 { 113 return 0; 114 } 104 115 } 105 116 … … 107 118 ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); 108 119 109 const bool validB = castDoubleRay && 110 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 120 // note: should we check for backward valitidy also for single rays? 121 const bool validB = //castDoubleRay && 122 ValidateRay(simpleRay.mOrigin, -simpleRay.mDirection, box, hitB); 111 123 112 124 #if DEBUG_RAYCAST … … 115 127 116 128 // reset both contributions 117 if (!validA || !validB) { 118 if (pruneInvalidRays) 119 return 0; 120 // reset both contributions of this ray 121 hitA.mObject = NULL; 122 hitB.mObject = NULL; 129 if (!validA || !validB) 130 { 131 if (pruneInvalidRays) 132 return 0; 133 134 // reset both contributions of this ray 135 hitA.mObject = NULL; 136 hitB.mObject = NULL; 123 137 } 124 138 125 126 const bool validSample = true;127 139 // 8.11. 2007 JB 128 140 // degenerate rays checked by geometrical constraint... … … 133 145 #endif 134 146 135 if (validSample) { 136 if (!pruneInvalidRays || hitA.mObject) { 137 VssRay *vssRay = new VssRay( 138 hitB.mPoint, 147 if (!pruneInvalidRays || hitA.mObject) 148 { 149 VssRay *vssRay = new VssRay(hitB.mPoint, 139 150 hitA.mPoint, 140 151 hitB.mObject, 141 152 hitA.mObject, 142 153 mPreprocessor.mPass, 143 simpleRay.mPdf 144 ); 145 154 simpleRay.mPdf); 155 146 156 if (validA) 147 vssRay->mFlags |= VssRay::Valid; 157 vssRay->mFlags |= VssRay::Valid; 158 148 159 vssRay->mDistribution = simpleRay.mDistribution; 149 160 vssRays.push_back(vssRay); 150 161 ++ hits; 151 162 //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 152 153 163 } 164 154 165 #if DEBUG_RAYCAST 155 166 Debug<<"PR3"<<flush; 156 167 #endif 157 168 158 if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 159 { 160 VssRay *vssRay = new VssRay( 161 hitA.mPoint, 162 hitB.mPoint, 163 hitA.mObject, 164 hitB.mObject, 165 mPreprocessor.mPass, 166 simpleRay.mPdf 167 ); 168 if (validB) 169 if (castDoubleRay && (!pruneInvalidRays || hitB.mObject)) 170 { 171 VssRay *vssRay = new VssRay(hitA.mPoint, 172 hitB.mPoint, 173 hitA.mObject, 174 hitB.mObject, 175 mPreprocessor.mPass, 176 simpleRay.mPdf); 177 178 if (validB) 169 179 vssRay->mFlags |= VssRay::Valid; 170 171 vssRay->mDistribution = simpleRay.mDistribution; 172 vssRays.push_back(vssRay); 173 ++ hits; 174 //cout << "vssray 2: " << *vssRay << endl; 175 } 180 181 vssRay->mDistribution = simpleRay.mDistribution; 182 vssRays.push_back(vssRay); 183 ++ hits; 184 //cout << "vssray 2: " << *vssRay << endl; 176 185 } 177 186 -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
r1824 r1932 43 43 @returns ray or NULL if invalid 44 44 */ 45 VssRay *CastRay( 46 const SimpleRay &simpleRay, 47 const AxisAlignedBox3 &box, 48 const bool castDoubleRay 49 ); 45 VssRay *CastRay(const SimpleRay &simpleRay, 46 const AxisAlignedBox3 &box); 47 //const bool castDoubleRay); 50 48 51 virtual int CastRay( 52 const SimpleRay &simpleRay, 53 VssRayContainer &vssRays, 54 const AxisAlignedBox3 &box, 55 const bool castDoubleRay, 56 const bool pruneInvalidRays = true 57 ) = 0; 49 virtual int CastRay(const SimpleRay &simpleRay, 50 VssRayContainer &vssRays, 51 const AxisAlignedBox3 &box, 52 const bool castDoubleRay, 53 const bool pruneInvalidRays = true 54 ) = 0; 58 55 59 virtual void CastRays16( 60 const int i, 61 SimpleRayContainer &rays, 62 VssRayContainer &vssRays, 63 const AxisAlignedBox3 &sbox, 64 const bool castDoubleRay, 65 const bool pruneInvalidRays = true 66 ) = 0; 56 virtual void CastRays16(const int i, 57 SimpleRayContainer &rays, 58 VssRayContainer &vssRays, 59 const AxisAlignedBox3 &sbox, 60 const bool castDoubleRay, 61 const bool pruneInvalidRays = true 62 ) = 0; 67 63 68 64 … … 86 82 87 83 88 int ProcessRay( 89 const SimpleRay &ray, 90 Intersection &hitA, 91 Intersection &hitB, 92 VssRayContainer &vssRays, 93 const AxisAlignedBox3 &box, 94 const bool castDoubleRay, 95 const bool pruneInvalidRays = true 96 ); 84 int ProcessRay(const SimpleRay &ray, 85 Intersection &hitA, 86 Intersection &hitB, 87 VssRayContainer &vssRays, 88 const AxisAlignedBox3 &box, 89 const bool castDoubleRay, 90 const bool pruneInvalidRays = true); 97 91 98 92 /** Checks if ray is valid. -
GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp
r1867 r1932 185 185 } 186 186 187 } 187 188 bool Triangle3::IntersectPlane(const Plane3 &plane, 189 Vector3 &intersectA, 190 Vector3 &intersectB) const 191 { 192 int side[3]; 193 194 // compute distance from plane 195 for (int i = 0; i < 3; ++ i) 196 { 197 side[i] = plane.Side(mVertices[i], Limits::Small); 198 } 199 200 ///// 201 // no intersection => early exit 202 if (((side[0] > 0) && (side[1] > 0) && (side[2] > 0)) || 203 ((side[0] < 0) && (side[1] < 0) && (side[2] < 0))) 204 { 205 return false; 206 } 207 208 ///////////// 209 // at least 2 triangle vertices lie in plane => early exit 210 211 for (int i = 0; i < 3; ++ i) 212 { 213 if (!side[i] && !side[(i + 1) % 3]) 214 { 215 intersectA = mVertices[i]; 216 intersectB = mVertices[(i + 1) % 3]; 217 218 return true; 219 } 220 } 221 222 bool foundA = false; 223 224 // compute intersection points 225 for (int i = 0; i < 3; ++ i) 226 { 227 const int i_2 = (i + 1) % 3; 228 229 // intersection found 230 if ((side[i] >= 0) && (side[i_2] <= 0)) 231 { 232 const float t = plane.FindT(mVertices[i], mVertices[i_2]); 233 234 if (!foundA) 235 { 236 intersectA = mVertices[i] + t * (mVertices[i_2] - mVertices[i]); 237 foundA = true; 238 } 239 else 240 { 241 intersectB = mVertices[i] + t * (mVertices[i_2] - mVertices[i]); 242 return true; 243 } 244 } 245 } 246 247 cout << "warning! wrong triangle - plane intersection" << endl; 248 return false; // something went wrong! 249 } 250 251 252 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h
r1420 r1932 9 9 class AxisAlignedBox3; 10 10 class Ray; 11 11 class Plane3; 12 12 13 13 struct Triangle3 … … 32 32 int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const; 33 33 34 35 34 friend ostream& operator<< (ostream &s, const Triangle3 &A); 35 friend istream& operator>> (istream &s, Triangle3 &A); 36 36 37 38 39 37 /** Checks if this triangle is ill-defined. 38 */ 39 bool CheckValidity() const; 40 40 41 ////////////////////////////// 42 /// the triangle vertices 43 Vector3 mVertices[3]; 41 /** Intersects triangle with plane, returns intersection points 42 if intersection is happening. 43 44 @returns true if triangle intersects plane 45 */ 46 bool IntersectPlane(const Plane3 &plane, Vector3 &intersectA, Vector3 &intersectB) const; 47 48 /////////////////// 49 50 /// the triangle vertices 51 Vector3 mVertices[3]; 44 52 }; 45 53 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1931 r1932 34 34 #define AVG_RAY_CONTRIBUTIONS 1 35 35 #define CONTRIBUTION_RELATIVE_TO_PVS_SIZE 1 36 #define PVS_ADD_DIRTY 1 36 37 37 38 namespace GtpVisibilityPreprocessor { … … 82 83 83 84 84 int ViewCellsManager::CastPassSamples2(const int samplesPerPass, VssRayContainer &passSamples) const 85 int ViewCellsManager::CastPassSamples2(const int samplesPerPass, 86 VssRayContainer &passSamples) const 85 87 { 86 88 long startTime = GetTime(); … … 2153 2155 2154 2156 2155 2156 #define PVS_ADD_DIRTY 1 2157 inline static void AddSampleToPvs(ObjectPvs &pvs, 2158 Intersectable *obj, 2159 const float pdf) 2160 { 2161 #if PVS_ADD_DIRTY 2162 pvs.AddSampleDirtyCheck(obj, pdf); 2163 2164 if (pvs.RequiresResort()) 2165 { 2166 pvs.SimpleSort(); 2167 } 2168 #else 2169 pvs.AddSample(obj, pdf); 2170 #endif 2171 } 2172 2173 2174 void ViewCellsManager::ComputeViewCellContribution(ViewCell *viewCell, 2175 VssRay &ray, 2176 Intersectable *obj, 2177 const Vector3 &pt, 2178 const bool addRays) 2179 { 2180 // check if we are outside of view space 2181 if (!obj || !viewCell->GetValid()) 2182 return; 2183 2184 // if ray not outside of view space 2185 float relContribution = 0.0f; 2186 float absContribution = 0.0f; 2187 2188 // todo: maybe not correct for kd node pvs 2189 if (viewCell->GetPvs().GetSampleContribution(obj, 2190 ray.mPdf, 2191 relContribution)) 2192 { 2193 absContribution = 1.0f; 2194 } 2195 2196 // $$ clear the relative contribution as it is currently not correct anyway 2197 relContribution = 0.0f; 2198 2199 if (absContribution == 1.0f) 2200 { 2201 ++ ray.mPvsContribution; 2202 relContribution = 1.0f; 2203 2204 if (addRays) 2205 { 2206 AddSampleToPvs(viewCell->GetPvs(), obj, ray.mPdf); 2207 } 2208 2209 #if DIST_WEIGHTED_CONTRIBUTION 2210 // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 2211 // object-> a new contribution in the proximity of the viewcell has a larger weight! 2212 relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), pt); 2213 2214 #endif 2215 } 2216 2217 #if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 2218 ray.mRelativePvsContribution += relContribution; 2219 #else 2220 // recalculate relative contribution - use max of AbsContribution 2221 if (ray.mRelativePvsContribution < absContribution) 2222 ray.mRelativePvsContribution = absContribution; 2223 #endif 2224 } 2225 2157 2226 2158 2227 float … … 2164 2233 ray.mRelativePvsContribution = 0.0f; 2165 2234 2166 if ( ray.mTerminationObject==NULL)2235 if (!ray.mTerminationObject) 2167 2236 return 0.0f; 2168 2237 2169 ViewCellContainer view cells;2238 ViewCellContainer viewCells; 2170 2239 2171 2240 static Ray hray; … … 2183 2252 2184 2253 // traverse the view space subdivision 2185 CastLineSegment(origin, termination, view cells);2254 CastLineSegment(origin, termination, viewCells); 2186 2255 2187 2256 if (storeViewCells) 2188 2257 { 2189 2258 // copy viewcells memory efficiently 2190 ray.mViewCells.reserve(viewcells.size()); 2191 ray.mViewCells = viewcells; 2192 } 2193 2194 ViewCellContainer::const_iterator it = viewcells.begin(); 2195 2259 ray.mViewCells.reserve(viewCells.size()); 2260 ray.mViewCells = viewCells; 2261 } 2262 2263 // optain pvs entry (can be different from hit object) 2196 2264 Intersectable *terminationObj = GetIntersectable(ray, true); 2197 2265 2198 2199 for (; it != viewcells.end(); ++ it) 2200 { 2201 ViewCell *viewcell = *it; 2202 2203 if (viewcell->GetValid()) 2204 { 2205 // if ray not outside of view space 2206 float relContribution = 0.0f; 2207 float absContribution = 0.0f; 2208 2209 if (terminationObj) 2210 { 2211 // todo: maybe not correct for kd node pvs 2212 if (viewcell->GetPvs().GetSampleContribution( 2213 terminationObj, 2214 ray.mPdf, 2215 relContribution)) 2216 absContribution = 1.0f; 2217 2218 // $$ clear the relative contribution as it is currently not correct anyway 2219 relContribution = 0.0f; 2220 2221 if (absContribution == 1.0f) 2222 { 2223 ++ ray.mPvsContribution; 2224 relContribution = 1.0f; 2225 if (addRays) { 2226 #if PVS_ADD_DIRTY 2227 viewcell->GetPvs().AddSampleDirtyCheck(terminationObj, ray.mPdf); 2228 if (viewcell->GetPvs().RequiresResort()) { 2229 viewcell->GetPvs().SimpleSort(); 2230 } 2231 #else 2232 viewcell->GetPvs().AddSample(terminationObj, ray.mPdf); 2233 #endif 2234 } 2235 2236 #if CONTRIBUTION_RELATIVE_TO_PVS_SIZE 2237 relContribution /= viewcell->GetPvs().GetSize(); 2238 #endif 2239 2240 #if DIST_WEIGHTED_CONTRIBUTION 2241 // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 2242 // object-> a new contribution in the proximity of the viewcell has a larger weight! 2243 relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), 2244 ray.mTermination); 2245 2246 #endif 2247 } 2248 #if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 2249 ray.mRelativePvsContribution += relContribution; 2250 #else 2251 // recalculate relative contribution - use max of AbsContribution 2252 if (ray.mRelativePvsContribution < absContribution) 2253 ray.mRelativePvsContribution = absContribution; 2254 #endif 2255 } 2256 } 2266 ViewCellContainer::const_iterator it = viewCells.begin(); 2267 2268 for (; it != viewCells.end(); ++ it) 2269 { 2270 ComputeViewCellContribution(*it, 2271 ray, 2272 terminationObj, 2273 ray.mTermination, 2274 addRays); 2257 2275 } 2258 2276 2259 2277 #if AVG_RAY_CONTRIBUTIONS 2260 ray.mRelativePvsContribution /= viewcells.size();2278 ray.mRelativePvsContribution /= (float)viewCells.size(); 2261 2279 #endif 2262 2280 #if USE_RAY_LENGTH_AS_CONTRIBUTION 2263 2264 if (terminationObj)2265 c = ray.Length();2266 2267 2281 float c = 0.0f; 2282 if (obj) 2283 c = ray.Length(); 2284 ray.mRelativePvsContribution = ray.mPvsContribution = c; 2285 return c; 2268 2286 #else 2269 return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution +2270 (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution;2287 return ABS_CONTRIBUTION_WEIGHT * ray.mPvsContribution + 2288 (1.0f - ABS_CONTRIBUTION_WEIGHT) * ray.mRelativePvsContribution; 2271 2289 #endif 2272 2290 } 2273 2274 2291 2275 2292 … … 3544 3561 if (p < raysOut) 3545 3562 { 3546 if ( (*rit)->mFlags & VssRay::BorderSample)3563 if (0 && (*rit)->mFlags & VssRay::BorderSample) 3547 3564 { 3548 cout << "b";3549 3565 vcRays.push_back(*rit); 3550 3566 } 3551 3567 else if ((*rit)->mFlags & VssRay::ReverseSample) 3552 3568 { 3569 cout << "l"; 3553 3570 vcRays2.push_back(*rit); 3554 cout << "r";3555 3571 } 3556 else 3572 else if(0) 3557 3573 { 3558 cout << "n";3559 3574 vcRays3.push_back(*rit); 3560 3575 } … … 5448 5463 5449 5464 if (0) 5450 { // real meshes are constructed at this stage 5465 { 5466 // real meshes are constructed at this stage 5451 5467 cout << "finalizing view cells ... "; 5452 5468 FinalizeViewCells(true); 5453 5469 cout << "finished" << endl; 5454 5470 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1920 r1932 486 486 a mesh is created representing the geometry 487 487 @param bconverter a conversion routine working with the similarities of bounding 488 boxes: if there is a certain similarity of overlap between bounding boxes, two tested 488 boxes: if there is a certain similarity of overlap between 489 bounding boxes, two tested 489 490 candidate objects are considered to be the same objects 490 491 @returns the view cells manager if loading was successful, false otherwise … … 501 502 // TODO: write own visibiltiy filter class 502 503 void ApplyFilter(KdTree *kdTree, 503 504 504 const float viewSpaceFilterSize, 505 const float spatialFilterSize); 505 506 506 507 // new adaptive version of the filter 507 508 PvsFilterStatistics 508 509 ApplyFilter2(ViewCell *viewCell, 509 const bool useViewSpaceFilter, 510 const float filterSize, 511 ObjectPvs &pvs, 512 vector<AxisAlignedBox3> *filteredBoxes = NULL 513 ); 510 const bool useViewSpaceFilter, 511 const float filterSize, 512 ObjectPvs &pvs, 513 vector<AxisAlignedBox3> *filteredBoxes = NULL); 514 514 515 515 void ApplySpatialFilter(KdTree *kdTree, … … 560 560 VssRayContainer *visRays = NULL) = NULL; 561 561 562 562 563 563 void ViewCellsManager::ResetPvs(); 564 565 566 return mPreprocessor;567 568 569 570 mPreprocessor = p;571 572 573 564 565 Preprocessor *GetPreprocessor() const { 566 return mPreprocessor; 567 } 568 569 void SetPreprocessor(Preprocessor *p) { 570 mPreprocessor = p; 571 } 572 573 void UpdatePvsForEvaluation(); 574 574 575 575 protected: 576 577 void ComputeViewCellContribution(ViewCell *viewCell, 578 VssRay &ray, 579 Intersectable *obj, 580 const Vector3 &pt, 581 const bool addRays); 576 582 577 583 void MergeViewCellsRecursivly(ObjectPvs &pvs, … … 581 587 582 588 /** Intersects box with the tree and returns the number of intersected boxes. 583 589 @returns number of view cells found 584 590 */ 585 591 virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box, … … 618 624 */ 619 625 void ResetViewCells(); 620 626 621 627 /** Sets this view cell to active. 622 628 */ … … 626 632 */ 627 633 virtual void CollectViewCells() = 0; 628 634 629 635 /** Evaluates view cells statistics and stores it in 630 636 mViewCellsStatistics. 631 637 */ 632 638 void EvaluateViewCellsStats(); 633 639 634 640 635 641 /////////////////////// 636 642 //-- helper functions for view cell visualization … … 641 647 const AxisAlignedBox3 *box, 642 648 const bool colorCode, 643 const AxisAlignedPlane *clipPlane 644 ) const; 649 const AxisAlignedPlane *clipPlane) const; 645 650 646 651 /** Sets exporter color. … … 649 654 ViewCell *vc, 650 655 const bool colorCode) const; 651 656 652 657 /** Creates meshes from the view cells. 653 658 */ 654 659 void CreateViewCellMeshes(); 655 660 656 661 /** Creates clip plane for visualization. 657 662 */ 658 663 void CreateClipPlane(); 659 664 660 665 AxisAlignedPlane *GetClipPlane(); 661 666 662 667 void ExportMergedViewCells(const ObjectContainer &objects); 663 668 … … 673 678 */ 674 679 ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell, 675 680 const ViewCellContainer &viewCells); 676 681 677 682 /** Constructs local view cell merge hierarchy based solely on similarity with the 678 683 current viewcell 679 684 */ 680 685 ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell, -
GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp
r1824 r1932 357 357 { 358 358 VssRayContainer::const_iterator it = begin(); 359 // ofstream s("contrib.log"); 360 for (; it != end(); it++) { 361 VssRay *ray = *it; 362 // s<<"(pass="<<ray->mPass<<", c="<<ray->mPvsContribution<<")"<<endl; 363 if (ray->mPass >= minPass && ray->mPvsContribution > 0) 364 selected.push_back(ray); 365 } 359 360 // ofstream s("contrib.log"); 361 362 for (; it != end(); it++) 363 { 364 VssRay *ray = *it; 365 366 // s<<"(pass="<<ray->mPass<<", c="<<ray->mPvsContribution<<")"<<endl; 367 if (ray->mPass >= minPass && ray->mPvsContribution > 0) 368 selected.push_back(ray); 369 } 370 366 371 return (int)selected.size(); 367 372 }
Note: See TracChangeset
for help on using the changeset viewer.