56 #include "DrawModes.hh" 57 #include "BaseNode.hh" 132 void name(
const std::string& _name) {
137 const std::string&
name()
const {
145 bool propertyBased()
const {
162 typedef std::vector< DrawModeInternal > VecDrawModes;
166 static VecDrawModes registeredDrawModes_;
178 envMapped_(_envMapping),
179 primitive_(_primitive),
180 lightStage_(_lightStage),
181 colorSource_(_colorSource),
182 texcoordSource_(_texcoordSource),
183 normalSource_(_normalSource)
188 DrawMode::DrawMode(
size_t _index)
191 if ( _index >= modeFlags_.size() ) {
192 std::cerr <<
"Illegal drawMode specification from unsigned int. This should not be a bitset!!!" << std::endl;
194 modeFlags_.set(_index);
200 DrawMode::DrawMode() {
205 DrawMode::DrawMode(
const ModeFlagSet& _flags) :
212 DrawMode DrawMode::getFromDescription(std::string _description)
216 std::istringstream f(_description);
218 while (std::getline(f, s,
'+')) {
219 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
220 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
221 if(modeIter->name() == s) {
222 val |= modeIter->id();
232 DrawMode::operator bool()
const {
233 return( modeFlags_ != NONE.modeFlags_ );
268 bool DrawMode::operator==(
const DrawMode& _mode)
const {
269 return modeFlags_ == _mode.modeFlags_;
274 modeFlags_ = _mode.modeFlags_;
281 bool DrawMode::operator!=(
const DrawMode& _mode2 )
const {
282 return (modeFlags_ != _mode2.modeFlags_);
286 if ( modeFlags_.count() != 1 ) {
287 std::cerr <<
"Operator ++ for drawMode which is not atomic!!" << std::endl;
304 for (
int i = (
int)andMode.
getNumLayers() - 1; i >= 0; --i)
316 modeFlags_ |= _mode2.modeFlags_;
318 for (
unsigned int i = 0; i < _mode2.
getNumLayers(); ++i)
327 modeFlags_ &= _mode2.modeFlags_;
351 for (
unsigned int i = 0; i < _mode2.
getNumLayers(); ++i)
367 std::vector<const DrawModeProperties*> tmpLayers;
376 tmpLayers.push_back(curProps);
381 for (
unsigned int i = 0; i < _mode2.
getNumLayers(); ++i)
385 if (!curProps)
continue;
392 for (
unsigned int k = 0; addToVec && k < tmpLayers.size(); ++k)
397 tmpLayers.erase(tmpLayers.begin() + k);
403 tmpLayers.push_back(curProps);
409 if (tmpLayers.empty())
419 for (
unsigned int i = 1; i < tmpLayers.size(); ++i)
428 DrawMode DrawMode::operator~( )
const {
435 if ( modeFlags_.count() == 1 ) {
436 for (
size_t i = 0 ; i < modeFlags_.size() ; ++i )
446 std::string text(
"");
448 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
449 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
451 if( (*
this) & modeIter->id() )
453 if (!text.empty()) text +=
"+";
454 text += modeIter->name();
465 modeFlags_ = (modeFlags_ | _filter.modeFlags_) ^ _filter.modeFlags_;
467 for (
unsigned int i = 0; i < _filter.
getNumLayers(); ++i)
482 modeFlags_ = (modeFlags_ ^ _mode.modeFlags_);
494 std::vector< DrawMode >
497 std::vector< DrawMode > draw_mode_ids;
499 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
500 for( modeIter = registeredDrawModes_.begin();
503 if( (*
this) & modeIter->id() )
504 draw_mode_ids.push_back( modeIter->id() );
506 return draw_mode_ids;
513 return(modeFlags_.count() == 1 );
522 return (*
this) & _atomicDrawMode;
528 return (modeFlags_.size() );
577 for (
unsigned int i = 0; i <
layers_.size(); ++i)
579 for (
unsigned int k = i+1; k <
layers_.size(); ++k)
597 for (
unsigned int k = 0; k <
layers_.size(); ++k)
599 if (
layers_[k].primitive() == PRIMITIVE_POINT)
613 if (!_prop)
return -1;
615 for (
unsigned int i = 0; i <
layers_.size(); ++i)
628 for (
unsigned int i = 0; i <
layers_.size(); ++i)
630 if (
layers_[i].primitive() == _type )
641 static bool initialized_ =
false;
646 registeredDrawModes_.clear();
708 registeredDrawModes_.push_back(
DrawModeInternal(
"Points (colored)", POINTS_COLORED ) );
709 registeredDrawModes_.push_back(
DrawModeInternal(
"Points (shaded)", POINTS_SHADED ) );
712 registeredDrawModes_.push_back(
DrawModeInternal(
"Edges Colored", EDGES_COLORED ) );
714 registeredDrawModes_.push_back(
DrawModeInternal(
"Wireframe", WIREFRAME ) );
718 registeredDrawModes_.push_back(
DrawModeInternal(
"Hiddenline", HIDDENLINE ) );
720 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (flat shaded)", SOLID_FLAT_SHADED ) );
721 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (smooth shaded)", SOLID_SMOOTH_SHADED ) );
722 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (Phong shaded)", SOLID_PHONG_SHADED ) );
724 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (colored per-face)", SOLID_FACES_COLORED ) );
725 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (colored per-vertex)", SOLID_POINTS_COLORED ) );
726 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (colored per-vertex, shaded)", SOLID_POINTS_COLORED_SHADED ) );
728 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (environment mapped)", SOLID_ENV_MAPPED ) );
730 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (textured)", SOLID_TEXTURED ) );
731 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (textured, shaded)", SOLID_TEXTURED_SHADED ) );
733 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (scalar field)", SOLID_1DTEXTURED ) );
734 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (scalar field, shaded)", SOLID_1DTEXTURED_SHADED ) );
736 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (3D textured)", SOLID_3DTEXTURED ) );
737 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (3D textured, shaded)", SOLID_3DTEXTURED_SHADED ) );
739 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (colored per-face, flat shaded)", SOLID_FACES_COLORED_FLAT_SHADED ) );
740 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (colored per-face, smooth shaded)", SOLID_FACES_COLORED_SMOOTH_SHADED ) );
742 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (colored per-face, face textured, smooth shaded)", SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED));
745 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (face textured)", SOLID_2DTEXTURED_FACE ) );
746 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (face textured, shaded)", SOLID_2DTEXTURED_FACE_SHADED ) );
747 registeredDrawModes_.push_back(
DrawModeInternal(
"Shader controlled", SOLID_SHADER ) );
749 registeredDrawModes_.push_back(
DrawModeInternal(
"Solid (smooth shaded, features)", SOLID_SMOOTH_SHADED_FEATURES ) );
752 registeredDrawModes_.push_back(
DrawModeInternal(
"Cells Colored", CELLS_COLORED ) );
754 registeredDrawModes_.push_back(
DrawModeInternal(
"Halfedges", HALFEDGES ) );
755 registeredDrawModes_.push_back(
DrawModeInternal(
"Halfedges Colored", HALFEDGES_COLORED ) );
768 VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
770 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
771 if( _name == modeIter->name() ) {
772 return modeIter->id();
778 registeredDrawModes_.push_back(
DrawModeInternal( _name, firstFreeID_ , _propertyBased) );
781 return registeredDrawModes_[ registeredDrawModes_.size() - 1 ].id();
792 VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
794 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
795 if( _name == modeIter->name() ) {
796 modeIter->properties() = _properties;
810 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
812 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
814 if( _name == modeIter->name() )
816 return modeIter->id();
827 VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
829 for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
831 if( _name == modeIter->name() )
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
DrawMode SOLID_PHONG_SHADED
draw phong shaded faces
DrawMode WIREFRAME
draw wireframe
Namespace providing different geometric functions concerning angles.
DrawMode EDGES_COLORED
draw edges with colors (without shading)
DrawMode getDrawModeFromIndex(unsigned int _index)
given an index of an atomic draw mode, return the drawmode
DrawModeLightStage
Lighting stage of a mesh: unlit, smooth, phong.
int getLayerIndex(const DrawModeProperties *_prop) const
returns layer index of a property, -1 if not in list
Definition of a draw mode.
DrawMode POINTS_SHADED
draw shaded points (requires point normals)
const DrawModeProperties * getDrawModeProperties() const
returns the base properties of this draw mode
void combine(DrawMode _mode)
combine with another drawmode
DrawMode id_
The id of the DrawMode.
bool isAtomic() const
Check if this is an atomic draw Mode.
DrawMode SOLID_3DTEXTURED_SHADED
draw smooth shaded textured faces
DrawModeColorSource
Source of Primitive Colors.
bool checkConsistency() const
checks consistency of property layers
DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED
draw smooth shaded and colored faces (requires vertex normals and face colors)
DrawMode SOLID_1DTEXTURED_SHADED
draw smooth shaded textured faces
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
DrawMode HALFEDGES
draw halfedges
DrawMode SOLID_ENV_MAPPED
draw environment mapped
DrawMode SOLID_SMOOTH_SHADED_FEATURES
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
void setDrawModeProperties(const DrawModeProperties *_props)
set the base properties of this draw mode
DrawMode SOLID_1DTEXTURED
draw textured faces
const DrawMode & getDrawMode(const std::string &_name)
Get a custom DrawMode.
DrawModePrimitive
Primitive mode of a mesh.
size_t getNumLayers() const
returns the layer count
bool drawModeExists(const std::string &_name)
Check if the given draw mode exists.
DrawModeTexCoordSource
Source of Texture Coordinates.
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.
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
DrawMode CELLS_COLORED
draw cells with colors (without shading)
const std::string & name() const
Get the name of the DrawMode.
std::vector< DrawModeProperties > layers_
DrawMode SOLID_FACES_COLORED_2DTEXTURED_FACE_SMOOTH_SHADED
draw per halfedge texture faces modulated with face colors with smooth shading
DrawMode HIDDENLINE
draw hidden line (2 rendering passes needed)
void addLayer(const DrawModeProperties *_props)
add another layer on top of this drawmode
DrawMode UNUSED
marks the last used ID
DrawMode NONE
not a valid draw mode
std::vector< DrawMode > getAtomicDrawModes() const
Separates this drawMode into a list of all separate atomic draw modes.
DrawMode SOLID_TEXTURED_SHADED
draw smooth shaded textured faces
bool removeLayer(unsigned int _i)
remove layer at index i
const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased)
Add a custom DrawMode.
DrawMode SOLID_2DTEXTURED_FACE
draw per halfedge textured faces
DrawModeProperties properties_
The properties associated with this DrawMode.
bool propertyBased_
Flag if the DrawMode is property based.
DrawMode SOLID_3DTEXTURED
draw textured faces
DrawModeInternal(const std::string &_name, const DrawMode &_id, const bool _propertyBased=false)
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
void filter(DrawMode _filter)
filter out one drawmode
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
size_t getIndex() const
get an index of the current drawMode
std::string description() const
DrawMode SOLID_2DTEXTURED_FACE_SHADED
draw per halfedge textured faces
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
int getLayerIndexByPrimitive(DrawModePrimitive _type) const
search for layer with specified primitive
DrawMode SOLID_TEXTURED
draw textured faces
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
void initializeDefaultDrawModes(void)
DrawMode POINTS
draw unlighted points using the default base color
DrawModeProperties stores a set of properties that defines, how to render an object.
std::string name_
Human Readable Name.
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
size_t maxModes() const
Get the number of maximum Modes which could be handled by the current implementation.
DrawMode SOLID_POINTS_COLORED_SHADED
draw faces, but use Gouraud shading to interpolate vertex colors
DrawModeNormalSource
Source of Normals.