Developer Documentation
DrawModes.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 //=============================================================================
48 //
49 // CLASS DrawModes
50 //
51 //=============================================================================
52 
53 #ifndef ACG_DRAWMODES_HH
54 #define ACG_DRAWMODES_HH
55 
56 
57 //== FORWARD DECLARATIONS =====================================================
58 
59 
60 namespace ACG
61 {
62  namespace SceneGraph
63  {
64  class BaseNode;
65  }
66 }
67 
68 
69 //== INCLUDES =================================================================
70 
71 #include <string>
72 #include <vector>
73 #include "../Config/ACGDefines.hh"
74 #include <bitset>
75 
76 // Avoid compiler warning in MSC
77 #if defined (_MSC_VER)
78 # pragma warning (disable:4251)
79 #endif
80 
81 //== NAMESPACES ===============================================================
82 
83 
84 namespace ACG {
85 namespace SceneGraph {
86 
93 namespace DrawModes {
94 
95 
108  {
112  };
113 
119  {
120  PRIMITIVE_POINT,
121  PRIMITIVE_EDGE,
122  PRIMITIVE_HALFEDGE,
123  PRIMITIVE_WIREFRAME,
124  PRIMITIVE_HIDDENLINE,
125  PRIMITIVE_POLYGON,
126  PRIMITIVE_CELL
127  };
128 
135  {
141  };
142 
148  {
152  // TEXCOORD_PER_FACE // TODO: discuss texcoords per face? is it useful?
153  };
154 
160  {
165  };
166 
167  typedef std::bitset<128> ModeFlagSet;
168 
177  class ACGDLLEXPORT DrawModeProperties {
178 
179  public:
181  DrawModePrimitive _primitive = PRIMITIVE_POLYGON,
182  DrawModeLightStage _lightStage = LIGHTSTAGE_UNLIT,
183  DrawModeNormalSource _normalSource = NORMAL_NONE,
184  DrawModeColorSource _colorSource = COLOR_NONE,
185  DrawModeTexCoordSource _texcoordSource = TEXCOORD_NONE,
186  bool _envMapping = false);
187 
188  //===========================================================================
191  //===========================================================================
192 
193  DrawModePrimitive primitive() const { return primitive_; }
194  void primitive(DrawModePrimitive _val) { primitive_ = _val; }
195 
196  DrawModeLightStage lightStage() const { return lightStage_; }
197  void lightStage(DrawModeLightStage _val) { lightStage_ = _val; }
198 
199  DrawModeColorSource colorSource() const { return colorSource_; }
200  void colorSource(DrawModeColorSource _val) { colorSource_ = _val; }
201 
202  DrawModeNormalSource normalSource() const { return normalSource_; }
203  void normalSource(DrawModeNormalSource _val) { normalSource_ = _val; }
204 
205  DrawModeTexCoordSource texcoordSource() const { return texcoordSource_; }
206  void texcoordSource(DrawModeTexCoordSource _val) { texcoordSource_ = _val; }
207 
210  //===========================================================================
213  //===========================================================================
214 
216  bool lighting() const { return lightStage_ != LIGHTSTAGE_UNLIT && normalSource_ != NORMAL_NONE; }
217 
219  bool textured() const { return texcoordSource_ != TEXCOORD_NONE; }
220 
222  bool colored() const { return colorSource_ != COLOR_NONE; }
223 
225  bool flatShaded() const { return normalSource_ == NORMAL_PER_FACE; }
228  //===========================================================================
231  //===========================================================================
232 
237  bool operator!=( const DrawModeProperties& _other ) const {
238  return ( (envMapped_ != _other.envMapped_) ||
239  (primitive_ != _other.primitive_) ||
240  (lightStage_ != _other.lightStage_) ||
241  (colorSource_ != _other.colorSource_) ||
242  (texcoordSource_ != _other.texcoordSource_) ||
243  (normalSource_ != _other.normalSource_)
244  );
245  }
246 
251  bool operator==( const DrawModeProperties& _other ) const {
252  return ( (envMapped_ == _other.envMapped_) &&
253  (primitive_ == _other.primitive_) &&
254  (lightStage_ == _other.lightStage_) &&
255  (colorSource_ == _other.colorSource_) &&
256  (texcoordSource_ == _other.texcoordSource_) &&
257  (normalSource_ == _other.normalSource_)
258  );
259  }
260 
263  private:
264 
265  bool envMapped_;
266 
269 
270  DrawModeLightStage lightStage_;
271 
272  DrawModeColorSource colorSource_;
273 
274  DrawModeTexCoordSource texcoordSource_;
275 
276  DrawModeNormalSource normalSource_;
277 
278  // TODO: Shaders
279 
280  };
281 
288  class ACGDLLEXPORT DrawMode {
289  public:
290 
291  DrawMode();
292 
304  explicit DrawMode(size_t _index);
305 
313  explicit DrawMode( const ModeFlagSet& _flags );
314 
315  /* \brief Returns a registered draw mode based on the description passed or if none could be found the default one.
316  *
317  * @param _description A description created by description().
318  */
319  static DrawMode getFromDescription(std::string _description);
320 
321 
322  //===========================================================================
325  //===========================================================================
326  DrawMode & operator = (const DrawMode& _mode );
327 
328  bool operator==(const DrawMode& _mode) const;
329 
330  DrawMode operator&(const DrawMode& _mode) const;
331 
332  DrawMode& operator++();
333 
334  DrawMode& operator|=( const DrawMode& _mode2 );
335 
336  DrawMode& operator&=( const DrawMode& _mode2 );
337 
338  bool operator!=( const DrawMode& _mode2 ) const;
339 
340  DrawMode operator|( const DrawMode& _mode2 ) const;
341 
342  DrawMode operator^( const DrawMode& _mode2 ) const;
343 
344  DrawMode operator~( ) const;
345 
346  operator bool() const;
347 
350  //===========================================================================
353  //===========================================================================
354 
371  void addLayer(const DrawModeProperties* _props); // same as bitwise or operator
372 
375  size_t getNumLayers() const;
376 
381  const DrawModeProperties* getLayer(unsigned int _i) const;
382 
387  bool removeLayer(unsigned int _i);
388 
393  bool removeLayer(const DrawModeProperties* _prop);
394 
395 
400  int getLayerIndex(const DrawModeProperties* _prop) const;
401 
410  size_t getIndex() const;
411 
416  void filter( DrawMode _filter );
417 
418 
421  void combine( DrawMode _mode );
422 
427  std::string description() const;
428 
433  bool isAtomic() const;
434 
437  bool containsAtomicDrawMode( const DrawMode& _atomicDrawMode ) const;
438 
444  std::vector< DrawMode > getAtomicDrawModes() const;
445 
448  size_t maxModes() const;
449 
450 
462  const DrawModeProperties* getDrawModeProperties() const;
463 
468  void setDrawModeProperties(const DrawModeProperties* _props);
469 
474  void setDrawModeProperties(const DrawModeProperties& _props);
475 
476 
481  bool checkConsistency() const;
482 
483 
489  int getLayerIndexByPrimitive(DrawModePrimitive _type) const;
490 
491 
492  private:
493  ModeFlagSet modeFlags_;
494 
499  std::vector<DrawModeProperties> layers_;
500  };
501 
502 
504  extern ACGDLLEXPORT DrawMode NONE;
506  extern ACGDLLEXPORT DrawMode DEFAULT;
507 
508  //======================================================================
509  // Point Based Rendering Modes
510  //======================================================================
512  extern ACGDLLEXPORT DrawMode POINTS;
513 
515  extern ACGDLLEXPORT DrawMode POINTS_COLORED;
517  extern ACGDLLEXPORT DrawMode POINTS_SHADED;
518 
519  //======================================================================
520  // Edge Based Rendering Modes
521  //======================================================================
523  extern ACGDLLEXPORT DrawMode EDGES;
524 
526  extern ACGDLLEXPORT DrawMode EDGES_COLORED;
528  extern ACGDLLEXPORT DrawMode WIREFRAME;
529 
530  //======================================================================
531  // Face Based Rendering Modes
532  //======================================================================
533  // draw faces
534  extern ACGDLLEXPORT DrawMode FACES;
535 
537  extern ACGDLLEXPORT DrawMode HIDDENLINE;
539  extern ACGDLLEXPORT DrawMode SOLID_FLAT_SHADED;
541  extern ACGDLLEXPORT DrawMode SOLID_SMOOTH_SHADED;
543  extern ACGDLLEXPORT DrawMode SOLID_PHONG_SHADED;
545  extern ACGDLLEXPORT DrawMode SOLID_FACES_COLORED;
547  extern ACGDLLEXPORT DrawMode SOLID_POINTS_COLORED;
549  extern ACGDLLEXPORT DrawMode SOLID_POINTS_COLORED_SHADED;
551  extern ACGDLLEXPORT DrawMode SOLID_ENV_MAPPED;
553  extern ACGDLLEXPORT DrawMode SOLID_TEXTURED;
555  extern ACGDLLEXPORT DrawMode SOLID_TEXTURED_SHADED;
557  extern ACGDLLEXPORT DrawMode SOLID_1DTEXTURED;
559  extern ACGDLLEXPORT DrawMode SOLID_1DTEXTURED_SHADED;
561  extern ACGDLLEXPORT DrawMode SOLID_3DTEXTURED;
563  extern ACGDLLEXPORT DrawMode SOLID_3DTEXTURED_SHADED;
565  extern ACGDLLEXPORT DrawMode SOLID_FACES_COLORED_FLAT_SHADED;
567  extern ACGDLLEXPORT DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED;
571  extern ACGDLLEXPORT DrawMode SOLID_2DTEXTURED_FACE;
573  extern ACGDLLEXPORT DrawMode SOLID_2DTEXTURED_FACE_SHADED;
576  extern ACGDLLEXPORT DrawMode SOLID_SHADER;
578  extern ACGDLLEXPORT DrawMode SOLID_SMOOTH_SHADED_FEATURES;
579 
580  //======================================================================
581  // Face Based Rendering Modes
582  //======================================================================
583  // draw cells
584  extern ACGDLLEXPORT DrawMode CELLS;
585 
587  extern ACGDLLEXPORT DrawMode CELLS_COLORED;
588 
589 
590  //======================================================================
591  // Halfedge Based Rendering Modes
592  //======================================================================
594  extern ACGDLLEXPORT DrawMode HALFEDGES;
595 
597  extern ACGDLLEXPORT DrawMode HALFEDGES_COLORED;
598 
599 
601  extern ACGDLLEXPORT DrawMode UNUSED;
602 
603 
604  //=======================================================================
605  // Non Member Functions
606  //=======================================================================
607 
611  ACGDLLEXPORT
612  void initializeDefaultDrawModes( void );
613 
626  ACGDLLEXPORT
627  const DrawMode& addDrawMode( const std::string & _name, bool _propertyBased = false);
628 
643  ACGDLLEXPORT
644  const DrawMode& addDrawMode( const std::string & _name, const DrawModeProperties& _properties);
645 
653  ACGDLLEXPORT
654  const DrawMode& getDrawMode( const std::string & _name);
655 
656 
660  ACGDLLEXPORT
661  bool drawModeExists(const std::string & _name);
662 
665  ACGDLLEXPORT
666  DrawMode getDrawModeFromIndex( unsigned int _index );
667 
668 //=============================================================================
669 } // namespace DrawModes
670 } // namespace SceneGraph
671 } // namespace ACG
672 //=============================================================================
673 #endif // ACG_DRAWMODES_HH defined
674 //=============================================================================
675 
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
bool textured() const
Is texturing enabled?
Definition: DrawModes.hh:219
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
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Definition: DrawModes.cc:75
DrawMode SOLID_3DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:93
bool operator==(const DrawModeProperties &_other) const
compare two properties
Definition: DrawModes.hh:251
DrawModeColorSource
Source of Primitive Colors.
Definition: DrawModes.hh:134
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
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
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
bool operator!=(const DrawModeProperties &_other) const
compare two properties
Definition: DrawModes.hh:237
bool flatShaded() const
Is flat shading used (Normals per face)?
Definition: DrawModes.hh:225
bool lighting() const
Is lighting enabled?
Definition: DrawModes.hh:216
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
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
bool colored() const
Are colors used?
Definition: DrawModes.hh:222
DrawMode UNUSED
marks the last used ID
Definition: DrawModes.cc:105
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:71
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:89
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
DrawMode SOLID_3DTEXTURED
draw textured faces
Definition: DrawModes.cc:92
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:84
DrawModePrimitive primitive_
Specify which type of primitives will get uploaded to the graphics card.
Definition: DrawModes.hh:268
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:81
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
DrawMode SOLID_TEXTURED
draw textured faces
Definition: DrawModes.cc:88
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
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
Definition: DrawModes.cc:94
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