1 //*******************************************************************
2 //
3 // License:  See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 // Description:
7 //
8 //*************************************************************************
9 // $Id: ossimHsiVector.h 9968 2006-11-29 14:01:53Z gpotts $
10 #ifndef ossimHsiVector_HEADER
11 #define ossimHsiVector_HEADER
12 #include <iostream>
13 #include <ossim/base/ossimConstants.h>
14 
15 class ossimRgbVector;
16 class ossimNormRgbVector;
17 
18 class OSSIMDLLEXPORT ossimHsiVector
19 {
20 public:
21    friend std::ostream& operator << (std::ostream& out, const ossimHsiVector & data)
22    {
23       out << "<" << data.theBuf[0] << ", "
24           << data.theBuf[1] << ", "
25           << data.theBuf[2] << ">";
26 
27       return out;
28    }
29    // assumed normalized ossim_float64s
30    //
31    //
32    ossimHsiVector(ossim_float64 h=0, ossim_float64 s=0, ossim_float64 i=0)
33    {
34       theBuf[0] = h;
35       theBuf[1] = s;
36       theBuf[2] = i;
37    }
38    ossimHsiVector(const ossimRgbVector& rgb);
39    ossimHsiVector(const ossimNormRgbVector& rgb);
40 
41    ossimHsiVector& operator =(const ossimRgbVector& rgb);
42    ossimHsiVector& operator =(const ossimNormRgbVector& rgb);
43 
44    void setFromRgb(ossim_float64 r, ossim_float64 g, ossim_float64 b);
45 
46    ossim_float64 getH()const { return theBuf[0]; }
47    ossim_float64 getS()const { return theBuf[1]; }
48    ossim_float64 getI()const { return theBuf[2]; }
49    void setH(ossim_float64 H) { theBuf[0] = H; }
50    void setS(ossim_float64 S) { theBuf[1] = S; }
51    void setI(ossim_float64 I) { theBuf[2] = I; }
52 
53    ossim_float64 clamp(ossim_float64 colorValue, ossim_float64 min=0, ossim_float64 max=1)const
54       {
55          colorValue = colorValue > max? max:colorValue;
56          colorValue = colorValue < min? min:colorValue;
57 
58          return colorValue;
59       }
60 
61 protected:
62    /*!
63     * buf[0] = hue
64     * buf[1] = saturation
65     * buf[2] = intensity
66     */
67    ossim_float64 theBuf[3];
68 };
69 
70 #endif
71