Ignore:
Timestamp:
01/24/07 01:33:39 (17 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2043 r2048  
    352352 
    353353 
    354 bool ViewCellsManager::GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells, 
     354/*bool ViewCellsManager::GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells, 
    355355                                                                                           const int nViewCells, 
    356356                                                                                           const int nViewPoints) 
     
    369369        ViewCellContainer::const_iterator vit, vit_end = rViewCells.end(); 
    370370     
    371         for (vit = rViewCells.begin(); vit != vit_end; ++ vit) 
     371        int i = 0; 
     372    for (vit = rViewCells.begin(); vit != vit_end; ++ vit, ++ i) 
    372373        { 
    373374                ViewCell *vc = *vit; 
     
    379380 
    380381                SimpleRayContainer viewPoints; 
     382                cout << "processing view cell " << i << endl; 
    381383                // generate random view points 
    382384                GenerateViewPoints(vc, nViewPoints, viewPoints); 
     
    388390                        vcPts->second.push_back(*pit);   
    389391                } 
     392        } 
     393 
     394        return true; 
     395}*/ 
     396 
     397 
     398bool ViewCellsManager::GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells, 
     399                                                                                           const int nViewCells, 
     400                                                                                           const int nViewPoints) 
     401{ 
     402        ViewCellContainer rViewCells; 
     403 
     404        cout << "generating " << nViewCells << " random view cells" << endl; 
     405        ///GenerateRandomViewCells(rViewCells, nViewCells); 
     406 
     407        //cout << "finished" << endl; 
     408 
     409        //for (int i = 0; i < viewCells.size(); ++ i) 
     410        //      cout << "vc " << i << ": " << viewCells[i]->GetId() << endl; 
     411 
     412        cout << "generating " << nViewPoints << " view points per view cell" << endl; 
     413             
     414        int generatedViewCells = 0; 
     415        int i = 0; 
     416    while (generatedViewCells < nViewCells) 
     417        { 
     418                ++ i; 
     419                 
     420                const int idx = (int)RandomValue(0.0f, (float)mViewCells.size() - 0.5f); 
     421                         
     422                ViewCell *viewCell = GetViewCell(idx); 
     423                 
     424                cout << "testing view cell: " << viewCell->GetId() << endl; 
     425 
     426                if (!viewCell->Mailed()) 
     427                { 
     428                        viewCell->Mail(); 
     429 
     430                        SimpleRayContainer viewPoints; 
     431                        cout<<"here18"<<endl; 
     432                        // generate random view points 
     433                        if (IsValidViewSpace(viewCell) &&  
     434                                GenerateViewPoints(viewCell, nViewPoints, viewPoints)) 
     435                        {cout << "here99" << endl; 
     436                                Debug << "vc: " << viewCell->GetId() << endl; 
     437 
     438                                ViewCellPoints *vcPts = new ViewCellPoints(); 
     439                                viewCells.push_back(vcPts); 
     440 
     441                                // valid view cell found 
     442                                vcPts->first = viewCell; 
     443 
     444                                // generate view points 
     445                                ++ generatedViewCells; 
     446 
     447                                SimpleRayContainer::const_iterator pit, pit_end = viewPoints.end(); 
     448 
     449                                for (pit = viewPoints.begin(); pit != pit_end; ++ pit) 
     450                                { 
     451                                        Debug << "vp: " << (*pit) << endl; 
     452                                        vcPts->second.push_back(*pit);   
     453                                } 
     454                                cout << "view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;       
     455                        } 
     456                        else 
     457                        { 
     458                                cout << "error: invalid view cell " << generatedViewCells << " with id " << viewCell->GetId() << endl;   
     459                        } 
     460                } 
     461 
     462                if (i > nViewCells * 1000000) // safety 
     463                { 
     464                        cout << "big error" << endl; 
     465                        break; 
     466                } 
     467                cout << "processd view cells " << generatedViewCells << " of " << nViewCells << endl << endl; 
    390468        } 
    391469 
     
    437515 
    438516 
     517bool ViewCellsManager::ImportRandomViewCells(const string &filename) 
     518{ 
     519        return ImportRandomViewCells(filename, mViewCellPoints); 
     520} 
     521 
     522 
    439523bool ViewCellsManager::GenerateViewPoints(ViewCell *viewCell,  
    440524                                                                                  const int numViewPoints, 
     
    445529        int i = 0; 
    446530 
     531        cout << "generating view points for view cell " << viewCell->GetId() << endl; 
     532 
    447533        while (generatedPts < numViewPoints) 
    448534        { 
     
    450536 
    451537                if (GenerateViewPoint(viewCell, pt)) 
    452                 { 
     538                {cout<<"here4"<<endl; 
    453539                        ++ generatedPts; 
     540                        cout << "generated view point " << generatedPts << endl; 
    454541                        viewPoints.push_back(pt); 
    455542                } 
    456543 
    457544                // savety criterium 
    458                 if (++ i > numViewPoints + 100000) 
     545                if (++ i > numViewPoints * 3) 
    459546                { 
    460547                        return false; 
     
    462549        } 
    463550         
     551        cout << "view point generation finished" << endl; 
     552 
    464553        return true; 
     554} 
     555 
     556 
     557bool ViewCellsManager::ExportRandomViewCells(const string &filename) 
     558{ 
     559        const int numViewCells = 100; 
     560        const int numViewPoints = 10; 
     561 
     562        preprocessor->mViewCellsManager-> 
     563                GenerateRandomViewCells(mViewCellPoints, numViewCells, numViewPoints); 
     564 
     565        //cout << "exporting random view cells" << endl; 
     566        return preprocessor->mViewCellsManager->ExportRandomViewCells(filename,  mViewCellPoints); 
    465567} 
    466568 
     
    473575        int tries = 0; 
    474576        Vector3 viewPoint, direction; 
    475         const int maxTries = 100; 
     577        const int maxTries = 10; 
    476578 
    477579        while (1)  
     
    499601                //halton.GenerateNext(); 
    500602 
    501                 //cout << "vp: " << viewPoint << endl; 
    502                 //cout << "dir: " << direction << endl; 
    503  
    504603                ViewCell *v = GetViewCell(viewPoint); 
    505604 
    506605                if (v && v->GetValid()) 
    507606                { 
    508                         //cout << "validating view point" << endl; 
    509  
    510607                        mPreprocessor->GetRenderer()->mViewPoint = viewPoint; 
    511608                        mPreprocessor->GetRenderer()->mViewDirection = direction; 
    512                         //preprocessor->renderer->EvalPvsStat(); 
    513 cout<<"*********hgere55"<<endl; 
    514                         if (preprocessor->renderer->ValidViewPoint()) 
     609                        //mPreprocessor->GetRenderer()->EvalPvsStat(); 
     610 
     611                        if (mPreprocessor->GetRenderer()->ValidViewPoint()) 
    515612                        { 
    516                                 cout << "view point valid" << endl; 
     613                                cout << "view point valid " << viewPoint << " " << direction << endl; 
    517614                                break; 
    518615                        } 
    519                         cout<<"here33"<<endl; 
     616                         
    520617                } 
    521618 
     
    526623                //      cout << "error!" << endl; 
    527624                if (++ tries > maxTries) 
     625                { 
     626                        cerr << "error: no view point computed" << endl; 
    528627                        return false; 
     628                } 
    529629        } 
    530630 
     
    584684                                else 
    585685                                { 
    586                                         cout << "error: invalid view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;        
     686                                        cout << "error: invalid view cell " << generatedViewCells << " with id " << viewCell->GetId() << endl;   
    587687                                } 
    588688                        } 
     
    615715 
    616716        DEL_PTR(mMixtureDistribution); 
     717         
     718        CLEAR_CONTAINER(mViewCellPoints); 
    617719} 
    618720 
     
    10051107                        vm->FinalizeViewCells(true); 
    10061108                        // vm->mViewCellsTree->AssignRandomColors(); 
     1109                } 
     1110 
     1111                if (0) 
     1112                { 
     1113                        cout << "=============== " << vm->GetViewCellById(5318)->GetPvs().GetSize() << "========" << endl; 
    10071114                } 
    10081115 
     
    26092716 
    26102717 
    2611  
    2612  
    26132718int ViewCellsManager::GetNumViewCells() const 
    26142719{ 
     
    35403645} 
    35413646 
     3647 
    35423648void ViewCellsManager::UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) 
    35433649{ 
Note: See TracChangeset for help on using the changeset viewer.