Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
colorschema.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __COLORSCHEMA_H
25 #define __COLORSCHEMA_H
26 
27 #include "color.h"
28 #include <selforg/stl_map.h>
29 #include <string>
30 #include <vector>
31 #include <iostream>
32 
33 namespace lpzrobots{
34 
35  /**
36  A store for colors with a set of aliases.
37  The alias-sets are numbered where the 0'th plays the role of a default set.
38  */
39  class ColorSchema
40  {
41  public:
42  typedef HashMap<std::string, Color> ColorMap;
43  typedef std::vector<std::string> AliasVector;
44  typedef HashMap<std::string, AliasVector > AliasMap;
45 
46  ColorSchema();
47 
48  /** retrieves a color with the given name/id/alias
49  if no color is found that matches the id/alias then
50  the default color is returned.
51  Always the alias-set 0 is checked first
52  */
53  Color color(const std::string& name_or_id_or_alias) const;
54 
55  /** retrieves a color with the given name/id/alias from given alias_set
56  if not found then the default alias_set (0) is checked
57  */
58  Color color(const std::string& name_or_id_or_alias, int alias_set) const;
59 
60  /** call by reference version
61  returns false if color not found
62  */
63  bool color(Color& color, const std::string& name_or_id_or_alias,
64  int alias_set = 0) const;
65 
66  /// checks whether color with the name exists (no aliases are checked)
67  bool existsColor(const std::string& name) const;
68 
69  /** loads a gpl (gimp pallette file) and returns the number loaded colors
70  The name of the colors should not contain white spaces!
71  */
72  int loadPalette(const std::string& gplfilename);
73  /** loads aliases from text file with lines containing:\n
74  aliasname colorname/id [alias-set]
75  @param alias_set_offset number that is added to the alias_set number in the file
76  */
77  int loadAliases(const std::string& filename, int alias_set_offset = 0);
78 
79  /** adds a color to the color store
80  (to add the id call the function twice with id as name)
81  */
82  void addColor(const Color& color, const std::string& name);
83 
84  /** adds a color alias (into the given alias-set)
85  @param name name/id of existing color
86  @param alias new name
87  @return true if alias was stored or
88  false if color name does not exists or
89  alias names a color and is therefor rejected
90  */
91  bool addAlias(const std::string& name, const std::string& alias, int alias_set = 0);
92 
93  void setDefaultColor(const Color& c);
94  const Color& getDefaultColor() const;
95 
96  /// returns error string for value returned by loadPalette and loadAliases
97  std::string getLoadErrorString(int value) const;
98 
99  /// prints all colors and aliases
100  void print(std::ostream& out) const ;
101 
102  protected:
103  // only name/id no alias checking
104  bool getColor(Color&, const std::string& name) const;
105 
106  private:
107  Color dummy;
108  ColorMap colors;
109  AliasMap aliases;
110  };
111 }
112 
113 #endif
int loadPalette(const std::string &gplfilename)
loads a gpl (gimp pallette file) and returns the number loaded colors The name of the colors should n...
Definition: colorschema.cpp:102
void setDefaultColor(const Color &c)
Definition: colorschema.cpp:202
std::string getLoadErrorString(int value) const
returns error string for value returned by loadPalette and loadAliases
Definition: colorschema.cpp:83
bool existsColor(const std::string &name) const
checks whether color with the name exists (no aliases are checked)
Definition: colorschema.cpp:210
HashMap< std::string, AliasVector > AliasMap
Definition: colorschema.h:44
bool getColor(Color &, const std::string &name) const
Definition: colorschema.cpp:241
A store for colors with a set of aliases.
Definition: colorschema.h:39
std::vector< std::string > AliasVector
Definition: colorschema.h:43
int loadAliases(const std::string &filename, int alias_set_offset=0)
loads aliases from text file with lines containing: aliasname colorname/id [alias-set] ...
Definition: colorschema.cpp:140
const Color & getDefaultColor() const
Definition: colorschema.cpp:206
Definition: color.h:32
HashMap< std::string, Color > ColorMap
Definition: colorschema.h:42
void addColor(const Color &color, const std::string &name)
adds a color to the color store (to add the id call the function twice with id as name) ...
Definition: colorschema.cpp:168
ColorSchema()
Definition: colorschema.cpp:43
int c
Definition: hexapod.cpp:56
void print(std::ostream &out) const
prints all colors and aliases
Definition: colorschema.cpp:226
Color color(const std::string &name_or_id_or_alias) const
retrieves a color with the given name/id/alias if no color is found that matches the id/alias then th...
bool addAlias(const std::string &name, const std::string &alias, int alias_set=0)
adds a color alias (into the given alias-set)
Definition: colorschema.cpp:172