colorHSV.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: colorHSV.h,v 1.21 2005/12/23 17:02:07 amoll Exp $
00005 //
00006 
00007 #ifndef BALL_VIEW_DATATYPE_COLORHSV_H
00008 #define BALL_VIEW_DATATYPE_COLORHSV_H
00009 
00010 #ifndef BALL_COMMON_H
00011 # include <BALL/common.h>
00012 #endif
00013 
00014 #ifndef BALL_DATATYPE_STRING_H
00015 # include <BALL/DATATYPE/string.h>
00016 #endif
00017 
00018 #ifndef BALL_VIEW_DATATYPE_COLORUNIT_H
00019 # include <BALL/VIEW/DATATYPE/colorUnit.h>
00020 #endif
00021 
00022 #ifndef BALL_VIEW_DATATYPE_COLORUNITHUE_H
00023 # include <BALL/VIEW/DATATYPE/colorUnitHue.h>
00024 #endif
00025 
00026 #include <iostream>
00027 #include <stdio.h>
00028 
00029 namespace BALL 
00030 {
00031   namespace VIEW 
00032   {
00033 
00034     class ColorRGBA;
00035 
00044     class BALL_VIEW_EXPORT ColorHSV
00045     {
00050       friend class ColorRGBA;
00051 
00052       public:
00053 
00054       BALL_CREATE(ColorHSV)
00055 
00056       
00059 
00064       ColorHSV();
00065 
00068       ColorHSV(const ColorHSV& color);
00069 
00072       ColorHSV(const ColorRGBA& color);
00073 
00087       ColorHSV(const char* value)
00088         throw(Exception::InvalidRange, ColorUnit::NotInHexFormat);
00089 
00100       ColorHSV(const String& value)
00101         throw(Exception::InvalidRange, ColorUnit::NotInHexFormat);
00102 
00109       ColorHSV
00110         (const ColorUnitHue& hue,
00111          const ColorUnit& saturation,
00112          const ColorUnit& value);
00113 
00115 
00118 
00121       virtual ~ColorHSV();
00122 
00130       virtual void clear();
00131 
00133 
00136 
00140       operator String () const;
00141 
00143 
00146 
00149       void set(const ColorHSV& color);
00150 
00154       const ColorHSV& operator = (const ColorHSV& color);
00155 
00159       void set(const ColorRGBA& color);
00160 
00169       const ColorHSV& operator = (const ColorRGBA& color);
00170 
00176       void get(ColorRGBA& color) const;
00177 
00185       void set(const char* value)
00186         throw(Exception::InvalidRange, ColorUnit::NotInHexFormat);
00187 
00196       const ColorHSV& operator = (const char* value)
00197         throw(Exception::InvalidRange, ColorUnit::NotInHexFormat);
00198 
00207       void get(char* value) const;
00208 
00217       void set(const String& value)
00218         throw(Exception::InvalidRange, ColorUnit::NotInHexFormat);
00219 
00228       const ColorHSV& operator = (const String& value)
00229         throw(Exception::InvalidRange, ColorUnit::NotInHexFormat);
00230 
00237       void get(String& value) const;
00238 
00241       void swap(ColorHSV& color);
00242 
00244 
00247 
00256       void setHue(const ColorUnitHue& hue);
00257 
00265       ColorUnitHue& getHue();
00266 
00270       const ColorUnitHue& getHue() const;
00271 
00275       void setSaturation(const ColorUnit& saturation);
00276 
00280       ColorUnit& getSaturation();
00281 
00284       const ColorUnit& getSaturation() const;
00285 
00288       void setValue(const ColorUnit& value);
00289 
00292       ColorUnit& getValue();
00293 
00297       const ColorUnit& getValue() const;
00298 
00301       void set (const ColorUnitHue& hue, const ColorUnit& saturation, const ColorUnit& value);
00302 
00305       void get (ColorUnitHue& hue, ColorUnit& saturation, ColorUnit& value) const;
00306 
00308 
00311 
00314       bool operator == (const ColorHSV& color) const;
00315 
00318       bool operator != (const ColorHSV& color) const;
00319 
00324       bool operator < (const ColorHSV& color) const;
00325 
00330       bool operator <= (const ColorHSV& color) const;
00331 
00336       bool operator > (const ColorHSV& color) const;
00337 
00342       bool operator >= (const ColorHSV& color) const;
00343 
00345 
00348   
00355       virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00356 
00358 
00361 
00370       friend std::istream& operator >> (std::istream& s, ColorHSV& color);
00371 
00380       friend std::ostream& operator << (std::ostream& s, const ColorHSV& color);
00381 
00383 
00384       private:
00385 
00386       void calculateHSV_ (const ColorUnit red, const ColorUnit green, const ColorUnit blue);
00387 
00388       void calculateRGB_ (ColorUnit& red, ColorUnit& green, ColorUnit& blue) const;
00389 
00390       void stringToHSV_ (const String& value)
00391         throw(Exception::InvalidRange, ColorUnit::NotInHexFormat);
00392 
00393       ColorUnitHue  hue_;
00394       ColorUnit     saturation_;
00395       ColorUnit     value_;
00396     };
00397 
00398 #   ifndef BALL_NO_INLINE_FUNCTIONS
00399 #     include <BALL/VIEW/DATATYPE/colorHSV.iC>
00400 #   endif
00401       
00402   } // namespace VIEW
00403 } // namespace BALL
00404 
00405 #endif // <BALL/VIEW_DATATYPE_COLORHSV_H