Ignore:
Timestamp:
01/22/07 23:35:03 (17 years ago)
Author:
mattausch
Message:

changed to static cast

File:
1 edited

Legend:

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

    r2015 r2017  
    238238                mEvaluationSamplingType = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION; 
    239239        } 
    240         /*else if (strcmp(buf, "interior") == 0) 
    241         { 
    242                 mEvaluationSamplingType = SamplingStrategy::OBJECTS_INTERIOR_DISTRIBUTION; 
    243         }*/ 
    244240        else 
    245241        { 
     
    311307 
    312308 
     309ViewCell *ViewCellsManager::GetViewCellById(const int id) 
     310{ 
     311        ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 
     312 
     313        for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 
     314        { 
     315                if ((*vit)->GetId() == id) 
     316                        return (*vit); 
     317        } 
     318        return NULL; 
     319} 
     320 
     321 
     322bool ViewCellsManager::ExportRandomViewCells(const string &filename, 
     323                                                                                         const vector<ViewCellPoints *> &viewCells) 
     324{ 
     325        std::ofstream outStream; 
     326        outStream.open(filename.c_str()); 
     327 
     328        vector<ViewCellPoints *>::const_iterator vit, vit_end = viewCells.end(); 
     329     
     330        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     331        { 
     332                ViewCell *vc = (*vit)->first; 
     333 
     334                outStream << "v " << vc->GetId() << endl; 
     335 
     336                SimpleRayContainer viewPoints; 
     337         
     338                SimpleRayContainer::const_iterator pit, pit_end = (*vit)->second.end(); 
     339 
     340                for (pit = (*vit)->second.begin(); pit != pit_end; ++ pit) 
     341                { 
     342                        const Vector3 pt = (*pit).mOrigin; 
     343                        const Vector3 dir = (*pit).mDirection; 
     344 
     345                        outStream << "p " << pt.x  << " " << pt.y  << " " << pt.z  
     346                                      << " "  << dir.x << " " << dir.y << " " << dir.z << endl; 
     347                } 
     348        } 
     349 
     350        return true; 
     351} 
     352 
     353 
     354bool ViewCellsManager::GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells, 
     355                                                                                           const int nViewCells, 
     356                                                                                           const int nViewPoints) 
     357{ 
     358        ViewCellContainer rViewCells; 
     359 
     360        cout << "generating " << nViewCells << " random view cells" << endl; 
     361        GenerateRandomViewCells(rViewCells, nViewCells); 
     362 
     363        cout << "finished" << endl; 
     364 
     365        //for (int i = 0; i < viewCells.size(); ++ i) 
     366        //      cout << "vc " << i << ": " << viewCells[i]->GetId() << endl; 
     367 
     368        cout << "generating " << nViewPoints << " view points per view cell" << endl; 
     369        ViewCellContainer::const_iterator vit, vit_end = rViewCells.end(); 
     370     
     371        for (vit = rViewCells.begin(); vit != vit_end; ++ vit) 
     372        { 
     373                ViewCell *vc = *vit; 
     374 
     375                ViewCellPoints *vcPts = new ViewCellPoints(); 
     376                viewCells.push_back(vcPts); 
     377 
     378                vcPts->first = vc; 
     379 
     380                SimpleRayContainer viewPoints; 
     381                // generate random view points 
     382                GenerateViewPoints(vc, nViewPoints, viewPoints); 
     383                 
     384                SimpleRayContainer::const_iterator pit, pit_end = viewPoints.end(); 
     385 
     386                for (pit = viewPoints.begin(); pit != pit_end; ++ pit) 
     387                { 
     388                        vcPts->second.push_back(*pit);   
     389                } 
     390        } 
     391 
     392        return true; 
     393} 
     394 
     395 
     396bool ViewCellsManager::ImportRandomViewCells(const string &filename,  
     397                                                                                         vector<ViewCellPoints *> &viewCells) 
     398{ 
     399        ifstream inStream(filename.c_str()); 
     400        if (!inStream.is_open()) 
     401                return false; 
     402 
     403        ViewCellPoints *currentViewCell = NULL; 
     404 
     405        string buf; 
     406        while (!(getline(inStream, buf)).eof()) 
     407        { 
     408                switch (buf[0]) 
     409                { 
     410                case 'v': 
     411                        { 
     412                                int id; 
     413                                sscanf(buf.c_str(), "v %d", &id); 
     414                         
     415                                currentViewCell = new ViewCellPoints(); 
     416                                currentViewCell->first = GetViewCellById(id); 
     417                                                 
     418                                viewCells.push_back(currentViewCell); 
     419                                break; 
     420                        } 
     421                case 'p': 
     422                        { 
     423                                Vector3 pt, dir; 
     424                                sscanf(buf.c_str(), "p %f %f %f %f %f %f", &pt.x, &pt.y, &pt.z, &dir.x, &dir.y, &dir.z); 
     425                                 
     426                                SimpleRay ray(pt, dir, 0, 1); 
     427                                currentViewCell->second.push_back(ray); 
     428                                break; 
     429                        } 
     430                default: 
     431                        break; 
     432                } 
     433        } 
     434 
     435        return true; 
     436} 
     437 
     438 
     439bool ViewCellsManager::GenerateViewPoints(ViewCell *viewCell,  
     440                                                                                  const int numViewPoints, 
     441                                                                                  SimpleRayContainer &viewPoints) 
     442{ 
     443        bool success = true; 
     444        int generatedPts = 0; 
     445        int i = 0; 
     446 
     447        while (generatedPts < numViewPoints) 
     448        { 
     449                SimpleRay pt; 
     450 
     451                if (GenerateViewPoint(viewCell, pt)) 
     452                { 
     453                        ++ generatedPts; 
     454                        viewPoints.push_back(pt); 
     455                } 
     456 
     457                // savety criterium 
     458                if (++ i > numViewPoints + 100000) 
     459                { 
     460                        return false; 
     461                } 
     462        } 
     463         
     464        return true; 
     465} 
     466 
     467 
     468bool ViewCellsManager::GenerateViewPoint(ViewCell *viewCell,  
     469                                                                                 SimpleRay &ray) 
     470{ 
     471        // do not use this function since it could return different viewpoints for 
     472        // different executions of the algorithm 
     473        int tries = 0; 
     474        Vector3 viewPoint, direction; 
     475        const int maxTries = 100; 
     476 
     477        while (1)  
     478        { 
     479                // hack 
     480                if (!viewCell->GetMesh()) 
     481                        CreateMesh(viewCell); 
     482 
     483        Mesh *mesh = viewCell->GetMesh(); 
     484                AxisAlignedBox3 box = mesh->mBox; 
     485                //cout <<"box: " << box << endl; 
     486                /*Vector3 pVector = Vector3(halton.GetNumber(1), 
     487                                                                  halton.GetNumber(2), 
     488                                                                  halton.GetNumber(3));*/ 
     489 
     490                Vector3 pVector = Vector3(Random(1.0f), 
     491                                                                  Random(1.0f), 
     492                                                                  Random(1.0f)); 
     493 
     494                viewPoint =  box.GetPoint(pVector); 
     495         
     496                //const Vector3 dVector = Vector3(2 * M_PI * halton.GetNumber(4), M_PI*halton.GetNumber(5),0.0f); 
     497                const Vector3 dVector = Vector3(2 * M_PI * Random(1.0f), M_PI * Random(1.0f), 0.0f); 
     498                direction = Normalize(Vector3(sin(dVector.x), 0.0f, cos(dVector.x))); 
     499                //halton.GenerateNext(); 
     500 
     501                //cout << "vp: " << viewPoint << endl; 
     502                //cout << "dir: " << direction << endl; 
     503 
     504                ViewCell *v = GetViewCell(viewPoint); 
     505 
     506                if (v && v->GetValid()) 
     507                { 
     508                        //cout << "validating view point" << endl; 
     509 
     510                        mPreprocessor->GetRenderer()->mViewPoint = viewPoint; 
     511                        mPreprocessor->GetRenderer()->mViewDirection = direction; 
     512 
     513                        if (mPreprocessor->GetRenderer()->ValidViewPoint()) 
     514                        { 
     515                                cout << "view point valid" << endl; 
     516                                break; 
     517                        } 
     518                } 
     519 
     520                // generate a new vector 
     521                //halton.GenerateNext(); 
     522 
     523                //if (!box.IsInside(viewPoint)) 
     524                //      cout << "error!" << endl; 
     525                if (++ tries > maxTries) 
     526                        return false; 
     527        } 
     528 
     529        ray = SimpleRay(viewPoint, direction, 0, 1); 
     530        //cout << "view point generated: " << viewPoint << " " << direction << endl; 
     531 
     532        return true; 
     533} 
     534 
     535 
     536bool ViewCellsManager::IsValidViewSpace(ViewCell *vc) 
     537{ 
     538        SimpleRay simpleRay; 
     539        //check if view point can be generated 
     540        return GenerateViewPoint(vc, simpleRay); 
     541} 
     542 
     543 
     544bool ViewCellsManager::GenerateRandomViewCells(ViewCellContainer &viewCells,  
     545                                                                                           const int numViewCells) 
     546{ 
     547        int generatedViewCells = 0; 
     548        //HaltonSequence halton; 
     549        //float r[1]; 
     550 
     551        ViewCell::NewMail(); 
     552 
     553        while (generatedViewCells < numViewCells) 
     554        { 
     555                // savety criterium 
     556                const int tries = 100000 + generatedViewCells; 
     557                int i = 0; 
     558 
     559                // generate next view cell 
     560                while (1) 
     561                { 
     562                        //halton.GetNext(1, r); 
     563                        //const int idx = (int)(r[0] * mViewCells.size() - 1.0f); 
     564                        const int idx = (int)RandomValue(0.0f, (float)mViewCells.size() - 0.5f); 
     565                         
     566                        ViewCell *viewCell = GetViewCell(idx); 
     567 
     568                        if (!viewCell->Mailed()) 
     569                        { 
     570                                viewCell->Mail(); 
     571 
     572                                // check for valid view space 
     573                                if (IsValidViewSpace(viewCell)) 
     574                                { 
     575                                        // valid view cell found 
     576                                        viewCells.push_back(viewCell); 
     577 
     578                        ++ generatedViewCells; 
     579                                        //cout << "view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;     
     580                                        break; 
     581                                } 
     582                                else 
     583                                { 
     584                                        cout << "error: invalid view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;        
     585                                } 
     586                        } 
     587 
     588                        if (++ i == tries) // no new view cell fond 
     589                        { 
     590                                cerr << "big error! no view cell found" << endl; 
     591                                return false; 
     592                        }                
     593                }                        
     594        } 
     595 
     596        return true; 
     597} 
     598 
     599 
    313600ViewCellsManager::~ViewCellsManager() 
    314601{ 
     
    575862                mRenderer->RenderScene(); 
    576863                SimulationStatistics ss; 
    577                 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
     864                static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
    578865 
    579866                Debug << ss << endl; 
     
    16161903                        if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 
    16171904                        { 
    1618                                 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 
     1905                                TransformedMeshInstance *mit = static_cast<TransformedMeshInstance *>(*oit); 
    16191906                                mesh = MeshManager::GetSingleton()->CreateResource(); 
    16201907                                mit->GetTransformedMesh(*mesh); 
     
    16221909                        else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 
    16231910                        { 
    1624                                 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 
     1911                                MeshInstance *mit = static_cast<MeshInstance *>(*oit); 
    16251912                                mesh = mit->GetMesh(); 
    16261913                        } 
     
    26082895        for (lit = leaves.begin(); lit != lit_end; ++ lit) 
    26092896        { 
    2610                 dynamic_cast<ViewCellLeaf *>(*lit)->SetActiveViewCell(vc); 
     2897                static_cast<ViewCellLeaf *>(*lit)->SetActiveViewCell(vc); 
    26112898        } 
    26122899} 
     
    26482935                for (it = objects.begin(); it != it_end; ++ it) 
    26492936                { 
    2650                         MeshInstance *mi = dynamic_cast<MeshInstance *>(*it); 
     2937                        MeshInstance *mi = static_cast<MeshInstance *>(*it); 
    26512938                        const AxisAlignedBox3 box = mi->GetBox(); 
    26522939 
     
    26712958                for (it = objects.begin(); it != it_end; ++ it) 
    26722959                {        
    2673                         MeshInstance *mi = dynamic_cast<MeshInstance *>(*it); 
     2960                        MeshInstance *mi = static_cast<MeshInstance *>(*it); 
    26742961                        const AxisAlignedBox3 box = mi->GetBox(); 
    26752962                        Vector3 bmin = box.Min(); 
     
    32523539        //-- interior node => propagate pvs up the tree 
    32533540 
    3254         ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 
     3541        ViewCellInterior *interior = static_cast<ViewCellInterior *>(root); 
    32553542 
    32563543        // reset interior pvs 
     
    39204207 
    39214208        Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
    3922  
     4209         
    39234210        IncludeNodeGeomInMesh(geom, *mesh); 
     4211        mesh->ComputeBoundingBox(); 
     4212 
    39244213        vc->SetMesh(mesh); 
    39254214} 
     
    41014390        if (root->IsLeaf()) 
    41024391        { 
    4103                 BspLeaf *leaf = dynamic_cast<BspLeaf *>(root); 
     4392                BspLeaf *leaf = static_cast<BspLeaf *>(root); 
    41044393                leaf->GetViewCell()->SetMergeCost(0.0f); 
    41054394                return leaf->GetViewCell(); 
    41064395        } 
    41074396         
    4108         BspInterior *interior = dynamic_cast<BspInterior *>(root); 
     4397        BspInterior *interior = static_cast<BspInterior *>(root); 
    41094398        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    41104399                 
     
    42434532 
    42444533                for (int i = 0; i < leafOut; ++ i) 
    4245                         kdLeaves.push_back(dynamic_cast<KdLeaf *>(mKdTree->GetRandomLeaf())); 
     4534                        kdLeaves.push_back(static_cast<KdLeaf *>(mKdTree->GetRandomLeaf())); 
    42464535 
    42474536                for (int i = 0; i < kdLeaves.size(); ++ i) 
     
    44064695        for (it = leaves.begin(); it != it_end; ++ it) 
    44074696        { 
    4408                 KdViewCell *kdVc = dynamic_cast<KdViewCell *>(*it); 
     4697                KdViewCell *kdVc = static_cast<KdViewCell *>(*it); 
    44094698                exporter->ExportBox(mKdTree->GetBox(kdVc->mLeaves[0])); 
    44104699        } 
     
    47465035 
    47475036        SimulationStatistics ss; 
    4748         dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
     5037        static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
    47495038    Debug << "render time before refine\n\n" << ss << endl; 
    47505039 
     
    48265115 
    48275116        cout << "\nview cells partition render time before compress" << endl << endl;; 
    4828         dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene(); 
     5117        static_cast<RenderSimulator *>(mRenderer)->RenderScene(); 
    48295118        SimulationStatistics ss; 
    4830         dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
     5119        static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
    48315120        cout << ss << endl; 
    48325121         
     
    48575146        if (root->IsLeaf()) 
    48585147        { 
    4859                 BspLeaf *leaf = dynamic_cast<BspLeaf *>(root); 
     5148                BspLeaf *leaf = static_cast<BspLeaf *>(root); 
    48605149                leaf->GetViewCell()->SetMergeCost(0.0f); 
    48615150                return leaf->GetViewCell(); 
     
    48635152         
    48645153         
    4865         BspInterior *interior = dynamic_cast<BspInterior *>(root); 
     5154        BspInterior *interior = static_cast<BspInterior *>(root); 
    48665155        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    48675156                 
     
    50955384                for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    50965385                        {        
    5097                                 BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0]; 
     5386                                BspLeaf *vcLeaf = static_cast<BspViewCell *>(*vit)->mLeaves[0]; 
    50985387                                VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
    50995388 
     
    53875676                for (int j = 0; j < (int)leaves.size(); ++ j) 
    53885677                { 
    5389                         BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaves[0]; 
     5678                        BspLeaf *leaf = static_cast<BspViewCell *>(leaves[i])->mLeaves[0]; 
    53905679 
    53915680                        if (i != j) 
    53925681                        { 
    5393                                 BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaves[0]; 
     5682                                BspLeaf *leaf2 =static_cast<BspViewCell *>(leaves[j])->mLeaves[0]; 
    53945683                                const int dist = mVspBspTree->TreeDistance(leaf, leaf2); 
    53955684                                 
     
    54225711         
    54235712        Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
     5713         
    54245714        IncludeNodeGeomInMesh(geom, *mesh); 
     5715        mesh->ComputeBoundingBox(); 
    54255716 
    54265717        vc->SetMesh(mesh); 
     
    55005791{ 
    55015792        // TODO: do I still need this here? 
    5502         if (0) 
    5503                 mVspBspTree->RepairViewCellsLeafLists(); 
     5793        if (0) mVspBspTree->RepairViewCellsLeafLists(); 
    55045794} 
    55055795 
     
    57486038 
    57496039        cout << "\nview cells partition render time before compress" << endl << endl; 
    5750         dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene(); 
     6040        static_cast<RenderSimulator *>(mRenderer)->RenderScene(); 
    57516041        SimulationStatistics ss; 
    5752         dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
     6042        static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
    57536043        cout << ss << endl; 
    57546044         
     
    57826072        if (root->IsLeaf()) 
    57836073        { 
    5784                 VspLeaf *leaf = dynamic_cast<VspLeaf *>(root); 
     6074                VspLeaf *leaf = static_cast<VspLeaf *>(root); 
    57856075                leaf->GetViewCell()->SetMergeCost(0.0f); 
    57866076                return leaf->GetViewCell(); 
    57876077        } 
    57886078         
    5789         VspInterior *interior = dynamic_cast<VspInterior *>(root); 
     6079        VspInterior *interior = static_cast<VspInterior *>(root); 
    57906080        ViewCellInterior *viewCellInterior = new ViewCellInterior(); 
    57916081                 
     
    58616151        for (it = leaves.begin(); it != it_end; ++ it) 
    58626152        { 
    5863                 VspViewCell *vspVc = dynamic_cast<VspViewCell *>(*it); 
     6153                VspViewCell *vspVc = static_cast<VspViewCell *>(*it); 
    58646154                VspLeaf *l = vspVc->mLeaves[0]; 
    58656155 
     
    59276217                        ObjectPvsEntry entry = pit.Next(); 
    59286218                                 
    5929                         BvhNode *node = dynamic_cast<BvhNode *>(entry.mObject); 
     6219                        BvhNode *node = static_cast<BvhNode *>(entry.mObject); 
    59306220                         
    59316221                        // hack!! 
     
    61656455                        for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    61666456                        { 
    6167                                 VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0]; 
     6457                                VspLeaf *vcLeaf = static_cast<VspViewCell *>(*vit)->mLeaves[0]; 
    61686458                                VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
    61696459 
     
    63116601void VspOspViewCellsManager::CreateMesh(ViewCell *vc) 
    63126602{ 
    6313         // matt: TODO 
    63146603        Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
    6315  
     6604         
    63166605        ViewCellContainer leaves; 
    63176606        mViewCellsTree->CollectLeaves(vc, leaves); 
     
    63216610    for (it = leaves.begin(); it != it_end; ++ it) 
    63226611        { 
    6323                 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0]; 
     6612                VspLeaf *leaf = static_cast<VspViewCell *>(*it)->mLeaves[0]; 
    63246613                const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); 
    63256614        IncludeBoxInMesh(box, *mesh); 
    63266615        } 
    63276616 
     6617        mesh->ComputeBoundingBox(); 
     6618 
    63286619        vc->SetMesh(mesh); 
    63296620} 
     
    63496640    for (it = leaves.begin(); it != it_end; ++ it) 
    63506641        { 
    6351                 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0]; 
     6642                VspLeaf *leaf = static_cast<VspViewCell *>(*it)->mLeaves[0]; 
    63526643                 
    63536644                const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); 
Note: See TracChangeset for help on using the changeset viewer.