Changeset 1551 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
- Timestamp:
- 10/02/06 19:07:38 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.