CVarColor.h
Go to the documentation of this file.
1 #ifndef icmm_CVarColor_included
2 #define icmm_CVarColor_included
3 
4 
5 // ACF includes
6 #include <iser/ISerializable.h>
7 #include <imath/IDoubleManip.h>
8 #include <imath/CVarVector.h>
9 #include <icmm/icmm.h>
10 
11 
12 namespace icmm
13 {
14 
15 
21 class CVarColor: public imath::CVarVector, virtual public iser::ISerializable
22 {
23 public:
25 
30  CVarColor();
31 
35  explicit CVarColor(int componentsCount, double value = 0);
36 
40  CVarColor(const CVarColor& color);
41 
45  template <int Size>
47  : BaseClass(vector)
48  {
49  }
50 
56  void GetRounded(const imath::IDoubleManip& manipulator, CVarColor& result);
57 
63  bool IsRoundedEqual(const CVarColor& color, const imath::IDoubleManip& manipulator) const;
64 
68  bool IsSimilar(const CVarColor& color, double tolerance = I_BIG_EPSILON) const;
69 
74  bool IsNormalized() const;
75 
80  void Normalize();
81 
86  void GetNormalized(CVarColor& result) const;
87 
88  CVarColor operator+(const CVarColor& color) const;
89  CVarColor operator-(const CVarColor& color) const;
90  CVarColor operator*(const CVarColor& color) const;
91  CVarColor operator/(const CVarColor& color) const;
92 
93  CVarColor operator*(double value) const;
94  CVarColor operator/(double value) const;
95 
96  CVarColor& operator=(const CVarColor& color);
97 
98  const CVarColor& operator+=(const CVarColor& color);
99  const CVarColor& operator-=(const CVarColor& color);
100  const CVarColor& operator*=(const CVarColor& color);
101  const CVarColor& operator/=(const CVarColor& color);
102 
103  const CVarColor& operator*=(double value);
104  const CVarColor& operator/=(double value);
105 
106  // reimplemented (iser::ISerializable)
107  bool Serialize(iser::IArchive& archive);
108 };
109 
110 
111 // inline methods
112 
113 inline bool CVarColor::IsSimilar(const CVarColor& color, double tolerance) const
114 {
115  return GetDistance(color) <= tolerance;
116 }
117 
118 
119 inline bool CVarColor::IsNormalized() const
120 {
121  int elementsCount = GetElementsCount();
122 
123  for (int i = 0; i < elementsCount; ++i){
124  double component = GetElement(i);
125 
126  if ((component < 0) || (component > 1)){
127  return false;
128  }
129  }
130 
131  return true;
132 }
133 
134 
135 inline CVarColor CVarColor::operator+(const CVarColor& color) const
136 {
137  CVarColor retVal(*this);
138 
139  retVal += color;
140 
141  return retVal;
142 }
143 
144 
145 inline CVarColor CVarColor::operator-(const CVarColor& color) const
146 {
147  CVarColor retVal(*this);
148 
149  retVal -= color;
150 
151  return retVal;
152 }
153 
154 
155 inline CVarColor CVarColor::operator*(const CVarColor& color) const
156 {
157  CVarColor retVal(*this);
158 
159  retVal *= color;
160 
161  return retVal;
162 }
163 
164 
165 inline CVarColor CVarColor::operator/(const CVarColor& color) const
166 {
167  CVarColor retVal(*this);
168 
169  retVal /= color;
170 
171  return retVal;
172 }
173 
174 
175 inline CVarColor CVarColor::operator*(double value) const
176 {
177  int elementsCount = GetElementsCount();
178 
179  CVarColor retVal(elementsCount);
180 
181  for (int i = 0; i < elementsCount; ++i){
182  retVal.SetElement(i, GetElement(i) * value);
183  }
184 
185  return retVal;
186 }
187 
188 
189 inline CVarColor CVarColor::operator/(double value) const
190 {
191  int elementsCount = GetElementsCount();
192 
193  CVarColor retVal(elementsCount);
194 
195  for (int i = 0; i < elementsCount; ++i){
196  retVal.SetElement(i, GetElement(i) / value);
197  }
198 
199  return retVal;
200 }
201 
202 
203 inline const CVarColor& CVarColor::operator*=(double value)
204 {
205  BaseClass::operator*=(value);
206 
207  return *this;
208 }
209 
210 
211 inline const CVarColor& CVarColor::operator/=(double value)
212 {
213  BaseClass::operator/=(value);
214 
215  return *this;
216 }
217 
218 
219 } // namespace icmm
220 
221 
222 #endif // !icmm_CVarColor_included
223 
224 
const CVarColor & operator/=(const CVarColor &color)
CVarVector operator-() const
Definition: CVarVector.h:598
void GetRounded(const imath::IDoubleManip &manipulator, CVarColor &result)
Get color after components value rounding with specified precision.
void Normalize()
Make this color to be normalized.
bool IsSimilar(const CVarColor &color, double tolerance=I_BIG_EPSILON) const
Allows to compare two colors with tolerance.
Definition: CVarColor.h:113
CVarVector & operator/=(double scalar)
Definition: CVarVector.h:578
int GetElementsCount() const
Get number of elements.
Definition: CVarVector.h:283
Interface for all manipulation using values represent as double.
Definition: IDoubleManip.h:20
Common class for all classes which objects can be archived or restored from archive.
Definition: ISerializable.h:23
bool IsNormalized() const
Check if this color value is normalized.
Definition: CVarColor.h:119
CVarVector & operator*=(double scalar)
Definition: CVarVector.h:567
Generic color implementation with variable number of color components.
Definition: CVarColor.h:21
const CVarColor & operator*=(const CVarColor &color)
Represent input/output persistence archive.
Definition: IArchive.h:30
CVarColor(const imath::TVector< Size > &vector)
Template conversion constructor.
Definition: CVarColor.h:46
CVarColor & operator=(const CVarColor &color)
CVarColor operator/(const CVarColor &color) const
Definition: CVarColor.h:165
CVarColor()
Default constructor.
CVarColor operator*(const CVarColor &color) const
Definition: CVarColor.h:155
bool IsRoundedEqual(const CVarColor &color, const imath::IDoubleManip &manipulator) const
Check if two values are equal after rounding.
void GetNormalized(CVarColor &result) const
Get normalized color.
imath::CVarVector BaseClass
Definition: CVarColor.h:24
void SetElement(int index, double value)
Set element at specified index.
Definition: CVarVector.h:317
bool Serialize(iser::IArchive &archive)
Load or store state of this object as a archive stream.
Simple implementation of variable-size vector.
Definition: CVarVector.h:34
static const double I_BIG_EPSILON
Definition: istd.h:26
const CVarColor & operator+=(const CVarColor &color)
const CVarColor & operator-=(const CVarColor &color)
double GetElement(int index) const
Get element at specified index.
Definition: CVarVector.h:305
double GetDistance(const CVarVector &vector) const
Return distance between two vectors.
Definition: CVarVector.h:442
CVarColor operator+(const CVarColor &color) const
Definition: CVarColor.h:135

© 2007-2017 Witold Gantzke and Kirill Lepskiy