Ignore:
Timestamp:
02/18/06 18:02:12 (18 years ago)
Author:
mattausch
Message:

exporting / loading full merge hierarchy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r590 r651  
    7070  , mVspBspTree(NULL) 
    7171  , mBspTree(NULL) 
     72  , mViewCellsTree(NULL) 
     73  , mParseViewCells(true) 
     74  , mCurrentViewCell(NULL) 
     75  , mCurrentBspNode(NULL) 
    7276{ 
    7377        mObjects = objects; 
     
    8993  StrX lname(name); 
    9094  string element(lname.LocalForm()); 
    91   if (element == "Interior") 
    92           EndBspInterior(); 
     95 
    9396  if (element == "ViewCells") 
    9497          EndViewCells(); 
     98 
     99  if (mParseViewCells) 
     100  { 
     101          if (element == "Interior") 
     102                  EndViewCellInterior(); 
     103  } 
     104  else 
     105  { 
     106        if (element == "Interior") 
     107                  EndBspInterior(); 
     108  } 
    95109} 
    96110 
     
    105119} 
    106120 
     121 
     122void ViewCellsParseHandlers::EndViewCellInterior() 
     123{ 
     124        // go one up in the tree 
     125        if (mCurrentViewCell->GetParent()) 
     126        {       cout << "]"; 
     127                mCurrentViewCell = mCurrentViewCell->GetParent(); 
     128        } 
     129} 
    107130 
    108131inline bool vlt(ViewCell *v1, ViewCell *v2) 
     
    151174        if (element == "Leaf")  
    152175        { 
     176                cout << "l"; 
     177                Debug << "leaf" << endl; 
    153178                StartBspLeaf(attributes); 
    154179        } 
     
    163188 
    164189        // decides the used view cell hierarchy 
     190        if (element == "ViewCells") 
     191        { 
     192                cout << "parsing view cells" << endl; 
     193                mParseViewCells = true; 
     194        } 
     195 
    165196        if (element == "Hierarchy") 
    166197        { 
    167                 cout << "h"; 
     198                cout << "parsing spatial hierarchy" << endl; 
     199                mParseViewCells = false; 
    168200                StartHierarchy(attributes); 
    169201        } 
     
    172204        if (element == "ViewSpaceBox") 
    173205        { 
    174                 cout << "vsb"; 
     206                cout << "b"; 
    175207                StartViewSpaceBox(attributes); 
    176208        } 
    177209 
    178         if (element == "ViewCell") 
    179         { 
    180                 cout << "v"; 
    181                 StartViewCell(attributes); 
    182         } 
    183210 
    184211        // use different methods for the given view cell hierarchy types 
    185         if (mViewCellsManager) 
    186         { 
    187                 switch (mViewCellsManager->GetType()) 
    188                 { 
    189                 case ViewCellsManager::BSP: 
    190                 case ViewCellsManager::VSP_BSP: 
    191                         startBspElement(element, attributes); 
    192                         break; 
     212        if (!mParseViewCells) 
     213        { 
     214                if (mViewCellsManager) 
     215                { 
     216                        switch (mViewCellsManager->GetType()) 
     217                        { 
     218                        case ViewCellsManager::BSP: 
     219                        case ViewCellsManager::VSP_BSP: 
     220                                startBspElement(element, attributes); 
     221                                break; 
    193222         
    194                 default: 
    195                         Debug << "not implemented" << endl; 
    196                         break; 
     223                        default: 
     224                                Debug << "not implemented" << endl; 
     225                                break; 
     226                        } 
     227                } 
     228        } 
     229        else 
     230        { 
     231                if (element == "Interior")  
     232                { 
     233                        cout << "["; 
     234                        StartViewCellInterior(attributes); 
     235                } 
     236 
     237                if (element == "Leaf")  
     238                { 
     239                        cout << "l"; 
     240                        StartViewCellLeaf(attributes); 
    197241                } 
    198242        } 
     
    209253 
    210254 
    211 void ViewCellsParseHandlers::StartViewCell(AttributeList&  attributes) 
     255void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, AttributeList&  attributes) 
    212256{ 
    213257        int len = attributes.getLength(); 
    214258        vector<int> objIndices; 
    215    
    216 //hack!! 
    217          
    218         ViewCell *viewCell = new ViewCellInterior();//mViewCellsManager->GenerateViewCell(); 
    219         viewCell->mIsActive = true; 
    220  
    221         mViewCells.push_back(viewCell); 
    222          
     259 
    223260        for (int i = 0; i < len; ++ i)  
    224261        { 
     
    284321                        viewCell->SetId(id); 
    285322                } 
     323                else if (attrName == "active") 
     324                { 
     325                        StrX attrValue(attributes.getValue(i)); 
     326                         
     327                        const char *ptr = attrValue.LocalForm(); 
     328                        char *endptr = NULL; 
     329                        const bool isActive = (bool)strtol(ptr, &endptr, 10); 
     330 
     331                        viewCell->mIsActive = isActive; 
     332                } 
     333                else if (attrName == "mergecost") 
     334                { 
     335                        StrX attrValue(attributes.getValue(i)); 
     336                         
     337                        const char *ptr = attrValue.LocalForm(); 
     338                        char *endptr = NULL; 
     339                        const float cost = (float)strtod(ptr, &endptr); 
     340 
     341                        viewCell->SetMergeCost(cost); 
     342                } 
    286343        } 
    287344} 
     
    357414                } 
    358415        } 
    359  
     416Debug << "here22" << endl; 
    360417         
    361418        if (viewCellId >= 0) // valid view cell 
     
    368425                        lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 
    369426                         
    370                 ViewCellInterior *viewCell = dynamic_cast<ViewCellInterior *>(*vit); 
    371  
    372                 // giant hack!! 
    373                 BspViewCell *l = dynamic_cast<BspViewCell *>(mViewCellsManager->GenerateViewCell()); 
    374                 viewCell->SetupChildLink(l); 
     427                BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit); 
     428 
     429                Debug << "here44" << endl; 
    375430 
    376431                if (viewCell->GetId() == viewCellId) 
    377432                { 
    378                         leaf->SetViewCell(l); 
    379                         l->mLeaf = leaf; 
     433                        leaf->SetViewCell(viewCell); 
     434                        viewCell->mLeaf = leaf; 
    380435                } 
    381436                else 
     
    392447                        mVspBspTree->PropagateUpValidity(leaf); 
    393448                } 
    394         } 
     449        }Debug << "here33" << endl; 
    395450} 
    396451 
     
    439494 
    440495 
     496void ViewCellsParseHandlers::StartViewCellLeaf(AttributeList& attributes) 
     497{ 
     498        Debug << "here111" << endl; 
     499        BspViewCell *viewCell = new BspViewCell(); 
     500 
     501        if (mCurrentViewCell) // replace front or (if not NULL) back child 
     502        { 
     503                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 
     504                interior->SetupChildLink(viewCell); 
     505        } 
     506        else // root 
     507        { 
     508                mViewCellsTree->SetRoot(viewCell); 
     509        } 
     510 
     511        StartViewCell(viewCell, attributes); 
     512 
     513        // collect leaves 
     514        mViewCells.push_back(viewCell); 
     515} 
     516 
     517 
     518void ViewCellsParseHandlers::StartViewCellInterior(AttributeList& attributes) 
     519{ 
     520        Debug << "here222" << endl; 
     521        ViewCellInterior* interior = new ViewCellInterior(); 
     522         
     523        if (mCurrentViewCell) // replace NULL child of parent with current node 
     524        { 
     525                ViewCellInterior *current = dynamic_cast<ViewCellInterior *>(mCurrentViewCell); 
     526 
     527                current->SetupChildLink(interior); 
     528        } 
     529        else 
     530        { 
     531                mViewCellsTree->SetRoot(interior); 
     532        } 
     533 
     534        mCurrentViewCell = interior; 
     535 
     536        StartViewCell(interior, attributes); 
     537} 
     538 
     539 
    441540 
    442541void ViewCellsParseHandlers::CreateViewCellsManager(const char *name) 
     
    448547                mBspTree = new BspTree(); 
    449548                mBspTree->mBox = mViewSpaceBox; 
    450                 mCurrentBspNode = mBspTree->GetRoot(); 
     549                //mCurrentBspNode = mBspTree->GetRoot(); 
    451550 
    452551                mViewCellsManager = new BspViewCellsManager(mBspTree); 
     
    457556 
    458557                mVspBspTree = new VspBspTree(); 
    459                 mCurrentBspNode = mVspBspTree->GetRoot(); 
     558                //mCurrentBspNode = mVspBspTree->GetRoot(); 
    460559 
    461560                mViewCellsManager = new VspBspViewCellsManager(mVspBspTree); 
     
    476575        } 
    477576 
     577        mViewCellsTree = mViewCellsManager->GetViewCellsTree(); 
    478578        mViewCellsManager->SetViewSpaceBox(mViewSpaceBox); 
    479579} 
     
    625725   // assign new view cells manager 
    626726  *viewCells = handler.mViewCellsManager; 
    627  
     727   
    628728  if (errorCount > 0) 
    629729    return false; 
Note: See TracChangeset for help on using the changeset viewer.