ACF $AcfVersion:0$
CVarColor.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
8#include <imath/CVarVector.h>
9#include <icmm/icmm.h>
10
11
12namespace icmm
13{
14
15
176{
177public:
179
185
189 explicit CVarColor(int componentsCount, double value = 0);
190
194 CVarColor(const CVarColor& color);
195
199 template <int Size>
201 : BaseClass(vector)
202 {
203 }
204
210 void GetRounded(const imath::IDoubleManip& manipulator, CVarColor& result);
211
217 bool IsRoundedEqual(const CVarColor& color, const imath::IDoubleManip& manipulator) const;
218
222 bool IsSimilar(const CVarColor& color, double tolerance = I_BIG_EPSILON) const;
223
228 bool IsNormalized() const;
229
234 void Normalize();
235
240 void GetNormalized(CVarColor& result) const;
241
242 CVarColor operator+(const CVarColor& color) const;
243 CVarColor operator-(const CVarColor& color) const;
244 CVarColor operator*(const CVarColor& color) const;
245 CVarColor operator/(const CVarColor& color) const;
246
247 CVarColor operator*(double value) const;
248 CVarColor operator/(double value) const;
249
251
252 const CVarColor& operator+=(const CVarColor& color);
253 const CVarColor& operator-=(const CVarColor& color);
254 const CVarColor& operator*=(const CVarColor& color);
255 const CVarColor& operator/=(const CVarColor& color);
256
257 const CVarColor& operator*=(double value);
258 const CVarColor& operator/=(double value);
259
260 // reimplemented (iser::ISerializable)
261 virtual bool Serialize(iser::IArchive& archive) override;
262};
263
264
265// inline methods
266
267inline bool CVarColor::IsSimilar(const CVarColor& color, double tolerance) const
268{
269 return GetDistance(color) <= tolerance;
270}
271
272
273inline bool CVarColor::IsNormalized() const
274{
275 int elementsCount = GetElementsCount();
276
277 for (int i = 0; i < elementsCount; ++i){
278 double component = GetElement(i);
279
280 if ((component < 0) || (component > 1)){
281 return false;
282 }
283 }
284
285 return true;
286}
287
288
289inline CVarColor CVarColor::operator+(const CVarColor& color) const
290{
291 CVarColor retVal(*this);
292
293 retVal += color;
294
295 return retVal;
296}
297
298
299inline CVarColor CVarColor::operator-(const CVarColor& color) const
300{
301 CVarColor retVal(*this);
302
303 retVal -= color;
304
305 return retVal;
306}
307
308
309inline CVarColor CVarColor::operator*(const CVarColor& color) const
310{
311 CVarColor retVal(*this);
312
313 retVal *= color;
314
315 return retVal;
316}
317
318
319inline CVarColor CVarColor::operator/(const CVarColor& color) const
320{
321 CVarColor retVal(*this);
322
323 retVal /= color;
324
325 return retVal;
326}
327
328
329inline CVarColor CVarColor::operator*(double value) const
330{
331 int elementsCount = GetElementsCount();
332
333 CVarColor retVal(elementsCount);
334
335 for (int i = 0; i < elementsCount; ++i){
336 retVal.SetElement(i, GetElement(i) * value);
337 }
338
339 return retVal;
340}
341
342
343inline CVarColor CVarColor::operator/(double value) const
344{
345 int elementsCount = GetElementsCount();
346
347 CVarColor retVal(elementsCount);
348
349 for (int i = 0; i < elementsCount; ++i){
350 retVal.SetElement(i, GetElement(i) / value);
351 }
352
353 return retVal;
354}
355
356
357inline const CVarColor& CVarColor::operator*=(double value)
358{
360
361 return *this;
362}
363
364
365inline const CVarColor& CVarColor::operator/=(double value)
366{
368
369 return *this;
370}
371
372
373} // namespace icmm
374
375
Generic color implementation with variable number of color components.
Definition CVarColor.h:176
const CVarColor & operator-=(const CVarColor &color)
CVarColor operator+(const CVarColor &color) const
Definition CVarColor.h:289
bool IsSimilar(const CVarColor &color, double tolerance=I_BIG_EPSILON) const
Allows to compare two colors with tolerance.
Definition CVarColor.h:267
imath::CVarVector BaseClass
Definition CVarColor.h:178
CVarColor(const imath::TVector< Size > &vector)
Template conversion constructor.
Definition CVarColor.h:200
const CVarColor & operator*=(const CVarColor &color)
void GetNormalized(CVarColor &result) const
Get normalized color.
bool IsNormalized() const
Check if this color value is normalized.
Definition CVarColor.h:273
void Normalize()
Make this color to be normalized.
CVarColor & operator=(const CVarColor &color)
CVarColor operator/(const CVarColor &color) const
Definition CVarColor.h:319
CVarColor(const CVarColor &color)
Copy constructor.
CVarColor()
Default constructor.
const CVarColor & operator/=(const CVarColor &color)
void GetRounded(const imath::IDoubleManip &manipulator, CVarColor &result)
Get color after components value rounding with specified precision.
CVarColor operator*(const CVarColor &color) const
Definition CVarColor.h:309
bool IsRoundedEqual(const CVarColor &color, const imath::IDoubleManip &manipulator) const
Check if two values are equal after rounding.
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
CVarColor(int componentsCount, double value=0)
Constructor with explicit initialization of number of elements.
const CVarColor & operator+=(const CVarColor &color)
Implementation of variable-size mathematical vector with double precision elements.
Definition CVarVector.h:110
CVarVector & operator*=(double scalar)
Definition CVarVector.h:671
CVarVector operator-() const
Definition CVarVector.h:702
double GetElement(int index) const
Get element at specified index.
Definition CVarVector.h:409
double GetDistance(const CVarVector &vector) const
Return distance between two vectors.
Definition CVarVector.h:546
CVarVector & operator/=(double scalar)
Definition CVarVector.h:682
int GetElementsCount() const
Get number of elements.
Definition CVarVector.h:387
void SetElement(int index, double value)
Set element at specified index.
Definition CVarVector.h:421
Interface for all manipulation using values represent as double.
Implementation of fixed-size mathematical vector with specified type of elements.
Definition TVector.h:95
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Common class for all classes which objects can be archived or restored from archive.
static const double I_BIG_EPSILON
Definition istd.h:26
Contains color management classes.