[1460] | 1 | #include "Environment.h"
|
---|
| 2 | #include "GvsPreprocessor.h"
|
---|
| 3 | #include "GlRenderer.h"
|
---|
[1473] | 4 | #include "VssRay.h"
|
---|
| 5 | #include "ViewCellsManager.h"
|
---|
[1486] | 6 | #include "Triangle3.h"
|
---|
[1489] | 7 | #include "IntersectableWrapper.h"
|
---|
[1500] | 8 | #include "Plane3.h"
|
---|
[1521] | 9 | #include "RayCaster.h"
|
---|
[1522] | 10 | #include "Exporter.h"
|
---|
[1545] | 11 | #include "SamplingStrategy.h"
|
---|
[1990] | 12 | #include "BvHierarchy.h"
|
---|
[2116] | 13 | #include "Polygon3.h"
|
---|
[2643] | 14 | #include "IntersectableWrapper.h"
|
---|
[1460] | 15 |
|
---|
[1473] | 16 |
|
---|
[2643] | 17 |
|
---|
[1460] | 18 | namespace GtpVisibilityPreprocessor
|
---|
| 19 | {
|
---|
| 20 |
|
---|
[2633] | 21 | #define GVS_DEBUG 0
|
---|
[1934] | 22 |
|
---|
[1522] | 23 | struct VizStruct
|
---|
| 24 | {
|
---|
| 25 | Polygon3 *enlargedTriangle;
|
---|
| 26 | Triangle3 originalTriangle;
|
---|
| 27 | VssRay *ray;
|
---|
| 28 | };
|
---|
[1460] | 29 |
|
---|
[2048] | 30 |
|
---|
[2017] | 31 | static const float MIN_DIST = 0.001f;
|
---|
[1990] | 32 |
|
---|
[2648] | 33 | static ObjectContainer myobjects;
|
---|
[1522] | 34 | static vector<VizStruct> vizContainer;
|
---|
| 35 |
|
---|
[2648] | 36 |
|
---|
[1533] | 37 | GvsPreprocessor::GvsPreprocessor():
|
---|
[1545] | 38 | Preprocessor(),
|
---|
[2000] | 39 | mSamplingType(SamplingStrategy::VIEWCELL_BASED_DISTRIBUTION),
|
---|
[1996] | 40 | mProcessedViewCells(0),
|
---|
[2625] | 41 | mCurrentViewCell(NULL),
|
---|
| 42 | mCurrentViewPoint(Vector3(0.0f, 0.0f, 0.0f))
|
---|
[1460] | 43 | {
|
---|
[1486] | 44 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples);
|
---|
| 45 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.initialSamples", mInitialSamples);
|
---|
[2048] | 46 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.gvsSamplesPerPass", mGvsSamplesPerPass);
|
---|
[1996] | 47 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.minContribution", mMinContribution);
|
---|
[1486] | 48 | Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.epsilon", mEps);
|
---|
[1500] | 49 | Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.threshold", mThreshold);
|
---|
[1990] | 50 | Environment::GetSingleton()->GetBoolValue("GvsPreprocessor.perViewCell", mPerViewCell);
|
---|
[1996] | 51 | Environment::GetSingleton()->GetIntValue("GvsPreprocessor.maxViewCells", mMaxViewCells);
|
---|
[1473] | 52 |
|
---|
[2048] | 53 | Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError", mEvaluatePixelError);
|
---|
| 54 |
|
---|
[2615] | 55 | Environment::GetSingleton()->GetBoolValue("ViewCells.useKdPvs", mUseKdPvs);
|
---|
| 56 |
|
---|
| 57 |
|
---|
[1934] | 58 | char gvsStatsLog[100];
|
---|
| 59 | Environment::GetSingleton()->GetStringValue("GvsPreprocessor.stats", gvsStatsLog);
|
---|
| 60 | mGvsStatsStream.open(gvsStatsLog);
|
---|
| 61 |
|
---|
[1486] | 62 | Debug << "Gvs preprocessor options" << endl;
|
---|
| 63 | Debug << "number of total samples: " << mTotalSamples << endl;
|
---|
| 64 | Debug << "number of initial samples: " << mInitialSamples << endl;
|
---|
[2048] | 65 | cout << "number of gvs samples per pass: " << mGvsSamplesPerPass << endl;
|
---|
| 66 | cout << "number of samples per pass: " << mSamplesPerPass << endl;
|
---|
[1501] | 67 | Debug << "threshold: " << mThreshold << endl;
|
---|
[1934] | 68 | Debug << "epsilon: " << mEps << endl;
|
---|
| 69 | Debug << "stats: " << gvsStatsLog << endl;
|
---|
[1996] | 70 | Debug << "per view cell: " << mPerViewCell << endl;
|
---|
| 71 | Debug << "max view cells: " << mMaxViewCells << endl;
|
---|
| 72 | Debug << "min contribution: " << mMinContribution << endl;
|
---|
[1486] | 73 |
|
---|
[1990] | 74 | if (1)
|
---|
| 75 | mOnlyRandomSampling = false;
|
---|
| 76 | else
|
---|
[1934] | 77 | mOnlyRandomSampling = true;
|
---|
| 78 |
|
---|
| 79 | mGvsStats.Reset();
|
---|
[2643] | 80 |
|
---|
[2648] | 81 | // hack: some generic statistical values that can be read
|
---|
| 82 | // by an application using the preprocessor
|
---|
[2643] | 83 | mGenericStats = 0;
|
---|
| 84 | mGenericStats2 = 0;
|
---|
[1460] | 85 | }
|
---|
| 86 |
|
---|
[1473] | 87 |
|
---|
[1990] | 88 | GvsPreprocessor::~GvsPreprocessor()
|
---|
| 89 | {
|
---|
[1996] | 90 | ClearRayQueue();
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | void GvsPreprocessor::ClearRayQueue()
|
---|
| 95 | {
|
---|
[1990] | 96 | // clean ray queue
|
---|
| 97 | while (!mRayQueue.empty())
|
---|
| 98 | {
|
---|
| 99 | // handle next ray
|
---|
| 100 | VssRay *ray = mRayQueue.top();
|
---|
| 101 | mRayQueue.pop();
|
---|
| 102 |
|
---|
[2048] | 103 | //delete ray;
|
---|
[1990] | 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
[2625] | 108 | ViewCell *GvsPreprocessor::NextViewCell()
|
---|
[1982] | 109 | {
|
---|
[1996] | 110 | if (mProcessedViewCells == (int)mViewCells.size())
|
---|
[2625] | 111 | return NULL; // no more view cells
|
---|
[1982] | 112 |
|
---|
[2625] | 113 | ViewCell *vc = mViewCells[mProcessedViewCells];
|
---|
[1982] | 114 |
|
---|
[2625] | 115 | if (!vc->GetMesh())
|
---|
| 116 | mViewCellsManager->CreateMesh(vc);
|
---|
[1990] | 117 |
|
---|
[2625] | 118 | mGvsStats.mViewCellId = vc->GetId();
|
---|
[1996] | 119 |
|
---|
[2625] | 120 | Debug << "vc: " << vc->GetId() << endl;
|
---|
[1996] | 121 |
|
---|
| 122 | ++ mProcessedViewCells;
|
---|
[1982] | 123 |
|
---|
[2625] | 124 | return vc;
|
---|
[1982] | 125 | }
|
---|
| 126 |
|
---|
| 127 |
|
---|
[1996] | 128 | int GvsPreprocessor::CheckDiscontinuity(const VssRay ¤tRay,
|
---|
| 129 | const Triangle3 &hitTriangle,
|
---|
| 130 | const VssRay &oldRay)
|
---|
[1460] | 131 | {
|
---|
[1932] | 132 | // the predicted hitpoint: we expect to hit the same mesh again
|
---|
| 133 | const Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
|
---|
| 134 |
|
---|
| 135 | const float predictedLen = Magnitude(predictedHit - currentRay.mOrigin);
|
---|
| 136 | const float len = Magnitude(currentRay.mTermination - currentRay.mOrigin);
|
---|
| 137 |
|
---|
| 138 | // distance large => this is likely to be a discontinuity
|
---|
[1933] | 139 | #if 1
|
---|
[1932] | 140 | if ((predictedLen - len) > mThreshold)
|
---|
[1933] | 141 | #else // rather use relative distance
|
---|
| 142 | if ((predictedLen / len) > mThreshold)
|
---|
| 143 | #endif
|
---|
[1500] | 144 | {
|
---|
[1934] | 145 | //cout << "r";
|
---|
[1933] | 146 | // apply reverse sampling to find the gap
|
---|
[1500] | 147 | VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay);
|
---|
[1933] | 148 |
|
---|
| 149 | if (!newRay)
|
---|
[1996] | 150 | return 1;
|
---|
[1933] | 151 |
|
---|
[1572] | 152 | // set flag for visualization
|
---|
[2053] | 153 | //newRay->mFlags |= VssRay::ReverseSample;
|
---|
[1580] | 154 |
|
---|
[1977] | 155 | // if ray is not further processed => delete ray
|
---|
[1521] | 156 | if (!HandleRay(newRay))
|
---|
[1933] | 157 | {
|
---|
[2048] | 158 | //delete newRay;
|
---|
[1933] | 159 | }
|
---|
[1999] | 160 |
|
---|
[1996] | 161 | return 1;
|
---|
[1500] | 162 | }
|
---|
| 163 |
|
---|
[1996] | 164 | return 0;
|
---|
[1486] | 165 | }
|
---|
[1473] | 166 |
|
---|
[2053] | 167 |
|
---|
[1999] | 168 | bool GvsPreprocessor::HasContribution(VssRay &ray)
|
---|
[1486] | 169 | {
|
---|
[1999] | 170 | if (!ray.mTerminationObject)
|
---|
| 171 | return false;
|
---|
[1933] | 172 |
|
---|
[1999] | 173 | bool result;
|
---|
| 174 |
|
---|
[1977] | 175 | if (!mPerViewCell)
|
---|
| 176 | {
|
---|
[1999] | 177 | // store the rays + the intersected view cells
|
---|
| 178 | const bool storeViewCells = false; //GVS_DEBUG;
|
---|
| 179 |
|
---|
| 180 | mViewCellsManager->ComputeSampleContribution(ray,
|
---|
[1977] | 181 | true,
|
---|
[1999] | 182 | storeViewCells,
|
---|
[1990] | 183 | true);
|
---|
[1999] | 184 |
|
---|
| 185 | result = ray.mPvsContribution > 0;
|
---|
[1977] | 186 | }
|
---|
[2625] | 187 | else // original per view cell gvs
|
---|
[1977] | 188 | {
|
---|
[1999] | 189 | Intersectable *obj = ray.mTerminationObject;
|
---|
| 190 |
|
---|
[2643] | 191 | if (obj->mCounter < 2)
|
---|
[1999] | 192 | {
|
---|
[2643] | 193 | obj->mCounter += 2;
|
---|
[1999] | 194 | mTrianglePvs.push_back(obj);
|
---|
[2615] | 195 |
|
---|
[2643] | 196 | mGenericStats = mTrianglePvs.size();
|
---|
| 197 |
|
---|
[2625] | 198 | // if using kd pvs, exchange the triangle with the node in the pvs
|
---|
[2615] | 199 | if (mUseKdPvs)
|
---|
| 200 | {
|
---|
| 201 | KdNode *node = mKdTree->GetPvsNode(ray.mTermination);
|
---|
[1999] | 202 |
|
---|
[2615] | 203 | if (!node->Mailed())
|
---|
| 204 | {
|
---|
| 205 | node->Mail();
|
---|
[2625] | 206 | KdIntersectable *kdInt = mKdTree->GetOrCreateKdIntersectable(node);
|
---|
| 207 | mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f);
|
---|
[2643] | 208 | //mCurrentViewCell->GetPvs().AddSampleDirtyCheck(kdInt, 1.0f);
|
---|
| 209 |
|
---|
[2625] | 210 | mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt);
|
---|
[2643] | 211 | myobjects.clear();
|
---|
| 212 | mKdTree->CollectObjects(node, myobjects);
|
---|
| 213 |
|
---|
| 214 | // account for kd object pvs
|
---|
| 215 | ObjectContainer::const_iterator oit, oit_end = myobjects.end();
|
---|
| 216 |
|
---|
| 217 | for (oit = myobjects.begin(); oit != oit_end; ++ oit)
|
---|
| 218 | {
|
---|
| 219 | TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit);
|
---|
| 220 |
|
---|
| 221 | if ((triObj->mCounter != 1) && (triObj->mCounter != 3))
|
---|
| 222 | {
|
---|
| 223 | ++ triObj->mCounter;
|
---|
| 224 | ++ mGenericStats2;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
[2615] | 227 | }
|
---|
| 228 | }
|
---|
[2643] | 229 |
|
---|
[1999] | 230 | result = true;
|
---|
| 231 | }
|
---|
| 232 | else
|
---|
| 233 | {
|
---|
| 234 | result = false;
|
---|
| 235 | }
|
---|
[1977] | 236 | }
|
---|
[1932] | 237 |
|
---|
[1999] | 238 | return result;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | bool GvsPreprocessor::HandleRay(VssRay *vssRay)
|
---|
| 243 | {
|
---|
| 244 | if (!HasContribution(*vssRay))
|
---|
[1977] | 245 | return false;
|
---|
| 246 |
|
---|
[2633] | 247 | // cout << "t";
|
---|
[2005] | 248 | if (0 && GVS_DEBUG)
|
---|
[1990] | 249 | mVssRays.push_back(new VssRay(*vssRay));
|
---|
| 250 |
|
---|
[1977] | 251 | // add new ray to ray queue
|
---|
| 252 | mRayQueue.push(vssRay);
|
---|
| 253 |
|
---|
[1990] | 254 | ++ mGvsStats.mTotalContribution;
|
---|
[1533] | 255 |
|
---|
[1977] | 256 | return true;
|
---|
[1460] | 257 | }
|
---|
| 258 |
|
---|
[1500] | 259 |
|
---|
| 260 | /** Creates 3 new vertices for triangle vertex with specified index.
|
---|
[1489] | 261 | */
|
---|
[1932] | 262 | void GvsPreprocessor::CreateDisplacedVertices(VertexContainer &vertices,
|
---|
| 263 | const Triangle3 &hitTriangle,
|
---|
| 264 | const VssRay &ray,
|
---|
| 265 | const int index) const
|
---|
[1460] | 266 | {
|
---|
[1486] | 267 | const int indexU = (index + 1) % 3;
|
---|
| 268 | const int indexL = (index == 0) ? 2 : index - 1;
|
---|
| 269 |
|
---|
[1524] | 270 | const Vector3 a = hitTriangle.mVertices[index] - ray.GetOrigin();
|
---|
[1486] | 271 | const Vector3 b = hitTriangle.mVertices[indexU] - hitTriangle.mVertices[index];
|
---|
| 272 | const Vector3 c = hitTriangle.mVertices[index] - hitTriangle.mVertices[indexL];
|
---|
[1492] | 273 |
|
---|
[1533] | 274 | const float len = Magnitude(a);
|
---|
[1932] | 275 |
|
---|
[1523] | 276 | const Vector3 dir1 = Normalize(CrossProd(a, b)); //N((pi-xp)×(pi+1- pi));
|
---|
| 277 | const Vector3 dir2 = Normalize(CrossProd(a, c)); // N((pi-xp)×(pi- pi-1))
|
---|
[1524] | 278 | const Vector3 dir3 = DotProd(dir2, dir1) > 0 ? // N((pi-xp)×di,i-1+di,i+1×(pi-xp))
|
---|
| 279 | Normalize(dir2 + dir1) : Normalize(CrossProd(a, dir1) + CrossProd(dir2, a));
|
---|
[1492] | 280 |
|
---|
[1486] | 281 | // compute the new three hit points
|
---|
[1500] | 282 | // pi, i + 1: pi+ e·|pi-xp|·di, j
|
---|
[1932] | 283 | const Vector3 pt1 = hitTriangle.mVertices[index] + mEps * len * dir1;
|
---|
[1500] | 284 | // pi, i - 1: pi+ e·|pi-xp|·di, j
|
---|
[1932] | 285 | const Vector3 pt2 = hitTriangle.mVertices[index] + mEps * len * dir2;
|
---|
[1500] | 286 | // pi, i: pi+ e·|pi-xp|·di, j
|
---|
[1932] | 287 | const Vector3 pt3 = hitTriangle.mVertices[index] + mEps * len * dir3;
|
---|
[1489] | 288 |
|
---|
[1524] | 289 | vertices.push_back(pt2);
|
---|
| 290 | vertices.push_back(pt3);
|
---|
[1500] | 291 | vertices.push_back(pt1);
|
---|
[1489] | 292 | }
|
---|
| 293 |
|
---|
| 294 |
|
---|
[1500] | 295 | void GvsPreprocessor::EnlargeTriangle(VertexContainer &vertices,
|
---|
| 296 | const Triangle3 &hitTriangle,
|
---|
[1932] | 297 | const VssRay &ray) const
|
---|
[1500] | 298 | {
|
---|
[1932] | 299 | CreateDisplacedVertices(vertices, hitTriangle, ray, 0);
|
---|
| 300 | CreateDisplacedVertices(vertices, hitTriangle, ray, 1);
|
---|
| 301 | CreateDisplacedVertices(vertices, hitTriangle, ray, 2);
|
---|
[1500] | 302 | }
|
---|
[1492] | 303 |
|
---|
[1500] | 304 |
|
---|
[1932] | 305 | Vector3 GvsPreprocessor::CalcPredictedHitPoint(const VssRay &newRay,
|
---|
| 306 | const Triangle3 &hitTriangle,
|
---|
| 307 | const VssRay &oldRay) const
|
---|
[1489] | 308 | {
|
---|
[1932] | 309 | // find the intersection of the plane induced by the
|
---|
| 310 | // hit triangle with the new ray
|
---|
[1500] | 311 | Plane3 plane(hitTriangle.GetNormal(), hitTriangle.mVertices[0]);
|
---|
| 312 |
|
---|
| 313 | const Vector3 hitPt =
|
---|
| 314 | plane.FindIntersection(newRay.mTermination, newRay.mOrigin);
|
---|
| 315 |
|
---|
| 316 | return hitPt;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 |
|
---|
| 320 | static bool EqualVisibility(const VssRay &a, const VssRay &b)
|
---|
| 321 | {
|
---|
| 322 | return a.mTerminationObject == b.mTerminationObject;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 |
|
---|
| 326 | int GvsPreprocessor::SubdivideEdge(const Triangle3 &hitTriangle,
|
---|
| 327 | const Vector3 &p1,
|
---|
| 328 | const Vector3 &p2,
|
---|
[1932] | 329 | const VssRay &ray1,
|
---|
| 330 | const VssRay &ray2,
|
---|
[1500] | 331 | const VssRay &oldRay)
|
---|
[2048] | 332 | {
|
---|
| 333 | //cout <<"y"<<Magnitude(p1 - p2) << " ";
|
---|
[1996] | 334 | int castRays = 0;
|
---|
| 335 |
|
---|
[1990] | 336 | // cast reverse rays if necessary
|
---|
[1996] | 337 | castRays += CheckDiscontinuity(ray1, hitTriangle, oldRay);
|
---|
| 338 | castRays += CheckDiscontinuity(ray2, hitTriangle, oldRay);
|
---|
[1500] | 339 |
|
---|
[2017] | 340 | if (EqualVisibility(ray1, ray2) || (SqrMagnitude(p1 - p2) <= MIN_DIST))
|
---|
[1500] | 341 | {
|
---|
[1996] | 342 | return castRays;
|
---|
[1500] | 343 | }
|
---|
[1932] | 344 |
|
---|
[1990] | 345 | // the new subdivision point
|
---|
| 346 | const Vector3 p = (p1 + p2) * 0.5f;
|
---|
[2017] | 347 | //cout << "p: " << p << " " << p1 << " " << p2 << endl;
|
---|
[1990] | 348 | // cast ray into the new point
|
---|
| 349 | SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f);
|
---|
[1932] | 350 |
|
---|
[1996] | 351 | VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell);
|
---|
| 352 |
|
---|
| 353 | ++ castRays;
|
---|
[1580] | 354 |
|
---|
[1996] | 355 | if (!newRay) return castRays;
|
---|
[1580] | 356 |
|
---|
[2053] | 357 | //newRay->mFlags |= VssRay::BorderSample;
|
---|
[1990] | 358 |
|
---|
| 359 | // add new ray to queue
|
---|
| 360 | const bool enqueued = HandleRay(newRay);
|
---|
| 361 |
|
---|
| 362 | // subdivide further
|
---|
[1996] | 363 | castRays += SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay);
|
---|
| 364 | castRays += SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay);
|
---|
[1990] | 365 |
|
---|
| 366 | // this ray will not be further processed
|
---|
[2048] | 367 | //if (!enqueued) delete newRay;
|
---|
[1990] | 368 |
|
---|
[1996] | 369 | return castRays;
|
---|
[1500] | 370 | }
|
---|
| 371 |
|
---|
| 372 |
|
---|
| 373 | int GvsPreprocessor::AdaptiveBorderSampling(const VssRay ¤tRay)
|
---|
| 374 | {
|
---|
| 375 | Intersectable *tObj = currentRay.mTerminationObject;
|
---|
[2597] | 376 | // q matt: can this be possible
|
---|
| 377 | if (!tObj) return 0;
|
---|
| 378 |
|
---|
[1486] | 379 | Triangle3 hitTriangle;
|
---|
[1489] | 380 |
|
---|
| 381 | // other types not implemented yet
|
---|
| 382 | if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
|
---|
[2017] | 383 | hitTriangle = static_cast<TriangleIntersectable *>(tObj)->GetItem();
|
---|
[1522] | 384 | else
|
---|
[2601] | 385 | cout << "border sampling: " << Intersectable::GetTypeName(tObj) << " not yet implemented" << endl;
|
---|
[1489] | 386 |
|
---|
[2601] | 387 | //cout << "type: " << Intersectable::GetTypeName(tObj) << endl;
|
---|
| 388 |
|
---|
[1500] | 389 | VertexContainer enlargedTriangle;
|
---|
| 390 |
|
---|
| 391 | /// create 3 new hit points for each vertex
|
---|
| 392 | EnlargeTriangle(enlargedTriangle, hitTriangle, currentRay);
|
---|
| 393 |
|
---|
| 394 | /// create rays from sample points and handle them
|
---|
[1492] | 395 | SimpleRayContainer simpleRays;
|
---|
| 396 | simpleRays.reserve(9);
|
---|
[1486] | 397 |
|
---|
[1500] | 398 | VertexContainer::const_iterator vit, vit_end = enlargedTriangle.end();
|
---|
[1486] | 399 |
|
---|
[1500] | 400 | for (vit = enlargedTriangle.begin(); vit != vit_end; ++ vit)
|
---|
| 401 | {
|
---|
| 402 | const Vector3 rayDir = (*vit) - currentRay.GetOrigin();
|
---|
[1990] | 403 |
|
---|
[1883] | 404 | SimpleRay sr(currentRay.GetOrigin(), rayDir, SamplingStrategy::GVS, 1.0f);
|
---|
[1990] | 405 | simpleRays.AddRay(sr);
|
---|
[1500] | 406 | }
|
---|
[1522] | 407 |
|
---|
[1566] | 408 | if (0)
|
---|
| 409 | {
|
---|
[1932] | 410 | // visualize enlarged triangles
|
---|
[1566] | 411 | VizStruct dummy;
|
---|
| 412 | dummy.enlargedTriangle = new Polygon3(enlargedTriangle);
|
---|
| 413 | dummy.originalTriangle = hitTriangle;
|
---|
| 414 | vizContainer.push_back(dummy);
|
---|
| 415 | }
|
---|
| 416 |
|
---|
[1524] | 417 | // cast rays to triangle vertices and determine visibility
|
---|
[1489] | 418 | VssRayContainer vssRays;
|
---|
[1533] | 419 |
|
---|
[1932] | 420 | // don't cast double rays as we need only the forward rays
|
---|
[1996] | 421 | const bool castDoubleRays = !mPerViewCell;
|
---|
[1990] | 422 | // cannot prune invalid rays because we have to compare adjacent rays.
|
---|
[1932] | 423 | const bool pruneInvalidRays = false;
|
---|
| 424 |
|
---|
[1996] | 425 |
|
---|
| 426 | //////////
|
---|
| 427 | //-- fill up simple rays with random rays so we can cast 16
|
---|
| 428 |
|
---|
| 429 | //const int numRandomRays = 0;
|
---|
| 430 | const int numRandomRays = 16 - (int)simpleRays.size();
|
---|
| 431 | ViewCellBasedDistribution vcStrat(*this, mCurrentViewCell);
|
---|
| 432 |
|
---|
| 433 | GenerateRays(numRandomRays, vcStrat, simpleRays);
|
---|
| 434 |
|
---|
[2053] | 435 |
|
---|
[1996] | 436 | /////////////////////
|
---|
| 437 |
|
---|
[1990] | 438 | // keep origin for per view cell sampling
|
---|
[1996] | 439 | CastRays(simpleRays, vssRays, castDoubleRays, pruneInvalidRays);
|
---|
[1932] | 440 |
|
---|
[1996] | 441 | const int numBorderSamples = (int)vssRays.size() - numRandomRays;
|
---|
[2648] | 442 |
|
---|
| 443 | #if 0
|
---|
[1580] | 444 | // set flags
|
---|
[2648] | 445 | VssRayContainer::const_iterator rit, rit_end = vssRays.end();
|
---|
[1996] | 446 | for (rit = vssRays.begin(); rit != rit_end; ++ rit, ++ i)
|
---|
[2053] | 447 | (*rit)->mFlags |= VssRay::BorderSample;
|
---|
[2648] | 448 | #endif
|
---|
| 449 |
|
---|
[1999] | 450 | int castRays = (int)simpleRays.size();
|
---|
| 451 |
|
---|
| 452 | VssRayContainer invalidSamples;
|
---|
| 453 |
|
---|
[1932] | 454 | // handle rays
|
---|
[1999] | 455 | EnqueueRays(vssRays, invalidSamples);
|
---|
| 456 |
|
---|
[1500] | 457 | // recursivly subdivide each edge
|
---|
[1996] | 458 | for (int i = 0; i < numBorderSamples; ++ i)
|
---|
[1500] | 459 | {
|
---|
[1932] | 460 | castRays += SubdivideEdge(hitTriangle,
|
---|
| 461 | enlargedTriangle[i],
|
---|
[1996] | 462 | enlargedTriangle[(i + 1) % numBorderSamples],
|
---|
[1932] | 463 | *vssRays[i],
|
---|
[1996] | 464 | *vssRays[(i + 1) % numBorderSamples],
|
---|
[1932] | 465 | currentRay);
|
---|
[1500] | 466 | }
|
---|
[1999] | 467 |
|
---|
[1934] | 468 | mGvsStats.mBorderSamples += castRays;
|
---|
[1932] | 469 |
|
---|
[2053] | 470 | //CLEAR_CONTAINER(invalidSamples);
|
---|
[2048] | 471 |
|
---|
| 472 | //cout << "cast rays: " << castRays << endl;
|
---|
[1533] | 473 | return castRays;
|
---|
[1473] | 474 | }
|
---|
| 475 |
|
---|
| 476 |
|
---|
[1996] | 477 | bool GvsPreprocessor::GetPassingPoint(const VssRay ¤tRay,
|
---|
| 478 | const Triangle3 &occluder,
|
---|
| 479 | const VssRay &oldRay,
|
---|
| 480 | Vector3 &newPoint) const
|
---|
[1933] | 481 | {
|
---|
| 482 | //-- The plane p = (xp, hit(x), hit(xold)) is intersected
|
---|
| 483 | //-- with the newly found occluder (xold is the previous ray from
|
---|
| 484 | //-- which x was generated). On the intersecting line, we select a point
|
---|
| 485 | //-- pnew which lies just outside of the new triangle so the ray
|
---|
| 486 | //-- just passes through the gap
|
---|
| 487 |
|
---|
| 488 | const Plane3 plane(currentRay.GetOrigin(),
|
---|
| 489 | currentRay.GetTermination(),
|
---|
| 490 | oldRay.GetTermination());
|
---|
| 491 |
|
---|
| 492 | Vector3 pt1, pt2;
|
---|
| 493 |
|
---|
| 494 | const bool intersects = occluder.GetPlaneIntersection(plane, pt1, pt2);
|
---|
| 495 |
|
---|
| 496 | if (!intersects)
|
---|
[1996] | 497 | {
|
---|
[1999] | 498 | //cerr << "big error!! no intersection " << pt1 << " " << pt2 << endl;
|
---|
[1996] | 499 | return false;
|
---|
| 500 | }
|
---|
[1933] | 501 |
|
---|
| 502 | // get the intersection point on the old ray
|
---|
| 503 | const Plane3 triPlane(occluder.GetNormal(), occluder.mVertices[0]);
|
---|
| 504 |
|
---|
| 505 | const float t = triPlane.FindT(oldRay.mOrigin, oldRay.mTermination);
|
---|
| 506 | const Vector3 pt3 = oldRay.mOrigin + t * (oldRay.mTermination - oldRay.mOrigin);
|
---|
| 507 |
|
---|
| 508 | // Evaluate new hitpoint just outside the triangle
|
---|
| 509 | const float eps = mEps;
|
---|
[1990] | 510 |
|
---|
[1933] | 511 | // the point is chosen to be on the side closer to the original ray
|
---|
| 512 | if (Distance(pt1, pt3) < Distance(pt2, pt3))
|
---|
| 513 | newPoint = pt1 + eps * (pt1 - pt2);
|
---|
| 514 | else
|
---|
| 515 | newPoint = pt2 + eps * (pt2 - pt1);
|
---|
| 516 |
|
---|
[1934] | 517 | //cout << "passing point: " << newPoint << endl << endl;
|
---|
[1996] | 518 | return true;
|
---|
[1500] | 519 | }
|
---|
| 520 |
|
---|
| 521 |
|
---|
| 522 | VssRay *GvsPreprocessor::ReverseSampling(const VssRay ¤tRay,
|
---|
| 523 | const Triangle3 &hitTriangle,
|
---|
| 524 | const VssRay &oldRay)
|
---|
| 525 | {
|
---|
[1933] | 526 | // get triangle occluding the path to the hit mesh
|
---|
| 527 | Triangle3 occluder;
|
---|
| 528 | Intersectable *tObj = currentRay.mTerminationObject;
|
---|
[1934] | 529 |
|
---|
[1933] | 530 | // q: why can this happen?
|
---|
| 531 | if (!tObj)
|
---|
| 532 | return NULL;
|
---|
| 533 |
|
---|
| 534 | // other types not implemented yet
|
---|
| 535 | if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
|
---|
[2048] | 536 | {
|
---|
[2017] | 537 | occluder = static_cast<TriangleIntersectable *>(tObj)->GetItem();
|
---|
[2048] | 538 | }
|
---|
[1933] | 539 | else
|
---|
[2048] | 540 | {
|
---|
| 541 | cout << "reverse sampling: " << tObj->Type() << " not yet implemented" << endl;
|
---|
| 542 | }
|
---|
[1933] | 543 | // get a point which is passing just outside of the occluder
|
---|
[1996] | 544 | Vector3 newPoint;
|
---|
| 545 |
|
---|
| 546 | // why is there sometimes no intersecton found?
|
---|
| 547 | if (!GetPassingPoint(currentRay, occluder, oldRay, newPoint))
|
---|
| 548 | return NULL;
|
---|
| 549 |
|
---|
[1500] | 550 | const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
|
---|
| 551 |
|
---|
[1990] | 552 | Vector3 newDir, newOrigin;
|
---|
| 553 |
|
---|
[1932] | 554 | //-- Construct the mutated ray with xnew,
|
---|
| 555 | //-- dir = predicted(x)- pnew as direction vector
|
---|
[1990] | 556 | newDir = predicted - newPoint;
|
---|
[1932] | 557 |
|
---|
[1933] | 558 | // take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ?
|
---|
[1500] | 559 | // difficult to say!!
|
---|
[1935] | 560 | const float offset = 0.5f;
|
---|
[1990] | 561 | newOrigin = newPoint - newDir * offset;
|
---|
| 562 |
|
---|
| 563 | //////////////
|
---|
| 564 | //-- for per view cell sampling, we must check for intersection
|
---|
| 565 | //-- with the current view cell
|
---|
[1500] | 566 |
|
---|
[1990] | 567 | if (mPerViewCell)
|
---|
| 568 | {
|
---|
| 569 | // send ray to view cell
|
---|
| 570 | static Ray ray;
|
---|
| 571 | ray.Clear();
|
---|
| 572 | ray.Init(newOrigin, -newDir, Ray::LOCAL_RAY);
|
---|
| 573 |
|
---|
| 574 | //cout << "z";
|
---|
| 575 | // check if ray intersects view cell
|
---|
| 576 | if (!mCurrentViewCell->CastRay(ray))
|
---|
| 577 | return NULL;
|
---|
[1981] | 578 |
|
---|
[1990] | 579 | Ray::Intersection &hit = ray.intersections[0];
|
---|
| 580 |
|
---|
| 581 | //cout << "q";
|
---|
| 582 | // the ray starts from the view cell
|
---|
| 583 | newOrigin = ray.Extrap(hit.mT);
|
---|
| 584 | }
|
---|
[1981] | 585 |
|
---|
[1933] | 586 | const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f);
|
---|
[1571] | 587 |
|
---|
[1933] | 588 | VssRay *reverseRay =
|
---|
[1996] | 589 | mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell);
|
---|
[1933] | 590 |
|
---|
[1934] | 591 | ++ mGvsStats.mReverseSamples;
|
---|
[1933] | 592 |
|
---|
| 593 | return reverseRay;
|
---|
[1473] | 594 | }
|
---|
| 595 |
|
---|
[1489] | 596 |
|
---|
| 597 | int GvsPreprocessor::CastInitialSamples(const int numSamples,
|
---|
| 598 | const int sampleType)
|
---|
| 599 | {
|
---|
[1473] | 600 | const long startTime = GetTime();
|
---|
[1595] | 601 |
|
---|
[1489] | 602 | // generate simple rays
|
---|
| 603 | SimpleRayContainer simpleRays;
|
---|
[1990] | 604 |
|
---|
| 605 | ViewCellBasedDistribution vcStrat(*this, mCurrentViewCell);
|
---|
| 606 | GenerateRays(numSamples, vcStrat, simpleRays);
|
---|
| 607 |
|
---|
| 608 | //cout << "sr: " << simpleRays.size() << endl;
|
---|
[1489] | 609 | // generate vss rays
|
---|
[1473] | 610 | VssRayContainer samples;
|
---|
[1990] | 611 |
|
---|
[1996] | 612 | const bool castDoubleRays = !mPerViewCell;
|
---|
[1990] | 613 | const bool pruneInvalidRays = true;
|
---|
| 614 |
|
---|
[1996] | 615 | CastRays(simpleRays, samples, castDoubleRays, pruneInvalidRays);
|
---|
| 616 |
|
---|
[1999] | 617 | VssRayContainer invalidSamples;
|
---|
| 618 |
|
---|
[1489] | 619 | // add to ray queue
|
---|
[1999] | 620 | EnqueueRays(samples, invalidSamples);
|
---|
[1533] | 621 |
|
---|
[2053] | 622 | //CLEAR_CONTAINER(invalidSamples);
|
---|
[2633] | 623 | //Debug << "generated " << numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
|
---|
[1990] | 624 | return (int)simpleRays.size();
|
---|
[1489] | 625 | }
|
---|
| 626 |
|
---|
| 627 |
|
---|
[1999] | 628 | void GvsPreprocessor::EnqueueRays(VssRayContainer &samples, VssRayContainer &invalidSamples)
|
---|
[1489] | 629 | {
|
---|
[1486] | 630 | // add samples to ray queue
|
---|
[1473] | 631 | VssRayContainer::const_iterator vit, vit_end = samples.end();
|
---|
[1576] | 632 | for (vit = samples.begin(); vit != vit_end; ++ vit)
|
---|
[1473] | 633 | {
|
---|
[1999] | 634 | VssRay *ray = *vit;
|
---|
| 635 |
|
---|
[2053] | 636 | HandleRay(ray);
|
---|
[2633] | 637 | //if (!HandleRay(ray)) invalidSamples.push_back(ray);
|
---|
[1460] | 638 | }
|
---|
| 639 | }
|
---|
| 640 |
|
---|
[1473] | 641 |
|
---|
[1990] | 642 | int GvsPreprocessor::ProcessQueue()
|
---|
[1460] | 643 | {
|
---|
[1533] | 644 | int castSamples = 0;
|
---|
[1990] | 645 | ++ mGvsStats.mGvsPass;
|
---|
[1545] | 646 |
|
---|
[2048] | 647 | while (!mRayQueue.empty())//&& (mGvsStats.mTotalSamples + castSamples < mTotalSamples) )
|
---|
[1990] | 648 | {
|
---|
[2597] | 649 | //cout << "queue size: " << mRayQueue.size() << endl;
|
---|
[1990] | 650 | // handle next ray
|
---|
| 651 | VssRay *ray = mRayQueue.top();
|
---|
| 652 | mRayQueue.pop();
|
---|
[1996] | 653 |
|
---|
[1990] | 654 | const int newSamples = AdaptiveBorderSampling(*ray);
|
---|
[1934] | 655 |
|
---|
[1990] | 656 | castSamples += newSamples;
|
---|
[2048] | 657 | //delete ray;
|
---|
[1473] | 658 | }
|
---|
| 659 |
|
---|
[2161] | 660 | /*if (mRayCaster->mVssRayPool.mIndex > mSamplesPerPass)
|
---|
[2048] | 661 | {
|
---|
| 662 | cout << "warning: new samples: " << castSamples << " " << "queue: " << (int)mRayQueue.size() << endl;
|
---|
| 663 | Debug << "warning: new samples: " << castSamples << " " << "queue: " << (int)mRayQueue.size() << endl;
|
---|
[2161] | 664 | }*/
|
---|
[2048] | 665 |
|
---|
[1533] | 666 | return castSamples;
|
---|
[1460] | 667 | }
|
---|
| 668 |
|
---|
[1473] | 669 |
|
---|
[1990] | 670 | void ExportVssRays(Exporter *exporter, const VssRayContainer &vssRays)
|
---|
[1460] | 671 | {
|
---|
[1990] | 672 | VssRayContainer vcRays, vcRays2, vcRays3;
|
---|
[1473] | 673 |
|
---|
[1990] | 674 | VssRayContainer::const_iterator rit, rit_end = vssRays.end();
|
---|
| 675 |
|
---|
| 676 | // prepare some rays for output
|
---|
| 677 | for (rit = vssRays.begin(); rit != rit_end; ++ rit)
|
---|
[1473] | 678 | {
|
---|
[1990] | 679 | //const float p = RandomValue(0.0f, (float)vssRays.size());
|
---|
[1545] | 680 |
|
---|
[1990] | 681 | if (1)//(p < raysOut)
|
---|
| 682 | {
|
---|
| 683 | if ((*rit)->mFlags & VssRay::BorderSample)
|
---|
| 684 | {
|
---|
| 685 | vcRays.push_back(*rit);
|
---|
| 686 | }
|
---|
| 687 | else if ((*rit)->mFlags & VssRay::ReverseSample)
|
---|
| 688 | {
|
---|
| 689 | vcRays2.push_back(*rit);
|
---|
| 690 | }
|
---|
| 691 | else
|
---|
| 692 | {
|
---|
| 693 | vcRays3.push_back(*rit);
|
---|
| 694 | }
|
---|
| 695 | }
|
---|
[1460] | 696 | }
|
---|
[1990] | 697 |
|
---|
[2005] | 698 | exporter->ExportRays(vcRays, RgbColor(1, 0, 0));
|
---|
| 699 | exporter->ExportRays(vcRays2, RgbColor(0, 1, 0));
|
---|
[2003] | 700 | exporter->ExportRays(vcRays3, RgbColor(1, 1, 1));
|
---|
[1990] | 701 | }
|
---|
| 702 |
|
---|
| 703 |
|
---|
[1999] | 704 | void GvsPreprocessor::VisualizeViewCell(const ObjectContainer &objects)
|
---|
[1990] | 705 | {
|
---|
| 706 | Intersectable::NewMail();
|
---|
| 707 | Material m;
|
---|
[1528] | 708 |
|
---|
[1996] | 709 | char str[64]; sprintf(str, "pass%06d.wrl", mProcessedViewCells);
|
---|
[1990] | 710 |
|
---|
| 711 | Exporter *exporter = Exporter::GetExporter(str);
|
---|
| 712 | if (!exporter)
|
---|
| 713 | return;
|
---|
| 714 |
|
---|
[1999] | 715 | ObjectContainer::const_iterator oit, oit_end = objects.end();
|
---|
| 716 |
|
---|
| 717 | for (oit = objects.begin(); oit != oit_end; ++ oit)
|
---|
| 718 | {
|
---|
| 719 | Intersectable *intersect = *oit;
|
---|
| 720 |
|
---|
| 721 | m = RandomMaterial();
|
---|
| 722 | exporter->SetForcedMaterial(m);
|
---|
| 723 | exporter->ExportIntersectable(intersect);
|
---|
[1990] | 724 | }
|
---|
| 725 |
|
---|
| 726 | cout << "vssrays: " << (int)mVssRays.size() << endl;
|
---|
| 727 | ExportVssRays(exporter, mVssRays);
|
---|
| 728 |
|
---|
[2597] | 729 |
|
---|
[1990] | 730 | /////////////////
|
---|
| 731 | //-- export view cell geometry
|
---|
| 732 |
|
---|
[2597] | 733 | //exporter->SetWireframe();
|
---|
[1990] | 734 |
|
---|
| 735 | m.mDiffuseColor = RgbColor(0, 1, 0);
|
---|
| 736 | exporter->SetForcedMaterial(m);
|
---|
| 737 |
|
---|
[1999] | 738 | //mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL);
|
---|
| 739 | //mViewCellsManager->ExportViewCellGeometry(exporter, mCurrentViewCell, NULL, NULL);
|
---|
| 740 |
|
---|
| 741 | AxisAlignedBox3 bbox = mCurrentViewCell->GetMesh()->mBox;
|
---|
| 742 | exporter->ExportBox(bbox);
|
---|
[1990] | 743 | //exporter->SetFilled();
|
---|
| 744 |
|
---|
[2053] | 745 | delete exporter;
|
---|
[1460] | 746 | }
|
---|
| 747 |
|
---|
| 748 |
|
---|
[1982] | 749 | void GvsPreprocessor::VisualizeViewCells()
|
---|
| 750 | {
|
---|
[1996] | 751 | char str[64]; sprintf(str, "tmp/pass%06d_%04d-", mProcessedViewCells, mPass);
|
---|
[1982] | 752 |
|
---|
| 753 | // visualization
|
---|
| 754 | if (mGvsStats.mPassContribution > 0)
|
---|
| 755 | {
|
---|
| 756 | const bool exportRays = true;
|
---|
| 757 | const bool exportPvs = true;
|
---|
| 758 |
|
---|
| 759 | mViewCellsManager->ExportSingleViewCells(mObjects,
|
---|
| 760 | 10,
|
---|
| 761 | false,
|
---|
| 762 | exportPvs,
|
---|
| 763 | exportRays,
|
---|
| 764 | 1000,
|
---|
| 765 | str);
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | // remove pass samples
|
---|
| 769 | ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end();
|
---|
| 770 |
|
---|
| 771 | for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit)
|
---|
| 772 | {
|
---|
| 773 | (*vit)->DelRayRefs();
|
---|
| 774 | }
|
---|
| 775 | }
|
---|
| 776 |
|
---|
| 777 |
|
---|
[1990] | 778 | void GvsPreprocessor::ProcessViewCell()
|
---|
[1982] | 779 | {
|
---|
[2597] | 780 | // compute object that directly intersect view cell
|
---|
[1999] | 781 | IntersectWithViewCell();
|
---|
| 782 |
|
---|
[1990] | 783 | mGvsStats.mPerViewCellSamples = 0;
|
---|
[2643] | 784 |
|
---|
[1996] | 785 | int oldContribution = mGvsStats.mTotalContribution;
|
---|
[1990] | 786 | int passSamples = 0;
|
---|
[2648] | 787 |
|
---|
[2633] | 788 | mGenericStats = 0;
|
---|
[2643] | 789 | mGenericStats2 = 0;
|
---|
[2597] | 790 |
|
---|
[1996] | 791 | //while (mGvsStats.mPerViewCellSamples < mTotalSamples)
|
---|
[2643] | 792 | while (1)
|
---|
[1982] | 793 | {
|
---|
[2048] | 794 | mRayCaster->InitPass();
|
---|
| 795 |
|
---|
[1990] | 796 | // Ray queue empty =>
|
---|
| 797 | // cast a number of uniform samples to fill ray queue
|
---|
| 798 | int newSamples = CastInitialSamples(mInitialSamples, mSamplingType);
|
---|
[1982] | 799 |
|
---|
[1990] | 800 | if (!mOnlyRandomSampling)
|
---|
| 801 | newSamples += ProcessQueue();
|
---|
[2003] | 802 |
|
---|
[2597] | 803 | passSamples += newSamples;
|
---|
| 804 | mGvsStats.mPerViewCellSamples += newSamples;
|
---|
| 805 |
|
---|
[2048] | 806 | if (passSamples >= mGvsSamplesPerPass)
|
---|
[1982] | 807 | {
|
---|
| 808 | ++ mPass;
|
---|
[1990] | 809 | mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution;
|
---|
| 810 |
|
---|
[1982] | 811 | ////////
|
---|
| 812 | //-- stats
|
---|
| 813 |
|
---|
| 814 | mGvsStats.mPass = mPass;
|
---|
| 815 |
|
---|
[1996] | 816 | cout << "\nPass " << mPass << " #samples: " << mGvsStats.mPerViewCellSamples << endl;
|
---|
| 817 | cout << "contribution=" << mGvsStats.mPassContribution << " (of " << mMinContribution << ")" << endl;
|
---|
[1990] | 818 |
|
---|
[2643] | 819 | //mGenericStats = mGvsStats.mPassContribution;
|
---|
[2633] | 820 |
|
---|
[1996] | 821 | // termination criterium
|
---|
| 822 | if (mGvsStats.mPassContribution < mMinContribution)
|
---|
| 823 | break;
|
---|
| 824 |
|
---|
[1990] | 825 | // reset
|
---|
| 826 | oldContribution = mGvsStats.mTotalContribution;
|
---|
| 827 | mGvsStats.mPassContribution = 0;
|
---|
| 828 | passSamples = 0;
|
---|
[1982] | 829 | }
|
---|
| 830 | }
|
---|
| 831 | }
|
---|
| 832 |
|
---|
| 833 |
|
---|
[1996] | 834 | void GvsPreprocessor::CompileViewCellsList()
|
---|
| 835 | {
|
---|
[2648] | 836 | // Receive list of view cells from view cells manager
|
---|
[2598] | 837 | ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList();
|
---|
[2053] | 838 |
|
---|
[2048] | 839 | if (!vcPoints->empty())
|
---|
| 840 | {
|
---|
[2597] | 841 | cout << "processing view cell list" << endl;
|
---|
[2053] | 842 |
|
---|
[2048] | 843 | vector<ViewCellPoints *>::const_iterator vit, vit_end = vcPoints->end();
|
---|
| 844 |
|
---|
| 845 | for (vit = vcPoints->begin(); vit != vit_end; ++ vit)
|
---|
[2648] | 846 | {
|
---|
[2048] | 847 | mViewCells.push_back((*vit)->first);
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 | return;
|
---|
| 851 | }
|
---|
| 852 |
|
---|
[1996] | 853 | while ((int)mViewCells.size() < mMaxViewCells)
|
---|
| 854 | {
|
---|
| 855 | if (0)
|
---|
| 856 | {
|
---|
| 857 | mViewCells.push_back(mViewCellsManager->GetViewCell((int)mViewCells.size()));
|
---|
[1999] | 858 | continue;
|
---|
[1996] | 859 | }
|
---|
[1999] | 860 |
|
---|
| 861 | // HACK
|
---|
| 862 | const int tries = 10000;
|
---|
| 863 | int i = 0;
|
---|
| 864 |
|
---|
| 865 | for (i = 0; i < tries; ++ i)
|
---|
[1996] | 866 | {
|
---|
[1999] | 867 | const int idx = (int)RandomValue(0.0f, (float)mViewCellsManager->GetNumViewCells() - 0.5f);
|
---|
| 868 |
|
---|
| 869 | ViewCell *viewCell = mViewCellsManager->GetViewCell(idx);
|
---|
[1996] | 870 |
|
---|
[1999] | 871 | if (!viewCell->Mailed())
|
---|
[1996] | 872 | {
|
---|
[1999] | 873 | viewCell->Mail();
|
---|
| 874 | break;
|
---|
| 875 | }
|
---|
[2597] | 876 |
|
---|
[1999] | 877 | mViewCells.push_back(viewCell);
|
---|
| 878 | }
|
---|
[1996] | 879 |
|
---|
[1999] | 880 | if (i == tries)
|
---|
| 881 | {
|
---|
| 882 | cerr << "big error! no view cell found" << endl;
|
---|
| 883 | return;
|
---|
| 884 | }
|
---|
| 885 | }
|
---|
| 886 | }
|
---|
[1996] | 887 |
|
---|
[1999] | 888 |
|
---|
| 889 | void GvsPreprocessor::IntersectWithViewCell()
|
---|
| 890 | {
|
---|
| 891 | mCurrentViewCell->GetMesh()->ComputeBoundingBox();
|
---|
| 892 | AxisAlignedBox3 box = mCurrentViewCell->GetMesh()->mBox;
|
---|
[2544] | 893 |
|
---|
[2643] | 894 | //vector<KdLeaf *> leaves;
|
---|
| 895 | //mKdTree->GetBoxIntersections(box, leaves);
|
---|
[1999] | 896 |
|
---|
[2643] | 897 | ObjectContainer kdobjects;
|
---|
| 898 | mKdTree->CollectKdObjects(box, kdobjects);
|
---|
| 899 | //vector<KdLeaf *>::const_iterator lit, lit_end = leaves.end();
|
---|
| 900 | //for (lit = leaves.begin(); lit != lit_end; ++ lit)
|
---|
| 901 | ObjectContainer::const_iterator oit, oit_end = kdobjects.end();
|
---|
| 902 | for (oit = kdobjects.begin(); oit != oit_end; ++ oit)
|
---|
[1999] | 903 | {
|
---|
[2643] | 904 | // add to kdnode pvs
|
---|
| 905 | KdIntersectable *kdInt = static_cast<KdIntersectable *>(*oit);
|
---|
[2615] | 906 |
|
---|
[2643] | 907 | //mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f);
|
---|
| 908 | mCurrentViewCell->GetPvs().AddSampleDirtyCheck(kdInt, 1.0f);
|
---|
| 909 | mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt);
|
---|
[2615] | 910 |
|
---|
[2643] | 911 | myobjects.clear();
|
---|
| 912 | mKdTree->CollectObjects(kdInt->GetItem(), myobjects);
|
---|
[1999] | 913 |
|
---|
[2643] | 914 | // account for kd object pvs
|
---|
| 915 | ObjectContainer::const_iterator oit, oit_end = myobjects.end();
|
---|
| 916 |
|
---|
| 917 | for (oit = myobjects.begin(); oit != oit_end; ++ oit)
|
---|
[1999] | 918 | {
|
---|
[2017] | 919 | TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit);
|
---|
[2643] | 920 |
|
---|
| 921 | // account for the overall pvs
|
---|
| 922 | if ((triObj->mCounter != 1) && (triObj->mCounter != 3))
|
---|
| 923 | {
|
---|
| 924 | ++ triObj->mCounter;
|
---|
| 925 | ++ mGenericStats2;
|
---|
| 926 | }
|
---|
| 927 |
|
---|
| 928 | // the triangle itself intersects
|
---|
[1999] | 929 | if (box.Intersects(triObj->GetItem()))
|
---|
[1996] | 930 | {
|
---|
[2643] | 931 | if ((triObj->mCounter < 2))
|
---|
[1999] | 932 | {
|
---|
[2643] | 933 | triObj->mCounter += 2;
|
---|
| 934 |
|
---|
[1999] | 935 | mTrianglePvs.push_back(triObj);
|
---|
[2643] | 936 | mGenericStats = mTrianglePvs.size();
|
---|
[1999] | 937 | }
|
---|
[2643] | 938 | }
|
---|
[1996] | 939 | }
|
---|
| 940 | }
|
---|
| 941 | }
|
---|
| 942 |
|
---|
| 943 |
|
---|
[1990] | 944 | void GvsPreprocessor::PerViewCellComputation()
|
---|
[1982] | 945 | {
|
---|
[2625] | 946 | ViewCell *vc;
|
---|
[1999] | 947 |
|
---|
[2625] | 948 | while (vc = NextViewCell())
|
---|
[1999] | 949 | {
|
---|
[2625] | 950 | // hack: reset counters
|
---|
| 951 | ObjectContainer::const_iterator oit, oit_end = mObjects.end();
|
---|
[2615] | 952 |
|
---|
[2625] | 953 | for (oit = mObjects.begin(); oit != oit_end; ++ oit)
|
---|
| 954 | (*oit)->mCounter = 0;
|
---|
[1982] | 955 |
|
---|
[2648] | 956 | ComputeViewCell(vc);
|
---|
[2625] | 957 | }
|
---|
| 958 | }
|
---|
[1990] | 959 |
|
---|
[1996] | 960 |
|
---|
[2625] | 961 | void GvsPreprocessor::PerViewCellComputation2()
|
---|
| 962 | {
|
---|
| 963 | ViewCell *vc;
|
---|
[1999] | 964 |
|
---|
[2625] | 965 | while (1)
|
---|
| 966 | {
|
---|
| 967 | if (!mRendererWidget)
|
---|
| 968 | continue;
|
---|
[1990] | 969 |
|
---|
[2625] | 970 | ViewCell *vc = mViewCellsManager->GetViewCell(mRendererWidget->GetViewPoint());
|
---|
[2601] | 971 |
|
---|
[2625] | 972 | // no valid view cell or view cell already computed
|
---|
[2643] | 973 | if (!vc || !vc->GetPvs().Empty() || !mRendererWidget->mComputeGVS)
|
---|
[2625] | 974 | continue;
|
---|
[2615] | 975 |
|
---|
[2643] | 976 | mRendererWidget->mComputeGVS = false;
|
---|
[2625] | 977 | // hack: reset counters
|
---|
| 978 | ObjectContainer::const_iterator oit, oit_end = mObjects.end();
|
---|
[2615] | 979 |
|
---|
[2625] | 980 | for (oit = mObjects.begin(); oit != oit_end; ++ oit)
|
---|
| 981 | (*oit)->mCounter = 0;
|
---|
[2601] | 982 |
|
---|
[2625] | 983 | ComputeViewCell(vc);
|
---|
| 984 | ++ mProcessedViewCells;
|
---|
| 985 | }
|
---|
| 986 | }
|
---|
[1999] | 987 |
|
---|
[1982] | 988 |
|
---|
[2048] | 989 | void GvsPreprocessor::StorePvs(const ObjectContainer &objectPvs)
|
---|
| 990 | {
|
---|
| 991 | ObjectContainer::const_iterator oit, oit_end = objectPvs.end();
|
---|
| 992 |
|
---|
| 993 | for (oit = objectPvs.begin(); oit != oit_end; ++ oit)
|
---|
| 994 | {
|
---|
| 995 | mCurrentViewCell->GetPvs().AddSample(*oit, 1);
|
---|
| 996 | }
|
---|
| 997 | }
|
---|
| 998 |
|
---|
| 999 |
|
---|
[1990] | 1000 | void GvsPreprocessor::UpdatePvs(ViewCell *currentViewCell)
|
---|
| 1001 | {
|
---|
| 1002 | ObjectPvs newPvs;
|
---|
| 1003 | BvhLeaf::NewMail();
|
---|
| 1004 |
|
---|
| 1005 | ObjectPvsIterator pit = currentViewCell->GetPvs().GetIterator();
|
---|
| 1006 |
|
---|
| 1007 | // output PVS of view cell
|
---|
| 1008 | while (pit.HasMoreEntries())
|
---|
| 1009 | {
|
---|
[2117] | 1010 | Intersectable *intersect = pit.Next();
|
---|
[1990] | 1011 |
|
---|
| 1012 | BvhLeaf *bv = intersect->mBvhLeaf;
|
---|
| 1013 |
|
---|
| 1014 | if (!bv || bv->Mailed())
|
---|
| 1015 | continue;
|
---|
| 1016 |
|
---|
| 1017 | bv->Mail();
|
---|
| 1018 |
|
---|
| 1019 | //m.mDiffuseColor = RgbColor(1, 0, 0);
|
---|
| 1020 | newPvs.AddSampleDirty(bv, 1.0f);
|
---|
[1982] | 1021 | }
|
---|
[1990] | 1022 |
|
---|
| 1023 | newPvs.SimpleSort();
|
---|
| 1024 |
|
---|
| 1025 | currentViewCell->SetPvs(newPvs);
|
---|
[1982] | 1026 | }
|
---|
| 1027 |
|
---|
[1999] | 1028 |
|
---|
| 1029 | void GvsPreprocessor::GetObjectPvs(ObjectContainer &objectPvs) const
|
---|
| 1030 | {
|
---|
[2053] | 1031 | objectPvs.reserve((int)mTrianglePvs.size());
|
---|
| 1032 |
|
---|
[1999] | 1033 | BvhLeaf::NewMail();
|
---|
[1982] | 1034 |
|
---|
[1999] | 1035 | ObjectContainer::const_iterator oit, oit_end = mTrianglePvs.end();
|
---|
| 1036 |
|
---|
| 1037 | for (oit = mTrianglePvs.begin(); oit != oit_end; ++ oit)
|
---|
| 1038 | {
|
---|
| 1039 | Intersectable *intersect = *oit;
|
---|
| 1040 |
|
---|
| 1041 | BvhLeaf *bv = intersect->mBvhLeaf;
|
---|
| 1042 |
|
---|
[2053] | 1043 | // hack: reset counter
|
---|
| 1044 | (*oit)->mCounter = 0;
|
---|
| 1045 |
|
---|
[1999] | 1046 | if (!bv || bv->Mailed())
|
---|
| 1047 | continue;
|
---|
[2615] | 1048 |
|
---|
[1999] | 1049 | bv->Mail();
|
---|
| 1050 | objectPvs.push_back(bv);
|
---|
| 1051 | }
|
---|
| 1052 | }
|
---|
| 1053 |
|
---|
| 1054 |
|
---|
[1990] | 1055 | void GvsPreprocessor::GlobalComputation()
|
---|
| 1056 | {
|
---|
| 1057 | int passSamples = 0;
|
---|
| 1058 | int oldContribution = 0;
|
---|
| 1059 |
|
---|
| 1060 | while (mGvsStats.mTotalSamples < mTotalSamples)
|
---|
| 1061 | {
|
---|
[2048] | 1062 | mRayCaster->InitPass();
|
---|
[1990] | 1063 | // Ray queue empty =>
|
---|
| 1064 | // cast a number of uniform samples to fill ray queue
|
---|
| 1065 | int newSamples = CastInitialSamples(mInitialSamples, mSamplingType);
|
---|
| 1066 |
|
---|
| 1067 | if (!mOnlyRandomSampling)
|
---|
| 1068 | newSamples += ProcessQueue();
|
---|
| 1069 |
|
---|
| 1070 | passSamples += newSamples;
|
---|
| 1071 | mGvsStats.mTotalSamples += newSamples;
|
---|
| 1072 |
|
---|
[2048] | 1073 | if (passSamples % (mGvsSamplesPerPass + 1) == mGvsSamplesPerPass)
|
---|
[1990] | 1074 | {
|
---|
| 1075 | ++ mPass;
|
---|
| 1076 |
|
---|
| 1077 | mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution;
|
---|
| 1078 |
|
---|
| 1079 | ////////
|
---|
| 1080 | //-- stats
|
---|
| 1081 |
|
---|
| 1082 | //cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl;
|
---|
| 1083 | mGvsStats.mPass = mPass;
|
---|
| 1084 | mGvsStats.Stop();
|
---|
| 1085 | mGvsStats.Print(mGvsStatsStream);
|
---|
| 1086 |
|
---|
| 1087 | // reset
|
---|
| 1088 | oldContribution = mGvsStats.mTotalContribution;
|
---|
| 1089 | mGvsStats.mPassContribution = 0;
|
---|
| 1090 | passSamples = 0;
|
---|
| 1091 |
|
---|
| 1092 | if (GVS_DEBUG)
|
---|
| 1093 | VisualizeViewCells();
|
---|
| 1094 | }
|
---|
| 1095 | }
|
---|
| 1096 | }
|
---|
| 1097 |
|
---|
| 1098 |
|
---|
[1489] | 1099 | bool GvsPreprocessor::ComputeVisibility()
|
---|
[1460] | 1100 | {
|
---|
[1533] | 1101 | cout << "Gvs Preprocessor started\n" << flush;
|
---|
[1545] | 1102 | const long startTime = GetTime();
|
---|
[1533] | 1103 |
|
---|
[1990] | 1104 | //Randomize(0);
|
---|
[1934] | 1105 | mGvsStats.Reset();
|
---|
| 1106 | mGvsStats.Start();
|
---|
[1545] | 1107 |
|
---|
[1486] | 1108 | if (!mLoadViewCells)
|
---|
[1563] | 1109 | {
|
---|
| 1110 | /// construct the view cells from the scratch
|
---|
| 1111 | ConstructViewCells();
|
---|
[1580] | 1112 | // reset pvs already gathered during view cells construction
|
---|
| 1113 | mViewCellsManager->ResetPvs();
|
---|
[1563] | 1114 | cout << "finished view cell construction" << endl;
|
---|
[1486] | 1115 | }
|
---|
[2625] | 1116 | #if 0
|
---|
| 1117 | else
|
---|
[1563] | 1118 | {
|
---|
[1551] | 1119 | //-- test successful view cells loading by exporting them again
|
---|
| 1120 | VssRayContainer dummies;
|
---|
| 1121 | mViewCellsManager->Visualize(mObjects, dummies);
|
---|
[1563] | 1122 | mViewCellsManager->ExportViewCells("test.xml.gz", mViewCellsManager->GetExportPvs(), mObjects);
|
---|
[1551] | 1123 | }
|
---|
[2625] | 1124 | #endif
|
---|
[1460] | 1125 |
|
---|
[1982] | 1126 | if (mPerViewCell)
|
---|
[1473] | 1127 | {
|
---|
[2648] | 1128 | #if 1
|
---|
[2597] | 1129 | // provide list of view cells to compute
|
---|
[1996] | 1130 | CompileViewCellsList();
|
---|
[2597] | 1131 | // start per view cell gvs
|
---|
[2048] | 1132 | PerViewCellComputation();
|
---|
[2625] | 1133 | #else
|
---|
| 1134 | PerViewCellComputation2();
|
---|
| 1135 |
|
---|
| 1136 | #endif
|
---|
[1460] | 1137 | }
|
---|
[1982] | 1138 | else
|
---|
| 1139 | {
|
---|
| 1140 | GlobalComputation();
|
---|
| 1141 | }
|
---|
[1460] | 1142 |
|
---|
[1934] | 1143 | cout << "cast " << 2 * mGvsStats.mTotalSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl;
|
---|
[1545] | 1144 |
|
---|
[1934] | 1145 | if (GVS_DEBUG)
|
---|
| 1146 | {
|
---|
| 1147 | Visualize();
|
---|
| 1148 | CLEAR_CONTAINER(mVssRays);
|
---|
| 1149 | }
|
---|
[2048] | 1150 |
|
---|
| 1151 | // export the preprocessed information to a file
|
---|
| 1152 | if (0 && mExportVisibility)
|
---|
| 1153 | {
|
---|
| 1154 | ExportPreprocessedData(mVisibilityFileName);
|
---|
| 1155 | }
|
---|
[2648] | 1156 |
|
---|
| 1157 | // compute the pixel error of this visibility solution
|
---|
| 1158 | if (mEvaluatePixelError)
|
---|
| 1159 | {
|
---|
| 1160 | ComputeRenderError();
|
---|
| 1161 | }
|
---|
[1934] | 1162 |
|
---|
[1473] | 1163 | return true;
|
---|
[1460] | 1164 | }
|
---|
| 1165 |
|
---|
[1522] | 1166 |
|
---|
[2048] | 1167 | void GvsPreprocessor::DeterminePvsObjects(VssRayContainer &rays)
|
---|
| 1168 | {
|
---|
[2187] | 1169 | // store triangle directly
|
---|
[2048] | 1170 | mViewCellsManager->DeterminePvsObjects(rays, true);
|
---|
| 1171 | }
|
---|
| 1172 |
|
---|
| 1173 |
|
---|
[1522] | 1174 | void GvsPreprocessor::Visualize()
|
---|
| 1175 | {
|
---|
| 1176 | Exporter *exporter = Exporter::GetExporter("gvs.wrl");
|
---|
| 1177 |
|
---|
| 1178 | if (!exporter)
|
---|
| 1179 | return;
|
---|
| 1180 |
|
---|
| 1181 | vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end();
|
---|
[1999] | 1182 |
|
---|
[1522] | 1183 | for (vit = vizContainer.begin(); vit != vit_end; ++ vit)
|
---|
| 1184 | {
|
---|
[1524] | 1185 | exporter->SetWireframe();
|
---|
[1522] | 1186 | exporter->ExportPolygon((*vit).enlargedTriangle);
|
---|
| 1187 | //Material m;
|
---|
[1524] | 1188 | exporter->SetFilled();
|
---|
| 1189 | Polygon3 poly = Polygon3((*vit).originalTriangle);
|
---|
| 1190 | exporter->ExportPolygon(&poly);
|
---|
[1522] | 1191 | }
|
---|
| 1192 |
|
---|
[1933] | 1193 | VssRayContainer::const_iterator rit, rit_end = mVssRays.end();
|
---|
[1999] | 1194 |
|
---|
[1933] | 1195 | for (rit = mVssRays.begin(); rit != rit_end; ++ rit)
|
---|
| 1196 | {
|
---|
| 1197 | Intersectable *obj = (*rit)->mTerminationObject;
|
---|
| 1198 | exporter->ExportIntersectable(obj);
|
---|
| 1199 | }
|
---|
| 1200 |
|
---|
[1990] | 1201 | ExportVssRays(exporter, mVssRays);
|
---|
| 1202 |
|
---|
[1522] | 1203 | delete exporter;
|
---|
[1460] | 1204 | }
|
---|
[1522] | 1205 |
|
---|
[1934] | 1206 |
|
---|
| 1207 | void GvsStatistics::Print(ostream &app) const
|
---|
| 1208 | {
|
---|
[2003] | 1209 | app << "#ViewCells\n" << mViewCells << endl;
|
---|
[2648] | 1210 | app << "#Id\n" << mViewCellId << endl;
|
---|
| 1211 | app << "#Time\n" << mTimePerViewCell << endl;;
|
---|
[2003] | 1212 | app << "#TrianglePvs\n" << mTrianglePvs << endl;
|
---|
[2648] | 1213 | app << "#ObjectPvs\n" << mPerViewCellPvs << endl;
|
---|
| 1214 | app << "#PvsCost\n" << (int)mPvsCost << endl;
|
---|
[2003] | 1215 |
|
---|
[2648] | 1216 | #if 0
|
---|
[2003] | 1217 | app << "#TotalPvs\n" << mTotalPvs << endl;
|
---|
[2648] | 1218 | app << "#TotalTime\n" << mTotalTime << endl;
|
---|
| 1219 | app << "#RaysPerSec\n" << RaysPerSec() << endl;
|
---|
[2003] | 1220 |
|
---|
| 1221 | app << "#PerViewCellSamples\n" << mPerViewCellSamples << endl;
|
---|
[1934] | 1222 | app << "#TotalSamples\n" << mTotalSamples << endl;
|
---|
| 1223 | app << "#SamplesContri\n" << mTotalContribution << endl;
|
---|
[2648] | 1224 | app << "#TotalTrianglePvs\n" << mTotalTrianglePvs << endl;
|
---|
| 1225 |
|
---|
| 1226 | #endif
|
---|
| 1227 |
|
---|
[2003] | 1228 | //app << "#ReverseSamples\n" << mReverseSamples << endl;
|
---|
| 1229 | //app << "#BorderSamples\n" << mBorderSamples << endl;
|
---|
| 1230 |
|
---|
| 1231 | //app << "#Pass\n" << mPass << endl;
|
---|
| 1232 | //app << "#ScDiff\n" << mPassContribution << endl;
|
---|
| 1233 | //app << "#GvsRuns\n" << mGvsPass << endl;
|
---|
| 1234 |
|
---|
| 1235 | app << endl;
|
---|
[1883] | 1236 | }
|
---|
[1934] | 1237 |
|
---|
| 1238 |
|
---|
[2625] | 1239 | void GvsPreprocessor::ComputeViewCell(ViewCell *vc)
|
---|
| 1240 | {
|
---|
| 1241 | mCurrentViewCell = vc;
|
---|
[2643] | 1242 | KdNode::NewMail();
|
---|
[2625] | 1243 |
|
---|
| 1244 | long startTime = GetTime();
|
---|
| 1245 | cout << "\n***********************\n"
|
---|
[2643] | 1246 | << "computing view cell " << mProcessedViewCells
|
---|
[2625] | 1247 | << " (id: " << mCurrentViewCell->GetId() << ")" << endl;
|
---|
| 1248 |
|
---|
| 1249 | // compute the pvs of the current view cell
|
---|
| 1250 | ProcessViewCell();
|
---|
| 1251 |
|
---|
| 1252 | //mGvsStats.mTrianglePvs = mCurrentViewCell->GetPvs().GetSize();
|
---|
| 1253 | mGvsStats.mTrianglePvs = (int)mTrianglePvs.size();
|
---|
| 1254 | mGvsStats.mTotalTrianglePvs += mGvsStats.mTrianglePvs;
|
---|
| 1255 |
|
---|
| 1256 | if (!mUseKdPvs)
|
---|
| 1257 | {
|
---|
| 1258 | ObjectContainer objectPvs;
|
---|
| 1259 |
|
---|
| 1260 | // optain object pvs
|
---|
| 1261 | GetObjectPvs(objectPvs);
|
---|
| 1262 |
|
---|
| 1263 | // add pvs
|
---|
| 1264 | ObjectContainer::const_iterator it, it_end = objectPvs.end();
|
---|
| 1265 |
|
---|
| 1266 | for (it = objectPvs.begin(); it != it_end; ++ it)
|
---|
| 1267 | {
|
---|
| 1268 | mCurrentViewCell->GetPvs().AddSampleDirty(*it, 1.0f);
|
---|
| 1269 | }
|
---|
| 1270 |
|
---|
| 1271 | cout << "triangle pvs of " << (int)mTrianglePvs.size()
|
---|
| 1272 | << " was converted to object pvs of " << (int)objectPvs.size() << endl;
|
---|
| 1273 |
|
---|
| 1274 | mGvsStats.mPerViewCellPvs = (int)objectPvs.size();
|
---|
| 1275 | }
|
---|
| 1276 | else
|
---|
| 1277 | {
|
---|
[2643] | 1278 | mGvsStats.mPerViewCellPvs = mCurrentViewCell->GetPvs().GetSize();
|
---|
[2648] | 1279 | mGvsStats.mPvsCost = mCurrentViewCell->GetPvs().EvalPvsCost();
|
---|
[2643] | 1280 |
|
---|
[2648] | 1281 | cout << "id: " << mCurrentViewCell->GetId() << " pvs cost: "
|
---|
| 1282 | << mGvsStats.mPvsCost << " pvs tri: " << mTrianglePvs.size() << endl;
|
---|
[2625] | 1283 | }
|
---|
| 1284 |
|
---|
| 1285 |
|
---|
| 1286 | ////////
|
---|
| 1287 | //-- stats
|
---|
| 1288 |
|
---|
| 1289 | mGvsStats.mViewCells = mProcessedViewCells;//mPass;
|
---|
| 1290 | mGvsStats.mTotalPvs += mGvsStats.mPerViewCellPvs;
|
---|
| 1291 | mGvsStats.mTotalSamples += mGvsStats.mPerViewCellSamples;
|
---|
| 1292 |
|
---|
| 1293 | // timing
|
---|
| 1294 | const long currentTime = GetTime();
|
---|
| 1295 |
|
---|
| 1296 | mGvsStats.mTimePerViewCell = TimeDiff(startTime, currentTime) * 1e-3f;
|
---|
| 1297 | mGvsStats.mTotalTime += mGvsStats.mTimePerViewCell;
|
---|
| 1298 |
|
---|
| 1299 | mGvsStats.Stop();
|
---|
| 1300 | mGvsStats.Print(mGvsStatsStream);
|
---|
| 1301 |
|
---|
| 1302 | mTrianglePvs.clear();
|
---|
[1934] | 1303 | }
|
---|
[2625] | 1304 |
|
---|
| 1305 | }
|
---|