Changeset 1551 for GTP/trunk/Lib
- Timestamp:
- 10/02/06 19:07:38 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1548 r1551 1445 1445 { 1446 1446 VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 1447 VspLeaf *leaf = vc->mLea f;1447 VspLeaf *leaf = vc->mLeaves[0]; 1448 1448 SubdivisionCandidate *candidate = leaf->GetSubdivisionCandidate(); 1449 1449 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1545 r1551 186 186 VssRay *newRay = mRayCaster->CastRay(sray, mViewSpaceBox, false); 187 187 //cout << "\np1: " << p1 << "\np : " << p << "\np2: " << p2 << endl; 188 if (!newRay) 189 return 0; 190 cout << "here42" << endl; 188 if (!newRay) return 0; 189 191 190 const bool enqueued = HandleRay(newRay); 192 191 … … 410 409 ConstructViewCells(mViewSpaceBox); 411 410 cout << "view cells loaded" << endl; 411 } 412 else if (1) 413 { cout << "here2255566" << endl; 414 //-- load view cells from file 415 //-- test successful view cells loading by exporting them again 416 VssRayContainer dummies; 417 mViewCellsManager->Visualize(mObjects, dummies); 418 mViewCellsManager->ExportViewCells("test.xml.zip", mViewCellsManager->GetExportPvs(), mObjects); 412 419 } 413 420 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1548 r1551 42 42 class Exporter; 43 43 44 #if 0 45 template <typename T> class GtPriority 46 { 47 public: 48 bool operator() (const T c1, const T c2) const 49 { 50 //return false; 51 return c1->GetPriority() < c2->GetPriority(); 52 } 53 }; 54 55 typedef std::priority_queue<SubdivisionCandidate *, 56 std::vector<SubdivisionCandidate *>, 57 GtPriority<std::vector<SubdivisionCandidate *>::value_type> > SplitQueue; 58 #endif 59 60 61 62 /** View space partition statistics. 44 45 46 /** View space / object space hierarchy statistics. 63 47 */ 64 48 class HierarchyStatistics: public StatisticsBase -
GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
r1528 r1551 41 41 hitA.mPoint = ray.Extrap(ray.intersections[0].mT); 42 42 hitA.mNormal = ray.intersections[0].mNormal; 43 // cout << "h ere91" << hitA.mPoint << " !obj: " << hitA.mObject << endl;43 // cout << "hita: " << hitA.mPoint << " !obj: " << hitA.mObject << endl; 44 44 } 45 45 -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1415 r1551 1028 1028 leaf->mViewCell = viewCell; 1029 1029 // push back pointer to this leaf 1030 viewCell->mLea f= leaf;1030 viewCell->mLeaves[0] = leaf; 1031 1031 vc.push_back(viewCell); 1032 1032 } else { -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
r1528 r1551 1585 1585 VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 1586 1586 1587 VspLeaf *leaf = vc->mLea f;1587 VspLeaf *leaf = vc->mLeaves[0]; 1588 1588 dirtyList.push_back(leaf->GetSubdivisionCandidate()); 1589 1589 } -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r1545 r1551 103 103 } 104 104 } 105 // cout << "here81 " << hitA.mObject << endl; 105 106 106 const bool validA = 107 107 ValidateRay(simpleRay.mOrigin, simpleRay.mDirection, box, hitA); … … 136 136 vssRays.push_back(vssRay); 137 137 ++ hits; 138 //cout << " here70vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl;138 //cout << "vssray 1: " << *vssRay << " " << vssRay->mTermination - vssRay->mOrigin << endl; 139 139 } 140 140 … … 152 152 vssRays.push_back(vssRay); 153 153 ++ hits; 154 //cout << " here71vssray 2: " << *vssRay << endl;154 //cout << "vssray 2: " << *vssRay << endl; 155 155 } 156 156 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1545 r1551 130 130 131 131 132 ViewCell::~ViewCell() 133 { 134 } 135 136 132 137 const ObjectPvs &ViewCell::GetPvs() const 133 138 { … … 250 255 { 251 256 const bool result = mPvs.AddSample(sample, pdf, contribution); 252 253 257 mPvsSizeValid = false; // have to recompute pvs size 254 258 … … 328 332 329 333 334 330 335 /************************************************************************/ 331 336 /* class ViewCellsStatistics implementation */ 332 337 /************************************************************************/ 333 334 335 338 336 339 … … 2227 2230 tstack.pop(); 2228 2231 2229 vc->SetId(currentId ++); 2232 if (vc->GetId() != -1) // out of bounds 2233 vc->SetId(currentId ++); 2230 2234 2231 2235 if (!vc->IsLeaf()) … … 2266 2270 stream << "pvs=\""; 2267 2271 2268 //-- export pvs 2272 //-- export pvs, i.e., the ids of the objects in the pvs 2269 2273 if (exportPvs) 2270 2274 { 2271 2275 ExportPvs(viewCell, stream); 2272 2276 } 2273 2274 2277 stream << "\" />" << endl; 2275 2278 } … … 2283 2286 stream << "pvs=\""; 2284 2287 2285 // --NOTE: do not export pvss for interior view cells because2288 // NOTE: do not export pvss for interior view cells because 2286 2289 // they can be completely reconstructed from the leaf pvss 2287 if (0) 2288 ExportPvs(viewCell, stream); 2290 // on the other hand: we could store a tag with the compression scheme, 2291 // then some scheme were pvs is in the interiors could be used 2292 if (0) ExportPvs(viewCell, stream); 2289 2293 2290 2294 stream << "\" >" << endl; … … 2327 2331 } 2328 2332 } 2333 } 2334 2335 2336 void ViewCellsTree::SetViewCellsManager(ViewCellsManager *vcm) 2337 { 2338 mViewCellsManager = vcm; 2329 2339 } 2330 2340 … … 2416 2426 2417 2427 2418 2419 2420 2428 /************************************************************************/ 2421 2429 /* MergeStatistics implementation */ -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1545 r1551 107 107 /** Default destructor. 108 108 */ 109 virtual ~ViewCell() {} 110 109 virtual ~ViewCell(); 111 110 /** Returns Pvs. 112 111 */ 113 112 const ObjectPvs &GetPvs() const; 114 115 113 /** Returns pvs. 116 114 */ 117 115 ObjectPvs &GetPvs(); 118 119 116 /** Completely substitutes the pvs. 120 117 */ 121 118 void SetPvs(const ObjectPvs &pvs); 122 123 119 /** Type of view cells. 124 120 */ 125 121 int Type() const; 126 127 128 122 /** Adds a passing ray to the passing ray container. 129 123 */ 130 124 void AddPassingRay(const Ray &ray, const int contributions); 131 132 125 /** Returns volume of the view cell. 133 126 */ 134 127 float GetVolume() const; 135 136 128 /** Returns area of the view cell. 137 129 */ 138 130 float GetArea() const; 139 140 131 /** Sets the volume of the view cell. 141 132 */ 142 133 void SetVolume(float volume); 143 144 134 /** Sets the area of the view cell. 145 135 */ 146 136 void SetArea(float area); 147 148 149 137 /** if this view cell is the root of a view cell hierarchy 150 138 */ 151 139 bool IsRoot() const; 152 153 140 /** Returns parent view cell. 154 141 */ 155 142 ViewCellInterior *GetParent() const; 156 157 143 /** Sets parent of this view cell. 158 144 */ 159 145 void SetParent(ViewCellInterior *parent); 160 161 162 146 /** Sets the mesh for this view cell. 163 147 */ … … 231 215 232 216 233 234 //////////////// 217 ////////// 235 218 //-- mailing stuff 236 237 219 238 220 static void NewMail(const int reserve = 1) … … 346 328 } 347 329 348 /** Returns if this view cell is active. 330 /** Returns active view cell, i.e. this view cell or 331 a parent view cell which is set as active view cell. 349 332 */ 350 333 ViewCell *GetActiveViewCell() const … … 355 338 void SetActiveViewCell(ViewCell *vc) 356 339 { mActiveViewCell = vc;} 357 358 340 359 341 /** points to the currently active view cell. This is the … … 375 357 ViewCellLeaf(mesh) { } 376 358 377 378 359 bool IsLeaf() const 379 360 { … … 381 362 } 382 363 383 384 /// Leaf of some hierarchy which is part of this view cell. 385 T mLeaf; 364 /// Leaves of some hierarchy which contains this view cell. 365 vector<T> mLeaves; 386 366 }; 387 367 … … 507 487 void SetRoot(ViewCell *root); 508 488 509 //float ComputeVolume(ViewCell *vc);510 511 489 /** Assignes unique ids to view cells. 512 490 */ … … 521 499 int CountKdPvs(const ViewCellLeaf *vc) const; 522 500 523 void SetViewCellsManager(ViewCellsManager *vcm) 524 { 525 mViewCellsManager = vcm; 526 } 501 /** Sets pointer to view cells manager. 502 */ 503 void SetViewCellsManager(ViewCellsManager *vcm); 527 504 528 505 protected: … … 595 572 void ResetMergeQueue(); 596 573 597 /** Updates the current top levelof view cells.574 /** Updates the current cut of view cells. 598 575 @returns number of newly merged view cells 599 576 */ … … 643 620 /// if the view cell tree hold compressed pvs 644 621 int mViewCellsStorage; 645 622 /// pointer to the view cells manager 646 623 ViewCellsManager *mViewCellsManager; 624 /// the root of the view cells hierarchy 647 625 ViewCell *mRoot; 648 626 649 627 /// if merge visualization should be shown 650 628 bool mExportMergedViewCells; 651 652 653 629 /// intermediate container of merged view cells. 654 630 ViewCellContainer mMergedViewCells; 655 656 657 631 /// if merged view cells are refined. 658 632 bool mRefineViewCells; 659 660 633 /// weights between variance and render cost increase (must be between zero and one) 661 634 float mRenderCostWeight; … … 666 639 float mDeviation; 667 640 float mAvgRenderCost; 641 668 642 /// the area is used for pvs heuristics 669 643 int mUseAreaForPvs; 670 644 /// number of currently active view cells (=current cut) 671 645 int mNumActiveViewCells; 672 673 646 /// minimal number of view cells 674 647 int mMergeMinViewCells; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r1545 r1551 420 420 if (!mOutOfBoundsCellPartOfTree) 421 421 { 422 cout << "here223" << endl; 422 423 // out of bounds cell not part of tree => 423 424 // delete manually 424 425 DEL_PTR(mOutOfBoundsCell); 425 } 426 }else cout << "here991" << endl; 426 427 } 427 428 … … 583 584 584 585 int polysSize = 0; 585 cout << "here55 " << mBbox << endl; 586 587 cout << "here99"; 586 588 587 for (int i = 0; i < limit; ++ i) 589 {cout << "q"; 590 Mesh *mesh = viewCells[i]->GetMesh(); 588 { 589 Mesh *mesh = viewCells[i]->GetMesh(); 590 591 591 if (mesh) 592 { cout << "w";592 { 593 593 // copy the mesh into polygons and add to BSP tree aabb 594 594 mBbox.Include(viewCells[i]->GetBox()); … … 596 596 } 597 597 } 598 cout << "here155 " << mBbox << endl; 598 599 599 return polysSize; 600 600 } … … 608 608 int limit = (maxObjects > 0) ? 609 609 Min((int)objects.size(), maxObjects) : (int)objects.size(); 610 cout << "here88";610 611 611 for (int i = 0; i < limit; ++i) 612 { cout << "e";612 { 613 613 Intersectable *object = objects[i]; 614 614 Mesh *mesh = NULL; … … 638 638 639 639 if (!mesh) continue; 640 640 641 // copy the mesh data to polygons 641 642 if (addToBbox) 642 { cout << "b";643 { 643 644 mBbox.Include(object->GetBox()); // add to BSP tree aabb 644 645 } … … 659 660 void BspTree::Construct(const ViewCellContainer &viewCells) 660 661 { 661 cout << "here5500000000" << endl;662 662 // construct hierarchy over the given view cells 663 663 mUsePredefinedViewCells = true; … … 1006 1006 1007 1007 leaf->SetViewCell(viewCell); 1008 viewCell->mLea f = leaf;1008 viewCell->mLeaves.push_back(leaf); 1009 1009 1010 1010 //float probability = max(0.0f, tData.mProbability); … … 2241 2241 } 2242 2242 } 2243 2244 // also add out of bounds cell2245 if (0 && !mOutOfBoundsCell->Mailed())2246 {2247 mOutOfBoundsCell->Mail();2248 viewCells.push_back(mOutOfBoundsCell);2249 }2250 2251 cout << "here555 " << viewCells.size() << endl;2252 2253 2243 } 2254 2244 … … 2389 2379 for (it = leaves.begin(); it != it_end; ++ it) 2390 2380 { 2391 BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf; 2392 ConstructGeometry(l, vcGeom); 2381 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*it); 2382 vector<BspLeaf *>::const_iterator bit, bit_end = bspVc->mLeaves.end(); 2383 2384 for (bit = bspVc->mLeaves.begin(); bit != bit_end; ++ bit) 2385 { 2386 BspLeaf *l = *bit; 2387 ConstructGeometry(l, vcGeom); 2388 } 2393 2389 } 2394 2390 } … … 2810 2806 iit = ray->mViewCells.begin(); 2811 2807 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++)); 2812 BspLeaf *leaf = bspVc->mLea f;2808 BspLeaf *leaf = bspVc->mLeaves[0]; 2813 2809 2814 2810 // traverse intersections … … 2819 2815 BspLeaf *prevLeaf = leaf; 2820 2816 bspVc = dynamic_cast<BspViewCell *>(*iit); 2821 leaf = bspVc->mLea f;2817 leaf = bspVc->mLeaves[0]; 2822 2818 2823 2819 // view space not valid or same view cell … … 3338 3334 3339 3335 3340 bool BspTree::Export( ofstream&stream)3336 bool BspTree::Export(OUT_STREAM &stream) 3341 3337 { 3342 3338 ExportNode(mRoot, stream); 3343 3344 3339 return true; 3345 3340 } 3346 3341 3347 3342 3348 void BspTree::ExportNode(BspNode *node, ofstream&stream)3343 void BspTree::ExportNode(BspNode *node, OUT_STREAM &stream) 3349 3344 { 3350 3345 if (node->IsLeaf()) 3351 3346 { 3352 3347 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 3353 3354 int id = -1; 3355 if (leaf->GetViewCell() != mOutOfBoundsCell) 3356 { 3357 id = leaf->GetViewCell()->GetId(); 3358 } 3348 ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell()); 3349 3350 const int id = viewCell->GetId(); 3359 3351 3360 3352 stream << "<Leaf viewCellId=\"" << id << "\" />" << endl; … … 3376 3368 } 3377 3369 3378 } 3370 3371 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
r1545 r1551 646 646 */ 647 647 void ConstructGeometry(ViewCell* vc, BspNodeGeometry &geom) const; 648 649 648 650 649 /** Sets pointer to view cells manager. … … 675 674 /** Exports Bsp tree to file. 676 675 */ 677 bool Export( ofstream&stream);676 bool Export(OUT_STREAM &stream); 678 677 679 678 /** Pointer to the view cells tree. … … 718 717 }; 719 718 720 void ExportNode(BspNode *node, ofstream&stream);719 void ExportNode(BspNode *node, OUT_STREAM &stream); 721 720 722 721 /** Evaluates tree stats in the BSP tree leafs. -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1548 r1551 30 30 31 31 32 33 32 namespace GtpVisibilityPreprocessor { 34 33 … … 667 666 { 668 667 //-- export bounding boxes 669 670 668 stream << "<BoundingBoxes>" << endl; 671 672 669 ObjectContainer::const_iterator oit, oit_end = objects.end(); 673 670 … … 677 674 const AxisAlignedBox3 box = mi->GetBox(); 678 675 676 //////////// 679 677 //-- the bounding boxes 680 678 stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\"" … … 687 685 688 686 687 ///////////// 689 688 //-- export the view cells and the pvs 690 689 691 690 const int numViewCells = mCurrentViewCellsStats.viewCells; 692 693 691 stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 694 692 695 693 mViewCellsTree->Export(stream, exportPvs); 696 694 … … 698 696 699 697 698 ////////// 700 699 //-- export the view space hierarchy 701 700 … … 753 752 Debug << "stepsize: " << stepSize << endl; 754 753 755 756 754 const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost(); 757 755 const float totalVol = GetViewSpaceBox().GetVolume(); 758 756 759 757 int currentPvs = minVal;//(int)ceil(minRenderCost); 760 761 758 762 759 int i = 0; 763 760 int j = 0; 764 765 761 float volSum = 0; 766 762 int smallerSum = 0; … … 1310 1306 { 1311 1307 // set view space box to bounding box of the view cells 1312 /*AxisAlignedBox3 bbox;1308 AxisAlignedBox3 bbox; 1313 1309 bbox.Initialize(); 1314 1310 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); … … 1317 1313 bbox.Include(GetViewCellBox(*it)); 1318 1314 } 1319 SetViewSpaceBox(bbox); */1315 SetViewSpaceBox(bbox); 1320 1316 1321 1317 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry from file " << filename << endl; … … 1965 1961 else // no view cells tree, handle view cells "myself" 1966 1962 { 1967 for (int i = 0; i < (int)mViewCells.size(); ++ i) 1968 { 1969 mViewCells[i]->SetId(i); 1963 int i = 0; 1964 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 1965 for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 1966 { 1967 if ((*vit)->GetId() != -1) 1968 mViewCells[i]->SetId(i ++); 1970 1969 } 1971 1970 } … … 2560 2559 } 2561 2560 else 2562 { cout << "here222" << endl;2561 { 2563 2562 // use predefined view cells geometry => 2564 2563 // contruct bsp hierarchy over them … … 2620 2619 2621 2620 2622 void BspViewCellsManager::ExportMergedViewCells(const ObjectContainer &objects)2621 void ViewCellsManager::ExportMergedViewCells(const ObjectContainer &objects) 2623 2622 { 2624 2623 // save color code … … 2725 2724 ObjectPvs pvs; 2726 2725 UpdatePvsForEvaluation(root, pvs); 2727 2728 2726 } 2729 2727 … … 2746 2744 } 2747 2745 2748 ResetViewCells(); // reset view cells 2746 // recompute view cells and stats 2747 ResetViewCells(); 2749 2748 Debug << "\nView cells after merge:\n" << mCurrentViewCellsStats << endl; 2750 2749 2750 // visualization of the view cells 2751 2751 if (1) ExportMergedViewCells(objects); 2752 2753 // only for debugging purpose: test if the subdivision is valid2754 if (0) TestSubdivision();2755 2752 2756 2753 // compute final meshes and volume / area … … 2787 2784 2788 2785 int savedColorCode = mColorCode; 2789 2786 2790 2787 if (1) // export final view cells 2791 2788 { … … 2807 2804 cout << "finished" << endl; 2808 2805 } 2806 2809 2807 // reset color code 2810 2808 mColorCode = savedColorCode; … … 2967 2965 { 2968 2966 BspNodeGeometry geom; 2969 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 2970 mBspTree->ConstructGeometry(leaf, geom); 2967 mBspTree->ConstructGeometry(*it, geom); 2971 2968 2972 2969 const float lVol = geom.GetVolume(); 2973 2974 2970 newVol += lVol; 2975 2971 subdivVol += (*it)->GetVolume(); 2976 2972 2977 float thres = 0.9f;2973 const float thres = 0.9f; 2978 2974 if ((lVol < ((*it)->GetVolume() * thres)) || 2979 2975 (lVol * thres > ((*it)->GetVolume()))) … … 2991 2987 const AxisAlignedBox3 *sceneBox, 2992 2988 const AxisAlignedPlane *clipPlane 2993 ) const 2994 { 2989 ) const 2990 {cout << "here55543 " << vc->GetId() << endl; 2991 // out of bounds cell 2992 if (vc->GetId() == -1) 2993 return; 2994 2995 2995 // export mesh if available 2996 2996 if (vc->GetMesh()) … … 2999 2999 return; 3000 3000 } 3001 3001 3002 // otherwise construct from leaves 3002 3003 if (clipPlane) … … 3011 3012 { 3012 3013 BspNodeGeometry geom; 3013 3014 3014 BspNodeGeometry front; 3015 3015 BspNodeGeometry back; 3016 3016 3017 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 3018 mBspTree->ConstructGeometry(leaf, geom); 3017 mBspTree->ConstructGeometry(*it, geom); 3019 3018 3020 3019 const float eps = 0.00000001f; … … 3033 3032 eps); 3034 3033 3035 //Debug << "geo size: " << geom.Size() << endl;3036 //Debug << "size b: " << back.Size() << " f: " << front.Size() << endl;3037 3034 if (back.Valid()) 3038 { 3035 { 3039 3036 exporter->ExportPolygons(back.GetPolys()); 3040 3037 } … … 3046 3043 BspNodeGeometry geom; 3047 3044 mBspTree->ConstructGeometry(vc, geom); 3048 3049 3045 exporter->ExportPolygons(geom.GetPolys()); 3050 3046 } … … 3054 3050 void BspViewCellsManager::CreateMesh(ViewCell *vc) 3055 3051 { 3056 // delete previous mesh 3057 ///DEL_PTR(vc->GetMesh()); 3052 // note: should previous mesh be deleted (via mesh manager?) 3058 3053 BspNodeGeometry geom; 3059 3054 mBspTree->ConstructGeometry(vc, geom); … … 3080 3075 { 3081 3076 BspNodeGeometry geom; 3082 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 3083 mBspTree->ConstructGeometry( leaf, geom);3077 3078 mBspTree->ConstructGeometry(*it, geom); 3084 3079 3085 3080 const float lVol = geom.GetVolume(); 3086 3081 const float lArea = geom.GetArea(); 3087 3082 3088 //(*it)->SetVolume(vol);3089 //(*it)->SetArea(area);3090 3091 3083 area += lArea; 3092 3084 volume += lVol; 3093 3094 3085 3086 CreateMesh(*it); 3095 3087 } 3096 3088 … … 3106 3098 return NULL; 3107 3099 } 3108 3109 3100 if (!mViewSpaceBox.IsInside(point)) 3110 3101 { 3111 3102 return NULL; 3112 3103 } 3113 3114 3104 return mBspTree->GetViewCell(point); 3115 3105 } … … 3141 3131 const ObjectContainer &objects) 3142 3132 { 3143 #if TODO 3133 if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 3134 { 3135 return false; 3136 } 3137 3144 3138 cout << "exporting view cells to xml ... "; 3145 std::ofstream stream; 3139 3140 OUT_STREAM stream(filename.c_str()); 3146 3141 3147 3142 // for output we need unique ids for each view cell 3148 3143 CreateUniqueViewCellIds(); 3149 3144 3150 3151 stream.open(filename.c_str());3152 3145 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 3153 3146 stream << "<VisibilitySolution>" << endl; 3154 3147 3155 //-- the view space bounding box 3156 stream << "<ViewSpaceBox" 3148 if (exportPvs) 3149 { 3150 ////////// 3151 //-- export bounding boxes: they are used to identify the objects from the pvs and 3152 //-- assign them to the entities in the rendering engine 3153 3154 stream << "<BoundingBoxes>" << endl; 3155 ObjectContainer::const_iterator oit, oit_end = objects.end(); 3156 3157 for (oit = objects.begin(); oit != oit_end; ++ oit) 3158 { 3159 MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 3160 const AxisAlignedBox3 box = mi->GetBox(); 3161 3162 stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\"" 3163 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 3164 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 3165 } 3166 3167 stream << "</BoundingBoxes>" << endl; 3168 } 3169 3170 /////////// 3171 //-- export the view cells and the pvs 3172 3173 const int numViewCells = mCurrentViewCellsStats.viewCells; 3174 stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 3175 3176 mViewCellsTree->Export(stream, exportPvs); 3177 3178 stream << "</ViewCells>" << endl; 3179 3180 ///////////// 3181 //-- export the view space hierarchy 3182 stream << "<ViewSpaceHierarchy type=\"bsp\"" 3157 3183 << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 3158 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl; 3159 3160 //-- the type of the view cells hierarchy 3161 3162 // NOTE: load in vsp bsp here because bsp and vsp bsp can use same tree and vsp bsp is bug free 3163 stream << "<Hierarchy name=\"vspBspTree\" >" << endl; 3164 3165 //-- load the view cells itself, i.e., the ids and the pvs 3166 stream << "<ViewCells>" << endl; 3167 3168 mViewCellsTree->Export(stream, exportPvs); 3169 3170 stream << "</ViewCells>" << endl; 3171 3172 //-- load the hierarchy 3173 stream << "<Hierarchy>" << endl; 3184 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl; 3185 3174 3186 mBspTree->Export(stream); 3175 stream << endl << "</Hierarchy>" << endl; 3176 3187 3188 // end tags 3189 stream << "</ViewSpaceHierarchy>" << endl; 3177 3190 stream << "</VisibilitySolution>" << endl; 3191 3178 3192 stream.close(); 3179 3180 3193 cout << "finished" << endl; 3181 #endif 3194 3182 3195 return true; 3183 3196 } … … 3516 3529 { 3517 3530 KdViewCell *kdVc = dynamic_cast<KdViewCell *>(*it); 3518 exporter->ExportBox(mKdTree->GetBox(kdVc->mLea f));3531 exporter->ExportBox(mKdTree->GetBox(kdVc->mLeaves[0])); 3519 3532 } 3520 3533 } … … 3851 3864 { 3852 3865 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(viewCell); 3853 3854 return bspVc->mLeaf; 3866 return bspVc->mLeaves[0]; 3855 3867 } 3856 3868 else … … 4082 4094 bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 4083 4095 { 4084 4085 4086 4087 4088 4089 4096 // $$JB -> implemented in viewcellsmanager (slower, but allows dynamic 4097 // validy update in preprocessor for all managers) 4098 return ViewCellsManager::ViewPointValid(viewPoint); 4099 4100 // return mViewSpaceBox.IsInside(viewPoint) && 4101 // mVspBspTree->ViewPointValid(viewPoint); 4090 4102 } 4091 4103 … … 4099 4111 VssRayContainer visRays; 4100 4112 GetRaySets(sampleRays, mVisualizationSamples, visRays); 4101 4102 4103 if (0) 4113 4114 if (1) 4104 4115 { 4105 4116 ////////////////// … … 4146 4157 } 4147 4158 4148 if (0) 4149 { 4150 cout << "exporting depth map ... "; 4151 4152 Exporter *exporter = Exporter::GetExporter("depth_map.x3d"); 4153 if (exporter) 4154 { 4155 if (1) 4156 { 4157 exporter->SetWireframe(); 4158 exporter->ExportBox(mViewSpaceBox); 4159 exporter->SetFilled(); 4160 } 4161 4162 if (mExportGeometry) 4163 { 4164 exporter->ExportGeometry(objects); 4165 } 4166 4167 const int maxDepth = mVspBspTree->GetStatistics().maxDepth; 4168 4169 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 4170 4171 for (vit = mViewCells.begin(); vit != mViewCells.end(); ++ vit) 4172 { 4173 ViewCell *vc = *vit; 4174 4175 ViewCellContainer leaves; 4176 mViewCellsTree->CollectLeaves(vc, leaves); 4177 4178 ViewCellContainer::const_iterator lit, lit_end = leaves.end(); 4179 4180 for (lit = leaves.begin(); lit != lit_end; ++ lit) 4181 { 4182 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*lit)->mLeaf; 4183 4184 Material m; 4185 4186 float relDepth = (float)leaf->GetDepth() / (float)maxDepth; 4187 m.mDiffuseColor.r = relDepth; 4188 m.mDiffuseColor.g = 0.0f; 4189 m.mDiffuseColor.b = 1.0f - relDepth; 4190 4191 exporter->SetForcedMaterial(m); 4192 4193 4194 BspNodeGeometry geom; 4195 mVspBspTree->ConstructGeometry(leaf, geom); 4196 exporter->ExportPolygons(geom.GetPolys()); 4197 } 4198 } 4199 4200 delete exporter; 4201 } 4202 4203 4204 cout << "finished" << endl; 4205 } 4206 4159 //////////////// 4207 4160 //-- visualization of the BSP splits 4161 4208 4162 bool exportSplits = false; 4209 4163 Environment::GetSingleton()->GetBoolValue("VspBspTree.Visualization.exportSplits", exportSplits); … … 4216 4170 } 4217 4171 4172 //////// 4218 4173 //-- export single view cells 4219 4174 ExportBspPvs(objects, visRays); … … 4308 4263 { 4309 4264 // output rays stored with the view cells during subdivision 4310 if (1) 4265 VssRayContainer vcRays; 4266 VssRayContainer collectRays; 4267 4268 raysOut = min((int)rays.size(), 100); 4269 4270 // collect intial view cells 4271 ViewCellContainer leaves; 4272 mViewCellsTree->CollectLeaves(vc, leaves); 4273 4274 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 4275 4276 for (vit = leaves.begin(); vit != vit_end; ++ vit) 4311 4277 { 4312 VssRayContainer vcRays; 4313 VssRayContainer collectRays; 4314 4315 raysOut = min((int)rays.size(), 100); 4316 4317 // collect intial view cells 4318 ViewCellContainer leaves; 4319 mViewCellsTree->CollectLeaves(vc, leaves); 4320 4321 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 4322 4323 for (vit = leaves.begin(); vit != vit_end; ++ vit) 4278 BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0]; 4279 4280 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 4281 4282 for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 4324 4283 { 4325 BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaf; 4326 4327 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 4328 4329 for (rit = vcLeaf->mVssRays.begin(); rit != rit_end; ++ rit) 4330 { 4331 collectRays.push_back(*rit); 4332 } 4284 collectRays.push_back(*rit); 4333 4285 } 4334 4335 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 4336 4337 for (rit = collectRays.begin(); rit != rit_end; ++ rit) 4338 { 4339 float p = RandomValue(0.0f, (float)collectRays.size()); 4286 } 4287 4288 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 4289 4290 for (rit = collectRays.begin(); rit != rit_end; ++ rit) 4291 { 4292 float p = RandomValue(0.0f, (float)collectRays.size()); 4340 4293 4341 if (p < raysOut) 4342 vcRays.push_back(*rit); 4343 } 4344 4345 //Debug << "#rays: " << (int)vcRays.size() << endl; 4346 4347 //-- export rays piercing this view cell 4348 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 4294 if (p < raysOut) 4295 vcRays.push_back(*rit); 4349 4296 } 4350 4351 // associate new rays with output view cell 4352 if (0) 4353 { 4354 VssRayContainer vcRays; 4355 raysOut = min((int)rays.size(), mVisualizationSamples); 4356 4357 // check whether we can add the current ray to the output rays 4358 for (int k = 0; k < raysOut; ++ k) 4359 { 4360 VssRay *ray = rays[k]; 4361 for (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 4362 { 4363 ViewCell *rayvc = ray->mViewCells[j]; 4364 4365 if (rayvc == vc) 4366 vcRays.push_back(ray); 4367 } 4368 } 4369 4370 //-- export rays piercing this view cell 4371 exporter->ExportRays(vcRays, RgbColor(1, 1, 0)); 4372 } 4373 4297 4298 ////////// 4299 //-- export rays piercing this view cell 4300 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 4374 4301 } 4375 4302 … … 4390 4317 //////// 4391 4318 //-- export pvs 4392 ObjectPvsMap::const_iterator oit, 4393 oit_end = pvs.mEntries.end(); 4319 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 4394 4320 4395 4321 Intersectable::NewMail(); … … 4573 4499 ) const 4574 4500 { 4501 // out of bounds cell 4502 if (vc->GetId() == -1) 4503 return; 4504 4575 4505 if (clipPlane) 4576 4506 { … … 4588 4518 BspNodeGeometry back; 4589 4519 4590 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 4591 mVspBspTree->ConstructGeometry(leaf, geom); 4520 mVspBspTree->ConstructGeometry(*it, geom); 4592 4521 4593 4522 const float eps = 0.0001f; … … 4605 4534 mViewSpaceBox, 4606 4535 eps); 4607 4608 //Debug << "geo size: " << geom.Size() << endl;4609 //Debug << "size b: " << back.Size() << " f: " << front.Size() << endl;4610 4536 4611 4537 if (back.Valid()) … … 4646 4572 for (int j = 0; j < (int)leaves.size(); ++ j) 4647 4573 { 4648 BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLea f;4574 BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaves[0]; 4649 4575 4650 4576 if (i != j) 4651 4577 { 4652 BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaf; 4653 4654 int dist = mVspBspTree->TreeDistance(leaf, leaf2); 4578 BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaves[0]; 4579 const int dist = mVspBspTree->TreeDistance(leaf, leaf2); 4655 4580 4656 4581 if (dist > maxDist) … … 4678 4603 void VspBspViewCellsManager::CreateMesh(ViewCell *vc) 4679 4604 { 4680 //if (vc->GetMesh()) delete vc->GetMesh();4681 4605 BspNodeGeometry geom; 4682 4683 4606 mVspBspTree->ConstructGeometry(vc, geom); 4684 4607 … … 4710 4633 { 4711 4634 BspNodeGeometry geom; 4712 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 4713 mVspBspTree->ConstructGeometry(leaf, geom); 4635 mVspBspTree->ConstructGeometry(*it, geom); 4714 4636 4715 4637 const float lVol = geom.GetVolume(); 4716 4638 const float lArea = geom.GetArea(); 4717 4718 //(*it)->SetVolume(vol);4719 //(*it)->SetArea(area);4720 4639 4721 4640 area += lArea; … … 4744 4663 { 4745 4664 BspNodeGeometry geom; 4746 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 4747 mVspBspTree->ConstructGeometry(leaf, geom); 4665 mVspBspTree->ConstructGeometry(*it, geom); 4748 4666 4749 4667 const float lVol = geom.GetVolume(); … … 5086 5004 { 5087 5005 VspViewCell *vspVc = dynamic_cast<VspViewCell *>(*it); 5088 VspLeaf *l = vspVc->mLea f;5006 VspLeaf *l = vspVc->mLeaves[0]; 5089 5007 5090 5008 const AxisAlignedBox3 box = 5091 mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLea f);5009 mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaves[0]); 5092 5010 5093 5011 if (sceneBox && !Overlap(*sceneBox, box)) … … 5272 5190 for (vit = leaves.begin(); vit != vit_end; ++ vit) 5273 5191 { 5274 VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLea f;5192 VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0]; 5275 5193 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 5276 5194 … … 5441 5359 for (it = leaves.begin(); it != it_end; ++ it) 5442 5360 { 5443 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLea f;5361 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0]; 5444 5362 const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); 5445 5446 5363 IncludeBoxInMesh(box, *mesh); 5447 5364 } … … 5471 5388 for (it = leaves.begin(); it != it_end; ++ it) 5472 5389 { 5473 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLea f;5390 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0]; 5474 5391 5475 5392 const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); … … 5477 5394 const float lVol = box.GetVolume(); 5478 5395 const float lArea = box.SurfaceArea(); 5479 5480 //(*it)->SetVolume(vol);5481 //(*it)->SetArea(area);5482 5396 5483 5397 area += lArea; … … 5714 5628 disposeRays(evaluationSamples, NULL); 5715 5629 } 5630 5716 5631 #endif 5717 5718 5719 } 5632 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1545 r1551 578 578 AxisAlignedPlane *GetClipPlane(); 579 579 580 void ExportMergedViewCells(const ObjectContainer &objects); 581 580 582 /////////////////////// 581 583 … … 777 779 */ 778 780 void TestSubdivision(); 779 780 void ExportMergedViewCells(const ObjectContainer &objects);781 781 }; 782 782 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1486 r1551 260 260 { 261 261 // sort view cells to help associating view cells according to their id 262 stable_sort(mViewCells.begin(), mViewCells.end(), vlt);262 //stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 263 263 264 264 // not parsing view cells anymore … … 393 393 { 394 394 cout << "["; 395 StartViewCell Interior(attributes);395 StartViewCell(attributes, false); 396 396 } 397 397 … … 399 399 { 400 400 cout << "l"; 401 StartViewCell Leaf(attributes);401 StartViewCell(attributes, true); 402 402 } 403 403 } … … 464 464 465 465 466 void ViewCellsParseHandlers::StartViewCellPvs(ViewCell *viewCell, 467 AttributeList& attributes) 468 { 469 int len = attributes.getLength(); 466 void ViewCellsParseHandlers::StartViewCellPvs(ObjectPvs &pvs, const char *ptr) 467 { 468 // handle obect indices 470 469 vector<int> objIndices; 471 472 for (int i = 0; i < len; ++ i) 473 { 474 string attrName(StrX(attributes.getName(i)).LocalForm()); 475 476 if (attrName == "pvs") 477 { 478 StrX attrValue(attributes.getValue(i)); 470 char *endptr; 479 471 480 // handle coordIndex 481 objIndices.clear(); 482 const char *ptr = attrValue.LocalForm(); 483 char *endptr; 484 485 while (1) 486 { 487 const int index = strtol(ptr, &endptr, 10); 488 489 if (ptr == endptr) break; 490 491 objIndices.push_back(index); 492 493 ptr = endptr; 494 } 495 496 //TODO: find objects and add them to pvs 497 // TODO: get view cell with specified id 498 MeshInstance dummyInst(NULL); 499 500 vector<int>::const_iterator it, it_end = objIndices.end(); 501 for (it = objIndices.begin(); it != it_end; ++ it) 502 { 503 const int objId = *it; 504 dummyInst.SetId(objId); 505 506 ObjectContainer::iterator oit = 507 lower_bound(mObjects->begin(), 508 mObjects->end(), 509 (Intersectable *)&dummyInst, ilt); 510 511 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 512 { 513 // $$JB we should store a float a per object which corresponds 514 // to sumof pdfs, i.e. its relative visibility 515 // temporarily set to 1.0f 516 viewCell->GetPvs().AddSample(*oit, 1.0f); 517 } 518 else 519 { 520 cout << "error: object with id " << objId << " does not exist" << endl; 521 } 522 } 523 } 524 else if (attrName == "id") 525 { 526 StrX attrValue(attributes.getValue(i)); 527 528 const char *ptr = attrValue.LocalForm(); 529 char *endptr = NULL; 530 const int id = strtol(ptr, &endptr, 10); 531 532 viewCell->SetId(id); 533 } 534 /*else if (attrName == "active") 535 { 536 StrX attrValue(attributes.getValue(i)); 537 538 const char *ptr = attrValue.LocalForm(); 539 char *endptr = NULL; 540 const bool isActive = (bool)strtol(ptr, &endptr, 10); 541 542 if (isActive) 543 viewCell->SetActive(); 544 }*/ 545 else if (attrName == "mergecost") 546 { 547 StrX attrValue(attributes.getValue(i)); 548 549 const char *ptr = attrValue.LocalForm(); 550 char *endptr = NULL; 551 const float cost = (float)strtod(ptr, &endptr); 552 553 viewCell->SetMergeCost(cost); 472 while (1) 473 { // read object ids 474 const int index = strtol(ptr, &endptr, 10); 475 if (ptr == endptr) 476 break; 477 objIndices.push_back(index); 478 ptr = endptr; 479 } 480 481 // TODO: 482 // 1) find objects and add them to pvs 483 // 2) get view cell with specified id 484 MeshInstance dummyInst(NULL); 485 486 vector<int>::const_iterator it, it_end = objIndices.end(); 487 for (it = objIndices.begin(); it != it_end; ++ it) 488 { 489 const int objId = *it; 490 dummyInst.SetId(objId); 491 492 ObjectContainer::iterator oit = 493 lower_bound(mObjects->begin(), 494 mObjects->end(), 495 (Intersectable *)&dummyInst, ilt); 496 497 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 498 { 499 // $$JB we should store a float a per object which corresponds 500 // to sumof pdfs, i.e. its relative visibility 501 // temporarily set to 1.0f 502 pvs.AddSample(*oit, 1.0f); 503 } 504 else 505 { 506 cout << "error: object with id " << objId << " does not exist" << endl; 554 507 } 555 508 } … … 705 658 } 706 659 660 /////////// 707 661 //-- find associated view cell 708 662 … … 728 682 { 729 683 // TODO: get view cell with specified id 730 ViewCellInterior dummyVc; 731 dummyVc.SetId(viewCellId); 732 733 ViewCellContainer::iterator vit = 734 lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 735 736 BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit); 684 ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 685 BspViewCell *viewCell = dynamic_cast<BspViewCell *>((*vit).second); 737 686 738 687 if (viewCell->GetId() == viewCellId) … … 740 689 // create new view cell for bsp nodes 741 690 leaf->SetViewCell(viewCell); 742 viewCell->mLea f = leaf;691 viewCell->mLeaves.push_back(leaf); 743 692 } 744 693 else … … 793 742 794 743 795 void ViewCellsParseHandlers::StartViewCellLeaf(AttributeList& attributes) 796 { 797 ViewCellLeaf *viewCell = new ViewCellLeaf(); 798 799 if (mCurrentViewCell) // replace front or (if not NULL) back child 800 { 801 ViewCellInterior *interior = 802 dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 803 interior->SetupChildLink(viewCell); 804 } 805 else // root 806 { 807 mViewCellsTree->SetRoot(viewCell); 808 } 809 810 StartViewCellPvs(viewCell, attributes); 811 812 // collect leaves 813 mViewCells.push_back(viewCell); 814 } 815 816 817 void ViewCellsParseHandlers::StartViewCellInterior(AttributeList& attributes) 818 { 819 ViewCellInterior* interior = new ViewCellInterior(); 744 ViewCell *ViewCellsParseHandlers::GetOrCreateViewCell(const int id, const bool isLeaf) 745 { 746 ViewCellsMap::iterator vit = mViewCells.find(id); 747 748 if (vit != mViewCells.end()) 749 { 750 return (*vit).second; 751 } 752 else 753 { 754 ViewCell *vc; 755 if (isLeaf) 756 { 757 vc = new ViewCellLeaf(); 758 } 759 else 760 { 761 vc = new ViewCellInterior(); 762 } 763 764 vc->SetId(id); 765 mViewCells[id] = vc; 766 return vc; 767 } 768 } 769 770 771 void ViewCellsParseHandlers::StartViewCell(AttributeList& attributes, const bool isLeaf) 772 { 773 ViewCell *viewCell = NULL; 820 774 821 if (mCurrentViewCell) // replace NULL child of parent with current node 822 { 823 ViewCellInterior *current = dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 824 825 current->SetupChildLink(interior); 826 } 827 else 828 { 829 mViewCellsTree->SetRoot(interior); 830 } 831 832 mCurrentViewCell = interior; 833 834 StartViewCellPvs(interior, attributes); 775 const int len = attributes.getLength(); 776 float mergeCost; 777 ObjectPvs pvs; 778 779 for (int i = 0; i < len; ++ i) 780 { 781 const string attrName(StrX(attributes.getName(i)).LocalForm()); 782 783 if (attrName == "id") 784 { 785 const StrX attrValue(attributes.getValue(i)); 786 const char *ptr = attrValue.LocalForm(); 787 char *endptr = NULL; 788 const int id = strtol(ptr, &endptr, 10); 789 790 // create new view cell, otherwise use reference. 791 viewCell = GetOrCreateViewCell(id, isLeaf); 792 793 if (mCurrentViewCell) // replace front or (if not NULL) back child 794 { 795 ViewCellInterior *interior = 796 dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 797 interior->SetupChildLink(viewCell); 798 } 799 else 800 { // set the new root 801 mViewCellsTree->SetRoot(viewCell); 802 } 803 804 if (!isLeaf) 805 { 806 mCurrentViewCell = viewCell; 807 } 808 } 809 if (attrName == "pvs") 810 { 811 StrX attrValue(attributes.getValue(i)); 812 const char *ptr = attrValue.LocalForm(); 813 814 // note: id must come before pvs! 815 // otherwise view cell is undefined 816 StartViewCellPvs(pvs, ptr); 817 } 818 else if (attrName == "active") 819 { 820 StrX attrValue(attributes.getValue(i)); 821 const char *ptr = attrValue.LocalForm(); 822 char *endptr = NULL; 823 const bool isActive = (bool)strtol(ptr, &endptr, 10); 824 825 if (isActive) 826 { 827 // TODO 828 } 829 } 830 else if (attrName == "mergecost") 831 { 832 StrX attrValue(attributes.getValue(i)); 833 834 const char *ptr = attrValue.LocalForm(); 835 char *endptr = NULL; 836 mergeCost = (float)strtod(ptr, &endptr); 837 } 838 } 839 840 viewCell->SetMergeCost(mergeCost); 841 viewCell->SetPvs(pvs); 835 842 } 836 843 … … 841 848 { 842 849 cout << "hierarchy type: Bsp" << endl; 843 844 850 mVspBspTree = new VspBspTree(); 845 851 … … 847 853 mVspBspTree->mBox = mViewSpaceBox; 848 854 849 ViewCellContainer::iterator vit, vit_end = mViewCells.end(); 850 851 // reset view cells using the current node type 855 ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 856 857 // remove view cells and exchange them with the 858 // view cells specialized for the current hierarchy node type 852 859 for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 853 860 { 854 ViewCell *vc = *vit; 855 861 ViewCell *vc = (*vit).second; 862 if (!vc->IsLeaf()) // exchange only leaves 863 continue; 856 864 BspViewCell *bspVc = new BspViewCell(); 865 bspVc->SetId(vc->GetId()); 857 866 bspVc->SetPvs(vc->GetPvs()); 858 bspVc->SetId(vc->GetId());859 867 860 868 if (vc->IsRoot()) … … 868 876 869 877 DEL_PTR(vc); 870 (*vit) = bspVc;878 (*vit).second = bspVc; 871 879 } 872 880 } … … 874 882 { 875 883 cout << "hierarchy type: Vsp" << endl; 876 877 884 mVspTree = new VspTree(); 878 885 … … 880 887 mVspTree->mBoundingBox = mViewSpaceBox; 881 888 882 ViewCell Container::iterator vit, vit_end = mViewCells.end();889 ViewCellsMap::iterator vit, vit_end = mViewCells.end(); 883 890 884 891 // reset view cells using the current node type 885 892 for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 886 893 { 887 ViewCell *vc = *vit;894 ViewCell *vc = (*vit).second; 888 895 889 896 VspViewCell *vspVc = new VspViewCell(); 890 897 vspVc->SetPvs(vc->GetPvs()); 891 898 vspVc->SetId(vc->GetId()); 899 900 if (!vc->IsLeaf()) // exchange only leaves 901 continue; 892 902 893 903 if (vc->IsRoot()) … … 901 911 902 912 DEL_PTR(vc); 903 (*vit) = vspVc;913 (*vit).second = vspVc; 904 914 } 905 915 … … 970 980 } 971 981 972 //-- find associated view cell 982 ///////////// 983 //-- find view cell associated with the id 984 973 985 int viewCellId; 974 986 … … 989 1001 } 990 1002 991 if (viewCellId >= 0) // valid view cell 1003 if (viewCellId >= 0) // valid view cell found 992 1004 { 993 1005 // TODO: get view cell with specified id 994 ViewCellInterior dummyVc;1006 /*ViewCellInterior dummyVc; 995 1007 dummyVc.SetId(viewCellId); 996 1008 997 //cout << "\nsearching view cell with id " << viewCellId << endl;998 1009 ViewCellContainer::iterator vit = 999 1010 lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 1000 1011 */ 1012 ViewCellsMap::iterator vit = mViewCells.find(viewCellId); 1001 1013 if (vit == mViewCells.end()) 1002 1014 cout << "error: view cell " << viewCellId << " not found" << endl; 1003 1015 1004 VspViewCell *viewCell = dynamic_cast<VspViewCell *>( *vit);1016 VspViewCell *viewCell = dynamic_cast<VspViewCell *>((*vit).second); 1005 1017 1006 1018 if (viewCell->GetId() == viewCellId) 1007 1019 { 1008 1020 leaf->SetViewCell(viewCell); 1009 viewCell->mLea f = leaf;1021 viewCell->mLeaves.push_back(leaf); 1010 1022 } 1011 1023 else -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
r1287 r1551 75 75 76 76 77 ///////////////////////// 78 77 79 VspBspTree *mVspBspTree; 78 80 HierarchyManager *mHierarchyManager; 79 //vHierarchy *mBvHierarchy; 80 81 81 82 BspTree *mBspTree; 82 83 ViewCellsTree *mViewCellsTree; … … 87 88 KdNode *mCurrentOspNode; 88 89 VspNode *mCurrentVspNode; 89 //KdNode *mCurrentKdNode; 90 90 91 91 ViewCell *mCurrentViewCell; 92 92 … … 95 95 ViewCell *mViewCellRoot; 96 96 97 ViewCellContainer mViewCells; 97 typedef map<int, ViewCell *> ViewCellsMap; 98 ViewCellsMap mViewCells; 99 98 100 ViewCellsManager *mViewCellsManager; 99 101 ObjectContainer *mObjects; … … 117 119 int mObjectSpaceHierarchyType; 118 120 121 //////////////////////////////// 122 123 119 124 // Handlers for X3D 125 ViewCell *GetOrCreateViewCell(const int id, const bool isLeaf); 126 120 127 void StartBspLeaf(AttributeList& attributes); 121 128 void StartBspInterior(AttributeList& attributes); … … 126 133 void EndVspInterior(); 127 134 128 void StartViewCellPvs(ViewCell *viewCell, AttributeList& attributes); 135 void StartViewCellPvs(ObjectPvs &pvs, const char *ptr); 136 129 137 void EndViewCells(); 130 138 void EndBoundingBoxes(); … … 137 145 138 146 void StartBoundingBox(AttributeList& attributes); 139 void StartViewCellLeaf(AttributeList& attributes); 140 void StartViewCellInterior(AttributeList& attributes); 147 void StartViewCell(AttributeList& attributes, const bool isLeaf); 141 148 void EndViewCellInterior(); 142 149 -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
r1528 r1551 128 128 const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir()); 129 129 130 // cout << "here45 origin " << a << " termination: " << b << endl;131 130 #if _DEBUG 132 131 bool isnan = false; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1545 r1551 875 875 } 876 876 877 viewCell->mLeaf = leaf;877 viewCell->mLeaves.push_back(leaf); 878 878 879 879 if (mUseAreaForPvs) … … 973 973 974 974 975 ////////////////// 975 976 //-- terminate traversal and create new view cell 976 977 if (newNode->IsLeaf()) … … 993 994 mBspStats.sampleContributions +=(int) sampCon; 994 995 996 viewCell->mLeaves.push_back(leaf); 997 998 /////////// 995 999 //-- store additional info 996 1000 if (mStoreRays) … … 1003 1007 } 1004 1008 } 1005 1006 1007 viewCell->mLeaf = leaf; 1008 1009 1009 1010 if (mUseAreaForPvs) 1010 1011 viewCell->SetArea(tData.mProbability); … … 2991 2992 BspNodeGeometry &vcGeom) const 2992 2993 { 2994 // if false, cannot construct geometry for interior leaf 2995 if (!mViewCellsTree) 2996 return; 2997 2993 2998 ViewCellContainer leaves; 2994 2995 2999 mViewCellsTree->CollectLeaves(vc, leaves); 2996 3000 … … 2999 3003 for (it = leaves.begin(); it != it_end; ++ it) 3000 3004 { 3001 BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf; 3002 3003 ConstructGeometry(l, vcGeom); 3005 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*it); 3006 vector<BspLeaf *>::const_iterator bit, bit_end = bspVc->mLeaves.end(); 3007 3008 for (bit = bspVc->mLeaves.begin(); bit != bit_end; ++ bit) 3009 { 3010 BspLeaf *l = *bit; 3011 ConstructGeometry(l, vcGeom); 3012 } 3004 3013 } 3005 3014 } … … 3806 3815 if (ray->mViewCells.size() < 2) 3807 3816 continue; 3808 //TODO viewcellhierarchy 3817 3809 3818 iit = ray->mViewCells.begin(); 3810 3819 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++)); 3811 BspLeaf *leaf = bspVc->mLea f;3820 BspLeaf *leaf = bspVc->mLeaves[0]; 3812 3821 3813 3822 // traverse intersections … … 3818 3827 BspLeaf *prevLeaf = leaf; 3819 3828 bspVc = dynamic_cast<BspViewCell *>(*iit); 3820 leaf = bspVc->mLea f;3829 leaf = bspVc->mLeaves[0]; // exactly one leaf 3821 3830 3822 3831 // view space not valid or same view cell … … 3984 3993 { 3985 3994 ExportNode(mRoot, stream); 3986 3987 3995 return true; 3988 3996 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1545 r1551 614 614 615 615 // set view cell values 616 viewCell->mLea f = leaf;616 viewCell->mLeaves.push_back(leaf); 617 617 618 618 viewCell->SetVolume(tData.mProbability);
Note: See TracChangeset
for help on using the changeset viewer.