Developer Documentation
StatusViewNodeT_impl.hh
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 //
45 // StatusViewNode: Combined rendering of multiple Status Nodes
46 //
47 //=============================================================================
48 
49 #ifndef STATUSVIEWNODE_C
50 #define STATUSVIEWNODE_C
51 
52 //== INCLUDES =================================================================
53 
54 #include "StatusViewNodeT.hh"
55 #include <ACG/Scenegraph/DrawModes.hh>
56 
57 namespace ACG
58 {
59 namespace SceneGraph
60 {
61 
62 
63 //== IMPLEMENTATION ==========================================================
64 
65 template<class MeshT>
66 StatusViewNodeT<MeshT>::StatusViewNodeT(
67  BaseNode* _parent,
68  const std::string& _name,
73  : BaseNode(_parent, _name),
74  statusNode_(_statusNode),
75  areaNode_(_areaNode),
76  handleNode_(_handleNode),
77  featureNode_(_featureNode),
78  statusNodeVis_(false),
79  areaNodeVis_(false),
80  handleNodeVis_(false),
81  featureNodeVis_(false)
82 {
83 }
84 
85 //----------------------------------------------------------------------------
86 
87 template <class MeshT>
88 void StatusViewNodeT<MeshT>::draw( GLState& _state, const DrawModes::DrawMode& _drawMode )
89 {
90  // extract all layers from drawmode
91 
92  DrawModes::DrawMode singleLayers[4]; // polygon, edge, halfedge, point
93 
94  // remove default property layer
95  for (int i = 0; i < 4; ++i)
96  singleLayers[i].removeLayer(0u);
97 
98  for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i)
99  {
100  const DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
101 
102  switch (props->primitive())
103  {
104  case DrawModes::PRIMITIVE_POLYGON: singleLayers[0].setDrawModeProperties(props); break;
105  case DrawModes::PRIMITIVE_EDGE: singleLayers[1].setDrawModeProperties(props); break;
106  case DrawModes::PRIMITIVE_HALFEDGE: singleLayers[2].setDrawModeProperties(props); break;
107  case DrawModes::PRIMITIVE_POINT: singleLayers[3].setDrawModeProperties(props); break;
108  default: break;
109  }
110  }
111 
112  // rendering order: faces -> edges -> halfedges -> points
113  // area -> handle -> feature -> selections
114  for (int i = 0; i < 4; ++i)
115  {
116 
117  if (singleLayers[i].getNumLayers() == 0)
118  {
119  DrawModes::DrawModeProperties defaultProps;
120 
121  switch (i)
122  {
123  case 0: defaultProps.primitive(DrawModes::PRIMITIVE_POLYGON); break;
124  case 1: defaultProps.primitive(DrawModes::PRIMITIVE_EDGE); break;
125  case 2: defaultProps.primitive(DrawModes::PRIMITIVE_HALFEDGE); break;
126  case 3: defaultProps.primitive(DrawModes::PRIMITIVE_POINT); break;
127  default: break;
128  }
129 
130  singleLayers[i].addLayer(&defaultProps);
131  }
132 
133  // call enter() and leave() to setup the correct material
134 
135  if (areaNodeVis_)
136  {
137  areaNode_->enter(_state, singleLayers[i]);
138  areaNode_->draw(_state, singleLayers[i]);
139  areaNode_->leave(_state, singleLayers[i]);
140  }
141 
142  if (handleNodeVis_)
143  {
144  handleNode_->enter(_state, singleLayers[i]);
145  handleNode_->draw(_state, singleLayers[i]);
146  handleNode_->leave(_state, singleLayers[i]);
147  }
148 
149  if (featureNodeVis_)
150  {
151  featureNode_->enter(_state, singleLayers[i]);
152  featureNode_->draw(_state, singleLayers[i]);
153  featureNode_->leave(_state, singleLayers[i]);
154  }
155 
156  if (statusNodeVis_)
157  {
158  statusNode_->enter(_state, singleLayers[i]);
159  statusNode_->draw(_state, singleLayers[i]);
160  statusNode_->leave(_state, singleLayers[i]);
161  }
162  }
163 
164 }
165 
166 //----------------------------------------------------------------------------
167 
168 template <class MeshT>
169 void StatusViewNodeT<MeshT>::getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat)
170 {
171 
172 
173 
174  // extract all layers from drawmode
175 
176  DrawModes::DrawMode singleLayers[4]; // polygon, edge, halfedge, point
177 
178  // remove default property layer
179  for (int i = 0; i < 4; ++i)
180  singleLayers[i].removeLayer(0u);
181 
182  for (unsigned int i = 0; i < _drawMode.getNumLayers(); ++i)
183  {
184  const DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
185 
186  switch (props->primitive())
187  {
188  case DrawModes::PRIMITIVE_POLYGON: singleLayers[0].setDrawModeProperties(props); break;
189  case DrawModes::PRIMITIVE_EDGE: singleLayers[1].setDrawModeProperties(props); break;
190  case DrawModes::PRIMITIVE_HALFEDGE: singleLayers[2].setDrawModeProperties(props); break;
191  case DrawModes::PRIMITIVE_POINT: singleLayers[3].setDrawModeProperties(props); break;
192  default: break;
193  }
194  }
195 
196  // rendering order: faces -> edges -> halfedges -> points
197  // area -> handle -> feature -> selections
198  // rendering order only depends on priority in render objects
199  for (int i = 0; i < 4; ++i)
200  {
201 
202  if (singleLayers[i].getNumLayers() == 0)
203  {
204  DrawModes::DrawModeProperties defaultProps;
205 
206  switch (i)
207  {
208  case 0: defaultProps.primitive(DrawModes::PRIMITIVE_POLYGON); break;
209  case 1: defaultProps.primitive(DrawModes::PRIMITIVE_EDGE); break;
210  case 2: defaultProps.primitive(DrawModes::PRIMITIVE_HALFEDGE); break;
211  case 3: defaultProps.primitive(DrawModes::PRIMITIVE_POINT); break;
212  default: break;
213  }
214 
215  singleLayers[i].addLayer(&defaultProps);
216  }
217 
218  if (statusNodeVis_)
219  statusNode_->getRenderObjects(_renderer, _state, singleLayers[i], _mat);
220 
221  if (areaNodeVis_)
222  areaNode_->getRenderObjects(_renderer, _state, singleLayers[i], _mat);
223 
224  if (handleNodeVis_)
225  handleNode_->getRenderObjects(_renderer, _state, singleLayers[i], _mat);
226 
227  if (featureNodeVis_)
228  featureNode_->getRenderObjects(_renderer, _state, singleLayers[i], _mat);
229  }
230 }
231 
232 
233 //----------------------------------------------------------------------------
234 
235 template <class MeshT>
237 {
238  statusNodeVis_ = statusNode_ && statusNode_->visible();
239  areaNodeVis_ = areaNode_ && areaNode_->visible();
240  handleNodeVis_ = handleNode_ && handleNode_->visible();
241  featureNodeVis_ = featureNode_ && featureNode_->visible();
242 
243  // these nodes are manually rendered in this StatusViewNode
244  // hide nodes to prevent drawing them again in the same draw traversal
245 
246  if (statusNodeVis_)
247  statusNode_->hide();
248  if (areaNodeVis_)
249  areaNode_->hide();
250  if (handleNodeVis_)
251  handleNode_->hide();
252  if (featureNodeVis_)
253  featureNode_->hide();
254 }
255 
256 //----------------------------------------------------------------------------
257 
258 template <class MeshT>
260 {
261  if (statusNodeVis_)
262  statusNode_->show();
263  if (areaNodeVis_)
264  areaNode_->show();
265  if (handleNodeVis_)
266  handleNode_->show();
267  if (featureNodeVis_)
268  featureNode_->show();
269 }
270 
271 
272 }
273 }
274 
275 #endif // STATUSVIEWNODE_C
Namespace providing different geometric functions concerning angles.
void draw(GLState &, const DrawModes::DrawMode &) override
Draw this node using the draw modes _drawMode.
void addLayer(const DrawModeProperties *_props)
add another layer on top of this drawmode
Definition: DrawModes.cc:532
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:177
void setDrawModeProperties(const DrawModeProperties *_props)
set the base properties of this draw mode
Definition: DrawModes.cc:251
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat) override
Deferred draw call with shader based renderer.
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const class Material *_mat) override
support for shader-pipeline
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode) override
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
Definition: DrawModes.cc:527
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode) override
size_t getNumLayers() const
returns the layer count
Definition: DrawModes.cc:523