Changeset 1286 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
- Timestamp:
- 08/25/06 18:25:09 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1284 r1286 89 89 , mCurrentBspNode(NULL) 90 90 , mCurrentVspNode(NULL) 91 , mCurrentKdNode(NULL) 91 , mCurrentOspNode(NULL) 92 , mCurrentBvhNode(NULL) 92 93 , mObjects(objects) 93 94 , mBoundingBoxConverter(bconverter) … … 114 115 115 116 if (element == "BoundingBoxes") 117 { 116 118 EndBoundingBoxes(); 119 } 117 120 118 121 if (element == "ViewCells") 122 { 119 123 EndViewCells(); 120 121 // inside the view cell description 122 if (mCurrentState == PARSE_VIEWCELLS) 123 { 124 if (element == "Interior") 125 EndViewCellInterior(); 126 } 127 else 128 { 129 if (element == "Interior") 130 EndBspInterior(); 124 } 125 126 if (element == "ObjectSpaceHierarchy") 127 { 128 EndObjectSpaceHierarchy(); 131 129 } 132 130 133 131 // finished, create view cells manager 134 132 if (element == "VisibilitySolution") 133 { 135 134 CreateViewCellsManager(); 135 } 136 137 if (element == "Interior") 138 { 139 switch (mCurrentState) 140 { 141 case PARSE_VIEWCELLS: 142 EndViewCellInterior(); 143 break; 144 case PARSE_OBJECTSPACE_HIERARCHY: 145 EndObjectSpaceHierarchyInterior(); 146 break; 147 case PARSE_VIEWSPACE_HIERARCHY: 148 EndViewSpaceHierarchyInterior(); 149 break; 150 default: 151 break; 152 } 153 } 154 } 155 156 157 void ViewCellsParseHandlers::EndObjectSpaceHierarchy() 158 { 159 if (mObjectSpaceHierarchyType == OSP) 160 { 161 mHierarchyManager->mOspTree->InsertObjects( 162 mHierarchyManager->mOspTree->mRoot, *mObjects); 163 } 164 } 165 166 167 void ViewCellsParseHandlers::EndViewSpaceHierarchyInterior() 168 { 169 switch (mViewSpaceHierarchyType) 170 { 171 case BSP: 172 EndBspInterior(); 173 break; 174 case VSP: 175 EndVspInterior(); 176 break; 177 default: 178 Debug << "not implemented view space hierarchy type " << mViewSpaceHierarchyType << endl; 179 break; 180 } 181 } 182 183 184 void ViewCellsParseHandlers::EndObjectSpaceHierarchyInterior() 185 { 186 switch (mObjectSpaceHierarchyType) 187 { 188 case OSP: 189 EndOspInterior(); 190 break; 191 case BVH: 192 EndBvhInterior(); 193 break; 194 default: 195 Debug << "not implemented object space hierarchy type " << mViewSpaceHierarchyType << endl; 196 break; 197 } 136 198 } 137 199 … … 143 205 { cout << "]"; 144 206 mCurrentBspNode = mCurrentBspNode->GetParent(); 207 } 208 } 209 210 211 void ViewCellsParseHandlers::EndBvhInterior() 212 { 213 // go one up in the tree 214 if (mCurrentBvhNode->GetParent()) 215 { cout << "]"; 216 mCurrentBvhNode = mCurrentBvhNode->GetParent(); 217 } 218 } 219 220 221 void ViewCellsParseHandlers::EndOspInterior() 222 { 223 // go one up in the tree 224 if (mCurrentOspNode->mParent) 225 { cout << "]"; 226 mCurrentOspNode = mCurrentOspNode->mParent; 145 227 } 146 228 } … … 243 325 StartVspInterior(attributes); 244 326 } 245 246 327 if (element == "Leaf") 247 328 { … … 289 370 AttributeList& attributes) 290 371 { 291 //if (!mViewCellsManager)return;292 293 372 //-- use cell type according to the chosen method 294 295 373 switch (mViewSpaceHierarchyType) 296 374 { 297 298 299 300 301 302 303 304 305 375 case BSP: 376 StartBspElement(element, attributes); 377 break; 378 case VSP: 379 StartVspElement(element, attributes); 380 break; 381 default: 382 Debug << "not implemented" << endl; 383 break; 306 384 } 307 385 } … … 412 490 413 491 414 void ViewCellsParseHandlers:: ParseViewCellPvs(ViewCell *viewCell,492 void ViewCellsParseHandlers::StartViewCellPvs(ViewCell *viewCell, 415 493 AttributeList& attributes) 416 494 { … … 433 511 while (1) 434 512 { 435 int index = strtol(ptr, &endptr, 10); 436 437 if (ptr == endptr) 438 break; 513 const int index = strtol(ptr, &endptr, 10); 514 515 if (ptr == endptr) break; 439 516 440 517 objIndices.push_back(index); … … 454 531 455 532 ObjectContainer::iterator oit = 456 lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt); 533 lower_bound(mObjects->begin(), 534 mObjects->end(), 535 (Intersectable *)&dummyInst, ilt); 457 536 458 537 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) … … 551 630 void ViewCellsParseHandlers::StartObjectSpaceHierarchy(AttributeList& attributes) 552 631 { 553 int len = attributes.getLength(); 554 632 const int len = attributes.getLength(); 555 633 Vector3 bmin, bmax; 556 cout << "here3" << endl; 634 557 635 for (int i = 0; i < len; ++ i) 558 636 { … … 567 645 { 568 646 cout << "\nobject space hierarchy: Osp" << endl; 647 569 648 mHierarchyManager = 570 649 new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV); 650 651 mObjectSpaceHierarchyType = OSP; 652 653 //std::stable_sort(objects.begin(), objects.end(), ilt); 654 mHierarchyManager->mOspTree->mBoundingBox.Initialize(); 655 ObjectContainer::const_iterator oit, oit_end = mObjects->end(); 656 657 //-- compute bounding box 658 for (oit = mObjects->begin(); oit != oit_end; ++ oit) 659 { 660 Intersectable *obj = *oit; 661 // compute bounding box of view space 662 mHierarchyManager->mOspTree->mBoundingBox.Include(obj->GetBox()); 663 } 571 664 } 572 665 else if (strcmp(ptr, "bvh") == 0) 573 666 { 574 667 cout << "\nobject space hierarchy: Bvh" << endl; 668 mObjectSpaceHierarchyType = BVH; 575 669 mHierarchyManager = 576 670 new HierarchyManager(mVspTree, HierarchyManager::BV_BASED_OBJ_SUBDIV); … … 579 673 } 580 674 } 581 582 675 583 676 … … 675 768 { 676 769 // add to invalid view space 677 if (mViewSpaceHierarchyType== ViewCellsManager::VSP_BSP) 678 { 679 leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell()); 680 leaf->SetTreeValid(false); 681 mVspBspTree->PropagateUpValidity(leaf); 682 } 770 leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell()); 771 leaf->SetTreeValid(false); 772 mVspBspTree->PropagateUpValidity(leaf); 683 773 } 684 774 } … … 736 826 } 737 827 738 ParseViewCellPvs(viewCell, attributes);828 StartViewCellPvs(viewCell, attributes); 739 829 740 830 // collect leaves … … 746 836 { 747 837 ViewCellInterior* interior = new ViewCellInterior(); 748 cout << "here7"<<endl;838 749 839 if (mCurrentViewCell) // replace NULL child of parent with current node 750 840 { … … 760 850 mCurrentViewCell = interior; 761 851 762 ParseViewCellPvs(interior, attributes);852 StartViewCellPvs(interior, attributes); 763 853 } 764 854 … … 767 857 { 768 858 ViewCellContainer::iterator it, it_end = mViewCells.end(); 769 Debug<< endl;859 cout << "\n====================" << endl << endl; 770 860 for (it = mViewCells.begin(); it != it_end; ++ it) 771 861 { 772 Debug<< (*it)->GetId() << " ";773 } 774 Debug<< endl;862 cout << (*it)->GetId() << " "; 863 } 864 cout << endl; 775 865 if (mViewSpaceHierarchyType == BSP) 776 866 { … … 799 889 else 800 890 { 801 vc->GetParent()->SetupChildLink(bspVc); 802 vc->GetParent()->RemoveChildLink(vc); 891 vc->GetParent()->ReplaceChildLink(vc, bspVc); 803 892 } 804 893 … … 806 895 (*vit) = bspVc; 807 896 } 808 809 897 } 810 898 else if (mViewSpaceHierarchyType == VSP) … … 834 922 else 835 923 { 836 vc->GetParent()->SetupChildLink(vspVc); 837 vc->GetParent()->RemoveChildLink(vc); 924 vc->GetParent()->ReplaceChildLink(vc, vspVc); 838 925 } 839 926 … … 849 936 } 850 937 } 851 Debug<< "************************" << endl;938 cout << "************************" << endl; 852 939 it_end = mViewCells.end(); 853 940 for (it = mViewCells.begin(); it != it_end; ++ it) 854 941 { 855 Debug<< (*it)->GetId() << " ";856 } 857 Debug<< endl;942 cout << (*it)->GetId() << " "; 943 } 944 cout << endl; 858 945 cout << "\nview space box: " << mViewSpaceBox << endl; 859 946 } … … 862 949 void ViewCellsParseHandlers::CreateViewCellsManager(/*const char *name*/) 863 950 { 864 if (mViewSpaceHierarchyType == BSP) //951 if (mViewSpaceHierarchyType == BSP) 865 952 { 866 953 Debug << "creating view cells manager: VspBsp" << endl; 867 954 868 //mVspBspTree = new VspBspTree();869 955 mViewCellsManager = new VspBspViewCellsManager(mViewCellsTree, mVspBspTree); 870 956 } … … 950 1036 if (vit == mViewCells.end()) 951 1037 cout << "error: view cell " << viewCellId << " not found" << endl; 952 1038 953 1039 VspViewCell *viewCell = dynamic_cast<VspViewCell *>(*vit); 954 1040 955 1041 if (viewCell->GetId() == viewCellId) 956 1042 { … … 964 1050 } 965 1051 else 966 { 1052 { 967 1053 // add to invalid view space 968 1054 leaf->SetViewCell(mVspTree->GetOrCreateOutOfBoundsCell()); … … 986 1072 if (attrName == "plane") 987 1073 { 988 sscanf(ptr, "% d %f", &plane.mAxis, &plane.mPosition);1074 sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis); 989 1075 } 990 1076 } … … 994 1080 if (mCurrentVspNode) // replace NULL child of parent with current node 995 1081 { 996 VspInterior *current = dynamic_cast<VspInterior *>(mCurrentVspNode); 997 998 current->ReplaceChildLink(NULL, interior); 999 interior->SetParent(current); 1082 VspInterior *parent = dynamic_cast<VspInterior *>(mCurrentVspNode); 1083 1084 parent->ReplaceChildLink(NULL, interior); 1085 interior->SetParent(parent); 1086 1087 AxisAlignedBox3 frontBox, backBox; 1088 1089 parent->GetBoundingBox().Split(parent->GetPlane().mAxis, parent->GetPlane().mPosition, frontBox, backBox); 1090 if (parent->GetFront() == interior) 1091 interior->SetBoundingBox(frontBox); 1092 else 1093 interior->SetBoundingBox(backBox); 1000 1094 } 1001 1095 else 1002 1096 { 1003 1097 mVspTree->mRoot = interior; 1098 interior->SetBoundingBox(mVspTree->GetBoundingBox()); 1004 1099 } 1005 1100 … … 1021 1116 if (attrName == "plane") 1022 1117 { 1023 sscanf(ptr, "%d %f", 1024 &plane.mAxis, &plane.mPosition); 1118 sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis); 1025 1119 } 1026 1120 } … … 1031 1125 interior->mPosition = plane.mPosition; 1032 1126 1033 if (mCurrent KdNode) // replace NULL child of parent with current node1034 { 1035 KdInterior *parent = dynamic_cast<KdInterior *>(mCurrent KdNode);1127 if (mCurrentOspNode) // replace NULL child of parent with current node 1128 { 1129 KdInterior *parent = dynamic_cast<KdInterior *>(mCurrentOspNode); 1036 1130 parent->ReplaceChildLink(NULL, interior); 1037 1131 interior->mParent = parent; 1132 1133 AxisAlignedBox3 frontBox, backBox; 1134 1135 parent->mBox.Split(parent->mAxis, parent->mPosition, frontBox, backBox); 1136 if (parent->mFront == interior) 1137 interior->mBox = frontBox; 1138 else 1139 interior->mBox = backBox; 1038 1140 } 1039 1141 else 1040 1142 { 1041 1143 mHierarchyManager->mOspTree->mRoot = interior; 1042 } 1043 1044 mCurrentKdNode = interior; 1144 interior->mBox = mHierarchyManager->mOspTree->mBoundingBox; 1145 } 1146 1147 mCurrentOspNode = interior; 1045 1148 } 1046 1149 … … 1049 1152 { 1050 1153 KdLeaf * leaf = 1051 new KdLeaf(dynamic_cast<KdInterior *>(mCurrent KdNode), NULL);1052 1053 if (mCurrent KdNode) // replace front or (if not NULL) back child1054 { 1055 dynamic_cast<KdInterior *>(mCurrent KdNode)->ReplaceChildLink(NULL, leaf);1154 new KdLeaf(dynamic_cast<KdInterior *>(mCurrentOspNode), NULL); 1155 1156 if (mCurrentOspNode) // replace front or (if not NULL) back child 1157 { 1158 dynamic_cast<KdInterior *>(mCurrentOspNode)->ReplaceChildLink(NULL, leaf); 1056 1159 } 1057 1160 else … … 1063 1166 1064 1167 void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes) 1065 {/* 1066 KdLeaf * leaf = 1067 new KdLeaf(dynamic_cast<KdInterior *>(mCurrentKdNode), NULL); 1068 1069 if (mCurrentKdNode) // replace front or (if not NULL) back child 1070 { 1071 dynamic_cast<KdInterior *>(mCurrentKdNode)->ReplaceChildLink(NULL, leaf); 1072 } 1073 else 1074 { 1075 mHierarchyManager->mBvHierarchy->mRoot = leaf; 1076 }*/ 1077 } 1078 1079 1080 void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes) 1081 {/* 1082 AxisAlignedPlane plane; 1083 int len = attributes.getLength(); 1168 { 1169 const int len = attributes.getLength(); 1170 Vector3 minBox, maxBox; 1171 1172 ObjectContainer objects; 1084 1173 1085 1174 for (int i = 0; i < len; ++ i) … … 1089 1178 const char *ptr = attrValue.LocalForm(); 1090 1179 1091 if (attrName == "plane") 1092 { 1093 sscanf(ptr, "%d %f", 1094 &plane.mAxis, &plane.mPosition); 1095 } 1096 } 1097 1098 KdInterior* interior = new KdInterior(NULL); 1099 1100 interior->mAxis = plane.mAxis; 1101 interior->mPosition = plane.mPosition; 1102 1103 if (mCurrentKdNode) // replace NULL child of parent with current node 1104 { 1105 KdInterior *parent = dynamic_cast<KdInterior *>(mCurrentKdNode); 1180 if (attrName == "min") 1181 { 1182 sscanf(ptr, "%f %f %f", &minBox); 1183 } 1184 if (attrName == "max") 1185 { 1186 sscanf(ptr, "%f %f %f", &maxBox); 1187 } 1188 if (attrName == "objects") 1189 { 1190 StartBvhLeafObjects(objects, ptr); 1191 } 1192 } 1193 1194 BvhLeaf * leaf = 1195 new BvhLeaf(AxisAlignedBox3(minBox, maxBox), 1196 dynamic_cast<BvhInterior *>(mCurrentBvhNode), (int)objects.size()); 1197 1198 leaf->mObjects = objects; 1199 1200 if (mCurrentBvhNode) // replace front or (if not NULL) back child 1201 { 1202 dynamic_cast<BvhInterior *>(mCurrentBvhNode)->ReplaceChildLink(NULL, leaf); 1203 } 1204 else 1205 { 1206 mHierarchyManager->mBvHierarchy->mRoot = leaf; 1207 } 1208 } 1209 1210 1211 void ViewCellsParseHandlers::StartBvhLeafObjects(ObjectContainer &objects, 1212 const char *ptr) 1213 { 1214 vector<int> objIndices; 1215 1216 char *endptr; 1217 1218 while (1) 1219 { 1220 const int index = strtol(ptr, &endptr, 10); 1221 1222 if (ptr == endptr) break; 1223 1224 objIndices.push_back(index); 1225 1226 ptr = endptr; 1227 } 1228 1229 //TODO: find objects and add them to pvs 1230 // TODO: get view cell with specified id 1231 MeshInstance dummyInst(NULL); 1232 1233 vector<int>::const_iterator it, it_end = objIndices.end(); 1234 1235 for (it = objIndices.begin(); it != it_end; ++ it) 1236 { 1237 const int objId = *it; 1238 dummyInst.SetId(objId); 1239 1240 ObjectContainer::iterator oit = 1241 lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt); 1242 1243 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 1244 { 1245 objects.push_back(*oit); 1246 } 1247 else 1248 { 1249 cout << "error: object with id " << objId << " does not exist" << endl; 1250 } 1251 } 1252 } 1253 1254 1255 void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes) 1256 { 1257 const int len = attributes.getLength(); 1258 Vector3 minBox, maxBox; 1259 1260 for (int i = 0; i < len; ++ i) 1261 { 1262 string attrName(StrX(attributes.getName(i)).LocalForm()); 1263 StrX attrValue(attributes.getValue(i)); 1264 const char *ptr = attrValue.LocalForm(); 1265 1266 if (attrName == "min") 1267 { 1268 sscanf(ptr, "%f %f %f", &minBox); 1269 } 1270 if (attrName == "max") 1271 { 1272 sscanf(ptr, "%f %f %f", &maxBox); 1273 } 1274 } 1275 1276 BvhInterior* interior = new BvhInterior(AxisAlignedBox3(minBox, maxBox)); 1277 1278 if (mCurrentBvhNode) // replace NULL child of parent with current node 1279 { 1280 BvhInterior *parent = dynamic_cast<BvhInterior *>(mCurrentBvhNode); 1106 1281 parent->ReplaceChildLink(NULL, interior); 1107 interior-> mParent = parent;1282 interior->SetParent(parent); 1108 1283 } 1109 1284 else 1110 1285 { 1111 mOspTree->mRoot = interior; 1112 } 1113 1114 mCurrentKdNode = interior;*/ 1115 } 1116 1286 mBvHierarchy->mRoot = interior; 1287 } 1288 1289 mCurrentBvhNode = interior; 1290 } 1117 1291 1118 1292
Note: See TracChangeset
for help on using the changeset viewer.