Changeset 2690 for GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
- Timestamp:
- 05/20/08 17:15:44 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r2689 r2690 152 152 #endif 153 153 { 154 //cout << "r";155 154 // apply reverse sampling to find the gap 156 155 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); … … 160 159 161 160 // set flag for visualization 162 //newRay->mFlags |= VssRay::ReverseSample;161 if (0) newRay->mFlags |= VssRay::ReverseSample; 163 162 164 163 // check if ray is not further processed (ray not deleted because using ray pool) … … 185 184 void GvsPreprocessor::UpdateStatsForVisualization(KdIntersectable *kdInt) 186 185 { 187 mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt);186 //mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt); 188 187 189 188 // count new objects in pvs due to kd node conversion … … 222 221 223 222 // counter < 2 => not accounted for yet 224 if (obj->mCounter < ACCOUNTED_OBJECT) 223 // test of triangle was accounted for yet 224 if (result = AddTriangleObject(obj)) 225 225 { 226 obj->mCounter += ACCOUNTED_OBJECT;227 mTrianglePvs.push_back(obj);228 229 mGenericStats = (int)mTrianglePvs.size();230 231 226 // exchange the triangle with the node in the pvs for kd pvs 232 227 if (mUseKdPvs) … … 664 659 665 660 while (!mRayQueue.empty())//&& (mGvsStats.mTotalSamples + castSamples < mTotalSamples) ) 666 {//cout<<"r"; 667 //cout << "queue size: " << mRayQueue.size() << endl; 661 { 668 662 // handle next ray 669 663 VssRay *ray = mRayQueue.top(); … … 794 788 795 789 796 void GvsPreprocessor::ProcessViewCell()797 {798 // compute object that directly intersect view cell799 IntersectWithViewCell();800 801 mGvsStats.mPerViewCellSamples = 0;802 803 int oldContribution = mGvsStats.mTotalContribution;804 int passSamples = 0;805 806 mGenericStats = 0;807 mGenericStats2 = 0;808 809 while (1)810 {811 mRayCaster->InitPass();812 813 // Ray queue empty =>814 // cast a number of uniform samples to fill ray queue815 int newSamples = CastInitialSamples(mInitialSamples, mSamplingType);816 817 if (!mOnlyRandomSampling)818 {819 int samplesPerRun = ProcessQueue();820 newSamples += samplesPerRun;821 //if (samplesPerRun > 0) cout << "spr: " << samplesPerRun << " ";822 }823 824 passSamples += newSamples;825 mGvsStats.mPerViewCellSamples += newSamples;826 827 if (passSamples >= mGvsSamplesPerPass)828 {829 ++ mPass;830 mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution;831 832 ////////833 //-- stats834 835 mGvsStats.mPass = mPass;836 837 cout << "\nPass " << mPass << " #samples: " << mGvsStats.mPerViewCellSamples << endl;838 cout << "contribution=" << mGvsStats.mPassContribution << " (of " << mMinContribution << ")" << endl;839 840 //mGenericStats = mGvsStats.mPassContribution;841 842 // termination criterium843 if (mGvsStats.mPassContribution < mMinContribution)844 break;845 846 // reset847 oldContribution = mGvsStats.mTotalContribution;848 mGvsStats.mPassContribution = 0;849 passSamples = 0;850 }851 }852 }853 854 855 790 void GvsPreprocessor::CompileViewCellsFromPointList() 856 791 { … … 945 880 } 946 881 947 #if 0882 #if 1 948 883 void GvsPreprocessor::IntersectWithViewCell() 949 884 { … … 1066 1001 void GvsPreprocessor::PerViewCellComputation() 1067 1002 { 1068 ViewCell *vc; 1069 1070 while (vc = NextViewCell()) 1003 while (mCurrentViewCell = NextViewCell()) 1071 1004 { 1072 1005 // hack: reset counters … … 1076 1009 (*oit)->mCounter = NOT_ACCOUNTED_OBJECT; 1077 1010 1078 ComputeViewCell( vc);1011 ComputeViewCell(); 1079 1012 } 1080 1013 } … … 1088 1021 continue; 1089 1022 1090 ViewCell *vc= mViewCellsManager->GetViewCell(mRendererWidget->GetViewPoint());1023 mCurrentViewCell = mViewCellsManager->GetViewCell(mRendererWidget->GetViewPoint()); 1091 1024 1092 1025 // no valid view cell or view cell already computed 1093 if (! vc || !vc->GetPvs().Empty() || !mRendererWidget->mComputeGVS)1026 if (!mCurrentViewCell || !mCurrentViewCell->GetPvs().Empty() || !mRendererWidget->mComputeGVS) 1094 1027 continue; 1095 1028 … … 1101 1034 (*oit)->mCounter = NOT_ACCOUNTED_OBJECT; 1102 1035 1103 ComputeViewCell( vc);1036 ComputeViewCell(); 1104 1037 ++ mProcessedViewCells; 1105 1038 } … … 1322 1255 app << "#Id\n" << mViewCellId << endl; 1323 1256 app << "#Time\n" << mTimePerViewCell << endl;; 1324 app << "#Tri aePvs\n" << mTrianglePvs << endl;1257 app << "#TriPvs\n" << mTrianglePvs << endl; 1325 1258 app << "#ObjectPvs\n" << mPerViewCellPvs << endl; 1326 1259 app << "#UpdatedPvs\n" << (int)mPvsCost << endl; … … 1351 1284 1352 1285 1353 void GvsPreprocessor::ComputeViewCell( ViewCell *vc)1286 void GvsPreprocessor::ComputeViewCell() 1354 1287 { 1355 1288 KdNode::NewMail(); 1356 1289 1357 mCurrentViewCell = vc;1358 1359 1290 const long startTime = GetTime(); 1360 1291 … … 1364 1295 1365 1296 // compute the pvs of the current view cell 1366 ProcessViewCell(); 1367 1368 1297 // compute object that directly intersect view cell 1298 //IntersectWithViewCell(); 1299 1300 mGvsStats.mPerViewCellSamples = 0; 1301 1302 int oldContribution = mGvsStats.mTotalContribution; 1303 int passSamples = 0; 1304 1305 mGenericStats = 0; 1306 mGenericStats2 = 0; 1307 1308 while (1) 1309 { 1310 int oldPvsSize = 0;//mCurrentViewCell->GetPvs().GetSize(); 1311 1312 mRayCaster->InitPass(); 1313 1314 // Ray queue empty => 1315 // cast a number of uniform samples to fill ray queue 1316 int newSamples = CastInitialSamples(mInitialSamples, mSamplingType); 1317 1318 if (!mOnlyRandomSampling) 1319 { 1320 int samplesPerRun = ProcessQueue(); 1321 newSamples += samplesPerRun; 1322 //if (samplesPerRun > 0) cout << "spr: " << samplesPerRun << " "; 1323 } 1324 1325 passSamples += newSamples; 1326 mGvsStats.mPerViewCellSamples += newSamples; 1327 1328 if (passSamples >= mGvsSamplesPerPass) 1329 { 1330 if (GVS_DEBUG) VisualizeViewCell(mTrianglePvs); 1331 1332 const bool convertPerPass = false; 1333 1334 if (convertPerPass) 1335 { 1336 int newObjects = ConvertObjectPvs(); 1337 1338 cout << "added " << newObjects << " triangles to triangle pvs" << endl; 1339 mGvsStats.mTotalContribution += newObjects; 1340 } 1341 1342 ++ mPass; 1343 mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution; 1344 1345 1346 //////// 1347 //-- stats 1348 1349 mGvsStats.mPass = mPass; 1350 1351 cout << "\nPass " << mPass << " #samples: " << mGvsStats.mPerViewCellSamples << endl; 1352 cout << "contribution=" << mGvsStats.mPassContribution << " (of " << mMinContribution << ")" << endl; 1353 cout << "obj contri=" << mCurrentViewCell->GetPvs().GetSize() - oldPvsSize << " (of " << mMinContribution << ")" << endl; 1354 1355 // termination criterium 1356 if (mGvsStats.mPassContribution < mMinContribution) 1357 break; 1358 1359 // reset 1360 oldContribution = mGvsStats.mTotalContribution; 1361 mGvsStats.mPassContribution = 0; 1362 passSamples = 0; 1363 } 1364 } 1365 1366 // finally add objects that directly intersect the view cell 1367 //IntersectWithViewCell(); 1368 1369 1369 1370 //////// 1370 1371 //-- stats 1371 1372 1373 // timing 1374 mGvsStats.mTimePerViewCell = TimeDiff(startTime, GetTime()) * 1e-3f; 1375 1376 ComputeStats(); 1377 1378 // clean up 1379 mTrianglePvs.clear(); 1380 } 1381 1382 1383 void GvsPreprocessor::ComputeStats() 1384 { 1372 1385 // compute pvs size using larger (bvh objects) 1373 1386 // note: for kd pvs we had to do this during gvs computation … … 1402 1415 1403 1416 mGvsStats.mTrianglePvs = (int)mTrianglePvs.size(); 1404 1405 // timing1406 const long currentTime = GetTime();1407 mGvsStats.mTimePerViewCell = TimeDiff(startTime, currentTime) * 1e-3f;1408 1417 1409 1418 … … 1411 1420 // global values 1412 1421 1413 mGvsStats.mViewCells = mProcessedViewCells; //mPass;1422 mGvsStats.mViewCells = mProcessedViewCells; 1414 1423 mGvsStats.mTotalTrianglePvs += mGvsStats.mTrianglePvs; 1415 1424 mGvsStats.mTotalTime += mGvsStats.mTimePerViewCell; … … 1421 1430 1422 1431 cout << "id: " << mCurrentViewCell->GetId() << " pvs cost: " 1423 << mGvsStats.mPvsCost << " pvs tri: " << mTrianglePvs.size() << endl; 1424 1425 1426 mTrianglePvs.clear(); 1427 } 1428 1429 } 1432 << mGvsStats.mPvsCost << " pvs tri: " << mTrianglePvs.size() << endl; 1433 } 1434 1435 1436 ObjectContainer triangles; 1437 1438 int GvsPreprocessor::ConvertObjectPvs() 1439 { 1440 int newObjects = 0; 1441 1442 ObjectPvsIterator pit = mCurrentViewCell->GetPvs().GetIterator(); 1443 1444 triangles.clear(); 1445 1446 // output PVS of view cell 1447 while (pit.HasMoreEntries()) 1448 { 1449 KdIntersectable *kdInt = static_cast<KdIntersectable *>(pit.Next()); 1450 1451 mKdTree->CollectObjectsWithDublicates(kdInt->GetItem(), triangles); 1452 1453 ObjectContainer::const_iterator oit, oit_end = triangles.end(); 1454 1455 for (oit = triangles.begin(); oit != oit_end; ++ oit) 1456 { 1457 if (AddTriangleObject(*oit)) 1458 ++ newObjects; 1459 } 1460 } 1461 1462 return newObjects; 1463 } 1464 1465 1466 bool GvsPreprocessor::AddTriangleObject(Intersectable *triObj) 1467 { 1468 if ((triObj->mCounter < ACCOUNTED_OBJECT)) 1469 { 1470 triObj->mCounter += ACCOUNTED_OBJECT; 1471 1472 mTrianglePvs.push_back(triObj); 1473 mGenericStats = (int)mTrianglePvs.size(); 1474 return true; 1475 } 1476 1477 return false; 1478 } 1479 1480 }
Note: See TracChangeset
for help on using the changeset viewer.