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