Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS DrawModes
56 //
57 //=============================================================================
58 
59 #ifndef ACG_DRAWMODES_HH
60 #define ACG_DRAWMODES_HH
61 
62 
63 //== FORWARD DECLARATIONS =====================================================
64 
65 
66 namespace ACG
67 {
68  namespace SceneGraph
69  {
70  class BaseNode;
71  }
72 }
73 
74 
75 //== INCLUDES =================================================================
76 
77 #include <string>
78 #include <vector>
79 #include "../Config/ACGDefines.hh"
80 #include <bitset>
81 
82 // Avoid compiler warning in MSC
83 #if defined (_MSC_VER)
84 # pragma warning (disable:4251)
85 #endif
86 
87 //== NAMESPACES ===============================================================
88 
89 
90 namespace ACG {
91 namespace SceneGraph {
92 
99 namespace DrawModes {
100 
101 
114  {
118  };
119 
125  {
126  PRIMITIVE_POINT,
127  PRIMITIVE_EDGE,
128  PRIMITIVE_HALFEDGE,
129  PRIMITIVE_WIREFRAME,
130  PRIMITIVE_HIDDENLINE,
131  PRIMITIVE_POLYGON,
132  PRIMITIVE_CELL
133  };
134 
141  {
147  };
148 
154  {
158  // TEXCOORD_PER_FACE // TODO: discuss texcoords per face? is it useful?
159  };
160 
166  {
171  };
172 
173  typedef std::bitset<128> ModeFlagSet;
174 
183  class ACGDLLEXPORT DrawModeProperties {
184 
185  public:
187  DrawModePrimitive _primitive = PRIMITIVE_POLYGON,
188  DrawModeLightStage _lightStage = LIGHTSTAGE_UNLIT,
189  DrawModeNormalSource _normalSource = NORMAL_NONE,
190  DrawModeColorSource _colorSource = COLOR_NONE,
191  DrawModeTexCoordSource _texcoordSource = TEXCOORD_NONE,
192  bool _envMapping = false);
193 
194  //===========================================================================
197  //===========================================================================
198 
199  DrawModePrimitive primitive() const { return primitive_; }
200  void primitive(DrawModePrimitive _val) { primitive_ = _val; }
201 
202  DrawModeLightStage lightStage() const { return lightStage_; }
203  void lightStage(DrawModeLightStage _val) { lightStage_ = _val; }
204 
205  DrawModeColorSource colorSource() const { return colorSource_; }
206  void colorSource(DrawModeColorSource _val) { colorSource_ = _val; }
207 
208  DrawModeNormalSource normalSource() const { return normalSource_; }
209  void normalSource(DrawModeNormalSource _val) { normalSource_ = _val; }
210 
211  DrawModeTexCoordSource texcoordSource() const { return texcoordSource_; }
212  void texcoordSource(DrawModeTexCoordSource _val) { texcoordSource_ = _val; }
213 
216  //===========================================================================
219  //===========================================================================
220 
222  bool lighting() const { return lightStage_ != LIGHTSTAGE_UNLIT && normalSource_ != NORMAL_NONE; }
223 
225  bool textured() const { return texcoordSource_ != TEXCOORD_NONE; }
226 
228  bool colored() const { return colorSource_ != COLOR_NONE; }
229 
231  bool flatShaded() const { return normalSource_ == NORMAL_PER_FACE; }
234  //===========================================================================
237  //===========================================================================
238 
243  bool operator!=( const DrawModeProperties& _other ) const {
244  return ( (envMapped_ != _other.envMapped_) ||
245  (primitive_ != _other.primitive_) ||
246  (lightStage_ != _other.lightStage_) ||
247  (colorSource_ != _other.colorSource_) ||
248  (texcoordSource_ != _other.texcoordSource_) ||
249  (normalSource_ != _other.normalSource_)
250  );
251  }
252 
257  bool operator==( const DrawModeProperties& _other ) const {
258  return ( (envMapped_ == _other.envMapped_) &&
259  (primitive_ == _other.primitive_) &&
260  (lightStage_ == _other.lightStage_) &&
261  (colorSource_ == _other.colorSource_) &&
262  (texcoordSource_ == _other.texcoordSource_) &&
263  (normalSource_ == _other.normalSource_)
264  );
265  }
266 
269  private:
270 
271  bool envMapped_;
272 
275 
276  DrawModeLightStage lightStage_;
277 
278  DrawModeColorSource colorSource_;
279 
280  DrawModeTexCoordSource texcoordSource_;
281 
282  DrawModeNormalSource normalSource_;
283 
284  // TODO: Shaders
285 
286  };
287 
294  class ACGDLLEXPORT DrawMode {
295  public:
296 
297  DrawMode();
298 
310  DrawMode(size_t _index);
311 
319  DrawMode( ModeFlagSet _flags );
320 
321  /* \brief Returns a registered draw mode based on the description passed or if none could be found the default one.
322  *
323  * @param _description A description created by description().
324  */
325  static DrawMode getFromDescription(std::string _description);
326 
327 
328  //===========================================================================
331  //===========================================================================
332  DrawMode & operator = (const DrawMode& _mode );
333 
334  bool operator==(const DrawMode& _mode) const;
335 
336  DrawMode operator&(const DrawMode& _mode) const;
337 
338  DrawMode& operator++();
339 
340  DrawMode& operator|=( const DrawMode& _mode2 );
341 
342  DrawMode& operator&=( const DrawMode& _mode2 );
343 
344  bool operator!=( const DrawMode& _mode2 ) const;
345 
346  DrawMode operator|( const DrawMode& _mode2 ) const;
347 
348  DrawMode operator^( const DrawMode& _mode2 ) const;
349 
350  DrawMode operator~( ) const;
351 
352  operator bool() const;
353 
356  //===========================================================================
359  //===========================================================================
360 
377  void addLayer(const DrawModeProperties* _props); // same as bitwise or operator
378 
381  size_t getNumLayers() const;
382 
387  const DrawModeProperties* getLayer(unsigned int _i) const;
388 
393  bool removeLayer(unsigned int _i);
394 
399  bool removeLayer(const DrawModeProperties* _prop);
400 
401 
406  int getLayerIndex(const DrawModeProperties* _prop) const;
407 
416  size_t getIndex() const;
417 
422  void filter( DrawMode _filter );
423 
424 
427  void combine( DrawMode _mode );
428 
433  std::string description() const;
434 
439  bool isAtomic() const;
440 
443  bool containsAtomicDrawMode( DrawMode _atomicDrawMode ) const;
444 
450  std::vector< DrawMode > getAtomicDrawModes() const;
451 
454  size_t maxModes() const;
455 
456 
468  const DrawModeProperties* getDrawModeProperties() const;
469 
474  void setDrawModeProperties(const DrawModeProperties* _props);
475 
480  void setDrawModeProperties(const DrawModeProperties& _props);
481 
482 
487  bool checkConsistency() const;
488 
489 
495  int getLayerIndexByPrimitive(DrawModePrimitive _type) const;
496 
497 
498  private:
499  ModeFlagSet modeFlags_;
500 
505  std::vector<DrawModeProperties> layers_;
506  };
507 
508 
510  extern ACGDLLEXPORT DrawMode NONE;
512  extern ACGDLLEXPORT DrawMode DEFAULT;
513 
514  //======================================================================
515  // Point Based Rendering Modes
516  //======================================================================
518  extern ACGDLLEXPORT DrawMode POINTS;
519 
521  extern ACGDLLEXPORT DrawMode POINTS_COLORED;
523  extern ACGDLLEXPORT DrawMode POINTS_SHADED;
524 
525  //======================================================================
526  // Edge Based Rendering Modes
527  //======================================================================
529  extern ACGDLLEXPORT DrawMode EDGES;
530 
532  extern ACGDLLEXPORT DrawMode EDGES_COLORED;
534  extern ACGDLLEXPORT DrawMode WIREFRAME;
535 
536  //======================================================================
537  // Face Based Rendering Modes
538  //======================================================================
539  // draw faces
540  extern ACGDLLEXPORT DrawMode FACES;
541 
543  extern ACGDLLEXPORT DrawMode HIDDENLINE;
545  extern ACGDLLEXPORT DrawMode SOLID_FLAT_SHADED;
547  extern ACGDLLEXPORT DrawMode SOLID_SMOOTH_SHADED;
549  extern ACGDLLEXPORT DrawMode SOLID_PHONG_SHADED;
551  extern ACGDLLEXPORT DrawMode SOLID_FACES_COLORED;
553  extern ACGDLLEXPORT DrawMode SOLID_POINTS_COLORED;
555  extern ACGDLLEXPORT DrawMode SOLID_POINTS_COLORED_SHADED;
557  extern ACGDLLEXPORT DrawMode SOLID_ENV_MAPPED;
559  extern ACGDLLEXPORT DrawMode SOLID_TEXTURED;
561  extern ACGDLLEXPORT DrawMode SOLID_TEXTURED_SHADED;
563  extern ACGDLLEXPORT DrawMode SOLID_1DTEXTURED;
565  extern ACGDLLEXPORT DrawMode SOLID_1DTEXTURED_SHADED;
567  extern ACGDLLEXPORT DrawMode SOLID_3DTEXTURED;
569  extern ACGDLLEXPORT DrawMode SOLID_3DTEXTURED_SHADED;
571  extern ACGDLLEXPORT DrawMode SOLID_FACES_COLORED_FLAT_SHADED;
573  extern ACGDLLEXPORT DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED;
577  extern ACGDLLEXPORT DrawMode SOLID_2DTEXTURED_FACE;
579  extern ACGDLLEXPORT DrawMode SOLID_2DTEXTURED_FACE_SHADED;
582  extern ACGDLLEXPORT DrawMode SOLID_SHADER;
584  extern ACGDLLEXPORT DrawMode SOLID_SMOOTH_SHADED_FEATURES;
585 
586  //======================================================================
587  // Face Based Rendering Modes
588  //======================================================================
589  // draw cells
590  extern ACGDLLEXPORT DrawMode CELLS;
591 
593  extern ACGDLLEXPORT DrawMode CELLS_COLORED;
594 
595 
596  //======================================================================
597  // Halfedge Based Rendering Modes
598  //======================================================================
600  extern ACGDLLEXPORT DrawMode HALFEDGES;
601 
603  extern ACGDLLEXPORT DrawMode HALFEDGES_COLORED;
604 
605 
607  extern ACGDLLEXPORT DrawMode UNUSED;
608 
609 
610  //=======================================================================
611  // Non Member Functions
612  //=======================================================================
613 
617  ACGDLLEXPORT
618  void initializeDefaultDrawModes( void );
619 
632  ACGDLLEXPORT
633  const DrawMode& addDrawMode( const std::string & _name, bool _propertyBased = false);
634 
649  ACGDLLEXPORT
650  const DrawMode& addDrawMode( const std::string & _name, const DrawModeProperties& _properties);
651 
659  ACGDLLEXPORT
660  const DrawMode& getDrawMode( const std::string & _name);
661 
662 
666  ACGDLLEXPORT
667  bool drawModeExists(const std::string & _name);
668 
671  ACGDLLEXPORT
672  DrawMode getDrawModeFromIndex( unsigned int _index );
673 
674 //=============================================================================
675 } // namespace DrawModes
676 } // namespace SceneGraph
677 } // namespace ACG
678 //=============================================================================
679 #endif // ACG_DRAWMODES_HH defined
680 //=============================================================================
681 
DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED
draw smooth shaded and colored faces (requires vertex normals and face colors)
Definition: DrawModes.cc:101
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Definition: DrawModes.cc:83
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
DrawMode SOLID_1DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:97
bool operator!=(const DrawModeProperties &_other) const
compare two properties
Definition: DrawModes.hh:243
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
Definition: DrawModes.cc:86
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
Definition: DrawModes.cc:78
DrawMode HALFEDGES
draw halfedges
Definition: DrawModes.cc:108
DrawMode SOLID_2DTEXTURED_FACE_SHADED
draw per halfedge textured faces
Definition: DrawModes.cc:103
DrawMode SOLID_2DTEXTURED_FACE
draw per halfedge textured faces
Definition: DrawModes.cc:102
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:87
DrawModeTexCoordSource
Source of Texture Coordinates.
Definition: DrawModes.hh:153
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
Definition: DrawModes.cc:813
void initializeDefaultDrawModes(void)
Definition: DrawModes.cc:645
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:88
DrawModeLightStage
Lighting stage of a mesh: unlit, smooth, phong.
Definition: DrawModes.hh:113
DrawModePrimitive
Primitive mode of a mesh.
Definition: DrawModes.hh:124
bool colored() const
Are colors used?
Definition: DrawModes.hh:228
DrawMode SOLID_ENV_MAPPED
draw environment mapped
Definition: DrawModes.cc:93
bool drawModeExists(const std::string &_name)
Check if the given draw mode exists.
Definition: DrawModes.cc:830
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Definition: DrawModes.cc:80
DrawModeColorSource
Source of Primitive Colors.
Definition: DrawModes.hh:140
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:183
DrawModePrimitive primitive_
Specify which type of primitives will get uploaded to the graphics card.
Definition: DrawModes.hh:274
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
bool flatShaded() const
Is flat shading used (Normals per face)?
Definition: DrawModes.hh:231
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Definition: DrawModes.cc:91
DrawModeNormalSource
Source of Normals.
Definition: DrawModes.hh:165
DrawMode SOLID_TEXTURED
draw textured faces
Definition: DrawModes.cc:94
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Definition: DrawModes.cc:81
DrawMode CELLS_COLORED
draw cells with colors (without shading)
Definition: DrawModes.cc:107
DrawMode SOLID_3DTEXTURED
draw textured faces
Definition: DrawModes.cc:98
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
Definition: DrawModes.cc:89
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:84
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:90
DrawMode SOLID_1DTEXTURED
draw textured faces
Definition: DrawModes.cc:96
bool textured() const
Is texturing enabled?
Definition: DrawModes.hh:225
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:95
bool lighting() const
Is lighting enabled?
Definition: DrawModes.hh:222
DrawMode EDGES
draw edges
Definition: DrawModes.cc:82
const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased)
Add a custom DrawMode.
Definition: DrawModes.cc:771
DrawMode SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED
draw per halfedge texture faces modulated with face colors with smooth shading
Definition: DrawModes.cc:110
bool operator==(const DrawModeProperties &_other) const
compare two properties
Definition: DrawModes.hh:257
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
Definition: DrawModes.cc:100
DrawMode SOLID_POINTS_COLORED_SHADED
draw faces, but use Gouraud shading to interpolate vertex colors
Definition: DrawModes.cc:92
DrawMode SOLID_SMOOTH_SHADED_FEATURES
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:105
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
Definition: DrawModes.cc:109
DrawMode getDrawModeFromIndex(unsigned int _index)
given an index of an atomic draw mode, return the drawmode
Definition: DrawModes.cc:846
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:77
DrawMode SOLID_3DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:99
std::vector< DrawModeProperties > layers_
Definition: DrawModes.hh:505