Ignore:
Timestamp:
05/23/08 17:47:22 (16 years ago)
Author:
mattausch
Message:

implemented dynamic object placement / removal

Location:
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface
Files:
4 edited

Legend:

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

    r2694 r2702  
    2020void ObjectPlacer::AddObject(SceneGraphLeaf *obj) 
    2121{ 
    22         mDynamicObjects.push_back(obj); 
     22        mLibraryObjects.push_back(obj); 
    2323} 
    2424 
     
    2626void ObjectPlacer::NextObject() 
    2727{ 
    28         mCurrentObject = (mCurrentObject + 1) % (int)mDynamicObjects.size(); 
     28        mCurrentObject = (mCurrentObject + 1) % (int)mLibraryObjects.size(); 
    2929} 
    3030 
     
    3232void ObjectPlacer::PreviousObject() 
    3333{ 
    34         mCurrentObject = (mCurrentObject - 1) % (int)mDynamicObjects.size(); 
     34        mCurrentObject = (mCurrentObject - 1) % (int)mLibraryObjects.size(); 
    3535} 
    3636 
     
    3838SceneGraphLeaf *ObjectPlacer::GetCurrentObject()  
    3939{  
    40         if (mCurrentObject >= mDynamicObjects.size()) 
     40        if (mCurrentObject >= mLibraryObjects.size()) 
    4141                return NULL; 
    4242 
    43         return mDynamicObjects[mCurrentObject]; 
     43        return mLibraryObjects[mCurrentObject]; 
    4444} 
    4545 
     
    4949        Vector3 p = pt; 
    5050 
    51         SceneGraphLeaf *obj = mDynamicObjects[mCurrentObject]; 
     51        SceneGraphLeaf *obj = mLibraryObjects[mCurrentObject]; 
    5252 
    5353        // set pivot to ground of object 
     
    5858} 
    5959 
    60  
    61 /*void TestApp::Placer(const String &parm) 
    62 { 
    63         if (parm.Empty()) 
    64         { 
    65                 OUT1("Object placement: place/load <libaryfile>/removelast/next/previous/save <objectfile>"); 
    66                 return; 
    67         } 
    68  
    69         ASM_RET(viewer->GetRoot(), "No scene"); 
    70          
    71         if (!placer) 
    72                 placer = new ObjectPlacer; 
    73  
    74         //-- make sure the placer visualization (which shows the already placed objects) is in the viewer 
    75         SearchNodeByNameVisitor search("placervis"); 
    76         search.Apply(viewer->GetRoot(), SearchNodeByNameVisitor::FIRST); 
    77         BranchGroup *placervis = search.GetNode(); 
    78         if (!placervis) 
    79         { 
    80                 placervis = placer->GetPlacedNodeVisualization(); 
    81                 viewer->GetRoot()->addChild(placervis); 
    82                 placervis->setName("placervis"); 
    83         } 
    84  
    85         if (parm == "place") 
    86         { 
    87                 int x, y; 
    88                 input_module->GetMousePos(x, y); 
    89  
    90                 Point3f pos = viewer->UnProject(x, y); 
    91                 if (viewer && viewer->GetRoot() && viewer->GetRoot()->getBoundingBox()->intersects(pos)) 
    92                 { 
    93                         placer->AddObject(pos); 
    94                         OUT1(x << " " << y << " " << pos); 
    95                 } 
    96                 else 
    97                 { 
    98                         OUT1("Point out of bounds"); 
    99                 } 
    100         } else if (parm == "removelast") { 
    101                 placer->RemoveLastObject(); 
    102         } else if (parm == "next") { 
    103                 placer->NextObject(); 
    104         } else if (parm == "previous") { 
    105                 placer->PreviousObject(); 
    106         } else if (parm.Left(5) == "save ") { 
    107                 String filename = parm.Right(parm.size()-5); 
    108                 if (!filename.Empty()) 
    109                         placer->SaveObjects(filename); 
    110         } else if (parm.Left(5) == "clear") { 
    111                 placer->Clear(); 
    112         } else if (parm.Left(5) == "load ") { 
    113                 String fn = sysutils::FindFile(parm.Right(parm.size()-5), settings->get_ObjectPath()); 
    114  
    115                 ASM_ELSE(!fn.empty(), "Couldn't find file " << fn) 
    116                 { 
    117                         OUT1("Loading library " << fn << "..."); 
    118                         SceneBasePtr<BranchGroup> root = ReadSceneGraph(fn, 0, 0, 1); 
    119  
    120                         BranchGroup *library = new BranchGroup; 
    121                         ASM_ELSE((root != NULL), "No scene found in file...") 
    122                         { 
    123                                 SearchNodeByNameVisitor search("start"); 
    124                                 search.Apply(root, SearchNodeByNameVisitor::FIRST); 
    125                                 BranchGroup *local_root = search.GetNode(); 
    126  
    127                                 if (local_root == NULL) 
    128                                 { 
    129                                         OUT1("Note: BranchGroup named \"start\" not found - using root node"); 
    130                                         local_root = root; 
    131                                 } 
    132  
    133                                 placer->SetLibrary(local_root); 
    134                                 BranchGroup *viz = placer->GetLibraryVisualization(); 
    135                                 mRenderArea->SetSceneRoot(viz); 
    136                                 mRenderArea->SetCamera(new Camera); 
    137                                 mRenderArea->GetCamera()->ViewAll(viz->getBoundingSphere()); 
    138                         } 
    139                 } 
    140         } else 
    141                 OUT1("Unknown placer command"); 
    14260} 
    143 */ 
    144  
    145 } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.h

    r2694 r2702  
    1  #ifndef OBJECTPLACER_H 
     1#ifndef OBJECTPLACER_H 
    22#define OBJECTPLACER_H 
    33 
     
    1515{ 
    1616public: 
    17         /** Default constructor taking a pointer to the currently used preprocessor. 
     17        /** Default constructor. 
    1818        */ 
    19 //      ObjectPlacer(Preprocessor *prep); 
    2019        ObjectPlacer(); 
    2120 
    22         /** Sets library objects. 
     21        virtual ~ObjectPlacer() {} 
     22 
     23        /** Adds a library objects. 
    2324        */ 
    24         void AddObject(SceneGraphLeaf *object); 
    25  
     25        void AddObject(SceneGraphLeaf *obj); 
    2626        /** Selects the next library object. 
    2727        */ 
     
    3333        */ 
    3434        void PlaceObject(const Vector3 &p); 
    35  
     35        /** Returns the currently active object. 
     36        */ 
    3637        SceneGraphLeaf *GetCurrentObject(); 
    37  
    38         virtual ~ObjectPlacer() {} 
    39  
    40         DynamicObjectsContainer &GetDynamicObjects() { return mDynamicObjects; } 
     38        /** Returns a ref to the object container. 
     39        */ 
     40        DynamicObjectsContainer &GetDynamicObjects() { return mLibraryObjects; } 
    4141 
    4242 
    4343protected: 
    4444 
    45         //Preprocessor *mPreprocessor; 
    46  
    47         DynamicObjectsContainer mDynamicObjects; 
    48                  
     45        DynamicObjectsContainer mLibraryObjects; 
    4946        int mCurrentObject; 
    5047 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp

    r2697 r2702  
    6363   GLuint names, *ptr; 
    6464 
    65    cout << "hits = %d" << endl;; 
     65   cout << "hits: " << hits << endl;; 
    6666   ptr = (GLuint *) buffer; 
    6767 
     
    7171           names = *ptr; 
    7272 
    73            printf (" number of names for hit = %d\n", names); ptr++; 
    74            printf("  z1 is %g;", (float) *ptr/0x7fffffff); ptr++; 
    75            printf(" z2 is %g\n", (float) *ptr/0x7fffffff); ptr++; 
    76            printf ("   the name is "); 
    77  
    78            for (j = 0; j < names; j++) {     /*  for each name */ 
     73           printf ("number of names for hit: %d\n", names); ptr ++; 
     74           printf("z1: %g;", (float) *ptr / 0x7fffffff); ptr ++; 
     75           printf("z2: %g\n", (float) *ptr / 0x7fffffff); ptr ++; 
     76           printf ("the name is "); 
     77 
     78           // for each name  
     79           for (j = 0; j < names; j++)  
    7980                   printf ("%d ", *ptr); ptr++; 
    80            } 
     81 
    8182           printf ("\n"); 
    8283   } 
     
    555556        glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices); 
    556557 
    557 #if DYNAMIC_OBJECTS_HACK 
    558558        // handle dynamic objects 
    559         DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicObjects.end(); 
    560  
    561         for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit) 
     559        DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicPvsObjects.end(); 
     560 
     561        for (dit = mDynamicPvsObjects.begin(); dit != dit_end; ++ dit) 
    562562        { 
    563563                _RenderDynamicObject(*dit); 
     
    565565 
    566566        // handle dynamic objects 
    567         dit, dit_end = mPendingDynamicObjects.end(); 
    568  
    569         for (dit = mPendingDynamicObjects.begin(); dit != dit_end; ++ dit) 
     567        Preprocessor *p = mViewCellsManager->GetPreprocessor(); 
     568        dit, dit_end = p->mDynamicObjects.end(); 
     569 
     570        for (dit = p->mDynamicObjects.begin(); dit != dit_end; ++ dit) 
    570571        { 
    571572                _RenderDynamicObject(*dit); 
     
    573574 
    574575        //_RenderDynamicObject(mPendingDynamicObject); 
    575 #endif 
    576576} 
    577577 
     
    586586        mPvsSize = pvs.GetSize(); 
    587587 
    588 #if DYNAMIC_OBJECTS_HACK 
    589         mDynamicObjects.clear(); 
    590 #endif 
     588        mDynamicPvsObjects.clear(); 
    591589 
    592590        ObjectPvsIterator it = pvs.GetIterator(); 
     
    604602                        } 
    605603                        break; 
    606 #if DYNAMIC_OBJECTS_HACK 
    607604 
    608605                case Intersectable::SCENEGRAPHLEAF_INTERSECTABLE: 
    609                         mDynamicObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem()); 
     606                        mDynamicPvsObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem()); 
    610607                        break; 
    611 #endif 
    612608                default: 
    613609                        cerr << "PreparePvs: type " << Intersectable::GetTypeName(obj) << " not handled yet" << endl; 
     
    807803 
    808804                        mPlacer->PlaceObject(pt); 
    809                         //mPendingDynamicObjects.push_back( mPlacer->GetCurrentObject()); 
     805                        SceneGraphLeaf *leaf = mPlacer->GetCurrentObject(); 
     806 
     807                        // hack: should just pass a IntersectableGroup as a whole 
     808                        // instead we duplicate the object container and create a new 
     809                        // leaf 
     810                        SceneGraphLeaf *newObj = new SceneGraphLeaf(*leaf); 
     811 
     812                        mViewCellsManager->GetPreprocessor()->RegisterDynamicObject(newObj); 
     813                        //mPendingDynamicObjects.push_back(); 
    810814                } 
    811815        } 
     
    825829                const Vector3 pt = Unproject(x, y); 
    826830 
    827                 int num = FindDynamicObject(pt); 
    828                 cout << "\n*****************\n" << "here4" << num << endl; 
    829                 //processHits(buf); 
    830  
     831                int idx = FindDynamicObject(x, y); 
     832                 
     833                Preprocessor *p = GetPreprocessor(); 
     834 
     835                swap(p->mDynamicObjects[idx], p->mDynamicObjects.back()); 
     836                p->mDynamicObjects.pop_back(); 
    831837                /*if (mCurrentDynamicObjectIdx >= 0) { 
    832838                preprocessor->ScheduleUpdateDynamicObjects(); 
     
    933939        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    934940 
    935         if (1)  
    936         { 
    937                 SetupCameraProjection(width(), height()); 
    938                 SetupCamera(); 
    939  
    940                 if (mRenderErrors)  
    941                 { 
    942                         RenderErrors(); 
    943                 }  
    944                 else  
    945                 { 
    946                         glColor3f(0.6f, 0.6f, 0.6f); 
    947                         VisualizePvs(); 
    948                 } 
    949  
    950                 if (mShowRays)  
    951                 { 
    952                         RenderRays(mViewCellsManager->mVizBuffer.GetRays(), mRayVisualizationMethod, mShowDistribution, 1); 
    953                 } 
    954         } 
    955  
     941        SetupCameraProjection(width(), height()); 
     942        SetupCamera(); 
     943 
     944        if (mRenderErrors)  
     945                RenderErrors(); 
     946        else  
     947        { 
     948                glColor3f(0.6f, 0.6f, 0.6f); 
     949                VisualizePvs(); 
     950        } 
     951 
     952        if (mShowRays)  
     953                RenderRays(mViewCellsManager->mVizBuffer.GetRays(), mRayVisualizationMethod, mShowDistribution, 1); 
     954         
    956955        RenderInfo(); 
    957         mFrame ++; 
     956 
     957        ++ mFrame; 
    958958        //      cout<<"vp="<<mViewPoint<<" vd="<<mViewDirection<<endl; 
    959959} 
     
    23672367        vbox->layout()->addWidget(button); 
    23682368        connect(button, SIGNAL(clicked()), SIGNAL(ComputeGVS())); 
    2369  
    2370 #else 
    2371          
     2369#endif 
     2370 
     2371#if 1    
    23722372        button = new QPushButton("Replay view points", vbox); 
    23732373        vbox->layout()->addWidget(button); 
     
    23762376#endif 
    23772377 
    2378 #if DYNAMIC_OBJECTS_HACK 
    2379  
    23802378        button = new QPushButton("Load object", vbox); 
    23812379        vbox->layout()->addWidget(button); 
    23822380        connect(button, SIGNAL(clicked()), SIGNAL(LoadObject())); 
    2383 #endif 
    23842381 
    23852382        /*cb = new QCheckBox("Stats", vbox); 
     
    26502647 
    26512648 
    2652 int QtGlRendererWidget::FindDynamicObject(const Vector3 &pos)  
     2649int QtGlRendererWidget::FindDynamicObject(float x, float y)  
    26532650{  
     2651        makeCurrent(); 
    26542652        // we need to lock the rendering context  
    26552653        //glw.lockGLContext();  
     
    26602658        // see below for an explanation on the buffer content  
    26612659        GLuint buffer[maxSize];  
    2662         GLint viewport[4]; 
    2663  
    2664         glGetIntegerv(GL_VIEWPORT, viewport);  
    26652660        glSelectBuffer(maxSize, buffer);  
    26662661         
     
    26732668        glPushMatrix();  
    26742669        glLoadIdentity();  
    2675         gluPickMatrix((GLdouble)pos.x, (GLdouble)(viewport[3] - pos.y), 5.0f, 5.0f, viewport);  
    2676          
    2677         GLfloat x = (GLfloat)width() / height();  
    2678         glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);  
    2679          
    2680          glLoadName(1); 
    2681  
    2682         _RenderDynamicObject(mPendingDynamicObjects[0]); 
     2670 
     2671        glViewport(0, 0, width(), height()); 
     2672 
     2673        GLint viewport[4]; 
     2674        glGetIntegerv(GL_VIEWPORT, viewport);  
     2675 
     2676        const float w = 1.0f; 
     2677 
     2678        //gluPickMatrix(x, y, 1000.0, 1000.0, viewport); 
     2679        gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), w, w, viewport);  
     2680 
     2681        GLfloat aspect = (GLfloat) width() / height();  
     2682        gluPerspective(70.0f, aspect, 0.1f, 2.0f * Magnitude(mSceneGraph->GetBox().Diagonal())); 
     2683         
     2684        glMatrixMode(GL_MODELVIEW); 
     2685        glPushMatrix();  
     2686        glLoadIdentity(); 
     2687        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     2688         
     2689         
     2690        SetupCamera(); 
     2691 
     2692        for (size_t i = 0; i < GetPreprocessor()->mDynamicObjects.size(); ++ i) 
     2693        { 
     2694                glLoadName(i); 
     2695                _RenderDynamicObject(GetPreprocessor()->mDynamicObjects[i]); 
     2696        } 
     2697 
     2698        glFlush(); 
     2699        glPopMatrix(); 
    26832700 
    26842701        glMatrixMode(GL_PROJECTION);  
    26852702        glPopMatrix(); 
    26862703 
     2704        //updateGL(); 
     2705 
     2706        int hits; 
    26872707        // finally release the rendering context again  
    2688         if (!glRenderMode(GL_RENDER))  
     2708        if ((hits = glRenderMode(GL_RENDER)) < 0)  
    26892709        {  
     2710                cout << "no object picked" << endl; 
    26902711                //glw.unlockGLContext();  
    26912712                return -1;  
    26922713        }  
     2714 
     2715 
     2716        //processHits(hits, buffer); 
     2717 
    26932718         
    26942719        //glw.unlockGLContext();  
     
    27032728        // (number of the surface).  
    27042729        // return the name of the clicked surface  
    2705          
    27062730        return buffer[3];  
    27072731} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h

    r2697 r2702  
    248248        ObjectPlacer *mPlacer; 
    249249 
    250 #if DYNAMIC_OBJECTS_HACK 
    251  
    252         DynamicObjectsContainer mPendingDynamicObjects; 
    253         DynamicObjectsContainer mDynamicObjects; 
    254  
    255 #endif 
     250        //DynamicObjectsContainer mPendingDynamicObjects; 
     251        DynamicObjectsContainer mDynamicPvsObjects; 
    256252 
    257253        QtGlRendererWidget(SceneGraph *sceneGraph, 
     
    329325        Vector3 Unproject(int x, int y); 
    330326         
    331         int FindDynamicObject(const Vector3 &pos); 
     327        int FindDynamicObject(float x, float y); 
    332328 
    333329 
Note: See TracChangeset for help on using the changeset viewer.