Changeset 577 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 01/25/06 17:45:45 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r576 r577 190 190 bool Preprocessor::PrepareViewCells() 191 191 { 192 //-- parse type of view cell container 193 char viewCellsStr[64]; 194 environment->GetStringValue("ViewCells.type", viewCellsStr); 195 196 mViewCellsManager = CreateViewCellsManager(viewCellsStr); 192 //-- parse view cells construction method 193 environment->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells); 194 char buf[100]; 195 196 if (mLoadViewCells) 197 { 198 environment->GetStringValue("ViewCells.filename", buf); 199 mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects); 200 } 201 else 202 { 203 //-- parse type of view cell container 204 char viewCellsStr[64]; 205 environment->GetStringValue("ViewCells.type", viewCellsStr); 206 mViewCellsManager = CreateViewCellsManager(viewCellsStr); 207 } 197 208 198 209 float objRenderCost = 0, vcOverhead = 0, moveSpeed = 0; … … 207 218 mViewCellsManager->SetRenderer(mRenderSimulator); 208 219 209 //-- parse view cells construction method210 environment->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells);211 char buf[100];212 213 if (mLoadViewCells)214 {215 environment->GetStringValue("ViewCells.filename", buf);216 mViewCellsFilename = buf;217 }218 220 219 221 if (mUseGlRenderer || mUseGlDebugger) … … 228 230 environment->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace); 229 231 230 231 232 232 return true; 233 233 } … … 242 242 else if (strcmp(name, "bspTree") == 0) 243 243 { 244 Debug << "view cell type: Bsp" << endl; 245 244 246 mBspTree = new BspTree(); 245 246 Debug << "view cell type: Bsp" << endl;247 248 247 mViewCellsManager = new BspViewCellsManager(mBspTree); 249 248 } 250 249 else if (strcmp(name, "vspBspTree") == 0) 251 250 { 251 Debug << "view cell type: VspBsp" << endl; 252 252 253 mVspBspTree = new VspBspTree(); 253 254 Debug << "view cell type: VspBsp" << endl;255 256 254 mViewCellsManager = new VspBspViewCellsManager(mVspBspTree); 257 255 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r576 r577 154 154 155 155 bool mLoadViewCells; 156 157 string mViewCellsFilename;158 156 159 157 bool mDetectEmptyViewSpace; -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r576 r577 467 467 468 468 mViewSpaceBox = NULL; 469 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 470 471 472 //-- load view cells from file if requested 473 if (mLoadViewCells) { 474 // load now because otherwise bounding box not correct 475 mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects); 476 // $$JB tmp make all viewcelss valid 477 mViewCellsManager->SetValidity(0, 9999999999); 478 479 } 480 else 481 { 469 470 // if not already loaded, construct view cells from file 471 if (!mLoadViewCells) { 472 473 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 474 482 475 // construct view cells using it's own set of samples 483 476 mViewCellsManager->Construct(this); … … 487 480 mViewCellsManager->PrintStatistics(Debug); 488 481 } 489 482 483 490 484 int rssPass = 0; 491 485 int rssSamples = 0; … … 515 509 516 510 if (mExportRays) { 511 517 512 char filename[64]; 518 513 sprintf(filename, "rss-rays-initial.x3d"); 519 514 ExportRays(filename, mVssRays, mExportNumRays); 515 520 516 } 521 517 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r575 r577 52 52 environment->GetIntValue("ViewCells.Construction.samplesPerPass", mSamplesPerPass); 53 53 54 environment->GetBoolValue("ViewCells.exportToFile", mExportViewCells); 55 54 56 mMinPvsSize = emptyViewCells ? 1 : 0; 55 57 … … 236 238 } 237 239 240 238 241 void 239 242 ViewCellsManager::SetValidity( … … 275 278 } 276 279 277 bool ViewCellsManager::LoadViewCells(const string filename, ObjectContainer *objects) 280 281 bool ViewCellsManager::LoadViewCellsGeometry(const string filename) 278 282 { 279 283 X3dParser parser; … … 575 579 { 576 580 mViewSpaceBox = box; 581 mTotalAreaValid = false; 577 582 } 578 583 … … 2176 2181 FinalizeViewCells(true); 2177 2182 EvaluateViewCellsStats(); 2183 2178 2184 return 0; 2179 2185 } … … 2279 2285 FinalizeViewCells(true); 2280 2286 2287 // for output we need unique ids for each view cell 2288 CreateUniqueViewCellIds(); 2289 2281 2290 // write view cells to disc 2282 2291 if (mExportViewCells) … … 2368 2377 delete exporter; 2369 2378 } 2379 } 2380 2381 if (1) 2382 { 2383 cout << "exporting depth map ... "; 2384 2385 Exporter *exporter = Exporter::GetExporter("depth_map.x3d"); 2386 if (exporter) 2387 { 2388 if (1) 2389 { 2390 exporter->SetWireframe(); 2391 exporter->ExportBox(mViewSpaceBox); 2392 exporter->SetFilled(); 2393 } 2394 2395 if (mExportGeometry) 2396 { 2397 exporter->ExportGeometry(objects); 2398 } 2399 2400 const int maxDepth = mVspBspTree->mBspStats.maxDepth; 2401 2402 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 2403 2404 for (vit = mViewCells.begin(); vit != mViewCells.end(); ++ vit) 2405 { 2406 BspViewCell *vc = dynamic_cast<BspViewCell *>(*vit); 2407 2408 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 2409 2410 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 2411 { 2412 BspLeaf *leaf = *lit; 2413 2414 Material m; 2415 2416 float relDepth = (float)leaf->GetDepth() / (float)maxDepth; 2417 m.mDiffuseColor.r = relDepth; 2418 m.mDiffuseColor.g = 0.0f; 2419 m.mDiffuseColor.b = 1.0f - relDepth; 2420 2421 exporter->SetForcedMaterial(m); 2422 2423 2424 BspNodeGeometry geom; 2425 mVspBspTree->ConstructGeometry(leaf, geom); 2426 exporter->ExportPolygons(geom.mPolys); 2427 } 2428 } 2429 2430 delete exporter; 2431 } 2432 2433 2434 cout << "finished" << endl; 2370 2435 } 2371 2436 … … 2661 2726 void VspBspViewCellsManager::CreateMesh(ViewCell *vc) 2662 2727 { 2728 if (vc->GetMesh()) 2729 delete vc->GetMesh(); 2730 2663 2731 BspNodeGeometry geom; 2664 2732 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); … … 2672 2740 2673 2741 2674 bool VspBspViewCellsManager::LoadViewCells(const string filename, ObjectContainer *objects) 2742 ViewCellsManager *ViewCellsManager::LoadViewCells(const string filename, 2743 ObjectContainer *objects) 2675 2744 { 2676 2745 ViewCellsParser parser; 2677 2746 2678 DEL_PTR(mVspBspTree); 2679 mVspBspTree = new VspBspTree(); 2680 2681 bool success ;//= parser.ParseFile(filename, &this, objects); 2682 mVspBspTree->RepairViewCellsLeafLists(); 2683 mVspBspTree->mBox = GetViewSpaceBox(); 2684 ResetViewCells(); 2685 2686 mViewCellsFinished = true; 2687 mMaxPvsSize = (int)objects->size(); 2688 2689 FinalizeViewCells(true); 2690 2691 Debug << (int)mViewCells.size() << " view cells loaded" << endl; 2692 2693 return success; 2747 ViewCellsManager *vm = NULL; 2748 2749 if (parser.ParseFile(filename, &vm, objects)) 2750 { 2751 vm->PrepareLoadedViewCells(); 2752 vm->ResetViewCells(); 2753 2754 vm->mViewCellsFinished = true; 2755 vm->mMaxPvsSize = (int)objects->size(); 2756 2757 vm->FinalizeViewCells(true); 2758 2759 Debug << (int)vm->mViewCells.size() << " view cells loaded" << endl; 2760 2761 //vm->ExportViewCells("test.xml"); 2762 } 2763 else 2764 { 2765 Debug << "failed loading view cells" << endl; 2766 DEL_PTR(vm); 2767 } 2768 2769 2770 return vm; 2694 2771 } 2695 2772 … … 2706 2783 std::ofstream stream; 2707 2784 2708 // for output we need unique ids 2709 CreateUniqueViewCellIds();2785 // for output we need unique ids for each view cell 2786 //CreateUniqueViewCellIds(); 2710 2787 2711 2788 stream.open(filename.c_str()); 2712 2789 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 2713 2790 stream << "<Visibility_Solution>" << endl; 2791 2792 //-- the view space bounding box 2793 stream << "<ViewSpaceBox" 2794 << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 2795 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl; 2796 2797 //-- the type of the view cells hierarchy 2798 stream << "<Hierarchy name=\"vspBspTree\" />" << endl; 2714 2799 2715 2800 //-- load the view cells itself, i.e., the ids and the pvs … … 2766 2851 2767 2852 2768 2853 void VspBspViewCellsManager::PrepareLoadedViewCells() 2854 { 2855 // TODO: do I still need this here? 2856 mVspBspTree->RepairViewCellsLeafLists(); 2857 } 2858 2859 2860 //////////////////////////////////77 2769 2861 ViewCellsManager *ViewCellsManagerFactory::Create(const string mName) 2770 2862 { -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r575 r577 120 120 @return true on success 121 121 */ 122 virtual bool LoadViewCells(const string filename, ObjectContainer *objects); 123 122 virtual bool LoadViewCellsGeometry(const string filename); 123 124 124 125 /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector. 125 126 @param the base triangle … … 314 315 virtual void FinalizeViewCells(const bool createMesh); 315 316 317 318 /** Loads view cells from file. The view cells manager is created with respect to the loaded 319 view cells. 320 321 @returns the view cells manager if loading was successful, false otherwise 322 */ 323 static ViewCellsManager *LoadViewCells(const string filename, ObjectContainer *objects); 324 316 325 protected: 317 326 … … 366 375 void ExportViewCell(ViewCell *viewCell, ofstream &stream); 367 376 368 /// the view cell corresponding to space ouside the valid view space 369 //ViewCell *mOutOfBoundsCell; 377 378 /** 379 Takes different measures to prepares the view cells after loading them from disc. 380 */ 381 virtual void PrepareLoadedViewCells() {}; 370 382 371 383 /// Renders the view cells. … … 641 653 void CreateMesh(ViewCell *vc); 642 654 643 bool LoadViewCells(const string filename, ObjectContainer *objects);655 //bool LoadViewCellsGeometry(const string filename, ObjectContainer *objects); 644 656 bool ExportViewCells(const string filename); 645 657 … … 671 683 void ExportColor(Exporter *exporter, ViewCell *vc) const; 672 684 685 void PrepareLoadedViewCells(); 686 673 687 /// the view space partition BSP tree. 674 688 VspBspTree *mVspBspTree; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParser.cpp
r575 r577 61 61 // StdInParseHandlers: Constructors and Destructor 62 62 // --------------------------------------------------------------------------- 63 ViewCellsParseHandlers::ViewCellsParseHandlers(ViewCellsManager **viewCells, 64 ObjectContainer *objects): 63 ViewCellsParseHandlers::ViewCellsParseHandlers(ObjectContainer *objects): 65 64 mElementCount(0) 66 65 , mAttrCount(0) 67 66 , mCharacterCount(0) 68 67 , mSpaceCount(0) 68 , mViewCellsManager(NULL) 69 , mVspBspTree(NULL) 70 , mBspTree(NULL) 69 71 { 70 72 mObjects = objects; 71 viewCells = &mViewCellsManager;72 //mPreprocessor = preprocessor;73 73 } 74 74 … … 142 142 AttributeList& attributes) 143 143 { 144 if (element == "Interior") 145 { 146 cout << "["; 147 StartBspInterior(attributes); 148 } 149 150 if (element == "Leaf") 151 { 152 StartBspLeaf(attributes); 153 } 154 } 155 156 157 void ViewCellsParseHandlers::startElement(const XMLCh* const name, 158 AttributeList& attributes) 159 { 160 StrX lname(name); 161 string element(lname.LocalForm()); 162 163 // decides the used view cell hierarchy 164 if (element == "Hierarchy") 165 { 166 cout << "h"; 167 StartHierarchy(attributes); 168 } 169 170 // decides the used view cell hierarchy 171 if (element == "ViewSpaceBox") 172 { 173 cout << "vsb"; 174 StartViewSpaceBox(attributes); 175 } 176 144 177 if (element == "ViewCell") 145 178 { … … 148 181 } 149 182 150 if (element == "Interior") 151 { 152 cout << "["; 153 StartBspInterior(attributes); 154 } 155 156 if (element == "Leaf") 157 { 158 StartBspLeaf(attributes); 159 } 160 } 161 162 163 void ViewCellsParseHandlers::startElement(const XMLCh* const name, 164 AttributeList& attributes) 165 { 166 StrX lname(name); 167 string element(lname.LocalForm()); 183 // use different methods for the given view cell hierarchy types 184 if (mViewCellsManager) 185 { 186 switch (mViewCellsManager->GetType()) 187 { 188 case ViewCellsManager::BSP: 189 case ViewCellsManager::VSP_BSP: 190 startBspElement(element, attributes); 191 break; 168 192 169 if (element == "Hierarchy") 170 { 171 cout << "h"; 172 StartHierarchy(attributes); 173 } 174 175 switch (mViewCellsManager->GetType()) 176 { 177 case ViewCellsManager::BSP: 178 case ViewCellsManager::VSP_BSP: 179 startBspElement(element, attributes); 180 break; 181 182 default: 183 Debug << "not implemented" << endl; 184 break; 185 186 } 187 193 default: 194 Debug << "not implemented" << endl; 195 break; 196 } 197 } 198 188 199 ++ mElementCount; 189 200 mAttrCount += attributes.getLength(); … … 272 283 273 284 285 void ViewCellsParseHandlers::StartViewSpaceBox(AttributeList& attributes) 286 { 287 int len = attributes.getLength(); 288 289 Vector3 bmin, bmax; 290 291 for (int i = 0; i < len; ++ i) 292 { 293 string attrName(StrX(attributes.getName(i)).LocalForm()); 294 StrX attrValue(attributes.getValue(i)); 295 const char *ptr = attrValue.LocalForm(); 296 297 if (attrName == "min") 298 { 299 sscanf(ptr, "%f %f %f", 300 &bmin.x, &bmin.y, &bmin.z); 301 } 302 else if (attrName == "max") 303 { 304 sscanf(ptr, "%f %f %f", 305 &bmax.x, &bmax.y, &bmax.z); 306 } 307 } 308 309 mViewSpaceBox = AxisAlignedBox3(bmin, bmax); 310 311 Debug << "view space box: " << mViewSpaceBox << endl; 312 } 313 314 274 315 void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes) 275 316 { … … 284 325 { 285 326 if (mViewCellsManager->GetType() == ViewCellsManager::BSP) 327 { 286 328 mBspTree->mRoot = leaf; 287 else 329 } 330 else if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP) 331 { 288 332 mVspBspTree->mRoot = leaf; 333 } 289 334 } 290 335 … … 369 414 { 370 415 if (mViewCellsManager->GetType() == ViewCellsManager::BSP) 416 { 371 417 mBspTree->mRoot = interior; 418 } 372 419 else 420 { 373 421 mVspBspTree->mRoot = interior; 422 } 374 423 } 375 424 … … 381 430 void ViewCellsParseHandlers::CreateViewCellsManager(const char *name) 382 431 { 383 384 432 if (strcmp(name, "bspTree") == 0) 385 433 { 434 Debug << "view cell type: Bsp" << endl; 435 386 436 mBspTree = new BspTree(); 387 388 Debug << "view cell type: Bsp" << endl;389 390 437 mCurrentNode = mBspTree->GetRoot(); 391 438 … … 394 441 else if (strcmp(name, "vspBspTree") == 0) 395 442 { 443 Debug << "view cell type: VspBsp" << endl; 444 396 445 mVspBspTree = new VspBspTree(); 397 398 Debug << "view cell type: VspBsp" << endl;399 446 mCurrentNode = mVspBspTree->GetRoot(); 400 447 401 448 mViewCellsManager = new VspBspViewCellsManager(mVspBspTree); 449 450 Debug << "creating vsp bsp view cells manager" << endl; 402 451 } 403 452 /*else if (strcmp(name, "vspKdTree") == 0) … … 412 461 exit(1); 413 462 } 463 464 mViewCellsManager->SetViewSpaceBox(mViewSpaceBox); 414 465 } 415 466 … … 503 554 // to do. 504 555 // 505 ViewCellsParseHandlers handler( viewCells,objects);556 ViewCellsParseHandlers handler(objects); 506 557 parser->setDocumentHandler(&handler); 507 558 parser->setErrorHandler(&handler); … … 558 609 XMLPlatformUtils::Terminate(); 559 610 611 // assign new view cells manager 612 *viewCells = handler.mViewCellsManager; 613 560 614 if (errorCount > 0) 561 615 return false; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParserXerces.h
r575 r577 23 23 // Constructors and Destructor 24 24 // ----------------------------------------------------------------------- 25 ViewCellsParseHandlers(ViewCellsManager **viewCellsManager, 26 ObjectContainer *objects); 25 ViewCellsParseHandlers(ObjectContainer *objects); 27 26 ~ViewCellsParseHandlers(); 28 27 … … 72 71 ObjectContainer *mObjects; 73 72 73 AxisAlignedBox3 mViewSpaceBox; 74 74 75 // Handlers for X3D 75 76 void StartBspLeaf(AttributeList& attributes); … … 83 84 84 85 void startBspElement(string element, AttributeList& attributes); 86 void StartViewSpaceBox(AttributeList& attributes); 85 87 // ----------------------------------------------------------------------- 86 88 // Handlers for the SAX ErrorHandler interface -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r574 r577 417 417 vm->CastBeam(beam); 418 418 419 Debug << "found " << beam.mViewCells.size() << " view cells and "420 << beam.mKdNodes.size() << " kd nodes" << endl;419 Debug << "found " << (int)beam.mViewCells.size() << " view cells and " 420 << (int)beam.mKdNodes.size() << " kd nodes" << endl; 421 421 422 422 BeamSampleStatistics stats; … … 526 526 { 527 527 mViewSpaceBox = box; 528 mViewCellsManager->SetViewSpaceBox(*box);529 528 } 530 529 else 531 530 { 532 531 mViewSpaceBox = NULL; 533 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 534 } 535 532 } 533 534 AxisAlignedBox3 vbox = mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox(); 535 536 536 //-- load view cells from file if requested 537 if (mLoadViewCells) 538 { 539 // load now because otherwise bounding box not correct 540 mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects); 541 } 542 else 543 { 537 if (!mLoadViewCells) 538 { 539 mViewCellsManager->SetViewSpaceBox(vbox); 544 540 // construct view cells using it's own set of samples 545 541 mViewCellsManager->Construct(this);
Note: See TracChangeset
for help on using the changeset viewer.