Developer Documentation
RenderPickingPlugin.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 #include "RenderPickingPlugin.hh"
45 
48 
49 #include <QGLFormat>
50 #include <QMenu>
51 
52 #include <QtWidgets>
53 
54 void RenderPickingPlugin::initializePlugin()
55 {
56  pickRendererMode_ = ACG::SceneGraph::PICK_ANYTHING;
57 }
58 
60 
61  QMenu* menu = new QMenu("Picking Renderer Target");
62 
63  // Recreate actionGroup
64  QActionGroup* pickingTargetsGroup = new QActionGroup( this );
65  pickingTargetsGroup->setExclusive( true );
66 
67  // Always set PickAnything ( will be overridden by others)
68  QAction * action = new QAction("PICK_ANYTHING" , pickingTargetsGroup );
69  action->setCheckable( true );
70  action->setChecked(true);
71 
72  action = new QAction("PICK_VERTEX" , pickingTargetsGroup );
73  action->setCheckable( true );
74  if (pickRendererMode_ == ACG::SceneGraph::PICK_VERTEX)
75  action->setChecked(true);
76 
77  action = new QAction("PICK_EDGE" , pickingTargetsGroup );
78  action->setCheckable( true );
79  if (pickRendererMode_ == ACG::SceneGraph::PICK_EDGE)
80  action->setChecked(true);
81 
82  action = new QAction("PICK_SPLINE" , pickingTargetsGroup );
83  action->setCheckable( true );
84  if (pickRendererMode_ == ACG::SceneGraph::PICK_SPLINE)
85  action->setChecked(true);
86 
87  action = new QAction("PICK_FACE" , pickingTargetsGroup );
88  action->setCheckable( true );
89  if (pickRendererMode_ == ACG::SceneGraph::PICK_FACE)
90  action->setChecked(true);
91 
92  action = new QAction("PICK_FRONT_VERTEX" , pickingTargetsGroup );
93  action->setCheckable( true );
94  if (pickRendererMode_ == ACG::SceneGraph::PICK_FRONT_VERTEX)
95  action->setChecked(true);
96 
97  action = new QAction("PICK_FRONT_EDGE" , pickingTargetsGroup );
98  action->setCheckable( true );
99  if (pickRendererMode_ == ACG::SceneGraph::PICK_FRONT_EDGE)
100  action->setChecked(true);
101 
102  action = new QAction("PICK_CELL" , pickingTargetsGroup );
103  action->setCheckable( true );
104  if (pickRendererMode_ == ACG::SceneGraph::PICK_CELL)
105  action->setChecked(true);
106 
107  menu->addActions(pickingTargetsGroup->actions());
108 
109  connect(pickingTargetsGroup,SIGNAL(triggered( QAction * )),this,SLOT(slotPickTargetChanged( QAction * )));
110 
111  return menu->menuAction();
112 }
113 
114 void RenderPickingPlugin::slotPickTargetChanged( QAction * _action) {
115 
116  // Prepare Picking Debugger Flag
117  if ( _action->text() == "PICK_ANYTHING") {
118  pickRendererMode_ = ACG::SceneGraph::PICK_ANYTHING;
119  } else if ( _action->text() == "PICK_VERTEX") {
120  pickRendererMode_ = ACG::SceneGraph::PICK_VERTEX;
121  } else if ( _action->text() == "PICK_EDGE") {
122  pickRendererMode_ = ACG::SceneGraph::PICK_EDGE;
123  } else if ( _action->text() == "PICK_SPLINE") {
124  pickRendererMode_ = ACG::SceneGraph::PICK_SPLINE;
125  } else if ( _action->text() == "PICK_FACE") {
126  pickRendererMode_ = ACG::SceneGraph::PICK_FACE;
127  } else if ( _action->text() == "PICK_FRONT_VERTEX") {
128  pickRendererMode_ = ACG::SceneGraph::PICK_FRONT_VERTEX;
129  } else if ( _action->text() == "PICK_FRONT_EDGE") {
130  pickRendererMode_ = ACG::SceneGraph::PICK_FRONT_EDGE;
131  } else if ( _action->text() == "PICK_CELL") {
132  pickRendererMode_ = ACG::SceneGraph::PICK_CELL;
133  } else {
134  std::cerr << "Error : optionHandling unable to find pick mode!!! " << _action->text().toStdString() << std::endl;
135  pickRendererMode_ = ACG::SceneGraph::PICK_ANYTHING;
136  }
137 
138 }
139 
140 QString RenderPickingPlugin::rendererName() {
141  return QString("Picking renderer");
142 }
143 
144 void RenderPickingPlugin::supportedDrawModes(ACG::SceneGraph::DrawModes::DrawMode& _mode) {
146 }
147 
148 
149 void RenderPickingPlugin::render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties) {
150 
151  //store and restore blend state ... no idea if this is actually necessary
152  bool blendState = _glState->blending();
153  if(_glState->compatibilityProfile())
154  {
155  ACG::GLState::disable(GL_LIGHTING);
156  }
157  glClear(GL_DEPTH_BUFFER_BIT);
158 
159  // do the picking
160  _glState->pick_init (true);
161  ACG::SceneGraph::PickAction action(*_glState, pickRendererMode_, _properties.drawMode());
162  _glState->enable(GL_DEPTH_TEST);
164 
165  if(_glState->compatibilityProfile())
166  {
167  ACG::GLState::enable(GL_LIGHTING);
168  }
169  if(!blendState)
170  ACG::GLState::disable(GL_BLEND);
171 
172 }
173 
174 QString RenderPickingPlugin::checkOpenGL() {
175  if (!ACG::openGLVersion(2, 0))
176  return QString("Insufficient OpenGL Version! OpenGL 2.0 or higher required");
177 
178  return QString("");
179 }
180 
181 
182 
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
Definition: GLState.cc:1507
picks edges (may not be implemented for all nodes)
Definition: PickTarget.hh:80
picks faces (should be implemented for all nodes)
Definition: PickTarget.hh:78
void pick_init(bool _color)
initialize name/color picking stack (like glInitNames())
Definition: GLState.cc:1043
picks only visible front verices (may not be implemented for all nodes)
Definition: PickTarget.hh:89
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
QAction * optionsAction()
Return options menu.
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
Definition: SceneGraph.hh:254
DrawMode DEFAULT
use the default (global) draw mode and not the node&#39;s own.
Definition: DrawModes.cc:72
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
Definition: GLState.cc:1527
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
picks verices (may not be implemented for all nodes)
Definition: PickTarget.hh:82
picks only visible front edges (may not be implemented for all nodes)
Definition: PickTarget.hh:87
bool openGLVersion(const int _major, const int _minor, bool _verbose)
Definition: gl.cc:129
picks faces (may not be implemented for all nodes)
Definition: PickTarget.hh:76
Pick spline curve or surface (picks u or u,v coords respectively)
Definition: PickTarget.hh:92
bool blending()
get whether transparenet or solid objects should be drawn
Definition: GLState.hh:1060