Changeset 1570 for GTP/trunk/Lib
- Timestamp:
- 10/04/06 20:43:07 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1566 r1570 65 65 { 66 66 VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay); 67 // ray is not pushed into the queue => can delete ray 67 68 if (!HandleRay(newRay)) 68 {69 69 delete newRay; 70 }70 71 71 return true; 72 72 } … … 78 78 bool GvsPreprocessor::HandleRay(VssRay *vssRay) 79 79 { 80 mViewCellsManager->ComputeSampleContribution(*vssRay, true, false); 80 const bool storeRaysForViz = true; 81 mViewCellsManager->ComputeSampleContribution(*vssRay, true, storeRaysForViz); 81 82 82 83 // some pvs contribution for this ray? … … 85 86 //cout << " h " << mSampleContriPerPass << " " << mSamplesPerPass << " " << mTotalSamples << endl; 86 87 mRayQueue.push(vssRay); 87 mVssRays.push_back(new VssRay(*vssRay)); 88 89 if (storeRaysForViz) 90 { 91 ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end(); 92 for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit) 93 { 94 (*vit)->mVssRays.push_back(new VssRay(*vssRay)); 95 } 96 } 97 //mVssRays.push_back(new VssRay(*vssRay)); 88 98 ++ mSampleContriPerPass; 89 99 … … 443 453 mViewCellsManager->PrintPvsStatistics(mStats); 444 454 455 char str[64]; sprintf(str, "tmp/pass%04d-", mPass); 456 445 457 // visualization 446 // mViewCellsManager->Visualize(mVssRays); 458 const bool exportRays = true; 459 const bool exportPvs = true; 460 mViewCellsManager->ExportSingleViewCells(mObjects, 10, false, exportPvs, exportRays, 100, str); 461 // remove pass samples 462 ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end(); 463 464 for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) 465 { 466 CLEAR_CONTAINER((*vit)->mVssRays); 467 } 468 447 469 CLEAR_CONTAINER(mVssRays); 448 470 // ComputeRenderError(); -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1344 r1570 39 39 /// unique object Id 40 40 int mId; 41 42 41 /// universal counter 43 42 int mCounter; 44 45 /// object based pvs46 KdPvs mKdPvs;47 48 /// view cell based pvs per object49 ViewCellPvs mViewCellPvs;50 43 51 44 /// pointer to the container bvh leaf 52 45 BvhLeaf *mBvhLeaf; 53 46 /// some rays piercing this intersectable 54 47 VssRayContainer mVssRays; 55 48 56 49 /// # of references to this instance 57 50 int mReferences; 51 52 ////////////////// 53 // note matt: delete these, they are only taking memory+ 54 55 /// object based pvs 56 KdPvs mKdPvs; 57 /// view cell based pvs per object 58 ViewCellPvs mViewCellPvs; 59 60 /////////////////////// 58 61 59 62 enum { MESH_INSTANCE, -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
r1551 r1570 27 27 28 28 29 //////////// 29 30 //-- static members 30 31 … … 39 40 { 40 41 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 41 //return false; 42 42 43 if (vdata) 43 44 { … … 1968 1969 { 1969 1970 contribution = 0; // todo 1970 1971 1971 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc); 1972 1972 … … 1979 1979 obj->mViewCellPvs.AddSample(vc, 1); 1980 1980 } 1981 1982 1981 vdata->Mail(); 1983 1982 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1564 r1570 803 803 } 804 804 805 // should never come here 806 return NULL; 805 return NULL; // should never come here 807 806 } 808 807 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1551 r1570 114 114 //mMailbox(0) 115 115 { 116 mId = -100; 116 117 } 117 118 … … 127 128 //mMailbox(0) 128 129 { 130 mId = -100; 129 131 } 130 132 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1566 r1570 822 822 int numSamples; 823 823 int castSamples = 0; 824 825 char s[64]; 824 char str[64]; 826 825 827 826 Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", samplesPerPass); … … 851 850 // statistics before casting more samples 852 851 cout << "compute new statistics ... "; 853 sprintf(s , "-%09d-eval.log", castSamples);854 string fName = string(statsPrefix) + string(s );852 sprintf(str, "-%09d-eval.log", castSamples); 853 string fName = string(statsPrefix) + string(str); 855 854 856 855 mViewCellsTree->ExportStats(fName); 857 856 cout << "finished" << endl; 858 857 } 858 859 859 cout << "finished" << endl; 860 861 860 cout << "Evaluating view cell partition ... " << endl; 862 861 … … 897 896 898 897 startTime = GetTime(); 899 900 898 cout << "compute new statistics ... " << endl; 901 899 … … 905 903 906 904 //-- output stats 907 sprintf(s , "-%09d-eval.log", castSamples);908 string fileName = string(statsPrefix) + string(s );905 sprintf(str, "-%09d-eval.log", castSamples); 906 string fileName = string(statsPrefix) + string(str); 909 907 910 908 mViewCellsTree->ExportStats(fileName); … … 918 916 919 917 920 //////////// 7918 //////////// 921 919 //-- histogram 922 920 … … 2824 2822 } 2825 2823 2826 // export single view cells 2827 ExportBspPvs(objects); 2824 int leafOut; 2825 Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.maxOutput", leafOut); 2826 const int raysOut = 100; 2827 ExportSingleViewCells(objects, leafOut, false, true, false, raysOut, ""); 2828 2828 } 2829 2829 … … 2858 2858 2859 2859 2860 void BspViewCellsManager::ExportBspPvs(const ObjectContainer &objects) 2861 { 2862 const int leafOut = 10; 2860 void BspViewCellsManager::ExportSingleViewCells(const ObjectContainer &objects, 2861 const int maxViewCells, 2862 const bool sortViewCells, 2863 const bool exportPvs, 2864 const bool exportRays, 2865 const int maxRays, 2866 const string prefix, 2867 VssRayContainer *visRays) 2868 { 2869 if (sortViewCells) 2870 { // sort view cells to visualize the largest view cells 2871 stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::LargerRenderCost); 2872 } 2873 2874 ////////// 2875 //-- some view cells for output 2876 2863 2877 ViewCell::NewMail(); 2864 2865 ////////// 2866 //-- some rays for output 2867 const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 2868 2869 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 2870 Debug << "\nOutput view cells: " << endl; 2871 2872 // sort view cells in order to find the largest view cells 2873 if (0) stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 2874 2875 int limit = min(leafOut, (int)mViewCells.size()); 2876 2878 const int limit = min(maxViewCells, (int)mViewCells.size()); 2879 2877 2880 for (int i = 0; i < limit; ++ i) 2878 2881 { 2879 cout << "creating output for view cell " << i << " ... "; 2880 VssRayContainer vcRays; 2881 Intersectable::NewMail(); 2882 ViewCell *vc; 2883 2884 if (0 || ((int)mViewCells.size() <= limit)) 2885 vc = mViewCells[i]; 2886 else 2887 vc = mViewCells[Random((int)mViewCells.size())]; 2888 2889 cout << "creating output for view cell " << i << " ... "; 2890 2891 if(0) 2892 { 2893 // check whether we can add the current ray to the output rays 2894 for (int k = 0; k < raysOut; ++ k) 2895 { 2896 BspRay *ray = mBspRays[k]; 2897 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 2882 const int idx = sortViewCells ? (int)RandomValue(0, (float)mViewCells.size() - 0.5f) : i; 2883 ViewCell *vc = mViewCells[idx]; 2884 2885 if (vc->Mailed() || vc->GetId() == OUT_OF_BOUNDS_ID) 2886 continue; 2887 2888 vc->Mail(); 2889 2890 ObjectPvs pvs; 2891 mViewCellsTree->GetPvs(vc, pvs); 2892 2893 char s[64]; sprintf(s, "%sviewcell%04d.wrl", prefix.c_str(), i); 2894 Exporter *exporter = Exporter::GetExporter(s); 2895 2896 cout << "view cell " << idx << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 2897 2898 if (exportRays) 2899 { 2900 //////////// 2901 //-- export rays piercing this view cell 2902 2903 // take rays stored with the view cells during subdivision 2904 VssRayContainer vcRays; 2905 VssRayContainer collectRays; 2906 2907 // collect initial view cells 2908 ViewCellContainer leaves; 2909 mViewCellsTree->CollectLeaves(vc, leaves); 2910 2911 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 2912 for (vit = leaves.begin(); vit != vit_end; ++ vit) 2913 { 2914 BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0]; 2915 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 2916 2917 for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 2898 2918 { 2899 BspLeaf *leaf = ray->intersections[j].mLeaf; 2900 if (vc == leaf->GetViewCell()) 2901 { 2902 vcRays.push_back(ray->vssRay); 2903 } 2919 collectRays.push_back(*rit); 2904 2920 } 2905 2921 } 2906 } 2907 2908 //bspLeaves[j]->Mail(); 2909 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 2910 2911 Exporter *exporter = Exporter::GetExporter(s); 2922 2923 const int raysOut = min((int)collectRays.size(), maxRays); 2924 cout << "here500 " << raysOut << endl; 2925 // prepare some rays for output 2926 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 2927 for (rit = collectRays.begin(); rit != rit_end; ++ rit) 2928 { 2929 const float p = RandomValue(0.0f, (float)collectRays.size()); 2930 2931 if (p < raysOut) 2932 { 2933 vcRays.push_back(*rit); 2934 } 2935 } 2936 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 2937 } 2938 2939 //////////////// 2940 //-- export view cell geometry 2912 2941 2913 2942 exporter->SetWireframe(); … … 2918 2947 2919 2948 ExportViewCellGeometry(exporter, vc, NULL, NULL); 2949 exporter->SetFilled(); 2950 2951 if (exportPvs) 2952 { 2953 Intersectable::NewMail(); 2954 2955 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 2956 cout << endl; 2957 // output PVS of view cell 2958 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 2959 { 2960 Intersectable *intersect = (*oit).first; 2961 2962 if (!intersect->Mailed()) 2963 { 2964 intersect->Mail(); 2965 m = RandomMaterial(); 2966 exporter->SetForcedMaterial(m); 2967 exporter->ExportIntersectable(intersect); 2968 cout << " i: " << intersect; 2969 } 2970 } 2971 cout << endl; 2972 } 2920 2973 2921 // export rays piercing this view cell2922 exporter->ExportRays(vcRays, RgbColor(0, 1, 0));2923 2924 m.mDiffuseColor = RgbColor(1, 0, 0);2925 exporter->SetForcedMaterial(m);2926 2927 ObjectPvsMap::const_iterator it,2928 it_end = vc->GetPvs().mEntries.end();2929 2930 exporter->SetFilled();2931 2932 // output PVS of view cell2933 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)2934 {2935 Intersectable *intersect = (*it).first;2936 2937 if (!intersect->Mailed())2938 {2939 Material m = RandomMaterial();2940 exporter->SetForcedMaterial(m);2941 2942 exporter->ExportIntersectable(intersect);2943 intersect->Mail();2944 }2945 }2946 2947 2974 DEL_PTR(exporter); 2948 2975 cout << "finished" << endl; 2949 2976 } 2950 2951 Debug << endl;2952 2977 } 2953 2978 … … 2989 3014 const AxisAlignedBox3 *sceneBox, 2990 3015 const AxisAlignedPlane *clipPlane 2991 3016 ) const 2992 3017 { 2993 3018 if (clipPlane) … … 3336 3361 3337 3362 3363 void KdViewCellsManager::ExportSingleViewCells(const ObjectContainer &objects, 3364 const int maxViewCells, 3365 const bool sortViewCells, 3366 const bool exportPvs, 3367 const bool exportRays, 3368 const int maxRays, 3369 const string prefix, 3370 VssRayContainer *visRays) 3371 { 3372 // TODO 3373 } 3374 3375 3338 3376 void KdViewCellsManager::Visualize(const ObjectContainer &objects, 3339 3377 const VssRayContainer &sampleRays) … … 3392 3430 3393 3431 ViewCell *vc = leaf->mViewCell; 3394 3395 //bspLeaves[j]->Mail(); 3396 char s[64]; sprintf(s, "kd-pvs%04d.x3d", i); 3397 3398 Exporter *exporter = Exporter::GetExporter(s); 3432 char str[64]; sprintf(str, "viewcell%04d.wrl", i); 3433 3434 Exporter *exporter = Exporter::GetExporter(str); 3399 3435 exporter->SetFilled(); 3400 3436 … … 3463 3499 3464 3500 exporter->SetFilled(); 3465 3466 3501 delete exporter; 3467 3502 } … … 3470 3505 { 3471 3506 Intersectable *object = objects[k]; 3472 char s[64]; 3473 sprintf(s, "sample-pvs%04d.x3d", k); 3474 3475 Exporter *exporter = Exporter::GetExporter(s); 3507 char str[64]; sprintf(str, "viewcell%04d.wrl", i); 3508 3509 Exporter *exporter = Exporter::GetExporter(str); 3476 3510 exporter->SetWireframe(); 3477 3511 … … 3707 3741 ////////////////////// 3708 3742 //-- recast the rest of the rays 3743 3709 3744 startTime = GetTime(); 3710 3745 … … 4165 4200 //////// 4166 4201 //-- export single view cells 4167 ExportBspPvs(objects, visRays); 4202 4203 int leafOut; 4204 Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.maxOutput", leafOut); 4205 const int raysOut = 100; 4206 4207 ExportSingleViewCells(objects, leafOut, false, true, false, raysOut, ""); 4168 4208 } 4169 4209 … … 4200 4240 exporter->ExportGeometry(objects); 4201 4241 } 4202 4203 4242 delete exporter; 4204 4243 } … … 4206 4245 4207 4246 4208 void VspBspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 4209 const VssRayContainer &rays) 4210 { 4211 int leafOut; 4212 Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.maxOutput", leafOut); 4247 void VspBspViewCellsManager::ExportSingleViewCells(const ObjectContainer &objects, 4248 const int maxViewCells, 4249 const bool sortViewCells, 4250 const bool exportPvs, 4251 const bool exportRays, 4252 const int maxRays, 4253 const string prefix, 4254 VssRayContainer *visRays) 4255 { 4256 if (sortViewCells) 4257 { 4258 // sort view cells to visualize the largest view cells 4259 stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::LargerRenderCost); 4260 } 4261 4262 ////////// 4263 //-- some view cells for output 4213 4264 4214 4265 ViewCell::NewMail(); 4215 4216 cout << "visualization using " << (int)rays.size() << " samples" << endl; 4217 Debug << "visualization using " << (int)rays.size() << " samples" << endl; 4218 Debug << "\nOutput view cells: " << endl; 4219 4220 const bool sortViewCells = true; 4221 4222 // sort view cells to visualize the largest view cells 4223 if (sortViewCells) 4224 { 4225 //stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 4226 stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::LargerRenderCost); 4227 } 4228 4229 ////////// 4230 //-- some rays for output 4231 4232 const int limit = min(leafOut, (int)mViewCells.size()); 4233 const int raysOut = min((int)rays.size(), 100); 4234 4266 const int limit = min(maxViewCells, (int)mViewCells.size()); 4267 4235 4268 for (int i = 0; i < limit; ++ i) 4236 4269 { 4237 4270 cout << "creating output for view cell " << i << " ... "; 4238 4271 4239 ViewCell *vc; 4240 4241 if (sortViewCells) // largest view cell pvs first 4242 vc = mViewCells[i]; 4243 else 4244 vc = mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 4272 ViewCell *vc = sortViewCells ? // largest view cell pvs first? 4273 mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 0.5f)] : mViewCells[i]; 4274 4275 if (vc->Mailed() || vc->GetId() == OUT_OF_BOUNDS_ID) 4276 continue; 4277 4278 vc->Mail(); 4245 4279 4246 4280 ObjectPvs pvs; 4247 4281 mViewCellsTree->GetPvs(vc, pvs); 4248 4282 4249 char s[64]; sprintf(s, " bsp-pvs%04d.wrl", i);4283 char s[64]; sprintf(s, "%sviewcell%04d.wrl", prefix.c_str(), i); 4250 4284 Exporter *exporter = Exporter::GetExporter(s); 4251 4285 4252 Debug << i<< ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl;4253 4254 if ( mExportRays)4286 cout << "view cell " << vc->GetId() << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 4287 4288 if (exportRays) 4255 4289 { 4256 4290 //////////// … … 4267 4301 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 4268 4302 for (vit = leaves.begin(); vit != vit_end; ++ vit) 4269 { 4303 { 4270 4304 BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0]; 4271 4305 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); … … 4277 4311 } 4278 4312 4313 const int raysOut = min((int)collectRays.size(), maxRays); 4314 cout << "here500 " << raysOut << endl; 4279 4315 // prepare some rays for output 4280 4316 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); … … 4304 4340 exporter->SetFilled(); 4305 4341 4306 if (1) 4307 { 4308 //////// 4309 //-- export pvs 4342 if (exportPvs) 4343 { 4310 4344 Intersectable::NewMail(); 4345 4311 4346 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 4312 4347 cout << endl; 4313 4348 // output PVS of view cell 4314 4349 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 4315 4350 { 4316 4351 Intersectable *intersect = (*oit).first; 4352 4317 4353 if (!intersect->Mailed()) 4318 4354 { 4355 intersect->Mail(); 4319 4356 m = RandomMaterial(); 4320 4357 exporter->SetForcedMaterial(m); 4321 4322 4358 exporter->ExportIntersectable(intersect); 4323 intersect->Mail();4359 cout << " i: " << intersect; 4324 4360 } 4325 4361 } 4362 cout << endl; 4326 4363 } 4327 4364 4328 if (0)4329 { // export scene geometry4330 m.mDiffuseColor = RgbColor(1, 0, 0);4331 exporter->SetForcedMaterial(m);4332 4333 exporter->ExportGeometry(objects);4334 }4335 4336 4365 DEL_PTR(exporter); 4337 4366 cout << "finished" << endl; 4338 4367 } 4339 4340 Debug << endl;4341 4368 } 4342 4369 … … 5105 5132 } 5106 5133 5107 // export pvss of some view cell 5108 ExportPvs(objects, visRays); 5109 } 5110 5111 5112 void VspOspViewCellsManager::ExportPvs(const ObjectContainer &objects, 5113 const VssRayContainer &rays) 5114 { 5134 // export some view cell 5115 5135 int leafOut; 5116 5136 Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.maxOutput", leafOut); 5117 5118 ViewCell::NewMail(); 5119 5120 cout << "visualization using " << (int)rays.size() << " samples" << endl; 5121 Debug << "visualization using " << (int)rays.size() << " samples" << endl; 5122 5123 const bool sortedViewCells = false; 5124 5125 if (sortedViewCells) 5137 const int raysOut = 100; 5138 5139 ExportSingleViewCells(objects, leafOut, false, true, false, raysOut, ""); 5140 } 5141 5142 5143 void VspOspViewCellsManager::ExportSingleViewCells(const ObjectContainer &objects, 5144 const int maxViewCells, 5145 const bool sortViewCells, 5146 const bool exportPvs, 5147 const bool exportRays, 5148 const int maxRays, 5149 const string prefix, 5150 VssRayContainer *visRays) 5151 { 5152 if (sortViewCells) 5126 5153 { 5127 5154 // sort view cells to visualize the view cells with highest render cost … … 5129 5156 } 5130 5157 5131 int limit = min(leafOut, (int)mViewCells.size()); 5132 int raysOut = 0; 5133 5134 cout << "\nOutput of " << limit << " view cells: " << endl; 5135 5136 /////////////// 5137 //-- some rays for output 5158 ViewCell::NewMail(); 5159 const int limit = min(maxViewCells, (int)mViewCells.size()); 5160 5161 cout << "\nExporting " << limit << " single view cells: " << endl; 5138 5162 5139 5163 for (int i = 0; i < limit; ++ i) … … 5142 5166 5143 5167 // largest view cell pvs first of random view cell 5144 ViewCell *vc = sort edViewCells ?5168 ViewCell *vc = sortViewCells ? 5145 5169 mViewCells[i] : mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 5146 5170 5171 if (vc->Mailed()) // already used 5172 continue; 5173 5174 vc->Mail(); 5175 5147 5176 ObjectPvs pvs; 5148 5177 mViewCellsTree->GetPvs(vc, pvs); 5149 5178 5150 char s[64]; sprintf(s, " bsp-pvs%04d.wrl", i);5179 char s[64]; sprintf(s, "%sviewcell%04d.wrl", prefix.c_str(), i); 5151 5180 Exporter *exporter = Exporter::GetExporter(s); 5152 5181 5153 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 5154 5155 //////////// 5156 //-- export the sample rays 5157 5158 if (1 || mExportRays) 5159 { 5160 // output rays stored with the view cells during subdivision 5161 if (1) 5162 { 5163 VssRayContainer vcRays; 5164 VssRayContainer collectRays; 5165 5166 raysOut = min((int)rays.size(), 100); 5167 5168 // collect intial view cells 5169 ViewCellContainer leaves; 5170 mViewCellsTree->CollectLeaves(vc, leaves); 5171 5172 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 5173 5174 for (vit = leaves.begin(); vit != vit_end; ++ vit) 5182 cout << "view cell " << vc->GetId() << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 5183 5184 if (exportPvs) 5185 { 5186 Material m; 5187 5188 Intersectable::NewMail(); 5189 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 5190 5191 // output PVS of view cell 5192 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 5193 { 5194 Intersectable *intersect = (*oit).first; 5195 if (!intersect->Mailed()) 5175 5196 { 5176 VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0]; 5177 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 5178 5179 for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 5180 { 5181 collectRays.push_back(*rit); 5182 } 5183 } 5184 5185 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 5186 5187 for (rit = collectRays.begin(); rit != rit_end; ++ rit) 5188 { 5189 const float p = RandomValue(0.0f, (float)collectRays.size()); 5190 5191 if (p < raysOut) 5192 vcRays.push_back(*rit); 5193 } 5194 5195 //-- export rays piercing this view cell 5196 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 5197 5198 //-- export objects seen from the rays 5199 Intersectable::NewMail(); 5200 5201 VssRayContainer::const_iterator vcit, vcit_end = vcRays.end(); 5202 for (vcit = vcRays.begin(); vcit != vcit_end; ++ vcit) 5203 { 5204 VssRay *ray = *vcit; 5205 //Intersectable *obj = ray->mTerminationObject; 5206 Intersectable *obj = mHierarchyManager->GetIntersectable(*ray, true); 5207 5208 if (obj && !obj->Mailed()) 5209 { 5210 obj->Mail(); 5211 exporter->ExportIntersectable(obj); 5212 } 5197 m = RandomMaterial(); 5198 exporter->SetForcedMaterial(m); 5199 5200 exporter->ExportIntersectable(intersect); 5201 intersect->Mail(); 5213 5202 } 5214 5203 } 5215 5204 } 5216 5205 5206 if (exportRays) 5207 { 5208 //////////// 5209 //-- export the sample rays 5210 5211 // output rays stored with the view cells during subdivision 5212 VssRayContainer vcRays; 5213 VssRayContainer collectRays; 5214 5215 // collect intial view cells 5216 ViewCellContainer leaves; 5217 mViewCellsTree->CollectLeaves(vc, leaves); 5218 5219 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 5220 5221 for (vit = leaves.begin(); vit != vit_end; ++ vit) 5222 { 5223 VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0]; 5224 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 5225 5226 for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 5227 { 5228 collectRays.push_back(*rit); 5229 } 5230 } 5231 5232 const int raysOut = min((int)collectRays.size(), maxRays); 5233 5234 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 5235 5236 for (rit = collectRays.begin(); rit != rit_end; ++ rit) 5237 { 5238 const float p = RandomValue(0.0f, (float)collectRays.size()); 5239 5240 if (p < raysOut) 5241 vcRays.push_back(*rit); 5242 } 5243 5244 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 5245 } 5246 5247 5217 5248 ///////////////// 5218 5249 //-- export view cell geometry … … 5231 5262 } 5232 5263 5233 Debug<< endl;5264 cout << endl; 5234 5265 } 5235 5266 … … 5535 5566 void VspOspViewCellsManager::EvalViewCellPartition() 5536 5567 { 5537 int castSamples = (int)storedRays.size(); 5538 5568 const int castSamples = (int)storedRays.size(); 5539 5569 char s[64]; 5540 5570 char statsPrefix[100]; … … 5545 5575 5546 5576 // should directional sampling be used? 5547 bool dirSamples = (mEvaluationSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION);5577 const bool dirSamples = (mEvaluationSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION); 5548 5578 5549 5579 cout << "reseting pvs ... "; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1557 r1570 113 113 /** Computes sample contribution of a simgle ray to the view cells PVS. 114 114 @param ray finds intersections with view cells and holds the contribution 115 @param castRay true if ray should be cast to gain the information, false if ray 116 is already holding the information and need not be recast. 117 115 @param addSample if sample should be added to the pvs 116 118 117 @returns number of sample contributions 119 118 */ … … 497 496 bool GetStoreKdPVs() const; 498 497 498 /** Adds a sample to the pvs of the specified view cell. 499 @param obj the hit object 500 @param hitPoint the point where the object is hit. 501 @param vc the sanpled view cell 502 @param pdf probability of the ray 503 @param contribution the relative pvs contribution 504 @returns true if the sample gives a contribution to the pvs. 505 */ 499 506 virtual bool AddSampleToPvs( 500 507 Intersectable *obj, … … 503 510 const float pdf, 504 511 float &contribution) const; 512 513 /** Exports single view cells for visualization. 514 @param objects the scene objects 515 @param limit the maximal number of output view cells 516 @param sortViewCells if the view cells should be sorted by pvs size 517 @param exportPvs if the pvs should also be exported 518 @param exportRays if sample rays should be exported as well 519 @param visRays additional rays 520 */ 521 virtual 522 void ExportSingleViewCells( 523 const ObjectContainer &objects, 524 const int maxViewCells, 525 const bool sortViewCells, 526 const bool exportPvs, 527 const bool exportRays, 528 const int maxRays, 529 const string prefix, 530 VssRayContainer *visRays = NULL) = NULL; 505 531 506 532 protected: … … 662 688 /// the width of the box filter 663 689 float mFilterWidth; 690 /// Maximal size of the filter in terms of contributing view cells 664 691 int mMaxFilterSize; 665 666 bool mStoreObjectPvs;692 693 667 694 668 695 ////////////////// … … 670 697 671 698 /// color code for view cells visualization 672 699 bool mShowVisualization; 673 700 int mColorCode; 674 701 bool mExportGeometry; … … 751 778 ViewCell *ConstructSpatialMergeTree(BspNode *root); 752 779 780 void ExportSingleViewCells( 781 const ObjectContainer &objects, 782 const int maxViewCells, 783 const bool sortViewCells, 784 const bool exportPvs, 785 const bool exportRays, 786 const int maxRays, 787 const string prefix, 788 VssRayContainer *visRays = NULL); 753 789 754 790 protected: … … 769 805 */ 770 806 void ExportSplits(const ObjectContainer &objects); 771 772 /** Exports visualization of the BSP PVS.773 */774 void ExportBspPvs(const ObjectContainer &objects);775 807 776 808 /** test if subdivision is valid in terms of volume / area. … … 830 862 vector<MergeCandidate> &candidates); 831 863 864 void ExportSingleViewCells( 865 const ObjectContainer &objects, 866 const int maxViewCells, 867 const bool sortViewCells, 868 const bool exportPvs, 869 const bool exportRays, 870 const int maxRays, 871 const string prefix, 872 VssRayContainer *visRays = NULL); 832 873 833 874 protected: … … 839 880 KdNode *GetNodeForPvs(KdLeaf *leaf); 840 881 882 //////////////////////////////////////// 841 883 842 884 /// the BSP tree. … … 849 891 }; 850 892 851 /** 852 893 894 /** Manages different higher order operations on the view cells. 853 895 */ 854 896 class VspBspViewCellsManager: public ViewCellsManager … … 914 956 915 957 958 void ExportSingleViewCells( 959 const ObjectContainer &objects, 960 const int maxViewCells, 961 const bool sortViewCells, 962 const bool exportPvs, 963 const bool exportRays, 964 const int maxRays, 965 const string prefix, 966 VssRayContainer *visRays = NULL); 967 968 916 969 protected: 917 970 … … 961 1014 void ExportSplits(const ObjectContainer &objects, 962 1015 const VssRayContainer &rays); 963 964 /** Exports visualization of the BSP PVS.965 */966 void ExportBspPvs(const ObjectContainer &objects,967 const VssRayContainer &rays);968 969 1016 970 1017 /// the view space partition BSP tree. … … 1049 1096 float &contribution) const; 1050 1097 1098 void ExportSingleViewCells( 1099 const ObjectContainer &objects, 1100 const int maxViewCells, 1101 const bool sortViewCells, 1102 const bool exportPvs, 1103 const bool exportRays, 1104 const int maxRays, 1105 const string prefix, 1106 VssRayContainer *visRays = NULL); 1107 1051 1108 protected: 1052 1109 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1551 r1570 56 56 } 57 57 58 58 #if WORK_WITH_VIEWCELLS 59 59 static bool ViewCellHasMultipleReferences(Intersectable *obj, 60 60 ViewCell *vc, … … 75 75 } 76 76 } 77 77 78 78 return false; 79 79 } 80 80 81 82 void VspTree::RemoveParentViewCellReferences(ViewCell *parent) const 83 { 84 KdLeaf::NewMail(); 85 86 // remove the parents from the object pvss 87 ObjectPvsMap::const_iterator oit, oit_end = parent->GetPvs().mEntries.end(); 88 89 for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 90 { 91 Intersectable *object = (*oit).first; 92 // HACK: make sure that the view cell is removed from the pvs 93 const float high_contri = 9999999; 94 95 // remove reference count of view cells 96 object->mViewCellPvs.RemoveSample(parent, high_contri); 97 } 98 } 99 100 101 void VspTree::AddViewCellReferences(ViewCell *vc) const 102 { 103 KdLeaf::NewMail(); 104 105 // Add front view cell to the object pvsss 106 ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 107 108 for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 109 { 110 Intersectable *object = (*oit).first; 111 112 // increase reference count of view cells 113 object->mViewCellPvs.AddSample(vc, 1); 114 } 115 } 116 117 #endif 81 118 82 119 void VspTreeStatistics::Print(ostream &app) const … … 826 863 ++ mVspStats.splits[splitPlane.mAxis]; 827 864 828 /////////////////////////////////////////// 865 866 /////////////////////// 829 867 //-- create front and back and subdivide further 830 868 … … 837 875 parent->ReplaceChildLink(leaf, interior); 838 876 interior->SetParent(parent); 839 877 #if WORK_WITH_VIEWCELLS 840 878 // remove "parent" view cell from pvs of all objects (traverse trough rays) 841 879 RemoveParentViewCellReferences(tData.mNode->GetViewCell()); 880 #endif 842 881 } 843 882 else // new root … … 866 905 #if WORK_WITH_VIEWCELL_PVS 867 906 // create front and back view cell 868 // add front and back view cell to "Potentially Visbilie View Cells" 907 // add front and back view cell to 908 // "potentially visible view cells" 869 909 // of the objects in front and back pvs 870 910 … … 880 920 881 921 882 void VspTree::RemoveParentViewCellReferences(ViewCell *parent) const883 {884 KdLeaf::NewMail();885 886 // remove the parents from the object pvss887 ObjectPvsMap::const_iterator oit, oit_end = parent->GetPvs().mEntries.end();888 889 for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)890 {891 Intersectable *object = (*oit).first;892 // HACK: make sure that the view cell is removed from the pvs893 const float high_contri = 9999999;894 895 // remove reference count of view cells896 object->mViewCellPvs.RemoveSample(parent, high_contri);897 }898 }899 900 901 void VspTree::AddViewCellReferences(ViewCell *vc) const902 {903 KdLeaf::NewMail();904 905 // Add front view cell to the object pvsss906 ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end();907 908 for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)909 {910 Intersectable *object = (*oit).first;911 912 // increase reference count of view cells913 object->mViewCellPvs.AddSample(vc, 1);914 }915 }916 922 917 923 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r1449 r1570 615 615 ViewCellContainer &viewCells) const; 616 616 617 /** Returns view cells of this ray, either taking precomputed cells 618 or by recomputation. 619 */ 620 void GetViewCells(const VssRay &ray, ViewCellContainer &viewCells); 621 622 /** Returns view cells tree. 623 */ 624 ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; } 625 626 /** Sets the view cells tree. 627 */ 628 void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 629 630 #if WORK_WITH_VIEWCELLS 617 631 /** Remove the references of the parent view cell from the kd nodes associated with 618 632 the objects. … … 623 637 */ 624 638 void AddViewCellReferences(ViewCell *vc) const; 625 626 /** Returns view cells of this ray, either taking precomputed cells 627 or by recomputation. 628 */ 629 void GetViewCells(const VssRay &ray, ViewCellContainer &viewCells); 630 631 /** Returns view cells tree. 632 */ 633 ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; } 634 635 /** Sets the view cells tree. 636 */ 637 void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 638 639 #endif 639 640 640 641 protected:
Note: See TracChangeset
for help on using the changeset viewer.