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
60namespace 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
84namespace ACG {
85namespace SceneGraph {
86
93namespace 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,
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 DrawMode(const DrawMode &) = default;
293
305 explicit DrawMode(size_t _index);
306
314 explicit DrawMode( const ModeFlagSet& _flags );
315
316 /* \brief Returns a registered draw mode based on the description passed or if none could be found the default one.
317 *
318 * @param _description A description created by description().
319 */
320 static DrawMode getFromDescription(std::string _description);
321
322
323 //===========================================================================
326 //===========================================================================
327 DrawMode & operator= (const DrawMode& _mode) = default;
328
329 bool operator==(const DrawMode& _mode) const;
330
331 DrawMode operator&(const DrawMode& _mode) const;
332
333 DrawMode& operator++();
334
335 DrawMode& operator|=( const DrawMode& _mode2 );
336
337 DrawMode& operator&=( const DrawMode& _mode2 );
338
339 bool operator!=( const DrawMode& _mode2 ) const;
340
341 DrawMode operator|( const DrawMode& _mode2 ) const;
342
343 DrawMode operator^( const DrawMode& _mode2 ) const;
344
345 DrawMode operator~( ) const;
346
347 operator bool() const;
348
351 //===========================================================================
354 //===========================================================================
355
372 void addLayer(const DrawModeProperties* _props); // same as bitwise or operator
373
376 size_t getNumLayers() const;
377
382 const DrawModeProperties* getLayer(unsigned int _i) const;
383
388 bool removeLayer(unsigned int _i);
389
394 bool removeLayer(const DrawModeProperties* _prop);
395
396
401 int getLayerIndex(const DrawModeProperties* _prop) const;
402
411 size_t getIndex() const;
412
417 void filter( DrawMode _filter );
418
419
422 void combine( DrawMode _mode );
423
428 std::string description() const;
429
434 bool isAtomic() const;
435
438 bool containsAtomicDrawMode( const DrawMode& _atomicDrawMode ) const;
439
445 std::vector< DrawMode > getAtomicDrawModes() const;
446
449 size_t maxModes() const;
450
451
463 const DrawModeProperties* getDrawModeProperties() const;
464
469 void setDrawModeProperties(const DrawModeProperties* _props);
470
475 void setDrawModeProperties(const DrawModeProperties& _props);
476
477
482 bool checkConsistency() const;
483
484
490 int getLayerIndexByPrimitive(DrawModePrimitive _type) const;
491
492
493 private:
494 ModeFlagSet modeFlags_;
495
500 std::vector<DrawModeProperties> layers_;
501 };
502
503
505 extern ACGDLLEXPORT DrawMode NONE;
507 extern ACGDLLEXPORT DrawMode DEFAULT;
508
509 //======================================================================
510 // Point Based Rendering Modes
511 //======================================================================
513 extern ACGDLLEXPORT DrawMode POINTS;
514
516 extern ACGDLLEXPORT DrawMode POINTS_COLORED;
518 extern ACGDLLEXPORT DrawMode POINTS_SHADED;
519
520 //======================================================================
521 // Edge Based Rendering Modes
522 //======================================================================
524 extern ACGDLLEXPORT DrawMode EDGES;
525
527 extern ACGDLLEXPORT DrawMode EDGES_COLORED;
529 extern ACGDLLEXPORT DrawMode WIREFRAME;
530
531 //======================================================================
532 // Face Based Rendering Modes
533 //======================================================================
534 // draw faces
535 extern ACGDLLEXPORT DrawMode FACES;
536
538 extern ACGDLLEXPORT DrawMode HIDDENLINE;
540 extern ACGDLLEXPORT DrawMode SOLID_FLAT_SHADED;
542 extern ACGDLLEXPORT DrawMode SOLID_SMOOTH_SHADED;
544 extern ACGDLLEXPORT DrawMode SOLID_PHONG_SHADED;
546 extern ACGDLLEXPORT DrawMode SOLID_FACES_COLORED;
548 extern ACGDLLEXPORT DrawMode SOLID_POINTS_COLORED;
550 extern ACGDLLEXPORT DrawMode SOLID_POINTS_COLORED_SHADED;
552 extern ACGDLLEXPORT DrawMode SOLID_ENV_MAPPED;
554 extern ACGDLLEXPORT DrawMode SOLID_TEXTURED;
556 extern ACGDLLEXPORT DrawMode SOLID_TEXTURED_SHADED;
558 extern ACGDLLEXPORT DrawMode SOLID_1DTEXTURED;
560 extern ACGDLLEXPORT DrawMode SOLID_1DTEXTURED_SHADED;
562 extern ACGDLLEXPORT DrawMode SOLID_3DTEXTURED;
564 extern ACGDLLEXPORT DrawMode SOLID_3DTEXTURED_SHADED;
566 extern ACGDLLEXPORT DrawMode SOLID_FACES_COLORED_FLAT_SHADED;
572 extern ACGDLLEXPORT DrawMode SOLID_2DTEXTURED_FACE;
574 extern ACGDLLEXPORT DrawMode SOLID_2DTEXTURED_FACE_SHADED;
577 extern ACGDLLEXPORT DrawMode SOLID_SHADER;
579 extern ACGDLLEXPORT DrawMode SOLID_SMOOTH_SHADED_FEATURES;
580
581 //======================================================================
582 // Face Based Rendering Modes
583 //======================================================================
584 // draw cells
585 extern ACGDLLEXPORT DrawMode CELLS;
586
588 extern ACGDLLEXPORT DrawMode CELLS_COLORED;
589
590
591 //======================================================================
592 // Halfedge Based Rendering Modes
593 //======================================================================
595 extern ACGDLLEXPORT DrawMode HALFEDGES;
596
598 extern ACGDLLEXPORT DrawMode HALFEDGES_COLORED;
599
600
602 extern ACGDLLEXPORT DrawMode UNUSED;
603
604
605 //=======================================================================
606 // Non Member Functions
607 //=======================================================================
608
612 ACGDLLEXPORT
613 void initializeDefaultDrawModes( void );
614
627 ACGDLLEXPORT
628 const DrawMode& addDrawMode( const std::string & _name, bool _propertyBased = false);
629
644 ACGDLLEXPORT
645 const DrawMode& addDrawMode( const std::string & _name, const DrawModeProperties& _properties);
646
654 ACGDLLEXPORT
655 const DrawMode& getDrawMode( const std::string & _name);
656
657
661 ACGDLLEXPORT
662 bool drawModeExists(const std::string & _name);
663
666 ACGDLLEXPORT
667 DrawMode getDrawModeFromIndex( unsigned int _index );
668
669//=============================================================================
670} // namespace DrawModes
671} // namespace SceneGraph
672} // namespace ACG
673//=============================================================================
674#endif // ACG_DRAWMODES_HH defined
675//=============================================================================
676
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:177
bool colored() const
Are colors used?
Definition: DrawModes.hh:222
bool textured() const
Is texturing enabled?
Definition: DrawModes.hh:219
bool operator==(const DrawModeProperties &_other) const
compare two properties
Definition: DrawModes.hh:251
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
DrawModePrimitive primitive_
Specify which type of primitives will get uploaded to the graphics card.
Definition: DrawModes.hh:268
std::vector< DrawModeProperties > layers_
Definition: DrawModes.hh:500
DrawMode EDGES
draw edges
Definition: DrawModes.cc:76
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:82
DrawModeLightStage
Lighting stage of a mesh: unlit, smooth, phong.
Definition: DrawModes.hh:108
DrawMode UNUSED
marks the last used ID
Definition: DrawModes.cc:105
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
Definition: DrawModes.cc:83
DrawMode HALFEDGES
draw halfedges
Definition: DrawModes.cc:102
DrawMode SOLID_ENV_MAPPED
draw environment mapped
Definition: DrawModes.cc:87
DrawMode SOLID_3DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:93
DrawMode SOLID_POINTS_COLORED_SHADED
draw faces, but use Gouraud shading to interpolate vertex colors
Definition: DrawModes.cc:86
DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED
draw smooth shaded and colored faces (requires vertex normals and face colors)
Definition: DrawModes.cc:95
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
Definition: DrawModes.cc:74
bool drawModeExists(const std::string &_name)
Check if the given draw mode exists.
Definition: DrawModes.cc:814
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
Definition: DrawModes.cc:103
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:89
DrawMode SOLID_2DTEXTURED_FACE
draw per halfedge textured faces
Definition: DrawModes.cc:96
DrawMode SOLID_2DTEXTURED_FACE_SHADED
draw per halfedge textured faces
Definition: DrawModes.cc:97
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:84
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
Definition: DrawModes.cc:797
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
Definition: DrawModes.cc:72
DrawModeColorSource
Source of Primitive Colors.
Definition: DrawModes.hh:135
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
Definition: DrawModes.cc:94
DrawMode WIREFRAME
draw wireframe
Definition: DrawModes.cc:78
DrawMode CELLS_COLORED
draw cells with colors (without shading)
Definition: DrawModes.cc:101
DrawModeTexCoordSource
Source of Texture Coordinates.
Definition: DrawModes.hh:148
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
Definition: DrawModes.cc:80
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 POINTS
draw unlighted points using the default base color
Definition: DrawModes.cc:73
DrawMode getDrawModeFromIndex(unsigned int _index)
given an index of an atomic draw mode, return the drawmode
Definition: DrawModes.cc:830
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
Definition: DrawModes.cc:75
DrawMode SOLID_1DTEXTURED
draw textured faces
Definition: DrawModes.cc:90
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Definition: DrawModes.cc:77
DrawMode NONE
not a valid draw mode
Definition: DrawModes.cc:71
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Definition: DrawModes.cc:85
DrawMode SOLID_3DTEXTURED
draw textured faces
Definition: DrawModes.cc:92
DrawMode SOLID_SMOOTH_SHADED_FEATURES
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:99
DrawModeNormalSource
Source of Normals.
Definition: DrawModes.hh:160
void initializeDefaultDrawModes(void)
Definition: DrawModes.cc:629
const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased)
Add a custom DrawMode.
Definition: DrawModes.cc:755
DrawMode SOLID_TEXTURED
draw textured faces
Definition: DrawModes.cc:88
DrawMode SOLID_1DTEXTURED_SHADED
draw smooth shaded textured faces
Definition: DrawModes.cc:91
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:81
DrawModePrimitive
Primitive mode of a mesh.
Definition: DrawModes.hh:119
Namespace providing different geometric functions concerning angles.