Color.hh
00001 /* 00002 * Copyright 2011 Nate Koenig & Andrew Howard 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 /* Desc: Color class 00018 * Author: Nate Koenig 00019 * Date: 08 May 2009 00020 */ 00021 00022 #ifndef GAZEBO_COLOR_HH 00023 #define GAZEBO_COLOR_HH 00024 00025 #include <iostream> 00026 #include "math/Vector3.hh" 00027 00028 namespace gazebo 00029 { 00030 namespace common 00031 { 00032 00035 00037 class Color 00038 { 00039 public: static const Color White; 00040 public: static const Color Black; 00041 public: static const Color Red; 00042 public: static const Color Green; 00043 public: static const Color Blue; 00044 00046 public: Color(); 00047 00049 public: Color( float r, float g, float b, float a=1.0 ); 00050 00052 public: Color( const Color &clr ); 00053 00055 public: virtual ~Color(); 00056 00058 public: void Reset(); 00059 00061 public: void Set(float r = 1, float g =1 , float b = 1, float a = 1); 00062 00064 public: math::Vector3 GetAsHSV() const; 00065 00067 public: void SetFromHSV(float h, float s, float v); 00068 00070 public: math::Vector3 GetAsYUV() const; 00071 00073 public: void SetFromYUV(float y, float u, float v); 00074 00076 public: const Color &operator=(const Color &_pt); 00077 00079 public: float operator[](unsigned int index); 00080 00082 public: float R() const; 00083 00085 public: float G() const; 00086 00088 public: float B() const; 00089 00091 public: float A() const; 00092 00094 public: void R(float r); 00095 00097 public: void G(float g); 00098 00100 public: void B(float b); 00101 00103 public: void A(float a); 00104 00105 // Addition operators 00106 public: Color operator+( const Color &pt ) const; 00107 public: Color operator+( const float &v ) const; 00108 public: const Color &operator+=( const Color &pt ); 00109 00110 // Subtraction operators 00111 public: Color operator-( const Color &pt ) const; 00112 public: Color operator-( const float &pt ) const; 00113 public: const Color &operator-=( const Color &pt ); 00114 00115 // Division operators 00116 public: const Color operator/( const float &i ) const; 00117 public: const Color operator/( const Color &pt ) const; 00118 public: const Color &operator/=( const Color &pt ); 00119 00120 // Multiplication operators 00121 public: const Color operator*(const float &i) const; 00122 public: const Color operator*( const Color &pt ) const; 00123 public: const Color &operator*=( const Color &pt ); 00124 00125 // Equality operators 00126 public: bool operator==( const Color &pt ) const; 00127 public: bool operator!=( const Color &pt ) const; 00128 00130 private: void Clamp(); 00131 00132 // Ostream operator 00133 public: friend std::ostream &operator<< (std::ostream &out, const Color &pt) { 00134 out << pt.r << " " << pt.g << " " << pt.b << " " << pt.a; 00135 return out; 00136 } 00137 00138 // Istream operator 00139 public: friend std::istream &operator>> (std::istream &in, Color &pt) 00140 { 00141 // Skip white spaces 00142 in.setf( std::ios_base::skipws ); 00143 in >> pt.r >> pt.g >> pt.b >> pt.a; 00144 return in; 00145 } 00146 00147 // The values 00148 private: float r, g, b, a; 00149 }; 00151 } 00152 } 00153 #endif

1.7.5.1