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 DrawMode & DrawMode::operator =(const DrawMode& _mode) {
274  modeFlags_ = _mode.modeFlags_;
275  layers_ = _mode.layers_;
276 
277  // checkConsistency();
278  return (*this);
279 }
280 
281 bool DrawMode::operator!=( const DrawMode& _mode2 ) const {
282  return (modeFlags_ != _mode2.modeFlags_);
283 }
284 
285 DrawMode& DrawMode::operator++() {
286  if ( modeFlags_.count() != 1 ) {
287  std::cerr << "Operator ++ for drawMode which is not atomic!!" << std::endl;
288  }
289 
290  modeFlags_ <<= 1;
291 
292  return (*this);
293 }
294 
295 DrawMode DrawMode::operator&(const DrawMode& _mode) const {
296  DrawMode andMode = DrawMode(modeFlags_ & _mode.modeFlags_);
297 
299 
300  for (unsigned int i = 1; i < getNumLayers(); ++i)
301  andMode.addLayer(getLayer(i));
302 
303  // remove all distinct layers
304  for (int i = (int)andMode.getNumLayers() - 1; i >= 0; --i)
305  {
306  int layerIndex = _mode.getLayerIndex(andMode.getLayer(i));
307 
308  if (layerIndex < 0)
309  andMode.removeLayer(i);
310  }
311 
312  return andMode;
313 }
314 
315 DrawMode& DrawMode::operator|=( const DrawMode& _mode2 ) {
316  modeFlags_ |= _mode2.modeFlags_;
317 
318  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
319  addLayer(_mode2.getLayer(i));
320 
321 // assert(checkConsistency());
322 
323  return (*this);
324 }
325 
326 DrawMode& DrawMode::operator&=( const DrawMode& _mode2 ) {
327  modeFlags_ &= _mode2.modeFlags_;
328 
329  // remove all distinct layers
330  for (int i = (int)getNumLayers() - 1; i >= 0; --i)
331  {
332  int layerIndex2 = _mode2.getLayerIndex(getLayer(i));
333 
334  if (layerIndex2 < 0)
335  removeLayer(i);
336  }
337 
338 // assert(checkConsistency());
339 
340  return (*this);
341 }
342 
343 DrawMode DrawMode::operator|( const DrawMode& _mode2 ) const {
344  DrawMode combined = DrawMode( modeFlags_ | _mode2.modeFlags_ );
345 
347 
348  for (unsigned int i = 1; i < getNumLayers(); ++i)
349  combined.addLayer(getLayer(i));
350 
351  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
352  combined.addLayer(_mode2.getLayer(i));
353 
354  return combined;
355 }
356 
357 DrawMode DrawMode::operator^( const DrawMode& _mode2 ) const {
358 
359  DrawMode xorMode = DrawMode( modeFlags_ ^ _mode2.modeFlags_ );
360 
361 
362  // xor on properties
363  const DrawModeProperties* curProps = 0;
364 
365  // do xor on new temporary DrawMode
366  // internal layers of this and _mode2 must stay the same
367  std::vector<const DrawModeProperties*> tmpLayers;
368 
369 
370  // initialize tmpLayers with my own layers
371  for (unsigned int i = 0; i < getNumLayers(); ++i)
372  {
373  curProps = getLayer(i);
374 
375  if (curProps)
376  tmpLayers.push_back(curProps);
377  }
378 
379 
380  // xor on tmpLayers
381  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
382  {
383  curProps = _mode2.getLayer(i);
384 
385  if (!curProps) continue;
386 
387 
388 
389  int addToVec = 1;
390 
391  // is the other layer already contained in my own list?
392  for (unsigned int k = 0; addToVec && k < tmpLayers.size(); ++k)
393  {
394  if (!memcmp(tmpLayers[k], curProps, sizeof(DrawModeProperties)))
395  {
396  // yes, remove it (layer exists in both drawmodes)
397  tmpLayers.erase(tmpLayers.begin() + k);
398  addToVec = 0;
399  }
400  }
401 
402  if (addToVec) // no, add it
403  tmpLayers.push_back(curProps);
404  }
405 
406 
407 
408  // DrawModes equal?
409  if (tmpLayers.empty())
410  {
411  xorMode.removeLayer(0u);
412  return xorMode; // return default property set to not cause exceptions
413  }
414 
415  // layers not empty,
416  // copy to temporary drawmode and return
417 
418  xorMode.setDrawModeProperties(tmpLayers[0]);
419  for (unsigned int i = 1; i < tmpLayers.size(); ++i)
420  xorMode.addLayer(tmpLayers[i]);
421 
422 
423 // assert(xorMode.checkConsistency());
424 
425  return xorMode;
426 }
427 
428 DrawMode DrawMode::operator~( ) const {
429  return( DrawMode(~modeFlags_) );
430 }
431 
432 
433 
434 size_t DrawMode::getIndex() const {
435  if ( modeFlags_.count() == 1 ) {
436  for ( size_t i = 0 ; i < modeFlags_.size() ; ++i )
437  if ( modeFlags_[i] )
438  return i;
439  }
440 
441  return 0;
442 }
443 
444 std::string DrawMode::description() const
445 {
446  std::string text("");
447 
448  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
449  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
450  {
451  if( (*this) & modeIter->id() )
452  {
453  if (!text.empty()) text += "+";
454  text += modeIter->name();
455  }
456  }
457 
458  return text;
459 }
460 
461 //----------------------------------------------------------------------------
462 
463 void DrawMode::filter( DrawMode _filter )
464 {
465  modeFlags_ = (modeFlags_ | _filter.modeFlags_) ^ _filter.modeFlags_;
466 
467  for (unsigned int i = 0; i < _filter.getNumLayers(); ++i)
468  {
469  int idx = getLayerIndex(_filter.getLayer(i));
470 
471  removeLayer((unsigned int)idx);
472  }
473 }
474 
475 
476 
477 //----------------------------------------------------------------------------
478 
480 {
481  // XOR on bitflag
482  modeFlags_ = (modeFlags_ ^ _mode.modeFlags_);
483 
484  // addLayer does redundancy check here
485  for (unsigned int i = 0; i < _mode.getNumLayers(); ++i)
486  addLayer(_mode.getLayer(i));
487 
488 // checkConsistency();
489 // assert(checkConsistency());
490 }
491 
492 //----------------------------------------------------------------------------
493 
494 std::vector< DrawMode >
496 {
497  std::vector< DrawMode > draw_mode_ids;
498 
499  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
500  for( modeIter = registeredDrawModes_.begin();
501  modeIter != modeEnd;
502  ++modeIter )
503  if( (*this) & modeIter->id() )
504  draw_mode_ids.push_back( modeIter->id() );
505 
506  return draw_mode_ids;
507 }
508 
509 
510 //----------------------------------------------------------------------------
511 
512 bool DrawMode::isAtomic() const {
513  return(modeFlags_.count() == 1 );
514 }
515 
516 
517 //----------------------------------------------------------------------------
518 
519 bool
520 DrawMode::containsAtomicDrawMode( const DrawMode& _atomicDrawMode) const
521 {
522  return (*this) & _atomicDrawMode;
523 }
524 
525 //----------------------------------------------------------------------------
526 
527 size_t DrawMode::maxModes() const {
528  return (modeFlags_.size() );
529 }
530 
531 size_t DrawMode::getNumLayers() const {
532  return layers_.size();
533 }
534 
535 const DrawModeProperties* DrawMode::getLayer( unsigned int i ) const {
536  return (i >= layers_.size() ? 0 : &layers_[i]);
537 }
538 
539 
541 {
542  if (getLayerIndex(_props) < 0 && _props)
543  layers_.push_back(*_props);
544 }
545 
546 bool DrawMode::removeLayer( unsigned int _i )
547 {
548  if (_i < layers_.size() )
549  {
550  layers_.erase(layers_.begin() + _i);
551  return true;
552  }
553 
554  return false;
555 }
556 
558 {
559  int layerId = getLayerIndex(_prop);
560 
561  if (layerId >= 0)
562  return removeLayer((unsigned int)layerId);
563 
564  return false;
565 }
566 
568 {
569  return getLayer(0);
570 }
571 
572 
574 {
575 
576  // allow at most one layer per primitive
577  for (unsigned int i = 0; i < layers_.size(); ++i)
578  {
579  for (unsigned int k = i+1; k < layers_.size(); ++k)
580  {
581  if (layers_[i].primitive() == layers_[k].primitive())
582  return false;
583  }
584  }
585 
586 
587 
588  // bitflag -> layer parallelism
589 
590  // points-mode in bitflag => point layer expected
591 
592  if ((*this & DrawModes::POINTS) ||
593  (*this & DrawModes::POINTS_COLORED) ||
594  (*this & DrawModes::POINTS_SHADED))
595  {
596  int pointsLayer = 0;
597  for (unsigned int k = 0; k < layers_.size(); ++k)
598  {
599  if (layers_[k].primitive() == PRIMITIVE_POINT)
600  pointsLayer++;
601  }
602 
603  if (!pointsLayer)
604  return false;
605  }
606 
607 
608  return true;
609 }
610 
612 {
613  if (!_prop) return -1;
614 
615  for (unsigned int i = 0; i < layers_.size(); ++i)
616  {
617  if ( layers_[i] == *_prop )
618  return (int)i;
619 
620  // if (!memcmp(&layers_[i], &bla, sizeof(DrawModeProperties)))
621  // return (int)i;
622  }
623  return -1;
624 }
625 
627 {
628  for (unsigned int i = 0; i < layers_.size(); ++i)
629  {
630  if ( layers_[i].primitive() == _type )
631  return (int)i;
632  }
633  return -1;
634 }
635 
636 //----------------------------------------------------------------------------
637 
638 
640 {
641  static bool initialized_ = false;
642 
643  if( initialized_ )
644  return;
645 
646  registeredDrawModes_.clear();
647 
648  NONE.removeLayer(0u);
649  DEFAULT.removeLayer(0u);
650 
651  POINTS. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POINT));
654 
655  EDGES. setDrawModeProperties(DrawModeProperties(PRIMITIVE_EDGE));
657 
658  WIREFRAME. setDrawModeProperties(DrawModeProperties(PRIMITIVE_EDGE));
660 
661  WIREFRAME. setDrawModeProperties(DrawModeProperties(PRIMITIVE_WIREFRAME));
662 
663  FACES. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON));
664 
665  HIDDENLINE. setDrawModeProperties(DrawModeProperties(PRIMITIVE_HIDDENLINE));
666 
667  SOLID_FLAT_SHADED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE));
668  SOLID_SMOOTH_SHADED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX));
669 
670  SOLID_PHONG_SHADED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_PHONG, NORMAL_PER_VERTEX));
671 
672  SOLID_FACES_COLORED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_FACE));
673 
674  SOLID_POINTS_COLORED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_VERTEX));
675  SOLID_POINTS_COLORED_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX, COLOR_PER_VERTEX));
676 
678 
681 
684 
687 
688  SOLID_FACES_COLORED_FLAT_SHADED. setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE, COLOR_PER_FACE));
689  SOLID_FACES_COLORED_SMOOTH_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX, COLOR_PER_FACE));
690  SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX, COLOR_PER_FACE, TEXCOORD_PER_HALFEDGE));
691 
694 
695  SOLID_SMOOTH_SHADED_FEATURES.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_HALFEDGE));
696 
697  CELLS.setDrawModeProperties(DrawModeProperties(PRIMITIVE_CELL));
699 
700  HALFEDGES.setDrawModeProperties(DrawModeProperties(PRIMITIVE_HALFEDGE));
702 
703 
704  registeredDrawModes_.push_back( DrawModeInternal( "<invalid>", NONE ) );
705  registeredDrawModes_.push_back( DrawModeInternal( "Default", DEFAULT ) );
706 
707  registeredDrawModes_.push_back( DrawModeInternal( "Points", POINTS ) );
708  registeredDrawModes_.push_back( DrawModeInternal( "Points (colored)", POINTS_COLORED ) );
709  registeredDrawModes_.push_back( DrawModeInternal( "Points (shaded)", POINTS_SHADED ) );
710 
711  registeredDrawModes_.push_back( DrawModeInternal( "Edges", EDGES ) );
712  registeredDrawModes_.push_back( DrawModeInternal( "Edges Colored", EDGES_COLORED ) );
713 
714  registeredDrawModes_.push_back( DrawModeInternal( "Wireframe", WIREFRAME ) );
715 
716  registeredDrawModes_.push_back( DrawModeInternal( "Faces", FACES ) );
717 
718  registeredDrawModes_.push_back( DrawModeInternal( "Hiddenline", HIDDENLINE ) );
719 
720  registeredDrawModes_.push_back( DrawModeInternal( "Solid (flat shaded)", SOLID_FLAT_SHADED ) );
721  registeredDrawModes_.push_back( DrawModeInternal( "Solid (smooth shaded)", SOLID_SMOOTH_SHADED ) );
722  registeredDrawModes_.push_back( DrawModeInternal( "Solid (Phong shaded)", SOLID_PHONG_SHADED ) );
723 
724  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face)", SOLID_FACES_COLORED ) );
725  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-vertex)", SOLID_POINTS_COLORED ) );
726  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-vertex, shaded)", SOLID_POINTS_COLORED_SHADED ) );
727 
728  registeredDrawModes_.push_back( DrawModeInternal( "Solid (environment mapped)", SOLID_ENV_MAPPED ) );
729 
730  registeredDrawModes_.push_back( DrawModeInternal( "Solid (textured)", SOLID_TEXTURED ) );
731  registeredDrawModes_.push_back( DrawModeInternal( "Solid (textured, shaded)", SOLID_TEXTURED_SHADED ) );
732 
733  registeredDrawModes_.push_back( DrawModeInternal( "Solid (scalar field)", SOLID_1DTEXTURED ) );
734  registeredDrawModes_.push_back( DrawModeInternal( "Solid (scalar field, shaded)", SOLID_1DTEXTURED_SHADED ) );
735 
736  registeredDrawModes_.push_back( DrawModeInternal( "Solid (3D textured)", SOLID_3DTEXTURED ) );
737  registeredDrawModes_.push_back( DrawModeInternal( "Solid (3D textured, shaded)", SOLID_3DTEXTURED_SHADED ) );
738 
739  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face, flat shaded)", SOLID_FACES_COLORED_FLAT_SHADED ) );
740  registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face, smooth shaded)", SOLID_FACES_COLORED_SMOOTH_SHADED ) );
741 
742  registeredDrawModes_.push_back(DrawModeInternal("Solid (colored per-face, face textured, smooth shaded)", SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED));
743 
744 
745  registeredDrawModes_.push_back( DrawModeInternal( "Solid (face textured)", SOLID_2DTEXTURED_FACE ) );
746  registeredDrawModes_.push_back( DrawModeInternal( "Solid (face textured, shaded)", SOLID_2DTEXTURED_FACE_SHADED ) );
747  registeredDrawModes_.push_back( DrawModeInternal( "Shader controlled", SOLID_SHADER ) );
748 
749  registeredDrawModes_.push_back( DrawModeInternal( "Solid (smooth shaded, features)", SOLID_SMOOTH_SHADED_FEATURES ) );
750 
751  registeredDrawModes_.push_back( DrawModeInternal( "Cells", CELLS ) );
752  registeredDrawModes_.push_back( DrawModeInternal( "Cells Colored", CELLS_COLORED ) );
753 
754  registeredDrawModes_.push_back( DrawModeInternal( "Halfedges", HALFEDGES ) );
755  registeredDrawModes_.push_back( DrawModeInternal( "Halfedges Colored", HALFEDGES_COLORED ) );
756 
757  firstFreeID_ = UNUSED;
758  initialized_ = true;
759 }
760 
761 
762 //----------------------------------------------------------------------------
763 
764 
765 const DrawMode& addDrawMode( const std::string & _name , bool _propertyBased)
766 {
767  // check if mode exists already
768  VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
769 
770  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
771  if( _name == modeIter->name() ) {
772  return modeIter->id();
773  }
774  }
775 
776 
777  // add new mode
778  registeredDrawModes_.push_back( DrawModeInternal( _name, firstFreeID_ , _propertyBased) );
779  ++firstFreeID_;
780 
781  return registeredDrawModes_[ registeredDrawModes_.size() - 1 ].id();
782 }
783 
784 //----------------------------------------------------------------------------
785 
786 ACGDLLEXPORT
787 const DrawMode& addDrawMode( const std::string & _name, const DrawModeProperties& _properties)
788 {
789  const DrawMode& drawmode = addDrawMode( _name , true );
790 
791  // Get the internal DrawMode
792  VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
793 
794  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
795  if( _name == modeIter->name() ) {
796  modeIter->properties() = _properties;
797  return drawmode;
798  }
799  }
800 
801  return drawmode;
802 }
803 
804 //----------------------------------------------------------------------------
805 
806 
807 const DrawMode& getDrawMode( const std::string & _name )
808 {
809  // check if mode exists
810  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
811 
812  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
813  {
814  if( _name == modeIter->name() )
815  {
816  return modeIter->id();
817  }
818  }
819 
820  // the DrawMode does not exists
821  return DrawModes::NONE;
822 }
823 
824 bool drawModeExists(const std::string & _name) {
825 
826  // check if mode exists
827  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
828 
829  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
830  {
831  if( _name == modeIter->name() )
832  return true;
833  }
834 
835  // the DrawMode does not exists
836  return false;
837 }
838 
839 
840 DrawMode getDrawModeFromIndex( unsigned int _index ) {
841  return DrawMode(_index);
842 }
843 
844 //=============================================================================
845 } // namespace DrawModes
846 } // namespace SceneGraph
847 } // namespace ACG
848 //=============================================================================
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:82
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
Definition: DrawModes.cc:83
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:78
Namespace providing different geometric functions concerning angles.
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Definition: DrawModes.cc:77
DrawMode getDrawModeFromIndex(unsigned int _index)
given an index of an atomic draw mode, return the drawmode
Definition: DrawModes.cc:840
DrawModeLightStage
Lighting stage of a mesh: unlit, smooth, phong.
Definition: DrawModes.hh:107
int getLayerIndex(const DrawModeProperties *_prop) const
returns layer index of a property, -1 if not in list
Definition: DrawModes.cc:611
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Definition: DrawModes.cc:75
const DrawModeProperties * getDrawModeProperties() const
returns the base properties of this draw mode
Definition: DrawModes.cc:567
void combine(DrawMode _mode)
combine with another drawmode
Definition: DrawModes.cc:479
DrawMode id_
The id of the DrawMode.
Definition: DrawModes.cc:156
bool isAtomic() const
Check if this is an atomic draw Mode.
Definition: DrawModes.cc:512
DrawMode SOLID_3DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:93
DrawModeColorSource
Source of Primitive Colors.
Definition: DrawModes.hh:134
bool checkConsistency() const
checks consistency of property layers
Definition: DrawModes.cc:573
DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED
draw smooth shaded and colored faces (requires vertex normals and face colors)
Definition: DrawModes.cc:95
DrawMode SOLID_1DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:91
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Definition: DrawModes.cc:74
DrawMode HALFEDGES
draw halfedges
Definition: DrawModes.cc:102
DrawMode SOLID_ENV_MAPPED
draw environment mapped
Definition: DrawModes.cc:87
DrawMode SOLID_SMOOTH_SHADED_FEATURES
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:99
void setDrawModeProperties(const DrawModeProperties *_props)
set the base properties of this draw mode
Definition: DrawModes.cc:251
DrawMode SOLID_1DTEXTURED
draw textured faces
Definition: DrawModes.cc:90
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
Definition: DrawModes.cc:807
DrawModePrimitive
Primitive mode of a mesh.
Definition: DrawModes.hh:118
DrawMode EDGES
draw edges
Definition: DrawModes.cc:76
size_t getNumLayers() const
returns the layer count
Definition: DrawModes.cc:531
bool drawModeExists(const std::string &_name)
Check if the given draw mode exists.
Definition: DrawModes.cc:824
DrawModeTexCoordSource
Source of Texture Coordinates.
Definition: DrawModes.hh:147
DrawMode DEFAULT
use the default (global) draw mode and not the node&#39;s own.
Definition: DrawModes.cc:72
void name(const std::string &_name)
Set the name of the DrawMode.
Definition: DrawModes.cc:132
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Definition: DrawModes.cc:85
DrawMode CELLS_COLORED
draw cells with colors (without shading)
Definition: DrawModes.cc:101
const std::string & name() const
Get the name of the DrawMode.
Definition: DrawModes.cc:137
std::vector< DrawModeProperties > layers_
Definition: DrawModes.hh:499
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 HIDDENLINE
draw hidden line (2 rendering passes needed)
Definition: DrawModes.cc:80
void addLayer(const DrawModeProperties *_props)
add another layer on top of this drawmode
Definition: DrawModes.cc:540
DrawMode UNUSED
marks the last used ID
Definition: DrawModes.cc:105
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:71
std::vector< DrawMode > getAtomicDrawModes() const
Separates this drawMode into a list of all separate atomic draw modes.
Definition: DrawModes.cc:495
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:89
bool removeLayer(unsigned int _i)
remove layer at index i
Definition: DrawModes.cc:546
const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased)
Add a custom DrawMode.
Definition: DrawModes.cc:765
DrawMode SOLID_2DTEXTURED_FACE
draw per halfedge textured faces
Definition: DrawModes.cc:96
DrawModeProperties properties_
The properties associated with this DrawMode.
Definition: DrawModes.cc:158
bool propertyBased_
Flag if the DrawMode is property based.
Definition: DrawModes.cc:157
DrawMode SOLID_3DTEXTURED
draw textured faces
Definition: DrawModes.cc:92
DrawModeInternal(const std::string &_name, const DrawMode &_id, const bool _propertyBased=false)
Definition: DrawModes.cc:124
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:84
void filter(DrawMode _filter)
filter out one drawmode
Definition: DrawModes.cc:463
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
Definition: DrawModes.cc:535
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:81
size_t getIndex() const
get an index of the current drawMode
Definition: DrawModes.cc:434
DrawMode SOLID_2DTEXTURED_FACE_SHADED
draw per halfedge textured faces
Definition: DrawModes.cc:97
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
Definition: DrawModes.cc:103
int getLayerIndexByPrimitive(DrawModePrimitive _type) const
search for layer with specified primitive
Definition: DrawModes.cc:626
DrawMode SOLID_TEXTURED
draw textured faces
Definition: DrawModes.cc:88
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
Definition: DrawModes.cc:520
void initializeDefaultDrawModes(void)
Definition: DrawModes.cc:639
DrawMode POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:177
std::string name_
Human Readable Name.
Definition: DrawModes.cc:155
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
Definition: DrawModes.cc:94
size_t maxModes() const
Get the number of maximum Modes which could be handled by the current implementation.
Definition: DrawModes.cc:527
DrawMode SOLID_POINTS_COLORED_SHADED
draw faces, but use Gouraud shading to interpolate vertex colors
Definition: DrawModes.cc:86
DrawModeNormalSource
Source of Normals.
Definition: DrawModes.hh:159