Ignore:
Timestamp:
05/21/08 18:44:16 (16 years ago)
Author:
mattausch
Message:

worked on moving objects

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

Legend:

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

    r2693 r2694  
    11#include "ObjectPlacer.h" 
     2#include "Matrix4x4.h" 
     3#include "SceneGraph.h" 
    24 
    3 namespace GtpVisibilityPreprocessor { 
     5 
     6 
     7namespace GtpVisibilityPreprocessor  
     8{ 
    49 
    510// --------------------------------------------------------------------------- 
    611//  ObjectPlacer implementation 
    712// --------------------------------------------------------------------------- 
    8 #if 0 
     13 
    914ObjectPlacer::ObjectPlacer() 
    10         :mCurrentLibaryObject(0), mPlacedNodes(new BranchGroup), mLibraryViz(new BranchGroup) 
     15: mCurrentObject(0) 
    1116{ 
    12         mLibraryViz->addChild(new BranchGroup); 
    13  
    14         BranchGroup *bg = new BranchGroup; 
    15         bg->addChild(new Box); 
    16         SetLibrary(bg); 
    1717} 
    1818 
    1919 
    20 void ObjectPlacer::SetLibrary(BranchGroup *library) 
     20void ObjectPlacer::AddObject(SceneGraphLeaf *obj) 
    2121{ 
    22         mLibrary = new BranchGroup; 
    23         if (!library) 
    24         { 
    25                 mLibrary->addChild(new Box); 
    26         } 
    27         else 
    28         { 
    29                 for (int i = 0; i < library->numChildren(); i ++) 
    30                 {        
    31                         Node *n = library->getChild(i); 
    32                         SharedGroup *s = new SharedGroup; 
    33                         s->addChild(n); 
    34                          
    35                         Link *l = new Link; 
    36                         l->setSharedGroup(s); 
    37                         mLibrary->addChild(l); 
    38                 } 
    39         } 
    40          
    41         UpdateLibraryViz(); 
    42 } 
    43  
    44 void ObjectPlacer::UpdateLibraryViz() 
    45 { 
    46         Link *l = new Link; 
    47         l->setSharedGroup(((Link *)mLibrary->getChild(mCurrentLibaryObject))->getSharedGroup()); 
    48  
    49         mLibraryViz->setChild(l, 0); 
     22        mDynamicObjects.push_back(obj); 
    5023} 
    5124 
     
    5326void ObjectPlacer::NextObject() 
    5427{ 
    55         if (mLibrary) 
    56                 mCurrentLibaryObject = (mCurrentLibaryObject + 1) % (mLibrary->numChildren()); 
    57         UpdateLibraryViz(); 
     28        mCurrentObject = (mCurrentObject + 1) % (int)mDynamicObjects.size(); 
    5829} 
     30 
    5931 
    6032void ObjectPlacer::PreviousObject() 
    6133{ 
    62         if (mLibrary) 
    63                 mCurrentLibaryObject = (mCurrentLibaryObject - 1) % (mLibrary->numChildren()); 
    64         UpdateLibraryViz(); 
    65 } 
    66  
    67 void ObjectPlacer::AddObject(const Point3f &p) 
    68 { 
    69         //BranchGroup *o = new BranchGroup; 
    70         TransformGroup *tg = new TransformGroup; 
    71         Transform3D t; 
    72         t.setTranslation(p - Origin3f); 
    73         tg->setTransform(t); 
    74         //o->addChild(tg); 
    75  
    76         Link *l = new Link; 
    77         l->setSharedGroup(((Link *)(mLibrary->getChild(mCurrentLibaryObject)))->getSharedGroup()); 
    78         tg->addChild(l); 
    79  
    80         mPlacedNodes->addChild(tg); 
    81 } 
    82  
    83 void ObjectPlacer::RemoveLastObject() 
    84 { 
    85         if (mPlacedNodes->numChildren() > 0) 
    86                 mPlacedNodes->removeChild(mPlacedNodes->numChildren()-1); 
    87 } 
    88  
    89 void ObjectPlacer::SaveObjects(const String &filename) 
    90 { 
    91         WriteActionIV wa(filename, ""); 
    92  
    93         wa.Apply(mPlacedNodes); 
    94 } 
    95  
    96 BranchGroup *ObjectPlacer::GetLibraryVisualization() 
    97 { 
    98         return mLibraryViz; 
    99 } 
    100  
    101 BranchGroup *ObjectPlacer::GetPlacedNodeVisualization() 
    102 { 
    103         return mPlacedNodes; 
    104 } 
    105  
    106 void ObjectPlacer::Clear() 
    107 { 
    108         mPlacedNodes->removeAllChildren();       
     34        mCurrentObject = (mCurrentObject - 1) % (int)mDynamicObjects.size(); 
    10935} 
    11036 
    11137 
    112 void TestApp::Placer(const String &parm) 
     38SceneGraphLeaf *ObjectPlacer::GetCurrentObject()  
     39{  
     40        if (mCurrentObject >= mDynamicObjects.size()) 
     41                return NULL; 
     42 
     43        return mDynamicObjects[mCurrentObject]; 
     44} 
     45 
     46 
     47void ObjectPlacer::PlaceObject(const Vector3 &pt) 
     48{ 
     49        Vector3 p = pt; 
     50 
     51        SceneGraphLeaf *obj = mDynamicObjects[mCurrentObject]; 
     52 
     53        // set pivot to ground of object 
     54        p.y -= obj->GetOriginalBox().Min().y; 
     55        Matrix4x4 trafo = TranslationMatrix(p); 
     56 
     57        obj->LoadTransform(trafo); 
     58} 
     59 
     60 
     61/*void TestApp::Placer(const String &parm) 
    11362{ 
    11463        if (parm.Empty()) 
     
    191140        } else 
    192141                OUT1("Unknown placer command"); 
     142} 
     143*/ 
    193144 
    194145} 
    195  
    196 #endif 
    197  
    198 } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.h

    r2693 r2694  
    11 #ifndef OBJECTPLACER_H 
    22#define OBJECTPLACER_H 
     3 
     4#include "Containers.h" 
    35 
    46namespace GtpVisibilityPreprocessor { 
    57 
    68class Vector3; 
     9class Preprocessor; 
    710 
    811 
     
    1215{ 
    1316public: 
     17        /** Default constructor taking a pointer to the currently used preprocessor. 
     18        */ 
     19//      ObjectPlacer(Preprocessor *prep); 
    1420        ObjectPlacer(); 
    1521 
    16         /// sets library objects 
    17         //void SetLibrary(BranchGroup *library); 
    18         /// selects the next library object 
     22        /** Sets library objects. 
     23        */ 
     24        void AddObject(SceneGraphLeaf *object); 
     25 
     26        /** Selects the next library object. 
     27        */ 
    1928        void NextObject(); 
    20         /// selects the previous library object 
     29        /** Selects the previous library object. 
     30        */ 
    2131        void PreviousObject(); 
    22         /// adds an object at the indicated position 
    23         void AddObject(const Vector3 &p); 
    24         /// remove the last added object 
    25         void RemoveLastObject(); 
     32        /** Adds an object at the indicated position. 
     33        */ 
     34        void PlaceObject(const Vector3 &p); 
    2635 
    27         /// Clear all objects 
    28         void Clear(); 
     36        SceneGraphLeaf *GetCurrentObject(); 
    2937 
    30         /// Save the objects 
    31         /*void SaveObjects(const std::string &filename); 
    32  
    33         /// Get a node to visualize from the library 
    34         BranchGroup *GetLibraryVisualization(); 
    35  
    36         /// Get the nodes that have already been placed 
    37         BranchGroup *GetPlacedNodeVisualization(); 
    38  
    39 */       
    4038        virtual ~ObjectPlacer() {} 
    4139 
     40        DynamicObjectsContainer &GetDynamicObjects() { return mDynamicObjects; } 
     41 
     42 
    4243protected: 
    43         /*SceneBasePtr<BranchGroup> mLibrary; 
    44         SceneBasePtr<BranchGroup> mPlacedNodes; 
    45         SceneBasePtr<BranchGroup> mLibraryViz; 
    46         int mCurrentLibaryObject; 
    4744 
    48         /// Get a link to an object in the library 
    49         void UpdateLibraryViz(); 
    50 */ 
     45        //Preprocessor *mPreprocessor; 
     46 
     47        DynamicObjectsContainer mDynamicObjects; 
     48                 
     49        int mCurrentObject; 
     50 
    5151}; 
    5252 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp

    r2693 r2694  
    1818#include "LogWriter.h" 
    1919#include "RayCaster.h" 
     20#include "ObjectPlacer.h" 
    2021 
    2122 
     
    271272        if (pixelCount > pixelThres)  
    272273        { 
    273                 cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << " vp: " << mViewPoint << endl; 
     274                cout << "f " << mFrame << " id " << viewcell->GetId() << " pvs " << pvsSize << " e " << pixelCount << " vp " << mViewPoint << " vd " << mViewDirection << endl; 
    274275         
    275276                if (mSnapErrorFrames)  
     
    510511                _RenderDynamicObject(*dit); 
    511512        } 
     513 
     514        if (mPendingDynamicObject) 
     515                _RenderDynamicObject(mPendingDynamicObject); 
    512516#endif 
    513517} 
     
    736740        mousePoint.y = y; 
    737741 
    738 } 
     742        if (e->button() == Qt::RightButton) 
     743        { 
     744                if (mPlacer->GetCurrentObject()) 
     745                { 
     746                        Vector3 pt = Unproject(x, y); 
     747                        cout << "unproject: " << pt << endl; 
     748 
     749                        mPlacer->PlaceObject(pt); 
     750                        mPendingDynamicObject = mPlacer->GetCurrentObject(); 
     751                } 
     752        } 
     753} 
     754 
    739755 
    740756void QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *e) 
     
    10471063 
    10481064        mRenderError = 0.0f; 
     1065 
    10491066        mShowRays = false; 
    1050  
    10511067        mReplayMode = false; 
     1068 
     1069        mPlacer = new ObjectPlacer(); 
     1070 
     1071        mPendingDynamicObject = NULL; 
    10521072 
    10531073        SetSceneCut(1000); 
     
    11831203        ++ mCurrentDynamicObjectIdx; 
    11841204 
    1185         if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename)) { 
    1186            
    1187           cout << "Loading finished" << endl; 
    1188         } else 
    1189           cerr << "Loading failed" << endl; 
     1205        SceneGraphLeaf *leaf =  
     1206                mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename); 
     1207 
     1208        if (leaf) 
     1209        { 
     1210                mPlacer->AddObject(leaf); 
     1211                cout << "Loading finished" << endl; 
     1212        } 
     1213        else 
     1214                cerr << "Loading failed" << endl; 
    11901215         
    11911216    updateGL(); 
    11921217} 
     1218 
    11931219 
    11941220void 
     
    25242550{ 
    25252551        // swap y coordinate 
    2526         //y = GetHeight() - y; 
     2552        y = GetHeight() - y; 
    25272553 
    25282554        // HACK: should come from camera! 
     
    25342560        const int viewport[4] = {0,0, GetWidth(), GetHeight()}; 
    25352561 
     2562        RenderScene(); 
     2563 
    25362564        float z; 
    25372565        glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); 
    2538  
    2539         RenderScene(); 
    2540  
     2566         
    25412567        GLdouble rx, ry, rz; 
    25422568        gluUnProject(x, y, z, modelview, projection, viewport, &rx, &ry, &rz); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h

    r2693 r2694  
    3939class OcclusionQuery; 
    4040class TransformedMeshInstance; 
     41class ObjectPlacer; 
    4142 
    4243 
     
    221222        float mTransferFunction; 
    222223 
    223  
    224224        Vector3 mDummyViewPoint; 
    225225 
     
    242242        int mReplayTimerId; 
    243243 
     244        ObjectPlacer *mPlacer; 
     245 
    244246#if DYNAMIC_OBJECTS_HACK 
     247         
     248        SceneGraphLeaf *mPendingDynamicObject; 
     249 
    245250        DynamicObjectsContainer mDynamicObjects; 
    246251#endif 
     
    254259 
    255260        QtGlRendererWidget() {}; 
     261 
     262        ~QtGlRendererWidget() { delete mPlacer; } 
    256263 
    257264        void SetThread(QtPreprocessorThread *t) 
Note: See TracChangeset for help on using the changeset viewer.