Changeset 2694 for GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface
- Timestamp:
- 05/21/08 18:44:16 (17 years ago)
- 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 1 1 #include "ObjectPlacer.h" 2 #include "Matrix4x4.h" 3 #include "SceneGraph.h" 2 4 3 namespace GtpVisibilityPreprocessor { 5 6 7 namespace GtpVisibilityPreprocessor 8 { 4 9 5 10 // --------------------------------------------------------------------------- 6 11 // ObjectPlacer implementation 7 12 // --------------------------------------------------------------------------- 8 #if 0 13 9 14 ObjectPlacer::ObjectPlacer() 10 :mCurrentLibaryObject(0), mPlacedNodes(new BranchGroup), mLibraryViz(new BranchGroup)15 : mCurrentObject(0) 11 16 { 12 mLibraryViz->addChild(new BranchGroup);13 14 BranchGroup *bg = new BranchGroup;15 bg->addChild(new Box);16 SetLibrary(bg);17 17 } 18 18 19 19 20 void ObjectPlacer:: SetLibrary(BranchGroup *library)20 void ObjectPlacer::AddObject(SceneGraphLeaf *obj) 21 21 { 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); 50 23 } 51 24 … … 53 26 void ObjectPlacer::NextObject() 54 27 { 55 if (mLibrary) 56 mCurrentLibaryObject = (mCurrentLibaryObject + 1) % (mLibrary->numChildren()); 57 UpdateLibraryViz(); 28 mCurrentObject = (mCurrentObject + 1) % (int)mDynamicObjects.size(); 58 29 } 30 59 31 60 32 void ObjectPlacer::PreviousObject() 61 33 { 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(); 109 35 } 110 36 111 37 112 void TestApp::Placer(const String &parm) 38 SceneGraphLeaf *ObjectPlacer::GetCurrentObject() 39 { 40 if (mCurrentObject >= mDynamicObjects.size()) 41 return NULL; 42 43 return mDynamicObjects[mCurrentObject]; 44 } 45 46 47 void 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) 113 62 { 114 63 if (parm.Empty()) … … 191 140 } else 192 141 OUT1("Unknown placer command"); 142 } 143 */ 193 144 194 145 } 195 196 #endif197 198 } -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.h
r2693 r2694 1 1 #ifndef OBJECTPLACER_H 2 2 #define OBJECTPLACER_H 3 4 #include "Containers.h" 3 5 4 6 namespace GtpVisibilityPreprocessor { 5 7 6 8 class Vector3; 9 class Preprocessor; 7 10 8 11 … … 12 15 { 13 16 public: 17 /** Default constructor taking a pointer to the currently used preprocessor. 18 */ 19 // ObjectPlacer(Preprocessor *prep); 14 20 ObjectPlacer(); 15 21 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 */ 19 28 void NextObject(); 20 /// selects the previous library object 29 /** Selects the previous library object. 30 */ 21 31 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); 26 35 27 /// Clear all objects 28 void Clear(); 36 SceneGraphLeaf *GetCurrentObject(); 29 37 30 /// Save the objects31 /*void SaveObjects(const std::string &filename);32 33 /// Get a node to visualize from the library34 BranchGroup *GetLibraryVisualization();35 36 /// Get the nodes that have already been placed37 BranchGroup *GetPlacedNodeVisualization();38 39 */40 38 virtual ~ObjectPlacer() {} 41 39 40 DynamicObjectsContainer &GetDynamicObjects() { return mDynamicObjects; } 41 42 42 43 protected: 43 /*SceneBasePtr<BranchGroup> mLibrary;44 SceneBasePtr<BranchGroup> mPlacedNodes;45 SceneBasePtr<BranchGroup> mLibraryViz;46 int mCurrentLibaryObject;47 44 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 51 51 }; 52 52 -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
r2693 r2694 18 18 #include "LogWriter.h" 19 19 #include "RayCaster.h" 20 #include "ObjectPlacer.h" 20 21 21 22 … … 271 272 if (pixelCount > pixelThres) 272 273 { 273 cout << "f rame " << 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; 274 275 275 276 if (mSnapErrorFrames) … … 510 511 _RenderDynamicObject(*dit); 511 512 } 513 514 if (mPendingDynamicObject) 515 _RenderDynamicObject(mPendingDynamicObject); 512 516 #endif 513 517 } … … 736 740 mousePoint.y = y; 737 741 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 739 755 740 756 void QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *e) … … 1047 1063 1048 1064 mRenderError = 0.0f; 1065 1049 1066 mShowRays = false; 1050 1051 1067 mReplayMode = false; 1068 1069 mPlacer = new ObjectPlacer(); 1070 1071 mPendingDynamicObject = NULL; 1052 1072 1053 1073 SetSceneCut(1000); … … 1183 1203 ++ mCurrentDynamicObjectIdx; 1184 1204 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; 1190 1215 1191 1216 updateGL(); 1192 1217 } 1218 1193 1219 1194 1220 void … … 2524 2550 { 2525 2551 // swap y coordinate 2526 //y = GetHeight() - y;2552 y = GetHeight() - y; 2527 2553 2528 2554 // HACK: should come from camera! … … 2534 2560 const int viewport[4] = {0,0, GetWidth(), GetHeight()}; 2535 2561 2562 RenderScene(); 2563 2536 2564 float z; 2537 2565 glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); 2538 2539 RenderScene(); 2540 2566 2541 2567 GLdouble rx, ry, rz; 2542 2568 gluUnProject(x, y, z, modelview, projection, viewport, &rx, &ry, &rz); -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
r2693 r2694 39 39 class OcclusionQuery; 40 40 class TransformedMeshInstance; 41 class ObjectPlacer; 41 42 42 43 … … 221 222 float mTransferFunction; 222 223 223 224 224 Vector3 mDummyViewPoint; 225 225 … … 242 242 int mReplayTimerId; 243 243 244 ObjectPlacer *mPlacer; 245 244 246 #if DYNAMIC_OBJECTS_HACK 247 248 SceneGraphLeaf *mPendingDynamicObject; 249 245 250 DynamicObjectsContainer mDynamicObjects; 246 251 #endif … … 254 259 255 260 QtGlRendererWidget() {}; 261 262 ~QtGlRendererWidget() { delete mPlacer; } 256 263 257 264 void SetThread(QtPreprocessorThread *t)
Note: See TracChangeset
for help on using the changeset viewer.