enki/Types.h

Go to the documentation of this file.
00001 /*
00002     Enki - a fast 2D robot simulator
00003     Copyright (C) 1999-2008 Stephane Magnenat <stephane at magnenat dot net>
00004     Copyright (C) 2004-2005 Markus Waibel <markus dot waibel at epfl dot ch>
00005     Copyright (c) 2004-2005 Antoine Beyeler <abeyeler at ab-ware dot com>
00006     Copyright (C) 2005-2006 Laboratory of Intelligent Systems, EPFL, Lausanne
00007     Copyright (C) 2006-2008 Laboratory of Robotics Systems, EPFL, Lausanne
00008     See AUTHORS for details
00009 
00010     This program is free software; the authors of any publication 
00011     arising from research using this software are asked to add the 
00012     following reference:
00013     Enki - a fast 2D robot simulator
00014     http://lis.epfl.ch/enki
00015     Stephane Magnenat <stephane at magnenat dot net>,
00016     Markus Waibel <markus dot waibel at epfl dot ch>
00017     Laboratory of Intelligent Systems, EPFL, Lausanne.
00018 
00019     You can redistribute this program and/or modify
00020     it under the terms of the GNU General Public License as published by
00021     the Free Software Foundation; either version 2 of the License, or
00022     (at your option) any later version.
00023 
00024     This program 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 General Public License for more details.
00028 
00029     You should have received a copy of the GNU General Public License
00030     along with this program; if not, write to the Free Software
00031     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00032 */
00033 
00034 #ifndef __ENKI_TYPES_H
00035 #define __ENKI_TYPES_H
00036 
00037 #include <vector>
00038 #include <cassert>
00039 
00049 namespace Enki
00050 {
00052     struct Color
00053     {
00055         double components[4];
00056         
00058         Color(double r = 0.0, double g = 0.0, double b = 0.0, double a = 1.0)
00059         {
00060             components[0] = r;
00061             components[1] = g;
00062             components[2] = b;
00063             components[3] = a;
00064         }
00065         
00067         const double& operator[](size_t i) const { assert((i >= 0) && (i < 4)); return components[i]; }
00069         double& operator[](size_t i) { assert((i >= 0) && (i < 4)); return components[i]; }
00070         
00071         // operations with scalar
00073         void operator +=(double d) { for (size_t i=0; i<3; i++) components[i] += d; }
00075         Color operator +(double d) const { Color c; for (size_t i=0; i<3; i++) c.components[i] = components[i] + d; return c; }
00076         
00078         void operator -=(double d) { for (size_t i=0; i<3; i++) components[i] -= d; }
00080         Color operator -(double d) const { Color c; for (size_t i=0; i<3; i++) c.components[i] = components[i] - d; return c; }
00081         
00083         void operator *=(double d) { for (size_t i=0; i<3; i++) components[i] *= d; }
00085         Color operator *(double d) const { Color c; for (size_t i=0; i<3; i++) c.components[i] = components[i] * d; return c; }
00086         
00088         void operator /=(double d) { for (size_t i=0; i<3; i++) components[i] /= d; }
00090         Color operator /(double d) const { Color c; for (size_t i=0; i<3; i++) c.components[i] = components[i] / d; return c; }
00091         
00092         // operation with another color
00094         void operator +=(const Color &oc) { for (size_t i=0; i<3; i++) components[i] += oc.components[i]; }
00096         Color operator +(const Color &oc) const { Color c; for (size_t i=0; i<3; i++) c.components[i] = components[i] + oc.components[i]; return c; }
00097         
00099         void operator -=(const Color &oc) { for (size_t i=0; i<3; i++) components[i] -= oc.components[i]; }
00101         Color operator -(const Color &oc) const { Color c; for (size_t i=0; i<3; i++) c.components[i] = components[i] - oc.components[i]; return c; }
00102         
00104         bool operator ==(const Color &c) const { for (size_t i=0; i<4; i++) if (components[i] != c.components[i]) return false; return true; }
00106         bool operator !=(const Color &c) const { return !(*this == c); }
00108         void threshold(const Color &limit) { for (size_t i=0; i<3; i++) components[i] = components[i] > limit.components[i] ? components[i] : 0; }
00110         double toGray() const { return (components[0] + components[1] + components[2]) / 3; }
00111         
00113         double r() { return components[0]; }
00114         
00116         void setR(double value) { components[0] = value; }
00117         
00119         double g() { return components[1]; }
00120         
00122         void setG(double value) { components[1] = value; }
00123         
00125         double b() { return components[2]; }
00126         
00128         void setB(double value) { components[2] = value; }
00129         
00131         double a() { return components[3]; }
00132         
00134         void setA(double value) { components[3] = value; }
00135         
00137         static const Color black;
00139         static const Color white;
00141         static const Color gray;
00143         static const Color red;
00145         static const Color green;
00147         static const Color blue;
00148     };
00149 
00151     typedef std::vector<Color> Texture;
00152     
00154     typedef std::vector<Texture> Textures;
00155 }
00156 
00157 #endif

Generated on Sun Mar 1 03:10:09 2009 for Enki by  doxygen 1.5.1