Changeset 1201 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 08/11/06 17:39:54 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1197 r1201 1135 1135 1136 1136 1137 1138 void KdTree::ExportBinLeaf(ofstream &stream, KdLeaf *leaf) 1137 void KdTree::ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf) 1139 1138 { 1140 1139 ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); … … 1157 1156 1158 1157 1159 KdLeaf *KdTree::ImportBinLeaf( ifstream&stream,1158 KdLeaf *KdTree::ImportBinLeaf(IN_STREAM &stream, 1160 1159 KdInterior *parent, 1161 1160 const ObjectContainer &objects) … … 1194 1193 1195 1194 1196 void KdTree::ExportBinInterior( ofstream&stream, KdInterior *interior)1195 void KdTree::ExportBinInterior(OUT_STREAM &stream, KdInterior *interior) 1197 1196 { 1198 1197 int interiorid = TYPE_INTERIOR; … … 1207 1206 1208 1207 1209 KdInterior *KdTree::ImportBinInterior( ifstream&stream, KdInterior *parent)1208 KdInterior *KdTree::ImportBinInterior(IN_STREAM &stream, KdInterior *parent) 1210 1209 { 1211 1210 KdInterior *interior = new KdInterior(parent); … … 1226 1225 bool KdTree::ExportBinTree(const string &filename) 1227 1226 { 1228 ofstream stream(filename.c_str(), ios::binary);1227 OUT_STREAM stream(filename.c_str(), OUT_BIN_MODE); 1229 1228 1230 if (!stream.is_open()) 1231 return false; 1229 //if (!stream.is_open()) return false; 1232 1230 1233 1231 // export binary version of mesh … … 1261 1259 1262 1260 1263 KdNode *KdTree::LoadNextNode( ifstream&stream,1261 KdNode *KdTree::LoadNextNode(IN_STREAM &stream, 1264 1262 KdInterior *parent, 1265 1263 const ObjectContainer &objects) … … 1288 1286 // export binary version of mesh 1289 1287 queue<TraversalData> tStack; 1290 ifstream stream(filename.c_str(), ios::binary); 1291 1292 if (!stream.is_open()) 1293 return false; 1288 IN_STREAM stream(filename.c_str(), IN_BIN_MODE); 1289 1290 //if (!stream.is_open()) return false; 1294 1291 1295 1292 std::stable_sort(objects.begin(), objects.end(), ilt); -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1197 r1201 557 557 void ProcessMultipleRefs(KdLeaf *leaf) const; 558 558 559 void ExportBinLeaf( ofstream&stream, KdLeaf *leaf);560 void ExportBinInterior( ofstream&stream, KdInterior *interior);561 KdLeaf *ImportBinLeaf( ifstream&stream, KdInterior *parent, const ObjectContainer &objects);562 KdInterior *ImportBinInterior( ifstream&stream, KdInterior *parent);563 KdNode *LoadNextNode( ifstream&stream, KdInterior *parent, const ObjectContainer &objects);559 void ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf); 560 void ExportBinInterior(OUT_STREAM &stream, KdInterior *interior); 561 KdLeaf *ImportBinLeaf(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 562 KdInterior *ImportBinInterior(IN_STREAM &stream, KdInterior *parent); 563 KdNode *LoadNextNode(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 564 564 565 565 int mTermMaxNodes; -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1199 r1201 323 323 mSceneGraph->CollectObjects(&root->mObjects); 324 324 325 long startTime = GetTime(); 326 327 cout << "building kd tree ... " << endl; 325 328 mKdTree->Construct(); 329 cout << "construction finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs " << endl; 326 330 return true; 327 331 } -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
r1166 r1201 24 24 Vector3 normal; 25 25 26 const int i = RandomValue(0, (int)mPreprocessor.mObjects.size() - 1);26 const int i = RandomValue(0, float((int)mPreprocessor.mObjects.size() - 1)); 27 27 28 28 Intersectable *object = mPreprocessor.mObjects[i]; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1199 r1201 2182 2182 2183 2183 2184 #if ZIPPED_VIEWCELLS 2185 bool ViewCellsTree::Export(ogzstream &stream, const bool exportPvs) 2186 #else 2187 bool ViewCellsTree::Export(ofstream &stream, const bool exportPvs) 2188 #endif 2184 bool ViewCellsTree::Export(OUT_STREAM &stream, const bool exportPvs) 2189 2185 { 2190 2186 // export recursivly all view cells from the root … … 2223 2219 } 2224 2220 2225 #if ZIPPED_VIEWCELLS 2226 void ViewCellsTree::ExportPvs(ViewCell *viewCell, ogzstream &stream) 2227 #else 2228 void ViewCellsTree::ExportPvs(ViewCell *viewCell, ofstream &stream) 2229 #endif 2221 2222 void ViewCellsTree::ExportPvs(ViewCell *viewCell, OUT_STREAM &stream) 2230 2223 { 2231 2224 ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); … … 2237 2230 } 2238 2231 2239 #if ZIPPED_VIEWCELLS 2240 void ViewCellsTree::ExportViewCell(ViewCell *viewCell, ogzstream &stream, const bool exportPvs) 2241 #else 2242 void ViewCellsTree::ExportViewCell(ViewCell *viewCell, ofstream &stream, const bool exportPvs) 2243 #endif 2232 2233 void ViewCellsTree::ExportViewCell(ViewCell *viewCell, 2234 OUT_STREAM &stream, 2235 const bool exportPvs) 2244 2236 { 2245 2237 if (viewCell->IsLeaf()) … … 2258 2250 2259 2251 stream << "\" />" << endl; 2260 //stream << " </Leaf>" << endl;2261 2252 } 2262 2253 else -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1168 r1201 487 487 /** Exports view cells to file. 488 488 */ 489 #if ZIPPED_VIEWCELLS 490 bool Export(ogzstream &stream, const bool exportPvs = false); 491 #else 492 bool Export(ofstream &stream, const bool exportPvs = false); 493 #endif 489 bool Export(OUT_STREAM &stream, const bool exportPvs = false); 494 490 495 491 /** Export statistics of this view cell tree. … … 603 599 NOTE: should be in exporter!! 604 600 */ 605 #if ZIPPED_VIEWCELLS 606 void ExportViewCell(ViewCell *viewCell, ogzstream &stream, const bool exportPvs); 607 #else 608 void ExportViewCell(ViewCell *viewCell, ofstream &stream, const bool exportPvs); 609 #endif 601 void ExportViewCell(ViewCell *viewCell, OUT_STREAM &stream, const bool exportPvs); 610 602 611 603 /** Exports pvs of a view cell. 612 604 */ 613 #if ZIPPED_VIEWCELLS 614 void ExportPvs(ViewCell *viewCell, ogzstream &stream); 615 #else 616 void ExportPvs(ViewCell *viewCell, ofstream &stream); 617 #endif 605 void ExportPvs(ViewCell *viewCell, OUT_STREAM &stream); 618 606 619 607 int GetEntriesInPvsForCompressedStorage(ViewCell *vc) const; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1199 r1201 716 716 cout << "exporting view cells to xml ... "; 717 717 718 #if ZIPPED_VIEWCELLS 719 ogzstream stream(filename.c_str()); 720 #else 721 std::ofstream stream(filename.c_str()); 722 #endif 718 OUT_STREAM stream(filename.c_str()); 723 719 724 720 // for output we need unique ids for each view cell … … 4897 4893 Debug << mOspTree->GetStatistics() << endl; 4898 4894 4895 OUT_STREAM stream("osptree.xml.zip"); 4896 mOspTree->Export(stream); 4897 4899 4898 // print view cell statistics 4900 4899 ResetViewCells(); … … 5456 5455 cout << "exporting view cells to xml ... "; 5457 5456 5458 #if ZIPPED_VIEWCELLS 5459 ogzstream stream(filename.c_str()); 5460 #else 5461 std::ofstream stream(filename.c_str()); 5462 #endif 5457 OUT_STREAM stream(filename.c_str()); 5463 5458 5464 5459 // for output we need unique ids for each view cell … … 5468 5463 stream << "<VisibilitySolution>" << endl; 5469 5464 5470 //-- the view space bounding box 5465 //-- export view space bounding box 5466 5471 5467 stream << "<ViewSpaceBox" 5472 5468 << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" … … 5475 5471 5476 5472 //-- export bounding boxes 5473 5477 5474 stream << "<BoundingBoxes>" << endl; 5478 5475 … … 5494 5491 5495 5492 //-- export the view cells and the pvs 5496 stream << "<HierarchyType name=\"vspTree\" />" << endl; 5497 5493 5494 stream << "<Hierarchy name=\"vspTree\" />" << endl; 5498 5495 const int numViewCells = mCurrentViewCellsStats.viewCells; 5499 5496 5500 5497 stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 5501 5502 5498 mViewCellsTree->Export(stream, exportPvs); 5503 5504 5499 stream << "</ViewCells>" << endl; 5505 5500 5506 5501 5507 //-- export the spatial hierarchy 5502 //-- export the view space hierarchy 5503 5504 // the type of the view space partition 5505 stream << "<ViewSpacePartition>" << endl; 5506 mVspTree->Export(stream); 5507 stream << endl << "</ViewSpacePartitioin>" << endl; 5508 5509 5510 //-- export the object space partition 5508 5511 5509 5512 // the type of the view cells hierarchy 5510 stream << "<Hierarchy>" << endl; 5511 mVspTree->Export(stream); 5512 stream << endl << "</Hierarchy>" << endl; 5513 stream << "<ObjectSpacePartition>" << endl; 5514 mOspTree->Export(stream); 5515 stream << endl << "</ObjectSpacePartition>" << endl; 5516 5513 5517 5514 5518 stream << "</VisibilitySolution>" << endl; 5515 5516 5517 5519 stream.close(); 5520 5518 5521 cout << "finished" << endl; 5519 5522 … … 5728 5731 } 5729 5732 5733 5734 ViewCellsManager *VspOspViewCellsManager::LoadViewCells(const string &filename, 5735 ObjectContainer *objects, 5736 const bool finalizeViewCells, 5737 BoundingBoxConverter *bconverter) 5738 5739 { 5740 ViewCellsManager *vm = 5741 ViewCellsManager::LoadViewCells(filename, objects, finalizeViewCells, bconverter); 5742 5743 mOspTree->InsertObjects(mOspTree->GetRoot(), *objects); 5744 5745 return vm; 5746 } 5747 5748 5730 5749 #if TEST_EVALUATION 5731 5750 void VspOspViewCellsManager::EvalViewCellPartition() -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1184 r1201 1011 1011 const bool storeViewCells); 1012 1012 1013 ViewCellsManager *LoadViewCells(const string &filename, 1014 ObjectContainer *objects, 1015 const bool finalizeViewCells, 1016 BoundingBoxConverter *bconverter); 1017 1018 1013 1019 protected: 1014 1020 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1197 r1201 31 31 #include "GzFileInputSource.h" 32 32 #include "VspOspTree.h" 33 #include "KdTree.h" 34 33 35 34 36 … … 81 83 , mBspTree(NULL) 82 84 , mViewCellsTree(NULL) 83 , m ParseViewCells(true)85 , mCurrentTask(PARSE_OPTIONS) 84 86 , mCurrentViewCell(NULL) 85 87 , mCurrentBspNode(NULL) 88 , mCurrentVspNode(NULL) 89 , mCurrentKdNode(NULL) 86 90 , mObjects(objects) 87 91 , mBoundingBoxConverter(bconverter) … … 113 117 114 118 // inside the view cell description 115 if (m ParseViewCells)119 if (mCurrentTask == PARSE_VIEWCELLS) 116 120 { 117 121 if (element == "Interior") … … 136 140 137 141 142 void ViewCellsParseHandlers::EndVspInterior() 143 { 144 // go one up in the tree 145 if (mCurrentVspNode->GetParent()) 146 { Debug << "]"; 147 mCurrentVspNode = mCurrentVspNode->GetParent(); 148 } 149 } 150 138 151 void ViewCellsParseHandlers::EndViewCellInterior() 139 152 { … … 156 169 // sort view cells to help associating view cells according to their id 157 170 stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 158 mParseViewCells = false; 171 172 // not parsing view cells anymore 173 mCurrentTask = PARSE_OPTIONS; 159 174 } 160 175 … … 195 210 196 211 197 void ViewCellsParseHandlers:: startBspElement(string element,212 void ViewCellsParseHandlers::StartBspElement(string element, 198 213 AttributeList& attributes) 199 214 { … … 212 227 213 228 229 void ViewCellsParseHandlers::StartVspElement(string element, 230 AttributeList& attributes) 231 { 232 if (element == "Interior") 233 { 234 Debug << "["; 235 StartVspInterior(attributes); 236 } 237 238 if (element == "Leaf") 239 { 240 Debug << "l"; 241 StartVspLeaf(attributes); 242 } 243 } 244 245 246 void ViewCellsParseHandlers::StartOspElement(string element, 247 AttributeList& attributes) 248 { 249 if (element == "Interior") 250 { 251 Debug << "["; 252 StartOspInterior(attributes); 253 } 254 255 if (element == "Leaf") 256 { 257 Debug << "l"; 258 StartOspLeaf(attributes); 259 } 260 } 261 262 void ViewCellsParseHandlers::StartViewSpacePartitionElement(const std::string &element, 263 AttributeList& attributes) 264 { 265 if (!mViewCellsManager) 266 return; 267 268 //-- use cell type according to the chosen view cell manager 269 switch (mViewCellsManager->GetType()) 270 { 271 case ViewCellsManager::BSP: 272 case ViewCellsManager::VSP_BSP: 273 StartBspElement(element, attributes); 274 break; 275 case ViewCellsManager::VSP_OSP: 276 StartVspElement(element, attributes); 277 break; 278 default: 279 Debug << "not implemented" << endl; 280 break; 281 } 282 } 283 284 285 void ViewCellsParseHandlers::StartObjectSpacePartitionElement(const std::string &element, 286 AttributeList& attributes) 287 { 288 if (!mViewCellsManager) 289 return; 290 291 //-- use cell type according to the chosen view cell manager 292 switch (mViewCellsManager->GetType()) 293 { 294 case ViewCellsManager::VSP_OSP: 295 StartOspElement(element, attributes); 296 break; 297 default: 298 Debug << "not implemented" << endl; 299 break; 300 } 301 } 302 303 304 void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element, 305 AttributeList& attributes) 306 { 307 // interiors + leaves interpreted view cells else 308 if (element == "Interior") 309 { 310 Debug << "["; 311 StartViewCellInterior(attributes); 312 } 313 314 if (element == "Leaf") 315 { 316 Debug << "l"; 317 StartViewCellLeaf(attributes); 318 } 319 } 320 321 214 322 void ViewCellsParseHandlers::startElement(const XMLCh* const name, 215 323 AttributeList& attributes) … … 218 326 string element(lname.LocalForm()); 219 327 220 221 328 if (element == "ViewCells") 222 329 { 223 Debug << "parsing view cells" << endl; 224 mParseViewCells = true; 330 cout << "parsing view cells" << endl; 331 mCurrentTask = PARSE_VIEWCELLS; 332 } 333 334 // decides about the view cells manager type 335 if (element == "Hierarchy") 336 { 337 cout << "parsing view cells manager type" << endl; 338 StartHierarchy(attributes); 225 339 } 226 340 227 341 // decides about the view cell hierarchy 228 if (element == "HierarchyType") 229 //if (element == "Hierarchy") 230 { 231 //Debug << "parsing spatial hierarchy" << endl; 232 //mParseViewCells = false; 233 StartHierarchy(attributes); 342 if (element == "ViewSpacePartition") 343 { 344 //StartViewSpacePartition(attributes); 345 cout << "parsing view space partition" << endl; 346 mCurrentTask = PARSE_VSP; 347 } 348 349 // decides about the view cell hierarchy 350 if (element == "ObjectSpacePartition") 351 { 352 //StartObjectSpacePartition(attributes); 353 cout << "parsing object space partition" << endl; 354 mCurrentTask = PARSE_OSP; 234 355 } 235 356 … … 248 369 } 249 370 250 251 if (!mParseViewCells) 252 { 253 //-- use different methods for the given view cell hierarchy types 254 if (mViewCellsManager) 255 { 256 switch (mViewCellsManager->GetType()) 257 { 258 case ViewCellsManager::BSP: 259 case ViewCellsManager::VSP_BSP: 260 startBspElement(element, attributes); 261 break; 262 263 default: 264 Debug << "not implemented" << endl; 265 break; 266 } 267 } 268 } 269 else 270 { 271 // interiors + leaves interpreted view cells else 272 if (element == "Interior") 273 { 274 Debug << "["; 275 StartViewCellInterior(attributes); 276 } 277 278 if (element == "Leaf") 279 { 280 Debug << "l"; 281 StartViewCellLeaf(attributes); 282 } 283 } 284 371 // parse view space partition 372 switch (mCurrentTask) 373 { 374 case PARSE_VSP: 375 StartViewSpacePartitionElement(element, attributes); 376 break; 377 case PARSE_OSP: 378 StartObjectSpacePartitionElement(element, attributes); 379 break; 380 case PARSE_VIEWCELLS: 381 StartViewCellHierarchyElement(element, attributes); 382 break; 383 default: 384 break; 385 } 386 285 387 ++ mElementCount; 286 388 mAttrCount += attributes.getLength(); … … 673 775 674 776 777 void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes) 778 { 779 VspLeaf * leaf = 780 new VspLeaf(dynamic_cast<VspInterior *>(mCurrentVspNode), NULL); 781 782 if (mCurrentVspNode) // replace front or (if not NULL) back child 783 { 784 dynamic_cast<VspInterior *>(mCurrentVspNode)->ReplaceChildLink(NULL, leaf); 785 } 786 else 787 { 788 mVspTree->mRoot = leaf; 789 } 790 791 //-- find associated view cell 792 int viewCellId; 793 794 int len = attributes.getLength(); 795 796 for (int i = 0; i < len; ++ i) 797 { 798 string attrName(StrX(attributes.getName(i)).LocalForm()); 799 StrX attrValue(attributes.getValue(i)); 800 801 const char *ptr = attrValue.LocalForm(); 802 char *endptr = NULL; 803 804 if (attrName == "viewCellId") 805 { 806 viewCellId = strtol(ptr, &endptr, 10); 807 } 808 } 809 810 if (viewCellId >= 0) // valid view cell 811 { 812 // TODO: get view cell with specified id 813 ViewCellInterior dummyVc; 814 dummyVc.SetId(viewCellId); 815 816 ViewCellContainer::iterator vit = 817 lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 818 819 VspViewCell *viewCell = dynamic_cast<VspViewCell *>(*vit); 820 821 if (viewCell->GetId() == viewCellId) 822 { 823 leaf->SetViewCell(viewCell); 824 viewCell->mLeaf = leaf; 825 } 826 else 827 { 828 Debug << "error: view cell does not exist" << endl; 829 } 830 } 831 else 832 { 833 // add to invalid view space 834 leaf->SetViewCell(mVspTree->GetOrCreateOutOfBoundsCell()); 835 leaf->SetTreeValid(false); 836 mVspTree->PropagateUpValidity(leaf); 837 } 838 } 839 840 841 void ViewCellsParseHandlers::StartVspInterior(AttributeList& attributes) 842 { 843 AxisAlignedPlane plane; 844 int len = attributes.getLength(); 845 846 for (int i = 0; i < len; ++ i) 847 { 848 string attrName(StrX(attributes.getName(i)).LocalForm()); 849 StrX attrValue(attributes.getValue(i)); 850 const char *ptr = attrValue.LocalForm(); 851 852 if (attrName == "plane") 853 { 854 sscanf(ptr, "%d %f", 855 &plane.mAxis, &plane.mPosition); 856 } 857 } 858 859 VspInterior* interior = new VspInterior(plane); 860 861 if (mCurrentVspNode) // replace NULL child of parent with current node 862 { 863 VspInterior *current = dynamic_cast<VspInterior *>(mCurrentVspNode); 864 865 current->ReplaceChildLink(NULL, interior); 866 interior->SetParent(current); 867 } 868 else 869 { 870 mVspTree->mRoot = interior; 871 } 872 873 mCurrentVspNode = interior; 874 } 875 876 877 void ViewCellsParseHandlers::StartOspInterior(AttributeList& attributes) 878 { 879 AxisAlignedPlane plane; 880 int len = attributes.getLength(); 881 882 for (int i = 0; i < len; ++ i) 883 { 884 string attrName(StrX(attributes.getName(i)).LocalForm()); 885 StrX attrValue(attributes.getValue(i)); 886 const char *ptr = attrValue.LocalForm(); 887 888 if (attrName == "plane") 889 { 890 sscanf(ptr, "%d %f", 891 &plane.mAxis, &plane.mPosition); 892 } 893 } 894 895 KdInterior* interior = new KdInterior(NULL); 896 897 interior->mAxis = plane.mAxis; 898 interior->mPosition = plane.mPosition; 899 900 if (mCurrentKdNode) // replace NULL child of parent with current node 901 { 902 KdInterior *parent = dynamic_cast<KdInterior *>(mCurrentKdNode); 903 parent->ReplaceChildLink(NULL, interior); 904 interior->mParent = parent; 905 } 906 else 907 { 908 mOspTree->mRoot = interior; 909 } 910 911 mCurrentKdNode = interior; 912 } 913 914 915 void ViewCellsParseHandlers::StartOspLeaf(AttributeList& attributes) 916 { 917 KdLeaf * leaf = 918 new KdLeaf(dynamic_cast<KdInterior *>(mCurrentKdNode), NULL); 919 920 if (mCurrentKdNode) // replace front or (if not NULL) back child 921 { 922 dynamic_cast<KdInterior *>(mCurrentKdNode)->ReplaceChildLink(NULL, leaf); 923 } 924 else 925 { 926 mOspTree->mRoot = leaf; 927 } 928 } 929 930 931 932 675 933 // --------------------------------------------------------------------------- 676 934 // StdInParseHandlers: Overrides of the SAX ErrorHandler interface 677 935 // --------------------------------------------------------------------------- 936 937 678 938 void 679 939 ViewCellsParseHandlers::error(const SAXParseException& e) … … 755 1015 { 756 1016 const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); 757 #if ZIPPED_VIEWCELLS1017 #if USE_GZLIB 758 1018 XMLCh *myFilePath = XMLString::transcode(filename.c_str()); 759 1019 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
r1022 r1201 8 8 #include "Mesh.h" 9 9 #include "BoundingBoxConverter.h" 10 //#include "gzstream.h" 10 11 11 12 12 namespace GtpVisibilityPreprocessor { … … 23 23 class VspTree; 24 24 class OspTree; 25 25 class VspNode; 26 26 27 27 … … 80 80 81 81 BspNode *mCurrentBspNode; 82 VspNode *mCurrentVspNode; 82 83 ViewCell *mCurrentViewCell; 84 KdNode *mCurrentKdNode; 83 85 84 86 ViewCellContainer mViewCells; … … 86 88 ObjectContainer *mObjects; 87 89 BoundingBoxConverter *mBoundingBoxConverter; 88 89 90 AxisAlignedBox3 mViewSpaceBox; 90 91 91 IndexedBoundingBoxContainer mIBoundingBoxes; 92 92 93 bool mParseViewCells; 93 /// current task for the parser 94 int mCurrentTask; 95 96 enum {PARSE_OPTIONS, PARSE_VIEWCELLS, PARSE_VSP, PARSE_OSP}; 94 97 95 98 // Handlers for X3D … … 97 100 void StartBspInterior(AttributeList& attributes); 98 101 void EndBspInterior(); 99 102 103 void StartVspLeaf(AttributeList& attributes); 104 void StartVspInterior(AttributeList& attributes); 105 void EndVspInterior(); 106 100 107 void StartViewCell(ViewCell *viewCell, AttributeList& attributes); 101 108 void EndViewCells(); … … 104 111 void StartHierarchy(AttributeList& attributes); 105 112 106 void startBspElement(string element, AttributeList& attributes); 113 void StartBspElement(string element, AttributeList& attributes); 114 void StartVspElement(string element, AttributeList& attributes); 115 107 116 void StartViewSpaceBox(AttributeList& attributes); 108 117 … … 111 120 void StartViewCellInterior(AttributeList& attributes); 112 121 void EndViewCellInterior(); 122 123 void StartViewSpacePartitionElement(const std::string &element, AttributeList& attributes); 124 void StartObjectSpacePartitionElement(const std::string &element, AttributeList& attributes); 125 void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes); 126 127 void StartOspElement(string element, AttributeList& attributes); 128 129 void StartOspLeaf(AttributeList& attributes); 130 void StartOspInterior(AttributeList& attributes); 113 131 114 132 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1193 r1201 4002 4002 } 4003 4003 4004 #if ZIPPED_VIEWCELLS 4005 bool VspBspTree::Export(ogzstream &stream) 4006 #else 4007 bool VspBspTree::Export(ofstream &stream) 4008 #endif 4004 4005 bool VspBspTree::Export(OUT_STREAM &stream) 4009 4006 { 4010 4007 ExportNode(mRoot, stream); … … 4013 4010 } 4014 4011 4015 #if ZIPPED_VIEWCELLS 4016 void VspBspTree::ExportNode(BspNode *node, ogzstream &stream) 4017 #else 4018 void VspBspTree::ExportNode(BspNode *node, ofstream &stream) 4019 #endif 4012 4013 void VspBspTree::ExportNode(BspNode *node, OUT_STREAM &stream) 4020 4014 { 4021 4015 if (node->IsLeaf()) -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
r1145 r1201 321 321 /** Writes tree to output stream 322 322 */ 323 #if ZIPPED_VIEWCELLS 324 bool Export(ogzstream &stream); 325 #else 326 bool Export(ofstream &stream); 327 #endif 323 bool Export(OUT_STREAM &stream); 328 324 329 325 /** Casts beam, i.e. a 5D frustum of rays, into tree. … … 697 693 @note: should be implemented as visitor. 698 694 */ 699 #if ZIPPED_VIEWCELLS 700 void ExportNode(BspNode *node, ogzstream &stream); 701 #else 702 void ExportNode(BspNode *node, ofstream &stream); 703 #endif 695 void ExportNode(BspNode *node, OUT_STREAM &stream); 704 696 705 697 /** Returns estimated memory usage of tree. -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1196 r1201 2702 2702 } 2703 2703 2704 #if ZIPPED_VIEWCELLS 2705 bool VspTree::Export(ogzstream &stream) 2706 #else 2707 bool VspTree::Export(ofstream &stream) 2708 #endif 2704 2705 bool VspTree::Export(OUT_STREAM &stream) 2709 2706 { 2710 2707 ExportNode(mRoot, stream); … … 2714 2711 2715 2712 2716 #if ZIPPED_VIEWCELLS 2717 void VspTree::ExportNode(VspNode *node, ogzstream &stream) 2718 #else 2719 void VspTree::ExportNode(VspNode *node, ofstream &stream) 2720 #endif 2713 void VspTree::ExportNode(VspNode *node, OUT_STREAM &stream) 2721 2714 { 2722 2715 if (node->IsLeaf()) … … 5416 5409 5417 5410 5411 bool OspTree::Export(OUT_STREAM &stream) 5412 { 5413 ExportNode(mRoot, stream); 5414 5415 return true; 5416 } 5417 5418 5419 void OspTree::ExportNode(KdNode *node, OUT_STREAM &stream) 5420 { 5421 if (node->IsLeaf()) 5422 { 5423 KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 5424 5425 stream << "<Leaf "; 5426 stream << "objects=\""; 5427 5428 //-- export objects in kd leaves 5429 //if (mExportObjects) ExportObjects(leaf, stream); 5430 5431 stream << "\" />" << endl; 5432 //stream << " </Leaf>" << endl; 5433 } 5434 else 5435 { 5436 KdInterior *interior = dynamic_cast<KdInterior *>(node); 5437 5438 stream << "<Interior plane=\"" << interior->mPosition << " " 5439 << interior->mAxis << "\">" << endl; 5440 5441 ExportNode(interior->mBack, stream); 5442 ExportNode(interior->mFront, stream); 5443 5444 stream << "</Interior>" << endl; 5445 } 5446 } 5447 5448 5449 struct KdObjectsTraversalData 5450 { 5451 KdNode *node; 5452 ObjectContainer *objects; 5453 }; 5454 5455 5456 void OspTree::InsertObjects(KdNode *node, const ObjectContainer &objects) 5457 { 5458 stack<KdObjectsTraversalData> tStack; 5459 5460 while (!tStack.empty()) 5461 { 5462 KdObjectsTraversalData tData = tStack.top(); 5463 tStack.pop(); 5464 5465 KdNode *node = tData.node; 5466 5467 if (node->IsLeaf()) 5468 { 5469 KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 5470 5471 ObjectContainer::const_iterator oit, oit_end = tData.objects->end(); 5472 5473 for (oit = tData.objects->begin(); oit != oit_end; ++ oit) 5474 { 5475 leaf->mObjects.push_back(*oit); 5476 } 5477 } 5478 else // interior 5479 { 5480 KdObjectsTraversalData frontData, backData; 5481 KdInterior *interior = dynamic_cast<KdInterior *>(node); 5482 5483 frontData.objects = new ObjectContainer(); 5484 backData.objects = new ObjectContainer(); 5485 5486 ObjectContainer::const_iterator oit, oit_end = tData.objects->end(); 5487 5488 for (oit = tData.objects->begin(); oit != oit_end; ++ oit) 5489 { 5490 Intersectable *object = *oit; 5491 5492 // determine the side of this ray with respect to the plane 5493 const AxisAlignedBox3 box = object->GetBox(); 5494 5495 if (box.Max(interior->mAxis) >= interior->mPosition) 5496 { 5497 frontData.objects->push_back(object); 5498 } 5499 5500 if (box.Min(interior->mAxis) < interior->mPosition) 5501 { 5502 backData.objects->push_back(object); 5503 } 5504 } 5505 5506 tStack.push(backData); 5507 tStack.push(frontData); 5508 } 5509 5510 DEL_PTR(tData.objects); 5511 } 5512 } 5513 5418 5514 5419 5515 /*******************************************************************/ -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1189 r1201 733 733 /** Writes tree to output stream 734 734 */ 735 #if ZIPPED_VIEWCELLS 736 bool Export(ogzstream &stream); 737 #else 738 bool Export(ofstream &stream); 739 #endif 735 bool Export(OUT_STREAM &stream); 740 736 741 737 /** Casts beam, i.e. a 5D frustum of rays, into tree. … … 1033 1029 @note: should be implemented as visitor. 1034 1030 */ 1035 #if ZIPPED_VIEWCELLS 1036 void ExportNode(VspNode *node, ogzstream &stream); 1037 #else 1038 void ExportNode(VspNode *node, ofstream &stream); 1039 #endif 1031 void ExportNode(VspNode *node, OUT_STREAM &stream); 1040 1032 1041 1033 /** Returns estimated memory usage of tree. … … 1335 1327 void CollectLeaves(vector<KdLeaf *> &leaves) const; 1336 1328 1337 1338 1329 /** Returns bounding box of the whole tree (= bbox of root node) 1339 1330 */ … … 1390 1381 /** Writes tree to output stream 1391 1382 */ 1392 #if ZIPPED_VIEWCELLS 1393 bool Export(ogzstream &stream); 1394 #else 1395 bool Export(ofstream &stream); 1396 #endif 1383 bool Export(OUT_STREAM &stream); 1397 1384 1398 1385 /** Returns or creates a new intersectable for use in a kd based pvs. … … 1423 1410 float EvalRenderCost(const VssRayContainer &myrays); 1424 1411 float EvalLeafCost(const OspTraversalData &tData); 1412 1413 /** Adds this objects to the kd leaf objects. 1414 @warning: Can corrupt the tree 1415 */ 1416 void InsertObjects(KdNode *node, const ObjectContainer &objects); 1425 1417 1426 1418 protected: … … 1621 1613 @note: should be implemented as visitor. 1622 1614 */ 1623 #if ZIPPED_VIEWCELLS 1624 void ExportNode(KdNode *node, ogzstream &stream); 1625 #else 1626 void ExportNode(KdNode *node, ofstream &stream); 1627 #endif 1615 void ExportNode(KdNode *node, OUT_STREAM &stream); 1628 1616 1629 1617 /** Returns estimated memory usage of tree. -
GTP/trunk/Lib/Vis/Preprocessing/src/common.h
r1161 r1201 75 75 #define strncasecmp strnicmp 76 76 #endif // __WATCOMC__ 77 78 // matt 79 80 #define USE_GZLIB 1 81 82 #if USE_GZLIB 83 84 #define OUT_BIN_MODE ios::out 85 #define IN_BIN_MODE ios::in 86 87 #else 77 88 78 89 #ifdef sgi … … 89 100 #endif // sgi 90 101 102 #endif 91 103 92 104 // #ifndef HAS_BOOL … … 483 495 } 484 496 485 // if the view cells should be exported and inported as gzstream 486 #define ZIPPED_VIEWCELLS 1 487 488 #endif 489 490 491 492 493 494 495 496 497 498 499 497 498 #if USE_GZLIB 499 // type of out put and input streams 500 #define OUT_STREAM ogzstream 501 #define IN_STREAM igzstream 502 #else 503 #define OUT_STREAM ofstream 504 #define IN_STREAM ifstream 505 #endif 506 507 #endif 508 509 510 511 512 513 514 515 516 517 -
GTP/trunk/Lib/Vis/Preprocessing/src/gzstream.h
r372 r1201 99 99 void close(); 100 100 gzstreambuf* rdbuf() { return &buf; } 101 int is_open() { return buf.is_open(); } 101 102 }; 102 103 -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1199 r1201 164 164 preprocessor->BuildKdTree(); 165 165 preprocessor->KdTreeStatistics(cout); 166 preprocessor->mKdTree->ExportBinTree("kd.bin ");166 preprocessor->mKdTree->ExportBinTree("kd.bin.gz"); 167 167 168 168 MeshManager::GetSingleton()->ExportEntries("meshes.bin"); 169 169 170 170 KdTree *kdTree2 = new KdTree; 171 kdTree2->LoadBinTree("kd.bin", preprocessor->mObjects); 172 Exporter *exporter = Exporter::GetExporter("testkd.x3d"); 173 171 172 cout << "loading kd tree ... "; 173 long startTime = GetTime(); 174 kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects); 175 176 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 177 178 Exporter *exporter = Exporter::GetExporter("testkd.x3d"); 174 179 MeshManager::GetSingleton()->ExportEntries("meshes.bin"); 175 180
Note: See TracChangeset
for help on using the changeset viewer.