Changeset 2598 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 01/15/08 15:37:02 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/FilterBasedDistribution.cpp
r2582 r2598 68 68 69 69 // pickup random object from the filtered pvs 70 int id = RandomValue(0, mFilteredPvs.GetSize()-1);70 int id = (int)RandomValue(0, (Real)((float)mFilteredPvs.GetSize() - 0.5f)); 71 71 72 72 ObjectPvsIterator pit = mFilteredPvs.GetIterator(); -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r2593 r2598 103 103 mUseGlLists = false; 104 104 105 if (mViewCellsManager->GetViewCellPoints ()->size())106 mPvsStatFrames = (int)mViewCellsManager->GetViewCellPoints ()->size();105 if (mViewCellsManager->GetViewCellPointsList()->size()) 106 mPvsStatFrames = (int)mViewCellsManager->GetViewCellPointsList()->size(); 107 107 else 108 108 Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames); -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
r2593 r2598 198 198 } 199 199 200 void SetViewPoint(const Vector3 &vp) { mViewPoint = vp; } 201 void SetViewDirection(const Vector3 &vd) { mViewDirection = vd; } 202 200 203 public: 201 204 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r2597 r2598 794 794 void GvsPreprocessor::CompileViewCellsList() 795 795 { 796 vector<ViewCellPoints *> *vcPoints = mViewCellsManager->GetViewCellPoints();796 ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList(); 797 797 798 798 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2593 r2598 1483 1483 // mutex.unlock(); 1484 1484 1485 if (mViewCellsManager->GetViewCellPoints ()->size()) {1485 if (mViewCellsManager->GetViewCellPointsList()->size()) { 1486 1486 1487 vector<ViewCellPoints *> *vcPoints = mViewCellsManager->GetViewCellPoints();1487 ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList(); 1488 1488 1489 vector<ViewCellPoints *>::const_iterator1489 ViewCellPointsList::const_iterator 1490 1490 vit = vcPoints->begin(), 1491 1491 vit_end = vcPoints->end(); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r2594 r2598 126 126 OptimizeForWindowsApplication="TRUE" 127 127 AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing;"$(QTDIR)\include\QtCore";"$(QTDIR)\include\QtGui";"$(QTDIR)\include";"$(QTDIR)\include\QtOpenGl";"$(CG_INC_PATH)";Timer;..\src\sparsehash\src\google\sparsehash;..\src\sparsehash\src\windows;..\src\sparsehash\src\google;..\src\sparsehash\src;..\src\ootl\;..\src\ootl\src\;..\src\ootl\src\cpp;..\src\ootl\src\cpp\include\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;..\src\ootl\src\cpp\include\ootl\mswin;..\src\havran" 128 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;USE_QT;USE_VERBOSE_PVS;USE_CG ;TRV000"128 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;USE_QT;USE_VERBOSE_PVS;USE_CG" 129 129 StringPooling="TRUE" 130 130 MinimalRebuild="TRUE" … … 684 684 </File> 685 685 <File 686 RelativePath=".\RandomViewCellsHandler.cpp"> 687 </File> 688 <File 689 RelativePath=".\RandomViewCellsHandler.h"> 690 </File> 691 <File 686 692 RelativePath="..\src\Ray.cpp"> 687 693 </File> … … 1129 1135 </File> 1130 1136 <File 1137 RelativePath=".\havran\ktbf2trv.cpp"> 1138 </File> 1139 <File 1131 1140 RelativePath=".\havran\ktbftrav.cpp"> 1132 1141 </File> … … 1148 1157 <File 1149 1158 RelativePath=".\havran\subdivm.h"> 1159 </File> 1160 <File 1161 RelativePath=".\havran\testrt.h"> 1150 1162 </File> 1151 1163 <File -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r2594 r2598 145 145 OptimizeForWindowsApplication="TRUE" 146 146 AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;"$(QTDIR)\include\QtOpenGl";"$(QTDIR)\include\Qt";"$(QTDIR)\include\QtCore";"$(QTDIR)\include";QtInterface;..\src\sparsehash\src\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;$(NOINHERIT)" 147 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;USE_CG;USE_VERBOSE_PVS;QT_OPENGL_LIB;QT_DLL ;TRV000"147 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;USE_CG;USE_VERBOSE_PVS;QT_OPENGL_LIB;QT_DLL" 148 148 StringPooling="TRUE" 149 149 MinimalRebuild="TRUE" -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2593 r2598 116 116 mSamplesStat.Reset(); 117 117 //mStats.open("mystats.log"); 118 119 mRandomViewCellsHandler = new RandomViewCellsHandler(this); 118 120 } 119 121 … … 157 159 158 160 return (int)passSamples.size(); 161 } 162 163 164 ViewCellsManager::~ViewCellsManager() 165 { 166 // HACK: if view cells tree does not 167 // handle view cells, we have to do it here 168 // question: rather create view cells resource manager? 169 if (!ViewCellsTreeConstructed()) 170 { 171 CLEAR_CONTAINER(mViewCells); 172 } 173 else 174 { 175 DEL_PTR(mViewCellsTree); 176 } 177 178 DEL_PTR(mMixtureDistribution); 179 DEL_PTR(mRandomViewCellsHandler); 159 180 } 160 181 … … 341 362 } 342 363 return NULL; 343 }344 345 346 bool ViewCellsManager::ExportRandomViewCells(const string &filename,347 const vector<ViewCellPoints *> &viewCells)348 {349 std::ofstream outStream;350 outStream.open(filename.c_str());351 352 vector<ViewCellPoints *>::const_iterator vit, vit_end = viewCells.end();353 354 for (vit = viewCells.begin(); vit != vit_end; ++ vit)355 {356 ViewCell *vc = (*vit)->first;357 358 outStream << "v " << vc->GetId() << endl;359 360 SimpleRayContainer viewPoints;361 362 SimpleRayContainer::const_iterator pit, pit_end = (*vit)->second.end();363 364 for (pit = (*vit)->second.begin(); pit != pit_end; ++ pit)365 {366 const Vector3 pt = (*pit).mOrigin;367 const Vector3 dir = (*pit).mDirection;368 369 outStream << "p " << pt.x << " " << pt.y << " " << pt.z370 << " " << dir.x << " " << dir.y << " " << dir.z << endl;371 }372 }373 374 return true;375 }376 377 378 bool ViewCellsManager::GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells,379 const int nViewCells,380 const int nViewPoints)381 {382 ViewCellContainer rViewCells;383 384 cout << "generating " << nViewCells << " random view cells" << endl;385 ///GenerateRandomViewCells(rViewCells, nViewCells);386 387 //cout << "finished" << endl;388 389 //for (int i = 0; i < viewCells.size(); ++ i)390 // cout << "vc " << i << ": " << viewCells[i]->GetId() << endl;391 392 cout << "generating " << nViewPoints << " view points per view cell" << endl;393 394 int generatedViewCells = 0;395 int i = 0;396 while (generatedViewCells < nViewCells)397 {398 ++ i;399 400 const int idx = (int)RandomValue(0.0f, (float)mViewCells.size() - 0.5f);401 402 ViewCell *viewCell = GetViewCell(idx);403 404 cout << "testing view cell: " << viewCell->GetId() << endl;405 406 if (!viewCell->Mailed())407 {408 viewCell->Mail();409 410 SimpleRayContainer viewPoints;411 412 // generate random view points413 if (IsValidViewSpace(viewCell) &&414 GenerateViewPoints(viewCell, nViewPoints, viewPoints))415 {416 Debug << "vc: " << viewCell->GetId() << endl;417 418 ViewCellPoints *vcPts = new ViewCellPoints();419 viewCells.push_back(vcPts);420 421 // valid view cell found422 vcPts->first = viewCell;423 424 // generate view points425 ++ generatedViewCells;426 427 SimpleRayContainer::const_iterator pit, pit_end = viewPoints.end();428 429 for (pit = viewPoints.begin(); pit != pit_end; ++ pit)430 {431 Debug << "vp: " << (*pit) << endl;432 vcPts->second.push_back(*pit);433 }434 cout << "view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;435 }436 else437 {438 cout << "error: invalid view cell " << generatedViewCells << " with id " << viewCell->GetId() << endl;439 }440 }441 442 if (i > nViewCells * 1000000) // safety443 {444 cout << "big error" << endl;445 break;446 }447 cout << "processd view cells " << generatedViewCells << " of " << nViewCells << endl << endl;448 }449 450 return true;451 }452 453 454 bool ViewCellsManager::ImportRandomViewCells(const string &filename,455 vector<ViewCellPoints *> &viewCells)456 {457 ifstream inStream(filename.c_str());458 if (!inStream.is_open())459 return false;460 461 ViewCellPoints *currentViewCell = NULL;462 463 string buf;464 while (!(getline(inStream, buf)).eof())465 {466 switch (buf[0])467 {468 case 'v':469 {470 int id;471 sscanf(buf.c_str(), "v %d", &id);472 473 currentViewCell = new ViewCellPoints();474 currentViewCell->first = GetViewCellById(id);475 476 viewCells.push_back(currentViewCell);477 break;478 }479 case 'p':480 {481 Vector3 pt, dir;482 sscanf(buf.c_str(), "p %f %f %f %f %f %f", &pt.x, &pt.y, &pt.z, &dir.x, &dir.y, &dir.z);483 484 SimpleRay ray(pt, dir, 0, 1);485 currentViewCell->second.push_back(ray);486 break;487 }488 default:489 break;490 }491 }492 493 return true;494 }495 496 497 bool ViewCellsManager::ImportRandomViewCells(const string &filename)498 {499 return ImportRandomViewCells(filename, mViewCellPoints);500 }501 502 503 bool ViewCellsManager::GenerateViewPoints(ViewCell *viewCell,504 const int numViewPoints,505 SimpleRayContainer &viewPoints)506 {507 bool success = true;508 int generatedPts = 0;509 int i = 0;510 511 cout << "generating view points for view cell " << viewCell->GetId() << endl;512 513 while (generatedPts < numViewPoints)514 {515 SimpleRay pt;516 517 if (GenerateViewPoint(viewCell, pt))518 {519 ++ generatedPts;520 cout << "generated view point " << generatedPts << endl;521 viewPoints.push_back(pt);522 }523 524 // savety criterium525 if (++ i > numViewPoints * 3)526 {527 return false;528 }529 }530 531 cout << "view point generation finished" << endl;532 533 return true;534 }535 536 537 bool ViewCellsManager::ExportRandomViewCells(const string &filename)538 {539 const int numViewCells = 100;540 const int numViewPoints = 10;541 542 preprocessor->mViewCellsManager->543 GenerateRandomViewCells(mViewCellPoints, numViewCells, numViewPoints);544 545 //cout << "exporting random view cells" << endl;546 return preprocessor->mViewCellsManager->ExportRandomViewCells(filename, mViewCellPoints);547 }548 549 550 bool ViewCellsManager::GenerateViewPoint(ViewCell *viewCell,551 SimpleRay &ray)552 {553 // do not use this function since it could return different554 // viewpoints for different executions of the algorithm555 556 int tries = 0;557 Vector3 viewPoint, direction;558 const int maxTries = 10;559 560 while (1)561 {562 // hack563 if (!viewCell->GetMesh())564 CreateMesh(viewCell);565 566 Mesh *mesh = viewCell->GetMesh();567 AxisAlignedBox3 box = mesh->mBox;568 569 Vector3 pVector = Vector3(Random(1.0f),570 Random(1.0f),571 Random(1.0f));572 573 viewPoint = box.GetPoint(pVector);574 575 const Vector3 dVector = Vector3(2 * M_PI * Random(1.0f), M_PI * Random(1.0f), 0.0f);576 direction = Normalize(Vector3(sin(dVector.x), 0.0f, cos(dVector.x)));577 578 ViewCell *v = GetViewCell(viewPoint);579 580 if (v && v->GetValid())581 {582 mPreprocessor->GetRenderer()->mViewPoint = viewPoint;583 mPreprocessor->GetRenderer()->mViewDirection = direction;584 585 if (mPreprocessor->GetRenderer()->ValidViewPoint())586 {587 cout << "view point valid " << viewPoint << " " << direction << endl;588 break;589 }590 591 }592 593 if (++ tries > maxTries)594 {595 cerr << "error: no view point computed" << endl;596 return false;597 }598 }599 600 ray = SimpleRay(viewPoint, direction, 0, 1);601 //cout << "view point generated: " << viewPoint << " " << direction << endl;602 603 return true;604 }605 606 607 bool ViewCellsManager::IsValidViewSpace(ViewCell *vc)608 {609 SimpleRay simpleRay;610 //check if view point can be generated611 return GenerateViewPoint(vc, simpleRay);612 }613 614 615 bool ViewCellsManager::GenerateRandomViewCells(ViewCellContainer &viewCells,616 const int numViewCells)617 {618 int generatedViewCells = 0;619 //HaltonSequence halton;620 //float r[1];621 622 ViewCell::NewMail();623 624 while (generatedViewCells < numViewCells)625 {626 // savety criterium627 const int tries = 100000 + generatedViewCells;628 int i = 0;629 630 // generate next view cell631 while (1)632 {633 //halton.GetNext(1, r);634 //const int idx = (int)(r[0] * mViewCells.size() - 1.0f);635 const int idx = (int)RandomValue(0.0f, (float)mViewCells.size() - 0.5f);636 637 ViewCell *viewCell = GetViewCell(idx);638 639 if (!viewCell->Mailed())640 {641 viewCell->Mail();642 643 // check for valid view space644 if (IsValidViewSpace(viewCell))645 {646 // valid view cell found647 viewCells.push_back(viewCell);648 649 ++ generatedViewCells;650 //cout << "view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;651 break;652 }653 else654 {655 cout << "error: invalid view cell " << generatedViewCells << " with id " << viewCell->GetId() << endl;656 }657 }658 659 if (++ i == tries) // no new view cell fond660 {661 cerr << "big error! no view cell found" << endl;662 return false;663 }664 }665 }666 667 return true;668 }669 670 671 ViewCellsManager::~ViewCellsManager()672 {673 // HACK: if view cells tree does not674 // handle view cells, we have to do it here675 // question: rather create view cells resource manager?676 if (!ViewCellsTreeConstructed())677 {678 CLEAR_CONTAINER(mViewCells);679 }680 else681 {682 DEL_PTR(mViewCellsTree);683 }684 685 DEL_PTR(mMixtureDistribution);686 CLEAR_CONTAINER(mViewCellPoints);687 364 } 688 365 … … 7387 7064 } 7388 7065 7389 } 7066 7067 ViewCellPointsList *ViewCellsManager::GetViewCellPointsList() 7068 { 7069 return mRandomViewCellsHandler->GetViewCellPointsList(); 7070 } 7071 7072 7073 bool ViewCellsManager::ExportRandomViewCells(const string &filename) 7074 { 7075 // export ten view cells with 100 random view points inside each 7076 const int numViewCells = 100; 7077 const int numViewPoints = 10; 7078 7079 //cout << "exporting random view cells" << endl; 7080 return mRandomViewCellsHandler->ExportRandomViewCells(filename); 7081 } 7082 7083 7084 bool ViewCellsManager::ImportViewCellsList(const string &filename) 7085 { 7086 return mRandomViewCellsHandler->ImportViewCellsList(filename); 7087 } 7088 7089 7090 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r2586 r2598 7 7 #include "Containers.h" 8 8 #include "ViewCell.h" 9 #include "RandomViewCellsHandler.h" 10 9 11 10 12 #define TEST_PACKETS 0 … … 45 47 struct BspRay; 46 48 class BspTree; 47 49 //class RandomViewCellsHandler; 48 50 49 51 … … 77 79 }; 78 80 79 typedef pair<ViewCell *, SimpleRayContainer> ViewCellPoints;80 81 81 82 struct VizBuffer … … 507 508 */ 508 509 int GetNumViewCells() const; 509 510 bool GenerateRandomViewCells(ViewCellContainer &viewCells, 511 const int numViewCells); 512 513 bool GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells, 514 const int nViewCells, 515 const int nViewPoints); 516 517 518 bool GenerateViewPoints(ViewCell *viewCell, 519 const int numViewPoints, 520 SimpleRayContainer &viewPoints); 521 522 bool ImportRandomViewCells(const string &filename, 523 vector<ViewCellPoints *> &viewCells); 524 525 bool ImportRandomViewCells(const string &filename); 526 527 bool ExportRandomViewCells(const string &filename, 528 const vector<ViewCellPoints *> &viewCells); 529 510 /** Returns the stored list of view cells and view points. 511 */ 512 ViewCellPointsList *GetViewCellPointsList(); 513 /** Exports list of random view cells. 514 */ 530 515 bool ExportRandomViewCells(const string &filename); 531 532 bool GenerateViewPoint(ViewCell *viewCell, SimpleRay &ray); 533 534 bool IsValidViewSpace(ViewCell *vc); 516 /** Imports list of random view cells and view points. 517 */ 518 bool ImportViewCellsList(const string &filename); 535 519 536 520 … … 642 626 { 643 627 mPreprocessor = p; 644 }645 646 vector<ViewCellPoints *> *GetViewCellPoints()647 {648 return &mViewCellPoints;649 628 } 650 629 … … 822 801 bool mCompressViewCells; 823 802 824 vector<ViewCellPoints *> mViewCellPoints; 803 /// Handler for generating and loading random view cells. 804 RandomViewCellsHandler *mRandomViewCellsHandler; 825 805 826 806 /// holds the current view cell statistics -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r2593 r2598 298 298 { 299 299 cout << "importing random view cells" << endl; 300 preprocessor->mViewCellsManager->Import RandomViewCells(viewCellPointsFile);300 preprocessor->mViewCellsManager->ImportViewCellsList(viewCellPointsFile); 301 301 cout << "finished" << endl; 302 302 }
Note: See TracChangeset
for help on using the changeset viewer.