DrawModes.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include "DrawModes.hh"
00056 #include "BaseNode.hh"
00057
00058 #include <algorithm>
00059
00060
00061
00062
00063 namespace ACG {
00064 namespace SceneGraph {
00065 namespace DrawModes {
00066
00067
00068
00069
00070
00072 class DrawMode {
00073
00074 public:
00076 DrawMode() {}
00077
00079 DrawMode( const std::string & _name, const int & _id )
00080 : name_( _name ), id_( _id ) {}
00081
00082 std::string name_;
00083 unsigned int id_;
00084 };
00085
00086 typedef std::vector< DrawMode > VecDrawModes;
00087
00090 static VecDrawModes currentDrawModes_;
00091
00093 static unsigned int firstFreeID_;
00094
00095
00096
00097
00098
00099
00100 std::string description(unsigned int _drawMode)
00101 {
00102
00103
00104
00105
00106
00107
00108
00109 std::string text("");
00110
00111 VecDrawModes::iterator modeIter, modeEnd( currentDrawModes_.end() );
00112 for( modeIter = currentDrawModes_.begin();
00113 modeIter != modeEnd;
00114 ++modeIter )
00115 {
00116 if( _drawMode & modeIter->id_ )
00117 {
00118 if (!text.empty()) text += "+";
00119 text += modeIter->name_;
00120 }
00121 }
00122
00123 return text;
00124 }
00125
00126
00127
00128
00129
00130 std::vector< unsigned int >
00131 getDrawModeIDs( unsigned int _drawModes )
00132 {
00133
00134
00135
00136
00137
00138
00139 std::vector< unsigned int > draw_mode_ids;
00140
00141 VecDrawModes::iterator modeIter, modeEnd( currentDrawModes_.end() );
00142 for( modeIter = currentDrawModes_.begin();
00143 modeIter != modeEnd;
00144 ++modeIter )
00145 if( _drawModes & modeIter->id_ )
00146 draw_mode_ids.push_back( modeIter->id_ );
00147
00148 return draw_mode_ids;
00149 }
00150
00151
00152
00153
00154
00155 bool
00156 containsId( unsigned int _drawMode, unsigned int _id )
00157 {
00158
00159
00160
00161
00162
00163
00164 return _drawMode & _id;
00165 }
00166
00167
00168
00169
00170
00171 void initializeDefaultDrawModes( void )
00172 {
00173 static bool initialized_ = false;
00174
00175 if( initialized_ )
00176 return;
00177
00178 currentDrawModes_.clear();
00179
00180 currentDrawModes_.push_back( DrawMode( "<invalid>", NONE ) );
00181 currentDrawModes_.push_back( DrawMode( "Default", DEFAULT ) );
00182
00183 currentDrawModes_.push_back( DrawMode( "Points", POINTS ) );
00184 currentDrawModes_.push_back( DrawMode( "Points (colored)", POINTS_COLORED ) );
00185 currentDrawModes_.push_back( DrawMode( "Points (shaded)", POINTS_SHADED ) );
00186
00187 currentDrawModes_.push_back( DrawMode( "Wireframe", WIREFRAME ) );
00188 currentDrawModes_.push_back( DrawMode( "Hiddenline", HIDDENLINE ) );
00189
00190 currentDrawModes_.push_back( DrawMode( "Solid (flat shaded)", SOLID_FLAT_SHADED ) );
00191 currentDrawModes_.push_back( DrawMode( "Solid (smooth shaded)", SOLID_SMOOTH_SHADED ) );
00192 currentDrawModes_.push_back( DrawMode( "Solid (Phong shaded)", SOLID_PHONG_SHADED ) );
00193
00194 currentDrawModes_.push_back( DrawMode( "Solid (colored per-face)", SOLID_FACES_COLORED ) );
00195 currentDrawModes_.push_back( DrawMode( "Solid (colored per-vertex)", SOLID_POINTS_COLORED ) );
00196
00197 currentDrawModes_.push_back( DrawMode( "Solid (environment mapped)", SOLID_ENV_MAPPED ) );
00198
00199 currentDrawModes_.push_back( DrawMode( "Solid (textured)", SOLID_TEXTURED ) );
00200 currentDrawModes_.push_back( DrawMode( "Solid (textured, shaded)", SOLID_TEXTURED_SHADED ) );
00201
00202 currentDrawModes_.push_back( DrawMode( "Solid (scalar field)", SOLID_1DTEXTURED ) );
00203 currentDrawModes_.push_back( DrawMode( "Solid (scalar field, shaded)", SOLID_1DTEXTURED_SHADED ) );
00204
00205 currentDrawModes_.push_back( DrawMode( "Solid (3D textured)", SOLID_3DTEXTURED ) );
00206 currentDrawModes_.push_back( DrawMode( "Solid (3D textured, shaded)", SOLID_3DTEXTURED_SHADED ) );
00207
00208 currentDrawModes_.push_back( DrawMode( "Solid (colored per-face, flat shaded)", SOLID_FACES_COLORED_FLAT_SHADED ) );
00209
00210 currentDrawModes_.push_back( DrawMode( "Solid (face textured)", SOLID_2DTEXTURED_FACE ) );
00211 currentDrawModes_.push_back( DrawMode( "Solid (face textured, shaded)", SOLID_2DTEXTURED_FACE_SHADED ) );
00212 currentDrawModes_.push_back( DrawMode( "Shader controlled", SOLID_SHADER ) );
00213
00214 firstFreeID_ = UNUSED;
00215 initialized_ = true;
00216 }
00217
00218
00219
00220
00221
00222 bool addDrawMode( const std::string & _name, unsigned int & _newId )
00223 {
00224
00225 VecDrawModes::iterator modeIter, modeEnd( currentDrawModes_.end() );
00226
00227 for( modeIter = currentDrawModes_.begin();
00228 modeIter != modeEnd;
00229 ++modeIter )
00230 {
00231 if( _name == modeIter->name_ )
00232 return modeIter->id_;
00233 }
00234
00235
00236 if( firstFreeID_ == (unsigned int) (1<<31) )
00237 return false;
00238
00239
00240 _newId = firstFreeID_;
00241 currentDrawModes_.push_back( DrawMode( _name, _newId ) );
00242 firstFreeID_ <<= 1;
00243
00244 return true;
00245 }
00246
00247
00248
00249
00250
00251 bool getDrawModeId( const std::string & _name, unsigned int & _Id )
00252 {
00253
00254 VecDrawModes::iterator modeIter, modeEnd( currentDrawModes_.end() );
00255
00256 for( modeIter = currentDrawModes_.begin();
00257 modeIter != modeEnd;
00258 ++modeIter )
00259 {
00260 if( _name == modeIter->name_ )
00261 {
00262 _Id = modeIter->id_;
00263 return true;
00264 }
00265 }
00266
00267
00268 return false;
00269 }
00270
00271
00272
00273 }
00274 }
00275 }
00276