colorschema.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  *                                                                         *
00023  ***************************************************************************/
00024 #ifndef __COLORSCHEMA_H
00025 #define __COLORSCHEMA_H
00026 
00027 #include "color.h"
00028 #include <selforg/stl_map.h>
00029 #include <string>
00030 #include <vector>
00031 #include <iostream>
00032 
00033 namespace lpzrobots{
00034 
00035   /**
00036      A store for colors with a set of aliases.
00037      The alias-sets are numbered where the 0'th plays the role of a default set.
00038    */
00039   class ColorSchema 
00040   {
00041   public:
00042     typedef HashMap<std::string, Color> ColorMap;
00043     typedef std::vector<std::string> AliasVector;
00044     typedef HashMap<std::string, AliasVector > AliasMap;    
00045 
00046     ColorSchema();
00047   
00048     /** retrieves a color with the given name/id/alias
00049         if no color is found that matches the id/alias then 
00050         the default color is returned.
00051         Always the alias-set 0 is checked first
00052     */
00053     Color color(const std::string& name_or_id_or_alias) const;
00054 
00055     /** retrieves a color with the given name/id/alias from given alias_set
00056         if not found then the default alias_set (0) is checked
00057      */
00058     Color color(const std::string& name_or_id_or_alias, int alias_set) const;
00059 
00060     /** call by reference version      
00061         returns false if color not found
00062     */
00063     bool color(Color& color, const std::string& name_or_id_or_alias, 
00064                int alias_set = 0) const;
00065 
00066     /// checks whether color with the name exists (no aliases are checked)
00067     bool existsColor(const std::string& name) const;
00068 
00069     /** loads a gpl (gimp pallette file) and returns the number loaded colors
00070         The name of the colors should not contain white spaces!
00071      */    
00072     int loadPalette(const std::string& gplfilename);
00073     /** loads aliases from text file with lines containing:\n
00074         aliasname colorname/id [alias-set]
00075         @param alias_set_offset number that is added to the alias_set number in the file
00076      */
00077     int loadAliases(const std::string& filename, int alias_set_offset = 0);
00078 
00079     /** adds a color to the color store 
00080         (to add the id call the function twice with id as name)
00081     */
00082     void addColor(const Color& color, const std::string& name);
00083 
00084     /** adds a color alias (into the given alias-set)
00085         @param name name/id of existing color 
00086         @param alias new name 
00087         @return true if alias was stored or
00088          false if color name does not exists or 
00089                alias names a color and is therefor rejected
00090     */
00091     bool addAlias(const std::string& name, const std::string& alias, int alias_set = 0);
00092 
00093     void setDefaultColor(const Color& c);
00094     const Color& getDefaultColor() const;
00095 
00096     /// returns error string for value returned by loadPalette and loadAliases
00097     std::string getLoadErrorString(int value) const;
00098     
00099     /// prints all colors and aliases
00100     void print(std::ostream& out) const ;
00101 
00102   protected:
00103     // only name/id no alias checking
00104     bool getColor(Color&, const std::string& name) const;
00105 
00106   private:
00107     Color dummy;
00108     ColorMap colors;
00109     AliasMap aliases;    
00110   };
00111 }
00112 
00113 #endif
Generated on Thu Jun 28 14:45:36 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3