Changeset 2702 for GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface
- Timestamp:
- 05/23/08 17:47:22 (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
r2694 r2702 20 20 void ObjectPlacer::AddObject(SceneGraphLeaf *obj) 21 21 { 22 m DynamicObjects.push_back(obj);22 mLibraryObjects.push_back(obj); 23 23 } 24 24 … … 26 26 void ObjectPlacer::NextObject() 27 27 { 28 mCurrentObject = (mCurrentObject + 1) % (int)m DynamicObjects.size();28 mCurrentObject = (mCurrentObject + 1) % (int)mLibraryObjects.size(); 29 29 } 30 30 … … 32 32 void ObjectPlacer::PreviousObject() 33 33 { 34 mCurrentObject = (mCurrentObject - 1) % (int)m DynamicObjects.size();34 mCurrentObject = (mCurrentObject - 1) % (int)mLibraryObjects.size(); 35 35 } 36 36 … … 38 38 SceneGraphLeaf *ObjectPlacer::GetCurrentObject() 39 39 { 40 if (mCurrentObject >= m DynamicObjects.size())40 if (mCurrentObject >= mLibraryObjects.size()) 41 41 return NULL; 42 42 43 return m DynamicObjects[mCurrentObject];43 return mLibraryObjects[mCurrentObject]; 44 44 } 45 45 … … 49 49 Vector3 p = pt; 50 50 51 SceneGraphLeaf *obj = m DynamicObjects[mCurrentObject];51 SceneGraphLeaf *obj = mLibraryObjects[mCurrentObject]; 52 52 53 53 // set pivot to ground of object … … 58 58 } 59 59 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 viewer75 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 else97 {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 } else141 OUT1("Unknown placer command");142 60 } 143 */144 145 } -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.h
r2694 r2702 1 1 #ifndef OBJECTPLACER_H 2 2 #define OBJECTPLACER_H 3 3 … … 15 15 { 16 16 public: 17 /** Default constructor taking a pointer to the currently used preprocessor.17 /** Default constructor. 18 18 */ 19 // ObjectPlacer(Preprocessor *prep);20 19 ObjectPlacer(); 21 20 22 /** Sets library objects. 21 virtual ~ObjectPlacer() {} 22 23 /** Adds a library objects. 23 24 */ 24 void AddObject(SceneGraphLeaf *object); 25 25 void AddObject(SceneGraphLeaf *obj); 26 26 /** Selects the next library object. 27 27 */ … … 33 33 */ 34 34 void PlaceObject(const Vector3 &p); 35 35 /** Returns the currently active object. 36 */ 36 37 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; } 41 41 42 42 43 43 protected: 44 44 45 //Preprocessor *mPreprocessor; 46 47 DynamicObjectsContainer mDynamicObjects; 48 45 DynamicObjectsContainer mLibraryObjects; 49 46 int mCurrentObject; 50 47 -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
r2697 r2702 63 63 GLuint names, *ptr; 64 64 65 cout << "hits = %d"<< endl;;65 cout << "hits: " << hits << endl;; 66 66 ptr = (GLuint *) buffer; 67 67 … … 71 71 names = *ptr; 72 72 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++) 79 80 printf ("%d ", *ptr); ptr++; 80 } 81 81 82 printf ("\n"); 82 83 } … … 555 556 glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices); 556 557 557 #if DYNAMIC_OBJECTS_HACK558 558 // handle dynamic objects 559 DynamicObjectsContainer::const_iterator dit, dit_end = mDynamic Objects.end();560 561 for (dit = mDynamic Objects.begin(); dit != dit_end; ++ dit)559 DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicPvsObjects.end(); 560 561 for (dit = mDynamicPvsObjects.begin(); dit != dit_end; ++ dit) 562 562 { 563 563 _RenderDynamicObject(*dit); … … 565 565 566 566 // 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) 570 571 { 571 572 _RenderDynamicObject(*dit); … … 573 574 574 575 //_RenderDynamicObject(mPendingDynamicObject); 575 #endif576 576 } 577 577 … … 586 586 mPvsSize = pvs.GetSize(); 587 587 588 #if DYNAMIC_OBJECTS_HACK 589 mDynamicObjects.clear(); 590 #endif 588 mDynamicPvsObjects.clear(); 591 589 592 590 ObjectPvsIterator it = pvs.GetIterator(); … … 604 602 } 605 603 break; 606 #if DYNAMIC_OBJECTS_HACK607 604 608 605 case Intersectable::SCENEGRAPHLEAF_INTERSECTABLE: 609 mDynamic Objects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem());606 mDynamicPvsObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem()); 610 607 break; 611 #endif612 608 default: 613 609 cerr << "PreparePvs: type " << Intersectable::GetTypeName(obj) << " not handled yet" << endl; … … 807 803 808 804 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(); 810 814 } 811 815 } … … 825 829 const Vector3 pt = Unproject(x, y); 826 830 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(); 831 837 /*if (mCurrentDynamicObjectIdx >= 0) { 832 838 preprocessor->ScheduleUpdateDynamicObjects(); … … 933 939 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 934 940 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 956 955 RenderInfo(); 957 mFrame ++; 956 957 ++ mFrame; 958 958 // cout<<"vp="<<mViewPoint<<" vd="<<mViewDirection<<endl; 959 959 } … … 2367 2367 vbox->layout()->addWidget(button); 2368 2368 connect(button, SIGNAL(clicked()), SIGNAL(ComputeGVS())); 2369 2370 #else 2371 2369 #endif 2370 2371 #if 1 2372 2372 button = new QPushButton("Replay view points", vbox); 2373 2373 vbox->layout()->addWidget(button); … … 2376 2376 #endif 2377 2377 2378 #if DYNAMIC_OBJECTS_HACK2379 2380 2378 button = new QPushButton("Load object", vbox); 2381 2379 vbox->layout()->addWidget(button); 2382 2380 connect(button, SIGNAL(clicked()), SIGNAL(LoadObject())); 2383 #endif2384 2381 2385 2382 /*cb = new QCheckBox("Stats", vbox); … … 2650 2647 2651 2648 2652 int QtGlRendererWidget::FindDynamicObject( const Vector3 &pos)2649 int QtGlRendererWidget::FindDynamicObject(float x, float y) 2653 2650 { 2651 makeCurrent(); 2654 2652 // we need to lock the rendering context 2655 2653 //glw.lockGLContext(); … … 2660 2658 // see below for an explanation on the buffer content 2661 2659 GLuint buffer[maxSize]; 2662 GLint viewport[4];2663 2664 glGetIntegerv(GL_VIEWPORT, viewport);2665 2660 glSelectBuffer(maxSize, buffer); 2666 2661 … … 2673 2668 glPushMatrix(); 2674 2669 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(); 2683 2700 2684 2701 glMatrixMode(GL_PROJECTION); 2685 2702 glPopMatrix(); 2686 2703 2704 //updateGL(); 2705 2706 int hits; 2687 2707 // finally release the rendering context again 2688 if ( !glRenderMode(GL_RENDER))2708 if ((hits = glRenderMode(GL_RENDER)) < 0) 2689 2709 { 2710 cout << "no object picked" << endl; 2690 2711 //glw.unlockGLContext(); 2691 2712 return -1; 2692 2713 } 2714 2715 2716 //processHits(hits, buffer); 2717 2693 2718 2694 2719 //glw.unlockGLContext(); … … 2703 2728 // (number of the surface). 2704 2729 // return the name of the clicked surface 2705 2706 2730 return buffer[3]; 2707 2731 } -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
r2697 r2702 248 248 ObjectPlacer *mPlacer; 249 249 250 #if DYNAMIC_OBJECTS_HACK 251 252 DynamicObjectsContainer mPendingDynamicObjects; 253 DynamicObjectsContainer mDynamicObjects; 254 255 #endif 250 //DynamicObjectsContainer mPendingDynamicObjects; 251 DynamicObjectsContainer mDynamicPvsObjects; 256 252 257 253 QtGlRendererWidget(SceneGraph *sceneGraph, … … 329 325 Vector3 Unproject(int x, int y); 330 326 331 int FindDynamicObject( const Vector3 &pos);327 int FindDynamicObject(float x, float y); 332 328 333 329
Note: See TracChangeset
for help on using the changeset viewer.