Ignore:
Timestamp:
01/25/06 11:08:35 (18 years ago)
Author:
mattausch
Message:

changed view cell parser. warning, not working yet!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsParser.cpp

    r556 r575  
    6161//  StdInParseHandlers: Constructors and Destructor 
    6262// --------------------------------------------------------------------------- 
    63 ViewCellsParseHandlers::ViewCellsParseHandlers(VspBspTree *tree, 
    64                                                                                            ViewCellsManager *viewCells, 
     63ViewCellsParseHandlers::ViewCellsParseHandlers(ViewCellsManager **viewCells, 
    6564                                                                                           ObjectContainer *objects): 
    6665  mElementCount(0) 
     
    6968  , mSpaceCount(0) 
    7069{ 
    71         mVspBspTree = tree; 
    72         mCurrentNode = tree->GetRoot(); 
    73         mViewCellsManager = viewCells; 
    7470        mObjects = objects; 
    75 } 
     71        viewCells = &mViewCellsManager; 
     72        //mPreprocessor = preprocessor; 
     73} 
     74 
    7675 
    7776ViewCellsParseHandlers::~ViewCellsParseHandlers() 
     
    9089  string element(lname.LocalForm()); 
    9190  if (element == "Interior") 
    92           EndInterior(); 
     91          EndBspInterior(); 
    9392  if (element == "ViewCells") 
    9493          EndViewCells(); 
     
    9695 
    9796 
    98 void ViewCellsParseHandlers::EndInterior() 
     97void ViewCellsParseHandlers::EndBspInterior() 
    9998{ 
    10099        // go one up in the tree 
     
    114113void ViewCellsParseHandlers::EndViewCells() 
    115114{ 
    116         // sort view cells for easily finding id 
     115        // sort view cells to help associating view cells according to their id 
    117116        stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 
     117} 
     118 
     119 
     120 
     121void ViewCellsParseHandlers::StartHierarchy(AttributeList&  attributes) 
     122{ 
     123        int len = attributes.getLength(); 
     124   
     125        for (int i = 0; i < len; ++ i)  
     126        { 
     127                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     128                 
     129                if (attrName == "name")  
     130                { 
     131                        StrX attrValue(attributes.getValue(i)); 
     132                         
     133                        const char *ptr = attrValue.LocalForm(); 
     134                         
     135                        CreateViewCellsManager(ptr); 
     136                } 
     137        } 
     138} 
     139 
     140 
     141void ViewCellsParseHandlers::startBspElement(string element, 
     142                                                                                         AttributeList& attributes) 
     143{ 
     144        if (element == "ViewCell") 
     145        { 
     146                cout << "v"; 
     147                StartViewCell(attributes); 
     148        } 
     149 
     150        if (element == "Interior")  
     151        { 
     152                cout << "["; 
     153                StartBspInterior(attributes); 
     154        } 
     155 
     156        if (element == "Leaf")  
     157        { 
     158                StartBspLeaf(attributes); 
     159        } 
    118160} 
    119161 
     
    125167        string element(lname.LocalForm()); 
    126168         
    127         if (element == "ViewCell") 
    128         { 
    129                 cout << "v"; 
    130                 StartViewCell(attributes); 
    131         } 
    132  
    133         if (element == "Interior")  
    134         { 
    135                 cout << "["; 
    136                 StartInterior(attributes); 
    137         } 
    138  
    139         if (element == "Leaf")  
    140         { 
    141                 StartLeaf(attributes); 
    142         } 
    143  
     169        if (element == "Hierarchy") 
     170        { 
     171                cout << "h"; 
     172                StartHierarchy(attributes); 
     173        } 
     174 
     175        switch (mViewCellsManager->GetType()) 
     176        { 
     177        case ViewCellsManager::BSP: 
     178        case ViewCellsManager::VSP_BSP: 
     179                startBspElement(element, attributes); 
     180                break; 
     181         
     182        default: 
     183                Debug << "not implemented" << endl; 
     184                break; 
     185 
     186        } 
     187         
    144188        ++ mElementCount; 
    145189        mAttrCount += attributes.getLength(); 
     
    228272 
    229273 
    230 void ViewCellsParseHandlers::StartLeaf(AttributeList& attributes) 
     274void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes) 
    231275{ 
    232276        BspLeaf * leaf =  
     
    239283        else 
    240284        { 
    241                 mVspBspTree->mRoot = leaf; 
     285                if (mViewCellsManager->GetType() == ViewCellsManager::BSP) 
     286                        mBspTree->mRoot = leaf; 
     287                else 
     288                        mVspBspTree->mRoot = leaf; 
    242289        } 
    243290 
     
    282329        else 
    283330        { 
    284                 leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell()); 
    285                 leaf->SetTreeValid(false); 
    286                 mVspBspTree->PropagateUpValidity(leaf); 
    287         } 
    288 } 
    289  
    290  
    291 void ViewCellsParseHandlers::StartInterior(AttributeList& attributes) 
     331                if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP) 
     332                { 
     333                        leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell()); 
     334                        leaf->SetTreeValid(false); 
     335                        mVspBspTree->PropagateUpValidity(leaf); 
     336                } 
     337        } 
     338} 
     339 
     340 
     341void ViewCellsParseHandlers::StartBspInterior(AttributeList& attributes) 
    292342{ 
    293343        Plane3 plane; 
     
    318368        else 
    319369        { 
    320                 mVspBspTree->mRoot = interior; 
     370                if (mViewCellsManager->GetType() == ViewCellsManager::BSP) 
     371                        mBspTree->mRoot = interior; 
     372                else 
     373                        mVspBspTree->mRoot = interior; 
    321374        } 
    322375 
    323376        mCurrentNode = interior; 
     377} 
     378 
     379 
     380 
     381void ViewCellsParseHandlers::CreateViewCellsManager(const char *name) 
     382{ 
     383         
     384        if (strcmp(name, "bspTree") == 0) 
     385        { 
     386                mBspTree = new BspTree(); 
     387 
     388                Debug << "view cell type: Bsp" << endl; 
     389 
     390                mCurrentNode = mBspTree->GetRoot(); 
     391 
     392                mViewCellsManager = new BspViewCellsManager(mBspTree); 
     393        } 
     394        else if (strcmp(name, "vspBspTree") == 0) 
     395        { 
     396                mVspBspTree = new VspBspTree(); 
     397 
     398                Debug << "view cell type: VspBsp" << endl; 
     399                mCurrentNode = mVspBspTree->GetRoot(); 
     400 
     401                mViewCellsManager = new VspBspViewCellsManager(mVspBspTree); 
     402        } 
     403        /*else if (strcmp(name, "vspKdTree") == 0) 
     404        { 
     405                mVspKdTree = new VspKdTree();            
     406         
     407                mViewCellsManager = VspKdViewCellsManager(mVspKdTree); 
     408        }*/ 
     409        else 
     410        { 
     411                cerr<<"Wrong view cells type" << name << endl; 
     412                exit(1); 
     413        } 
    324414} 
    325415 
     
    380470 
    381471bool ViewCellsParser::ParseFile(const string filename,  
    382                                                                 VspBspTree *tree, 
    383                                                                 ViewCellsManager *viewCells, 
     472                                                                ViewCellsManager **viewCells, 
    384473                                                                ObjectContainer *objects) 
    385474{ 
     
    414503  //  to do. 
    415504  // 
    416   ViewCellsParseHandlers handler(tree, viewCells, objects); 
     505  ViewCellsParseHandlers handler(viewCells, objects); 
    417506  parser->setDocumentHandler(&handler); 
    418507  parser->setErrorHandler(&handler); 
Note: See TracChangeset for help on using the changeset viewer.