Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 #include "RenderPickingPlugin.hh"
51
52 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
53 #include <OpenFlipper/common/GlobalOptions.hh>
54
55 #include <QGLFormat>
56 #include <QMenu>
57
58 #if QT_VERSION >= 0x050000
59 #include <QtWidgets>
60 #else
61 #include <QtGui>
62 #endif
63
64 void RenderPickingPlugin::initializePlugin()
65 {
66 pickRendererMode_ = ACG::SceneGraph::PICK_ANYTHING;
67 }
68
69 QAction* RenderPickingPlugin::optionsAction() {
70
71 QMenu* menu = new QMenu("Picking Renderer Target");
72
73 // Recreate actionGroup
74 QActionGroup* pickingTargetsGroup = new QActionGroup( this );
75 pickingTargetsGroup->setExclusive( true );
76
77 // Always set PickAnything ( will be overridden by others)
78 QAction * action = new QAction("PICK_ANYTHING" , pickingTargetsGroup );
79 action->setCheckable( true );
80 action->setChecked(true);
81
82 action = new QAction("PICK_VERTEX" , pickingTargetsGroup );
83 action->setCheckable( true );
84 if (pickRendererMode_ == ACG::SceneGraph::PICK_VERTEX)
85 action->setChecked(true);
86
87 action = new QAction("PICK_EDGE" , pickingTargetsGroup );
88 action->setCheckable( true );
89 if (pickRendererMode_ == ACG::SceneGraph::PICK_EDGE)
90 action->setChecked(true);
91
92 action = new QAction("PICK_SPLINE" , pickingTargetsGroup );
93 action->setCheckable( true );
94 if (pickRendererMode_ == ACG::SceneGraph::PICK_SPLINE)
95 action->setChecked(true);
96
97 action = new QAction("PICK_FACE" , pickingTargetsGroup );
98 action->setCheckable( true );
99 if (pickRendererMode_ == ACG::SceneGraph::PICK_FACE)
100 action->setChecked(true);
101
102 action = new QAction("PICK_FRONT_VERTEX" , pickingTargetsGroup );
103 action->setCheckable( true );
104 if (pickRendererMode_ == ACG::SceneGraph::PICK_FRONT_VERTEX)
105 action->setChecked(true);
106
107 action = new QAction("PICK_FRONT_EDGE" , pickingTargetsGroup );
108 action->setCheckable( true );
109 if (pickRendererMode_ == ACG::SceneGraph::PICK_FRONT_EDGE)
110 action->setChecked(true);
111
112 action = new QAction("PICK_CELL" , pickingTargetsGroup );
113 action->setCheckable( true );
114 if (pickRendererMode_ == ACG::SceneGraph::PICK_CELL)
115 action->setChecked(true);
116
117 menu->addActions(pickingTargetsGroup->actions());
118
119 connect(pickingTargetsGroup,SIGNAL(triggered( QAction * )),this,SLOT(slotPickTargetChanged( QAction * )));
120
121 return menu->menuAction();
122 }
123
124 void RenderPickingPlugin::slotPickTargetChanged( QAction * _action) {
125
126 // Prepare Picking Debugger Flag
127 if ( _action->text() == "PICK_ANYTHING") {
128 pickRendererMode_ = ACG::SceneGraph::PICK_ANYTHING;
129 } else if ( _action->text() == "PICK_VERTEX") {
130 pickRendererMode_ = ACG::SceneGraph::PICK_VERTEX;
131 } else if ( _action->text() == "PICK_EDGE") {
132 pickRendererMode_ = ACG::SceneGraph::PICK_EDGE;
133 } else if ( _action->text() == "PICK_SPLINE") {
134 pickRendererMode_ = ACG::SceneGraph::PICK_SPLINE;
135 } else if ( _action->text() == "PICK_FACE") {
136 pickRendererMode_ = ACG::SceneGraph::PICK_FACE;
137 } else if ( _action->text() == "PICK_FRONT_VERTEX") {
138 pickRendererMode_ = ACG::SceneGraph::PICK_FRONT_VERTEX;
139 } else if ( _action->text() == "PICK_FRONT_EDGE") {
140 pickRendererMode_ = ACG::SceneGraph::PICK_FRONT_EDGE;
141 } else if ( _action->text() == "PICK_CELL") {
142 pickRendererMode_ = ACG::SceneGraph::PICK_CELL;
143 } else {
144 std::cerr << "Error : optionHandling unable to find pick mode!!! " << _action->text().toStdString() << std::endl;
145 pickRendererMode_ = ACG::SceneGraph::PICK_ANYTHING;
146 }
147
148 }
149
150 QString RenderPickingPlugin::rendererName() {
151 return QString("Picking renderer");
152 }
153
154 void RenderPickingPlugin::supportedDrawModes(ACG::SceneGraph::DrawModes::DrawMode& _mode) {
155 _mode = ACG::SceneGraph::DrawModes::DEFAULT;
156 }
157
158
159 void RenderPickingPlugin::render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties) {
160
161 ACG::GLState::disable(GL_LIGHTING);
162 ACG::GLState::disable(GL_BLEND);
163 glClear(GL_DEPTH_BUFFER_BIT);
164
165 // do the picking
166 _glState->pick_init (true);
167 ACG::SceneGraph::PickAction action(*_glState, pickRendererMode_, _properties.drawMode());
168 ACG::SceneGraph::traverse_multipass( PluginFunctions::getSceneGraphRootNode() , action,*_glState);
169
170 ACG::GLState::enable(GL_LIGHTING);
171 ACG::GLState::enable(GL_BLEND);
172
173 }
174
175 QString RenderPickingPlugin::checkOpenGL() {
176 if (!ACG::openGLVersion(2, 0))
177 return QString("Insufficient OpenGL Version! OpenGL 2.0 or higher required");
178
179 return QString("");
180 }
181
182
183 #if QT_VERSION < 0x050000
184 Q_EXPORT_PLUGIN2( renderpickingplugin , RenderPickingPlugin );
185 #endif
186
ACG::SceneGraph::PICK_SPLINE
Pick spline curve or surface (picks u or u,v coords respectively)
Definition: BaseNode.hh:118
Viewer::ViewerProperties
Definition: ViewerProperties.hh:119
ACG::GLState::enable
static void enable(GLenum _cap)
replaces glEnable, but supports locking
Definition: GLState.cc:1490
ACG::SceneGraph::PickAction
Definition: SceneGraph.hh:752
ACG::SceneGraph::DrawModes::DEFAULT
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
Definition: DrawModes.cc:78
ACG::SceneGraph::PICK_FACE
picks faces (should be implemented for all nodes)
Definition: BaseNode.hh:104
ACG::SceneGraph::PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
Viewer::ViewerProperties::drawMode
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
Definition: ViewerProperties.cc:162
ACG::openGLVersion
bool openGLVersion(const int _major, const int _minor)
Definition: gl.cc:95
ACG::SceneGraph::traverse_multipass
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
Definition: SceneGraph.hh:260
PluginFunctions::getSceneGraphRootNode
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
Definition: PluginFunctions.cc:961
ACG::GLState
Definition: GLState.hh:220
RenderPickingPlugin::optionsAction
QAction * optionsAction()
Return options menu.
Definition: RenderPickingPlugin.cc:69
ACG::SceneGraph::PICK_VERTEX
picks verices (may not be implemented for all nodes)
Definition: BaseNode.hh:108
ACG::SceneGraph::PICK_EDGE
picks edges (may not be implemented for all nodes)
Definition: BaseNode.hh:106
ACG::SceneGraph::PICK_FRONT_VERTEX
picks only visible front verices (may not be implemented for all nodes)
Definition: BaseNode.hh:115
ACG::SceneGraph::DrawModes::DrawMode
Specifies a DrawMode.
Definition: DrawModes.hh:294
RenderPickingPlugin
Definition: RenderPickingPlugin.hh:58
ACG::GLState::pick_init
void pick_init(bool _color)
initialize name/color picking stack (like glInitNames())
Definition: GLState.cc:1039
GlobalOptions.hh
ACG::SceneGraph::PICK_CELL
picks faces (may not be implemented for all nodes)
Definition: BaseNode.hh:102
ACG::GLState::disable
static void disable(GLenum _cap)
replaces glDisable, but supports locking
Definition: GLState.cc:1504
PluginFunctions.hh
ACG::SceneGraph::PICK_FRONT_EDGE
picks only visible front edges (may not be implemented for all nodes)
Definition: BaseNode.hh:113