DrawModes.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS DrawModes - IMPLEMENTATION
00049 //
00050 //=============================================================================
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 #include "DrawModes.hh"
00056 #include "BaseNode.hh"
00057 
00058 #include <algorithm>
00059 
00060 
00061 //== NAMESPACES ============================================================== 
00062 
00063 namespace ACG {
00064 namespace SceneGraph {
00065 namespace DrawModes {
00066 
00067 
00068 //== IMPLEMENTATION ========================================================== 
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   /* HACK TODO!! Required when using plugins under windows. ACG as static lib
00103         links a static drawmodes for each plugins->only one initialized.
00104         Solution : Build ACG as dll under windows */
00105  // if ( currentDrawModes_.empty() )
00106         //initializeDefaultDrawModes();
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   /* HACK TODO!! Required when using plugins under windows. ACG as static lib
00134         links a static drawmodes for each plugins->only one initialized.
00135         Solution : Build ACG as dll under windows */
00136  // if ( currentDrawModes_.empty() )
00137 //      initializeDefaultDrawModes();
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   /* HACK TODO!! Required when using plugins under windows. ACG as static lib
00159         links a static drawmodes for each plugins->only one initialized.
00160         Solution : Build ACG as dll under windows */
00161  // if ( currentDrawModes_.empty() )
00162 //      initializeDefaultDrawModes();
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     // check if mode exists already
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     // check if there is another ID available
00236     if( firstFreeID_ == (unsigned int) (1<<31) )
00237         return false;
00238 
00239     // add new mode
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     // check if mode exists
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     // the DrawMode does not exists
00268     return false;
00269 }
00270 
00271 
00272 //=============================================================================
00273 } // namespace DrawModes
00274 } // namespace SceneGraph
00275 } // namespace ACG
00276 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .