Developer Documentation
DrawModes.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 
45 
46 
47 //=============================================================================
48 //
49 // CLASS DrawModes - IMPLEMENTATION
50 //
51 //=============================================================================
52 
53 
54 //== INCLUDES =================================================================
55 
56 #include "DrawModes.hh"
57 #include "BaseNode.hh"
58 
59 #include <sstream>
60 
61 
62 //== NAMESPACES ==============================================================
63 
64 namespace ACG {
65 namespace SceneGraph {
66 namespace DrawModes {
67 
68 
69 // == Default Draw Mode initialization ======================================
70 
71 DrawMode NONE = DrawMode( ModeFlagSet(0) );
72 DrawMode DEFAULT = DrawMode( ModeFlagSet(1) );
73 DrawMode POINTS = DrawMode( ModeFlagSet(1) << 1 );
74 DrawMode POINTS_COLORED = DrawMode( ModeFlagSet(1) << 2 );
75 DrawMode POINTS_SHADED = DrawMode( ModeFlagSet(1) << 3 );
76 DrawMode EDGES = DrawMode( ModeFlagSet(1) << 4 );
77 DrawMode EDGES_COLORED = DrawMode( ModeFlagSet(1) << 5 );
78 DrawMode WIREFRAME = DrawMode( ModeFlagSet(1) << 6 );
79 DrawMode FACES = DrawMode( ModeFlagSet(1) << 7 );
80 DrawMode HIDDENLINE = DrawMode( ModeFlagSet(1) << 8 );
81 DrawMode SOLID_FLAT_SHADED = DrawMode( ModeFlagSet(1) << 9 );
82 DrawMode SOLID_SMOOTH_SHADED = DrawMode( ModeFlagSet(1) << 10 );
83 DrawMode SOLID_PHONG_SHADED = DrawMode( ModeFlagSet(1) << 11 );
84 DrawMode SOLID_FACES_COLORED = DrawMode( ModeFlagSet(1) << 12 );
85 DrawMode SOLID_POINTS_COLORED = DrawMode( ModeFlagSet(1) << 13 );
86 DrawMode SOLID_POINTS_COLORED_SHADED = DrawMode( ModeFlagSet(1) << 14 );
87 DrawMode SOLID_ENV_MAPPED = DrawMode( ModeFlagSet(1) << 15 );
88 DrawMode SOLID_TEXTURED = DrawMode( ModeFlagSet(1) << 16 );
89 DrawMode SOLID_TEXTURED_SHADED = DrawMode( ModeFlagSet(1) << 17 );
90 DrawMode SOLID_1DTEXTURED = DrawMode( ModeFlagSet(1) << 18 );
91 DrawMode SOLID_1DTEXTURED_SHADED = DrawMode( ModeFlagSet(1) << 19 );
92 DrawMode SOLID_3DTEXTURED = DrawMode( ModeFlagSet(1) << 20 );
93 DrawMode SOLID_3DTEXTURED_SHADED = DrawMode( ModeFlagSet(1) << 21 );
96 DrawMode SOLID_2DTEXTURED_FACE = DrawMode( ModeFlagSet(1) << 24 );
98 DrawMode SOLID_SHADER = DrawMode( ModeFlagSet(1) << 26 );
100 DrawMode CELLS = DrawMode( ModeFlagSet(1) << 28 );
101 DrawMode CELLS_COLORED = DrawMode( ModeFlagSet(1) << 29 );
102 DrawMode HALFEDGES = DrawMode( ModeFlagSet(1) << 30 );
103 DrawMode HALFEDGES_COLORED = DrawMode( ModeFlagSet(1) << 31 );
105 DrawMode UNUSED = DrawMode( ModeFlagSet(1) << 33 );
106 
107 
108 //== IMPLEMENTATION ==========================================================
109 
110 
120 
121  public:
122 
124  DrawModeInternal(const std::string & _name, const DrawMode & _id, const bool _propertyBased = false) :
125  name_(_name),
126  id_(_id),
127  propertyBased_(_propertyBased)
128  {
129  }
130 
132  void name(const std::string& _name) {
133  name_ = _name;
134  }
135 
137  const std::string& name() const {
138  return name_;
139  }
140 
141  const DrawMode& id() const {
142  return id_;
143  }
144 
145  bool propertyBased() const {
146  return propertyBased_;
147  }
148 
149 
150  DrawModeProperties& properties() {
151  return properties_;
152  }
153 
154  private:
155  std::string name_;
159 };
160 
161 
162 typedef std::vector< DrawModeInternal > VecDrawModes;
163 
166 static VecDrawModes registeredDrawModes_;
167 
169 static DrawMode firstFreeID_;
170 
171 
172 DrawModeProperties::DrawModeProperties(DrawModePrimitive _primitive,
173  DrawModeLightStage _lightStage,
174  DrawModeNormalSource _normalSource,
175  DrawModeColorSource _colorSource,
176  DrawModeTexCoordSource _texcoordSource,
177  bool _envMapping):
178 envMapped_(_envMapping),
179 primitive_(_primitive),
180 lightStage_(_lightStage),
181 colorSource_(_colorSource),
182 texcoordSource_(_texcoordSource),
183 normalSource_(_normalSource)
184 {
185 }
186 
187 
188 DrawMode::DrawMode(size_t _index)
189 {
190  modeFlags_.reset();
191  if ( _index >= modeFlags_.size() ) {
192  std::cerr << "Illegal drawMode specification from unsigned int. This should not be a bitset!!!" << std::endl;
193  } else {
194  modeFlags_.set(_index);
195  }
196  layers_.resize(1);
197  layers_[0] = DrawModeProperties();
198 }
199 
200 DrawMode::DrawMode() {
201  layers_.resize(1);
202  layers_[0] = DrawModeProperties();
203 }
204 
205 DrawMode::DrawMode(const ModeFlagSet& _flags) :
206  modeFlags_(_flags)
207 {
208  layers_.resize(1);
210 }
211 
212 DrawMode DrawMode::getFromDescription(std::string _description)
213 {
214  DrawMode val;
215  bool found = false;
216  std::istringstream f(_description);
217  std::string s;
218  while (std::getline(f, s, '+')) {
219  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
220  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
221  if(modeIter->name() == s) {
222  val |= modeIter->id();
223  found = true;
224  }
225  }
226  }
227  if(!found)
228  return DEFAULT;
229  else return val;
230 }
231 
232 DrawMode::operator bool() const {
233  return( modeFlags_ != NONE.modeFlags_ );
234 }
235 /*
236 bool DrawMode::propertyBased() const {
237  if ( isAtomic() ) {
238  return registeredDrawModes_[getIndex()].propertyBased();
239  } else {
240  // Combined drawmode, iterate over all contained modes and return
241  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
242  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
243  if( ((*this) & modeIter->id()) && modeIter->propertyBased() )
244  return true;
245 
246  return false;
247  }
248 }
249 */
250 
252  if (_props)
253  {
254  if (layers_.empty())
255  layers_.push_back(*_props);
256  else
257  layers_[0] = *_props;
258  }
259  else
260  layers_.erase(layers_.begin());
261 }
262 
264 {
265  setDrawModeProperties(&_props);
266 }
267 
268 bool DrawMode::operator==(const DrawMode& _mode) const {
269  return modeFlags_ == _mode.modeFlags_;
270  //return ((modeFlags_ & _mode.modeFlags_).any());
271 }
272 
273 bool DrawMode::operator!=( const DrawMode& _mode2 ) const {
274  return (modeFlags_ != _mode2.modeFlags_);
275 }
276 
277 DrawMode& DrawMode::operator++() {
278  if ( modeFlags_.count() != 1 ) {
279  std::cerr << "Operator ++ for drawMode which is not atomic!!" << std::endl;
280  }
281 
282  modeFlags_ <<= 1;
283 
284  return (*this);
285 }
286 
287 DrawMode DrawMode::operator&(const DrawMode& _mode) const {
288  DrawMode andMode = DrawMode(modeFlags_ & _mode.modeFlags_);
289 
291 
292  for (unsigned int i = 1; i < getNumLayers(); ++i)
293  andMode.addLayer(getLayer(i));
294 
295  // remove all distinct layers
296  for (int i = (int)andMode.getNumLayers() - 1; i >= 0; --i)
297  {
298  int layerIndex = _mode.getLayerIndex(andMode.getLayer(i));
299 
300  if (layerIndex < 0)
301  andMode.removeLayer(i);
302  }
303 
304  return andMode;
305 }
306 
307 DrawMode& DrawMode::operator|=( const DrawMode& _mode2 ) {
308  modeFlags_ |= _mode2.modeFlags_;
309 
310  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
311  addLayer(_mode2.getLayer(i));
312 
313 // assert(checkConsistency());
314 
315  return (*this);
316 }
317 
318 DrawMode& DrawMode::operator&=( const DrawMode& _mode2 ) {
319  modeFlags_ &= _mode2.modeFlags_;
320 
321  // remove all distinct layers
322  for (int i = (int)getNumLayers() - 1; i >= 0; --i)
323  {
324  int layerIndex2 = _mode2.getLayerIndex(getLayer(i));
325 
326  if (layerIndex2 < 0)
327  removeLayer(i);
328  }
329 
330 // assert(checkConsistency());
331 
332  return (*this);
333 }
334 
335 DrawMode DrawMode::operator|( const DrawMode& _mode2 ) const {
336  DrawMode combined = DrawMode( modeFlags_ | _mode2.modeFlags_ );
337 
339 
340  for (unsigned int i = 1; i < getNumLayers(); ++i)
341  combined.addLayer(getLayer(i));
342 
343  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
344  combined.addLayer(_mode2.getLayer(i));
345 
346  return combined;
347 }
348 
349 DrawMode DrawMode::operator^( const DrawMode& _mode2 ) const {
350 
351  DrawMode xorMode = DrawMode( modeFlags_ ^ _mode2.modeFlags_ );
352 
353 
354  // xor on properties
355  const DrawModeProperties* curProps = 0;
356 
357  // do xor on new temporary DrawMode
358  // internal layers of this and _mode2 must stay the same
359  std::vector<const DrawModeProperties*> tmpLayers;
360 
361 
362  // initialize tmpLayers with my own layers
363  for (unsigned int i = 0; i < getNumLayers(); ++i)
364  {
365  curProps = getLayer(i);
366 
367  if (curProps)
368  tmpLayers.push_back(curProps);
369  }
370 
371 
372  // xor on tmpLayers
373  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
374  {
375  curProps = _mode2.getLayer(i);
376 
377  if (!curProps) continue;
378 
379 
380 
381  int addToVec = 1;
382 
383  // is the other layer already contained in my own list?
384  for (unsigned int k = 0; addToVec && k < tmpLayers.size(); ++k)
385  {
386  if (!memcmp(tmpLayers[k], curProps, sizeof(DrawModeProperties)))
387  {
388  // yes, remove it (layer exists in both drawmodes)
389  tmpLayers.erase(tmpLayers.begin() + k);
390  addToVec = 0;
391  }
392  }
393 
394  if (addToVec) // no, add it
395  tmpLayers.push_back(curProps);
396  }
397 
398 
399 
400  // DrawModes equal?
401  if (tmpLayers.empty())
402  {
403  xorMode.removeLayer(0u);
404  return xorMode; // return default property set to not cause exceptions
405  }
406 
407  // layers not empty,
408  // copy to temporary drawmode and return
409 
410  xorMode.setDrawModeProperties(tmpLayers[0]);
411  for (unsigned int i = 1; i < tmpLayers.size(); ++i)
412  xorMode.addLayer(tmpLayers[i]);
413 
414 
415 // assert(xorMode.checkConsistency());
416 
417  return xorMode;
418 }
419 
420 DrawMode DrawMode::operator~( ) const {
421  return( DrawMode(~modeFlags_) );
422 }
423 
424 
425 
426 size_t DrawMode::getIndex() const {
427  if ( modeFlags_.count() == 1 ) {
428  for ( size_t i = 0 ; i < modeFlags_.size() ; ++i )
429  if ( modeFlags_[i] )
430  return i;
431  }
432 
433  return 0;
434 }
435 
436 std::string DrawMode::description() const
437 {
438  std::string text("");
439 
440  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
441  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
442  {
443  if( (*this) & modeIter->id() )
444  {
445  if (!text.empty()) text += "+";
446  text += modeIter->name();
447  }
448  }
449 
450  return text;
451 }
452 
453 //----------------------------------------------------------------------------
454 
455 void DrawMode::filter( DrawMode _filter )
456 {
457  modeFlags_ = (modeFlags_ | _filter.modeFlags_) ^ _filter.modeFlags_;
458 
459  for (unsigned int i = 0; i < _filter.getNumLayers(); ++i)
460  {
461  int idx = getLayerIndex(_filter.getLayer(i));
462 
463  removeLayer((unsigned int)idx);
464  }
465 }
466 
467 
468 
469 //----------------------------------------------------------------------------
470 
472 {
473  // XOR on bitflag
474  modeFlags_ = (modeFlags_ ^ _mode.modeFlags_);
475 
476  // addLayer does redundancy check here
477  for (unsigned int i = 0; i < _mode.getNumLayers(); ++i)
478  addLayer(_mode.getLayer(i));
479 
480 // checkConsistency();
481 // assert(checkConsistency());
482 }
483 
484 //----------------------------------------------------------------------------
485 
486 std::vector< DrawMode >
488 {
489  std::vector< DrawMode > draw_mode_ids;
490 
491  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
492  for( modeIter = registeredDrawModes_.begin();
493  modeIter != modeEnd;
494  ++modeIter )
495  if( (*this) & modeIter->id() )
496  draw_mode_ids.push_back( modeIter->id() );
497 
498  return draw_mode_ids;
499 }
500 
501 
502 //----------------------------------------------------------------------------
503 
504 bool DrawMode::isAtomic() const {
505  return(modeFlags_.count() == 1 );
506 }
507 
508 
509 //----------------------------------------------------------------------------
510 
511 bool
512 DrawMode::containsAtomicDrawMode( const DrawMode& _atomicDrawMode) const
513 {
514  return (*this) & _atomicDrawMode;
515 }
516 
517 //----------------------------------------------------------------------------
518 
519 size_t DrawMode::maxModes() const {
520  return (modeFlags_.size() );
521 }
522 
523 size_t DrawMode::getNumLayers() const {
524  return layers_.size();
525 }
526 
527 const DrawModeProperties* DrawMode::getLayer( unsigned int i ) const {
528  return (i >= layers_.size() ? 0 : &layers_[i]);
529 }
530 
531 
533 {
534  if (getLayerIndex(_props) < 0 && _props)
535  layers_.push_back(*_props);
536 }
537 
538 bool DrawMode::removeLayer( unsigned int _i )
539 {
540  if (_i < layers_.size() )
541  {
542  layers_.erase(layers_.begin() + _i);
543  return true;
544  }
545 
546  return false;
547 }
548 
550 {
551  int layerId = getLayerIndex(_prop);
552 
553  if (layerId >= 0)
554  return removeLayer((unsigned int)layerId);
555 
556  return false;
557 }
558 
560 {
561  return getLayer(0);
562 }
563 
564 
566 {
567 
568  // allow at most one layer per primitive
569  for (unsigned int i = 0; i < layers_.size(); ++i)
570  {
571  for (unsigned int k = i+1; k < layers_.size(); ++k)
572  {
573  if (layers_[i].primitive() == layers_[k].primitive())
574  return false;
575  }
576  }
577 
578 
579 
580  // bitflag -> layer parallelism
581 
582  // points-mode in bitflag => point layer expected
583 
584  if ((*this & DrawModes::POINTS) ||
585  (*this & DrawModes::POINTS_COLORED) ||
586  (*this & DrawModes::POINTS_SHADED))
587  {
588  int pointsLayer = 0;
589  for (unsigned int k = 0; k < layers_.size(); ++k)
590  {
591  if (layers_[k].primitive() == PRIMITIVE_POINT)
592  pointsLayer++;
593  }
594 
595  if (!pointsLayer)
596  return false;
597  }
598 
599 
600  return true;
601 }
602 
604 {
605  if (!_prop) return -1;
606 
607  for (unsigned int i = 0; i < layers_.size(); ++i)
608  {
609  if ( layers_[i] == *_prop )
610  return (int)i;
611 
612  // if (!memcmp(&layers_[i], &bla, sizeof(DrawModeProperties)))
613  // return (int)i;
614  }
615  return -1;
616 }
617 
619 {
620  for (unsigned int i = 0; i < layers_.size(); ++i)
621  {
622  if ( layers_[i].primitive() == _type )
623  return (int)i;
624  }
625  return -1;
626 }
627 
628 //----------------------------------------------------------------------------
629 
630 
632 {
633  static bool initialized_ = false;
634 
635  if( initialized_ )
636  return;
637 
638  registeredDrawModes_.clear();
639 
640  NONE.removeLayer(0u);
641  DEFAULT.removeLayer(0u);
642 
643  POINTS. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POINT));
646 
647  EDGES. setDrawModeProperties(DrawModeProperties(PRIMITIVE_EDGE));
649 
650  WIREFRAME. setDrawModeProperties(DrawModeProperties(PRIMITIVE_EDGE));
652 
653  WIREFRAME. setDrawModeProperties(DrawModeProperties(PRIMITIVE_WIREFRAME));
654 
655  FACES. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON));
656 
657  HIDDENLINE. setDrawModeProperties(DrawModeProperties(PRIMITIVE_HIDDENLINE));
658 
659  SOLID_FLAT_SHADED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE));
660  SOLID_SMOOTH_SHADED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX));
661 
662  SOLID_PHONG_SHADED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_PHONG, NORMAL_PER_VERTEX));
663 
664  SOLID_FACES_COLORED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_FACE));
665 
666  SOLID_POINTS_COLORED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_VERTEX));
667  SOLID_POINTS_COLORED_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX, COLOR_PER_VERTEX));
668 
670 
673 
676 
679 
680  SOLID_FACES_COLORED_FLAT_SHADED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE, COLOR_PER_FACE));
681  SOLID_FACES_COLORED_SMOOTH_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX, COLOR_PER_FACE));
682  SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX, COLOR_PER_FACE, TEXCOORD_PER_HALFEDGE));
683 
686 
687  SOLID_SMOOTH_SHADED_FEATURES.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_HALFEDGE));
688 
689  CELLS.setDrawModeProperties(DrawModeProperties(PRIMITIVE_CELL));
691 
692  HALFEDGES.setDrawModeProperties(DrawModeProperties(PRIMITIVE_HALFEDGE));
694 
695 
696  registeredDrawModes_.push_back( DrawModeInternal( "<invalid>", NONE ) );
697  registeredDrawModes_.push_back( DrawModeInternal( "Default", DEFAULT ) );
698 
699  registeredDrawModes_.push_back( DrawModeInternal( "Points", POINTS ) );
700  registeredDrawModes_.push_back( DrawModeInternal( "Points (colored)", POINTS_COLORED ) );
701  registeredDrawModes_.push_back( DrawModeInternal( "Points (shaded)", POINTS_SHADED ) );
702 
703  registeredDrawModes_.push_back( DrawModeInternal( "Edges", EDGES ) );
704  registeredDrawModes_.push_back( DrawModeInternal( "Edges Colored", EDGES_COLORED ) );
705 
706  registeredDrawModes_.push_back( DrawModeInternal( "Wireframe", WIREFRAME ) );
707 
708  registeredDrawModes_.push_back( DrawModeInternal( "Faces", FACES ) );
709 
710  registeredDrawModes_.push_back( DrawModeInternal( "Hiddenline", HIDDENLINE ) );
711 
712  registeredDrawModes_.push_back( DrawModeInternal( "Solid (flat shaded)", SOLID_FLAT_SHADED ) );
713  registeredDrawModes_.push_back( DrawModeInternal( "Solid (smooth shaded)", SOLID_SMOOTH_SHADED ) );
714  registeredDrawModes_.push_back( DrawModeInternal( "Solid (Phong shaded)", SOLID_PHONG_SHADED ) );
715 
716  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face)", SOLID_FACES_COLORED ) );
717  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-vertex)", SOLID_POINTS_COLORED ) );
718  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-vertex, shaded)", SOLID_POINTS_COLORED_SHADED ) );
719 
720  registeredDrawModes_.push_back( DrawModeInternal( "Solid (environment mapped)", SOLID_ENV_MAPPED ) );
721 
722  registeredDrawModes_.push_back( DrawModeInternal( "Solid (textured)", SOLID_TEXTURED ) );
723  registeredDrawModes_.push_back( DrawModeInternal( "Solid (textured, shaded)", SOLID_TEXTURED_SHADED ) );
724 
725  registeredDrawModes_.push_back( DrawModeInternal( "Solid (scalar field)", SOLID_1DTEXTURED ) );
726  registeredDrawModes_.push_back( DrawModeInternal( "Solid (scalar field, shaded)", SOLID_1DTEXTURED_SHADED ) );
727 
728  registeredDrawModes_.push_back( DrawModeInternal( "Solid (3D textured)", SOLID_3DTEXTURED ) );
729  registeredDrawModes_.push_back( DrawModeInternal( "Solid (3D textured, shaded)", SOLID_3DTEXTURED_SHADED ) );
730 
731  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face, flat shaded)", SOLID_FACES_COLORED_FLAT_SHADED ) );
732  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face, smooth shaded)", SOLID_FACES_COLORED_SMOOTH_SHADED ) );
733 
734  registeredDrawModes_.push_back(DrawModeInternal("Solid (colored per-face, face textured, smooth shaded)", SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED));
735 
736 
737  registeredDrawModes_.push_back( DrawModeInternal( "Solid (face textured)", SOLID_2DTEXTURED_FACE ) );
738  registeredDrawModes_.push_back( DrawModeInternal( "Solid (face textured, shaded)", SOLID_2DTEXTURED_FACE_SHADED ) );
739  registeredDrawModes_.push_back( DrawModeInternal( "Shader controlled", SOLID_SHADER ) );
740 
741  registeredDrawModes_.push_back( DrawModeInternal( "Solid (smooth shaded, features)", SOLID_SMOOTH_SHADED_FEATURES ) );
742 
743  registeredDrawModes_.push_back( DrawModeInternal( "Cells", CELLS ) );
744  registeredDrawModes_.push_back( DrawModeInternal( "Cells Colored", CELLS_COLORED ) );
745 
746  registeredDrawModes_.push_back( DrawModeInternal( "Halfedges", HALFEDGES ) );
747  registeredDrawModes_.push_back( DrawModeInternal( "Halfedges Colored", HALFEDGES_COLORED ) );
748 
749  firstFreeID_ = UNUSED;
750  initialized_ = true;
751 }
752 
753 
754 //----------------------------------------------------------------------------
755 
756 
757 const DrawMode& addDrawMode( const std::string & _name , bool _propertyBased)
758 {
759  // check if mode exists already
760  VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
761 
762  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
763  if( _name == modeIter->name() ) {
764  return modeIter->id();
765  }
766  }
767 
768 
769  // add new mode
770  registeredDrawModes_.push_back( DrawModeInternal( _name, firstFreeID_ , _propertyBased) );
771  ++firstFreeID_;
772 
773  return registeredDrawModes_[ registeredDrawModes_.size() - 1 ].id();
774 }
775 
776 //----------------------------------------------------------------------------
777 
778 ACGDLLEXPORT
779 const DrawMode& addDrawMode( const std::string & _name, const DrawModeProperties& _properties)
780 {
781  const DrawMode& drawmode = addDrawMode( _name , true );
782 
783  // Get the internal DrawMode
784  VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
785 
786  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
787  if( _name == modeIter->name() ) {
788  modeIter->properties() = _properties;
789  return drawmode;
790  }
791  }
792 
793  return drawmode;
794 }
795 
796 //----------------------------------------------------------------------------
797 
798 
799 const DrawMode& getDrawMode( const std::string & _name )
800 {
801  // check if mode exists
802  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
803 
804  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
805  {
806  if( _name == modeIter->name() )
807  {
808  return modeIter->id();
809  }
810  }
811 
812  // the DrawMode does not exists
813  return DrawModes::NONE;
814 }
815 
816 bool drawModeExists(const std::string & _name) {
817 
818  // check if mode exists
819  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
820 
821  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
822  {
823  if( _name == modeIter->name() )
824  return true;
825  }
826 
827  // the DrawMode does not exists
828  return false;
829 }
830 
831 
832 DrawMode getDrawModeFromIndex( unsigned int _index ) {
833  return DrawMode(_index);
834 }
835 
836 //=============================================================================
837 } // namespace DrawModes
838 } // namespace SceneGraph
839 } // namespace ACG
840 //=============================================================================
DrawMode SOLID_2DTEXTURED_FACE
draw per halfedge textured faces
Definition: DrawModes.cc:96
std::vector< DrawModeProperties > layers_
Definition: DrawModes.hh:500
int getLayerIndexByPrimitive(DrawModePrimitive _type) const
search for layer with specified primitive
Definition: DrawModes.cc:618
bool removeLayer(unsigned int _i)
remove layer at index i
Definition: DrawModes.cc:538
DrawModePrimitive
Primitive mode of a mesh.
Definition: DrawModes.hh:118
DrawModeInternal(const std::string &_name, const DrawMode &_id, const bool _propertyBased=false)
Definition: DrawModes.cc:124
DrawMode SOLID_3DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:93
std::string name_
Human Readable Name.
Definition: DrawModes.cc:155
bool isAtomic() const
Check if this is an atomic draw Mode.
Definition: DrawModes.cc:504
DrawMode SOLID_ENV_MAPPED
draw environment mapped
Definition: DrawModes.cc:87
Namespace providing different geometric functions concerning angles.
DrawModeNormalSource
Source of Normals.
Definition: DrawModes.hh:159
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
Definition: DrawModes.cc:512
DrawMode EDGES
draw edges
Definition: DrawModes.cc:76
DrawModeLightStage
Lighting stage of a mesh: unlit, smooth, phong.
Definition: DrawModes.hh:107
const DrawModeProperties * getDrawModeProperties() const
returns the base properties of this draw mode
Definition: DrawModes.cc:559
int getLayerIndex(const DrawModeProperties *_prop) const
returns layer index of a property, -1 if not in list
Definition: DrawModes.cc:603
DrawMode SOLID_SMOOTH_SHADED_FEATURES
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:99
DrawMode SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED
draw per halfedge texture faces modulated with face colors with smooth shading
Definition: DrawModes.cc:104
DrawMode SOLID_2DTEXTURED_FACE_SHADED
draw per halfedge textured faces
Definition: DrawModes.cc:97
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
Definition: DrawModes.cc:80
DrawMode UNUSED
marks the last used ID
Definition: DrawModes.cc:105
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:82
const std::string & name() const
Get the name of the DrawMode.
Definition: DrawModes.cc:137
void addLayer(const DrawModeProperties *_props)
add another layer on top of this drawmode
Definition: DrawModes.cc:532
DrawMode SOLID_3DTEXTURED
draw textured faces
Definition: DrawModes.cc:92
bool drawModeExists(const std::string &_name)
Check if the given draw mode exists.
Definition: DrawModes.cc:816
bool propertyBased_
Flag if the DrawMode is property based.
Definition: DrawModes.cc:157
DrawMode SOLID_POINTS_COLORED_SHADED
draw faces, but use Gouraud shading to interpolate vertex colors
Definition: DrawModes.cc:86
DrawMode HALFEDGES
draw halfedges
Definition: DrawModes.cc:102
void name(const std::string &_name)
Set the name of the DrawMode.
Definition: DrawModes.cc:132
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
Definition: DrawModes.cc:83
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
Definition: DrawModes.cc:103
DrawMode DEFAULT
use the default (global) draw mode and not the node&#39;s own.
Definition: DrawModes.cc:72
DrawMode SOLID_1DTEXTURED
draw textured faces
Definition: DrawModes.cc:90
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Definition: DrawModes.cc:85
void combine(DrawMode _mode)
combine with another drawmode
Definition: DrawModes.cc:471
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
Definition: DrawModes.cc:799
DrawModeTexCoordSource
Source of Texture Coordinates.
Definition: DrawModes.hh:147
DrawMode SOLID_TEXTURED
draw textured faces
Definition: DrawModes.cc:88
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
Definition: DrawModes.cc:94
bool checkConsistency() const
checks consistency of property layers
Definition: DrawModes.cc:565
DrawModeColorSource
Source of Primitive Colors.
Definition: DrawModes.hh:134
DrawMode CELLS_COLORED
draw cells with colors (without shading)
Definition: DrawModes.cc:101
const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased)
Add a custom DrawMode.
Definition: DrawModes.cc:757
std::vector< DrawMode > getAtomicDrawModes() const
Separates this drawMode into a list of all separate atomic draw modes.
Definition: DrawModes.cc:487
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:71
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
void filter(DrawMode _filter)
filter out one drawmode
Definition: DrawModes.cc:455
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
size_t getIndex() const
get an index of the current drawMode
Definition: DrawModes.cc:426
DrawModeProperties properties_
The properties associated with this DrawMode.
Definition: DrawModes.cc:158
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:81
DrawMode SOLID_1DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:91
DrawMode getDrawModeFromIndex(unsigned int _index)
given an index of an atomic draw mode, return the drawmode
Definition: DrawModes.cc:832
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:78
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:84
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Definition: DrawModes.cc:74
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Definition: DrawModes.cc:77
DrawMode id_
The id of the DrawMode.
Definition: DrawModes.cc:156
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:89
void initializeDefaultDrawModes(void)
Definition: DrawModes.cc:631
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
Definition: DrawModes.cc:527
DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED
draw smooth shaded and colored faces (requires vertex normals and face colors)
Definition: DrawModes.cc:95
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Definition: DrawModes.cc:75
size_t getNumLayers() const
returns the layer count
Definition: DrawModes.cc:523
size_t maxModes() const
Get the number of maximum Modes which could be handled by the current implementation.
Definition: DrawModes.cc:519