62 #include "DrawModes.hh"
63 #include "BaseNode.hh"
71 namespace SceneGraph {
85 DrawMode FACES = ModeFlagSet(1) << 7;
106 DrawMode CELLS = ModeFlagSet(1) << 28;
138 void name(
const std::string& _name) {
143 const std::string&
name()
const {
151 bool propertyBased()
const {
156 DrawModeProperties& properties() {
168 typedef std::vector< DrawModeInternal > VecDrawModes;
172 static VecDrawModes registeredDrawModes_;
184 envMapped_(_envMapping),
185 primitive_(_primitive),
186 lightStage_(_lightStage),
187 colorSource_(_colorSource),
188 texcoordSource_(_texcoordSource),
189 normalSource_(_normalSource)
194 DrawMode::DrawMode(
size_t _index)
197 if ( _index >= modeFlags_.size() ) {
198 std::cerr <<
"Illegal drawMode specification from unsigned int. This should not be a bitset!!!" << std::endl;
200 modeFlags_.set(_index);
206 DrawMode::DrawMode() {
211 DrawMode::DrawMode(ModeFlagSet _flags) :
218 DrawMode DrawMode::getFromDescription(std::string _description)
222 std::istringstream f(_description);
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();
238 DrawMode::operator bool()
const {
239 return( modeFlags_ != NONE.modeFlags_ );
274 bool DrawMode::operator==(
const DrawMode& _mode)
const {
275 return modeFlags_ == _mode.modeFlags_;
279 DrawMode & DrawMode::operator =(
const DrawMode& _mode) {
280 modeFlags_ = _mode.modeFlags_;
287 bool DrawMode::operator!=(
const DrawMode& _mode2 )
const {
288 return (modeFlags_ != _mode2.modeFlags_);
291 DrawMode& DrawMode::operator++() {
292 if ( modeFlags_.count() != 1 ) {
293 std::cerr <<
"Operator ++ for drawMode which is not atomic!!" << std::endl;
301 DrawMode DrawMode::operator&(
const DrawMode& _mode)
const {
302 DrawMode andMode = (modeFlags_ & _mode.modeFlags_);
310 for (
int i = (
int)andMode.getNumLayers() - 1; i >= 0; --i)
312 int layerIndex = _mode.getLayerIndex(andMode.getLayer(i));
315 andMode.removeLayer(i);
321 DrawMode& DrawMode::operator|=(
const DrawMode& _mode2 ) {
322 modeFlags_ |= _mode2.modeFlags_;
324 for (
unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
332 DrawMode& DrawMode::operator&=(
const DrawMode& _mode2 ) {
333 modeFlags_ &= _mode2.modeFlags_;
338 int layerIndex2 = _mode2.getLayerIndex(
getLayer(i));
349 DrawMode DrawMode::operator|(
const DrawMode& _mode2 )
const {
350 DrawMode combined = ( modeFlags_ | _mode2.modeFlags_ );
357 for (
unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
358 combined.addLayer(_mode2.getLayer(i));
363 DrawMode DrawMode::operator^(
const DrawMode& _mode2 )
const {
365 DrawMode xorMode = ( modeFlags_ ^ _mode2.modeFlags_ );
369 const DrawModeProperties* curProps = 0;
373 std::vector<const DrawModeProperties*> tmpLayers;
382 tmpLayers.push_back(curProps);
387 for (
unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
389 curProps = _mode2.getLayer(i);
391 if (!curProps)
continue;
398 for (
unsigned int k = 0; addToVec && k < tmpLayers.size(); ++k)
400 if (!memcmp(tmpLayers[k], curProps,
sizeof(DrawModeProperties)))
403 tmpLayers.erase(tmpLayers.begin() + k);
409 tmpLayers.push_back(curProps);
415 if (tmpLayers.empty())
417 xorMode.removeLayer(0u);
424 xorMode.setDrawModeProperties(tmpLayers[0]);
425 for (
unsigned int i = 1; i < tmpLayers.size(); ++i)
426 xorMode.addLayer(tmpLayers[i]);
434 DrawMode DrawMode::operator~( )
const {
435 return( ~modeFlags_ );
441 if ( modeFlags_.count() == 1 ) {
442 for (
size_t i = 0 ; i < modeFlags_.size() ; ++i )
452 std::string text(
"");
454 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
455 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
457 if( (*
this) & modeIter->id() )
459 if (!text.empty()) text +=
"+";
460 text += modeIter->name();
471 modeFlags_ = (modeFlags_ | _filter.modeFlags_) ^ _filter.modeFlags_;
473 for (
unsigned int i = 0; i < _filter.
getNumLayers(); ++i)
488 modeFlags_ = (modeFlags_ ^ _mode.modeFlags_);
500 std::vector< DrawMode >
503 std::vector< DrawMode > draw_mode_ids;
505 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
506 for( modeIter = registeredDrawModes_.begin();
509 if( (*
this) & modeIter->id() )
510 draw_mode_ids.push_back( modeIter->id() );
512 return draw_mode_ids;
519 return(modeFlags_.count() == 1 );
528 return (*
this) & _atomicDrawMode;
534 return (modeFlags_.size() );
583 for (
unsigned int i = 0; i <
layers_.size(); ++i)
585 for (
unsigned int k = i+1; k <
layers_.size(); ++k)
603 for (
unsigned int k = 0; k <
layers_.size(); ++k)
605 if (
layers_[k].primitive() == PRIMITIVE_POINT)
619 if (!_prop)
return -1;
621 for (
unsigned int i = 0; i <
layers_.size(); ++i)
634 for (
unsigned int i = 0; i <
layers_.size(); ++i)
636 if (
layers_[i].primitive() == _type )
647 static bool initialized_ =
false;
652 registeredDrawModes_.clear();
710 registeredDrawModes_.push_back( DrawModeInternal(
"<invalid>", NONE ) );
711 registeredDrawModes_.push_back( DrawModeInternal(
"Default", DEFAULT ) );
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 ) );
717 registeredDrawModes_.push_back( DrawModeInternal(
"Edges", EDGES ) );
718 registeredDrawModes_.push_back( DrawModeInternal(
"Edges Colored", EDGES_COLORED ) );
720 registeredDrawModes_.push_back( DrawModeInternal(
"Wireframe", WIREFRAME ) );
722 registeredDrawModes_.push_back( DrawModeInternal(
"Faces", FACES ) );
724 registeredDrawModes_.push_back( DrawModeInternal(
"Hiddenline", HIDDENLINE ) );
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 ) );
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 ) );
734 registeredDrawModes_.push_back( DrawModeInternal(
"Solid (environment mapped)", SOLID_ENV_MAPPED ) );
736 registeredDrawModes_.push_back( DrawModeInternal(
"Solid (textured)", SOLID_TEXTURED ) );
737 registeredDrawModes_.push_back( DrawModeInternal(
"Solid (textured, shaded)", SOLID_TEXTURED_SHADED ) );
739 registeredDrawModes_.push_back( DrawModeInternal(
"Solid (scalar field)", SOLID_1DTEXTURED ) );
740 registeredDrawModes_.push_back( DrawModeInternal(
"Solid (scalar field, shaded)", SOLID_1DTEXTURED_SHADED ) );
742 registeredDrawModes_.push_back( DrawModeInternal(
"Solid (3D textured)", SOLID_3DTEXTURED ) );
743 registeredDrawModes_.push_back( DrawModeInternal(
"Solid (3D textured, shaded)", SOLID_3DTEXTURED_SHADED ) );
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 ) );
748 registeredDrawModes_.push_back(DrawModeInternal(
"Solid (colored per-face, face textured, smooth shaded)", SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED));
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 ) );
755 registeredDrawModes_.push_back( DrawModeInternal(
"Solid (smooth shaded, features)", SOLID_SMOOTH_SHADED_FEATURES ) );
757 registeredDrawModes_.push_back( DrawModeInternal(
"Cells", CELLS ) );
758 registeredDrawModes_.push_back( DrawModeInternal(
"Cells Colored", CELLS_COLORED ) );
760 registeredDrawModes_.push_back( DrawModeInternal(
"Halfedges", HALFEDGES ) );
761 registeredDrawModes_.push_back( DrawModeInternal(
"Halfedges Colored", HALFEDGES_COLORED ) );
774 VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
776 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
777 if( _name == modeIter->name() ) {
778 return modeIter->id();
784 registeredDrawModes_.push_back( DrawModeInternal( _name, firstFreeID_ , _propertyBased) );
787 return registeredDrawModes_[ registeredDrawModes_.size() - 1 ].id();
798 VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
800 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
801 if( _name == modeIter->name() ) {
802 modeIter->properties() = _properties;
816 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
818 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
820 if( _name == modeIter->name() )
822 return modeIter->id();
833 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
835 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
837 if( _name == modeIter->name() )
DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED
draw smooth shaded and colored faces (requires vertex normals and face colors)
DrawModePrimitive
Primitive mode of a mesh.
ACGDLLEXPORT DrawMode NONE
not a valid draw mode
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
size_t maxModes() const
Get the number of maximum Modes which could be handled by the current implementation.
size_t getNumLayers() const
returns the layer count
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Namespace providing different geometric functions concerning angles.
DrawMode SOLID_1DTEXTURED_SHADED
draw smooth shaded textured faces
DrawModeInternal(const std::string &_name, const DrawMode &_id, const bool _propertyBased=false)
std::string name_
Human Readable Name.
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
void setDrawModeProperties(const DrawModeProperties *_props)
set the base properties of this draw mode
DrawModeProperties properties_
The properties associated with this DrawMode.
size_t getIndex() const
get an index of the current drawMode
bool propertyBased_
Flag if the DrawMode is property based.
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
bool checkConsistency() const
checks consistency of property layers
DrawMode HALFEDGES
draw halfedges
DrawMode SOLID_2DTEXTURED_FACE_SHADED
draw per halfedge textured faces
void addLayer(const DrawModeProperties *_props)
add another layer on top of this drawmode
ACGDLLEXPORT DrawMode POINTS_SHADED
draw shaded points (requires point normals)
DrawMode SOLID_2DTEXTURED_FACE
draw per halfedge textured faces
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
DrawModeTexCoordSource
Source of Texture Coordinates.
ACGDLLEXPORT DrawMode getDrawModeFromIndex(unsigned int _index)
given an index of an atomic draw mode, return the drawmode
std::vector< DrawModeProperties > layers_
ACGDLLEXPORT void initializeDefaultDrawModes(void)
ACGDLLEXPORT const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
DrawModeLightStage
Lighting stage of a mesh: unlit, smooth, phong.
DrawModePrimitive
Primitive mode of a mesh.
void combine(DrawMode _mode)
combine with another drawmode
ACGDLLEXPORT DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
DrawMode SOLID_ENV_MAPPED
draw environment mapped
void filter(DrawMode _filter)
filter out one drawmode
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
DrawModeColorSource
Source of Primitive Colors.
bool isAtomic() const
Check if this is an atomic draw Mode.
DrawModeProperties stores a set of properties that defines, how to render an object.
DrawMode UNUSED
marks the last used ID
const DrawModeProperties * getDrawModeProperties() const
returns the base properties of this draw mode
int getLayerIndexByPrimitive(DrawModePrimitive _type) const
search for layer with specified primitive
std::string description() const
DrawMode POINTS
draw unlighted points using the default base color
const std::string & name() const
Get the name of the DrawMode.
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
DrawModeNormalSource
Source of Normals.
std::vector< DrawMode > getAtomicDrawModes() const
Separates this drawMode into a list of all separate atomic draw modes.
DrawMode SOLID_TEXTURED
draw textured faces
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
DrawMode CELLS_COLORED
draw cells with colors (without shading)
DrawMode SOLID_3DTEXTURED
draw textured faces
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
DrawModeProperties stores a set of properties that defines, how to render an object.
DrawMode WIREFRAME
draw wireframe
Definition of a draw mode.
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
DrawMode id_
The id of the DrawMode.
bool containsAtomicDrawMode(DrawMode _atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
DrawMode SOLID_1DTEXTURED
draw textured faces
ACGDLLEXPORT DrawMode POINTS
draw unlighted points using the default base color
ACGDLLEXPORT DrawMode UNUSED
marks the last used ID
bool removeLayer(unsigned int _i)
remove layer at index i
ACGDLLEXPORT DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
void name(const std::string &_name)
Set the name of the DrawMode.
ACGDLLEXPORT bool drawModeExists(const std::string &_name)
Check if the given draw mode exists.
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
ACGDLLEXPORT const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased=false)
Add a custom DrawMode.
DrawMode SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED
draw per halfedge texture faces modulated with face colors with smooth shading
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
DrawMode SOLID_POINTS_COLORED_SHADED
draw faces, but use Gouraud shading to interpolate vertex colors
DrawMode SOLID_SMOOTH_SHADED_FEATURES
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
DrawMode NONE
not a valid draw mode
DrawMode SOLID_3DTEXTURED_SHADED
draw smooth shaded textured faces
int getLayerIndex(const DrawModeProperties *_prop) const
returns layer index of a property, -1 if not in list
std::vector< DrawModeProperties > layers_