ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
icmm::CVarColor Class Reference

Generic color implementation with variable number of color components. More...

#include <CVarColor.h>

Inheritance diagram for icmm::CVarColor:
imath::CVarVector iser::ISerializable istd::IChangeable istd::IPolymorphic

Public Types

typedef imath::CVarVector BaseClass
 
- Public Types inherited from imath::CVarVector
typedef std::vector< double > Elements
 
- Public Types inherited from istd::IChangeable
enum  ChangeFlags {
  CF_ACF_INTERNAL = 0 , CF_ALL_DATA , CF_ANY , CF_DESTROYING ,
  CF_DELEGATED , CF_NO_UNDO
}
 Data model change notification flags. More...
 
enum  SupportedOperations {
  SO_NONE = 0 , SO_OBSERVE = 1 << 0 , SO_COPY = 1 << 1 , SO_CLONE = 1 << 2 ,
  SO_COMPARE = 1 << 3 , SO_RESET = 1 << 4
}
 Flags for supported operations. More...
 
enum  CompatibilityMode { CM_STRICT , CM_WITHOUT_REFS , CM_WITH_REFS , CM_CONVERT }
 Control how relationship betweeen objects are interpreted. More...
 
typedef QMultiMap< QByteArray, QVariant > ChangeInfoMap
 

Public Member Functions

 CVarColor ()
 Default constructor.
 
 CVarColor (int componentsCount, double value=0)
 Constructor with explicit initialization of number of elements.
 
 CVarColor (const CVarColor &color)
 Copy constructor.
 
template<int Size>
 CVarColor (const imath::TVector< Size > &vector)
 Template conversion constructor.
 
void GetRounded (const imath::IDoubleManip &manipulator, CVarColor &result)
 Get color after components value rounding with specified precision.
 
bool IsRoundedEqual (const CVarColor &color, const imath::IDoubleManip &manipulator) const
 Check if two values are equal after rounding.
 
bool IsSimilar (const CVarColor &color, double tolerance=I_BIG_EPSILON) const
 Allows to compare two colors with tolerance.
 
bool IsNormalized () const
 Check if this color value is normalized.
 
void Normalize ()
 Make this color to be normalized.
 
void GetNormalized (CVarColor &result) const
 Get normalized color.
 
CVarColor operator+ (const CVarColor &color) const
 
CVarColor operator- (const CVarColor &color) const
 
CVarColor operator* (const CVarColor &color) const
 
CVarColor operator/ (const CVarColor &color) const
 
CVarColor operator* (double value) const
 
CVarColor operator/ (double value) const
 
CVarColoroperator= (const CVarColor &color)
 
const CVarColoroperator+= (const CVarColor &color)
 
const CVarColoroperator-= (const CVarColor &color)
 
const CVarColoroperator*= (const CVarColor &color)
 
const CVarColoroperator/= (const CVarColor &color)
 
const CVarColoroperator*= (double value)
 
const CVarColoroperator/= (double value)
 
virtual bool Serialize (iser::IArchive &archive) override
 Load or store state of this object as a archive stream.
 
- Public Member Functions inherited from imath::CVarVector
 CVarVector ()
 Create the vector without components.
 
 CVarVector (int componentsCount, double value=0)
 Create vector and initialize number of components.
 
template<typename Iterator >
 CVarVector (Iterator beginIter, Iterator endIter)
 Creates a vector from a range of values using iterators.
 
 CVarVector (const CVarVector &vector)
 Copy constructor.
 
template<int Size>
 CVarVector (const TVector< Size, double > &vector)
 Creates a variable-size vector from a fixed-size TVector.
 
bool IsEmpty () const
 Get true, if the element ist is empty.
 
int GetElementsCount () const
 Get number of elements.
 
bool SetElementsCount (int count, double value=0)
 Set number of elements.
 
double GetElement (int index) const
 Get element at specified index.
 
double & GetElementRef (int index)
 Get reference to element at specified index.
 
void SetElement (int index, double value)
 Set element at specified index.
 
void SetAllElements (double value)
 Set some value to all elements.
 
void Reset ()
 Set size to zero.
 
void Reset (int elementsCount, double value)
 Set number of elements and set all elements to specified value.
 
void Clear ()
 Set all coordinates to zero.
 
void SetElementsFrom (const CVarVector &vector, double expansionValue=0)
 Set elements from other vector without resizing.
 
const ElementsGetElements () const
 Get read-only access to internal element container.
 
ElementsGetElementsRef ()
 Get access to internal element container.
 
bool EnsureElementsCount (int count, double value=0)
 Ensure, that number of elements is at least the specified value.
 
void Translate (const CVarVector &vector)
 Translate the point.
 
CVarVector GetTranslated (const CVarVector &vector)
 Get translated point.
 
void GetTranslated (const CVarVector &vector, CVarVector &result)
 /overloaded
 
void ScaledCumulate (const CVarVector &vector, double scale)
 Add second vector scaled by specified factor.
 
bool IsNull (double tolerance=I_BIG_EPSILON) const
 Check if this vector is null.
 
double GetDotProduct (const CVarVector &vector) const
 Return dot product of two vectors.
 
double GetLength2 () const
 Return euclidean length square.
 
double GetLength () const
 Return euclidian length.
 
double GetDistance2 (const CVarVector &vector) const
 Return distance square between two vectors.
 
double GetDistance (const CVarVector &vector) const
 Return distance between two vectors.
 
double GetElementsSum () const
 Get simple sum of all elements.
 
bool Normalize (double length=1.0)
 Normalize vector to specified length.
 
bool GetNormalized (CVarVector &result, double length=1.0) const
 Return normalized vector with the same direction and specified length.
 
void GetMinimal (const CVarVector &vector, CVarVector &result) const
 Get vector with minimal elements values.
 
void GetMaximal (const CVarVector &vector, CVarVector &result) const
 Get vector with maximal elements values.
 
bool Serialize (iser::IArchive &archive)
 Serialize this vector to specified archive.
 
bool operator== (const CVarVector &vector) const
 
bool operator!= (const CVarVector &vector) const
 
bool operator< (const CVarVector &vector) const
 
bool operator> (const CVarVector &vector) const
 
bool operator<= (const CVarVector &vector) const
 
bool operator>= (const CVarVector &vector) const
 
CVarVector operator- () const
 
CVarVector operator+ (const CVarVector &vector) const
 
CVarVector operator- (const CVarVector &vector) const
 
CVarVector operator* (double scalar) const
 
CVarVector operator/ (double scalar) const
 
CVarVectoroperator+= (const CVarVector &vector)
 
CVarVectoroperator-= (const CVarVector &vector)
 
CVarVectoroperator*= (double scalar)
 
CVarVectoroperator/= (double scalar)
 
CVarVectoroperator= (const CVarVector &vector)
 
double operator[] (int i) const
 
double & operator[] (int i)
 
- Public Member Functions inherited from iser::ISerializable
virtual quint32 GetMinimalVersion (int versionId) const
 Get minimal needed version to correct storing of this data.
 
- Public Member Functions inherited from istd::IChangeable
virtual int GetSupportedOperations () const
 Get set of flags for supported operations.
 
virtual bool CopyFrom (const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
 Copy this object from another one.
 
virtual bool IsEqual (const IChangeable &object) const
 Compare this object with another object.
 
virtual istd::TUniqueInterfacePtr< istd::IChangeableCloneMe (CompatibilityMode mode=CM_WITHOUT_REFS) const
 Make a copy of this object.
 
virtual bool ResetData (CompatibilityMode mode=CM_WITHOUT_REFS)
 Reset data to its default state.
 
virtual void BeginChanges (const ChangeSet &changeSet)
 Starts the change transaction.
 
virtual void EndChanges (const ChangeSet &changeSet)
 Ends the change transaction.
 
virtual void BeginChangeGroup (const ChangeSet &changeSet)
 Starts group of changes.
 
virtual void EndChangeGroup (const ChangeSet &changeSet)
 Ends group of changes.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Additional Inherited Members

- Static Public Member Functions inherited from istd::IChangeable
static const ChangeSetGetNoChanges ()
 Get empty set of changes.
 
static const ChangeSetGetAnyChange ()
 Get anonymous change set.
 
static const ChangeSetGetAllChanges ()
 Get anonymous change set.
 
static const ChangeSetGetDelegatedChanges ()
 Get delegated change set.
 
- Protected Member Functions inherited from istd::IChangeable
virtual void OnBeginChanges ()
 Callback function for begin change event.
 
virtual void OnEndChanges (const ChangeSet &changeSet)
 Callback function for end change event.
 

Detailed Description

Generic color implementation with variable number of color components.

Purpose

CVarColor provides a flexible color representation that can accommodate any color space with any number of components. Unlike fixed-size color classes (CRgb, CCmyk), CVarColor's dimensionality is determined at runtime, making it ideal for generic color processing, color transformations, and working with exotic or custom color spaces.

Flexibility and Use Cases

CVarColor is used when:

Usage Examples

// Example 1: Creating colors of different dimensions
icmm::CVarColor rgb(3); // RGB (3 components)
rgb.SetElement(0, 1.0); // Red
rgb.SetElement(1, 0.5); // Green
rgb.SetElement(2, 0.0); // Blue
icmm::CVarColor cmyk(4); // CMYK (4 components)
cmyk.SetElement(0, 0.0); // Cyan
cmyk.SetElement(1, 0.5); // Magenta
cmyk.SetElement(2, 1.0); // Yellow
cmyk.SetElement(3, 0.0); // Black
icmm::CVarColor spectral(31); // Spectral (many components)
// Example 2: Working with generic transformations
void TransformColor(const icmm::CVarColor& input,
icmm::CVarColor& output,
const icmm::IColorTransformation* transform)
{
if (transform && transform->Calculate(input, output)) {
// Transformation successful
qDebug() << "Transformed" << input.GetElementsCount()
<< "component color to"
<< output.GetElementsCount() << "components";
}
}
// Example 3: Color comparison with tolerance
bool ColorsMatch(const icmm::CVarColor& color1,
const icmm::CVarColor& color2,
double tolerance = 0.01)
{
return color1.IsSimilar(color2, tolerance);
}
c1.SetElement(0, 0.5);
c1.SetElement(1, 0.5);
c1.SetElement(2, 0.5);
c2.SetElement(0, 0.501);
c2.SetElement(1, 0.499);
c2.SetElement(2, 0.502);
bool match = ColorsMatch(c1, c2, 0.01); // true
// Example 4: Normalization (clamping to [0,1])
icmm::CVarColor color(3, 1.5); // All components = 1.5 (out of range)
if (!color.IsNormalized()) {
color.Normalize(); // Clamp to [0, 1]
// Now all components are 1.0
}
// Example 5: Color arithmetic
a.SetElement(0, 0.8);
a.SetElement(1, 0.3);
a.SetElement(2, 0.2);
b.SetElement(0, 0.2);
b.SetElement(1, 0.5);
b.SetElement(2, 0.7);
// Component-wise operations
icmm::CVarColor sum = a + b; // {1.0, 0.8, 0.9}
icmm::CVarColor diff = a - b; // {0.6, -0.2, -0.5}
icmm::CVarColor product = a * b; // {0.16, 0.15, 0.14}
icmm::CVarColor scaled = a * 0.5; // {0.4, 0.15, 0.1}
// Example 6: Rounded comparison for precision control
icmm::CVarColor precise1(3, 0.123456789);
icmm::CVarColor precise2(3, 0.123456788);
// Create rounding manipulator (e.g., 6 decimal places)
// imath::CDoubleRounder rounder(6);
// bool equalRounded = precise1.IsRoundedEqual(precise2, rounder);
// Example 7: Converting from fixed-size vectors
vec3.SetElement(0, 1.0);
vec3.SetElement(1, 0.0);
vec3.SetElement(2, 0.0);
icmm::CVarColor fromVector(vec3); // Convert TVector to CVarColor
// Example 8: Generic color palette
QList<icmm::CVarColor> CreatePalette(int colorCount, int components)
{
QList<icmm::CVarColor> palette;
for (int i = 0; i < colorCount; ++i) {
icmm::CVarColor color(components);
// Generate color values
for (int c = 0; c < components; ++c) {
color.SetElement(c,
static_cast<double>(i) / colorCount);
}
palette.append(color);
}
return palette;
}
// Example 9: Serialization
void SaveColor(const icmm::CVarColor& color, const QString& filename)
{
ifile::CFileWriteArchive archive(filename);
if (archive.IsOpen()) {
icmm::CVarColor copy = color;
copy.Serialize(archive);
}
}
Generic color implementation with variable number of color components.
Definition CVarColor.h:176
bool IsSimilar(const CVarColor &color, double tolerance=I_BIG_EPSILON) const
Allows to compare two colors with tolerance.
Definition CVarColor.h:267
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
Basic interface for color transformations between color models.
Simple implementation of archive writing to own ACF format binary file.
int GetElementsCount() const
Get number of elements.
Definition CVarVector.h:387
Implementation of fixed-size mathematical vector with specified type of elements.
Definition TVector.h:95
void SetElement(int i, const Element &value)
Sets the element at the specified index.
Definition TVector.h:560

Performance Considerations

Best Practices

Note
The dimension (number of components) is set at construction time and can be changed later, unlike fixed-size color classes.
See also
icmm::TComposedColor, icmm::CRgb, icmm::CHsv, icmm::CCmyk, icmm::CLab, imath::CVarVector, icmm::IColorTransformation

Definition at line 175 of file CVarColor.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 178 of file CVarColor.h.

Constructor & Destructor Documentation

◆ CVarColor() [1/4]

icmm::CVarColor::CVarColor ( )

Default constructor.

It set number of elements to 0.

◆ CVarColor() [2/4]

icmm::CVarColor::CVarColor ( int  componentsCount,
double  value = 0 
)
explicit

Constructor with explicit initialization of number of elements.

◆ CVarColor() [3/4]

icmm::CVarColor::CVarColor ( const CVarColor color)

Copy constructor.

◆ CVarColor() [4/4]

template<int Size>
icmm::CVarColor::CVarColor ( const imath::TVector< Size > &  vector)
inline

Template conversion constructor.

Definition at line 200 of file CVarColor.h.

Member Function Documentation

◆ GetNormalized()

void icmm::CVarColor::GetNormalized ( CVarColor result) const

Get normalized color.

Normalized values have all components in the range [0, 1].

◆ GetRounded()

void icmm::CVarColor::GetRounded ( const imath::IDoubleManip manipulator,
CVarColor result 
)

Get color after components value rounding with specified precision.

Parameters
manipulatormanipulator object used to round single components.
resultresult object.

◆ IsNormalized()

bool icmm::CVarColor::IsNormalized ( ) const
inline

Check if this color value is normalized.

Normalized values have all components in the range [0, 1].

Definition at line 273 of file CVarColor.h.

References imath::CVarVector::GetElement(), and imath::CVarVector::GetElementsCount().

◆ IsRoundedEqual()

bool icmm::CVarColor::IsRoundedEqual ( const CVarColor color,
const imath::IDoubleManip manipulator 
) const

Check if two values are equal after rounding.

Parameters
colorsecond color to comparision.
manipulatorvalue manipulator used to round single components.

◆ IsSimilar()

bool icmm::CVarColor::IsSimilar ( const CVarColor color,
double  tolerance = I_BIG_EPSILON 
) const
inline

Allows to compare two colors with tolerance.

Definition at line 267 of file CVarColor.h.

References imath::CVarVector::GetDistance().

◆ Normalize()

void icmm::CVarColor::Normalize ( )

Make this color to be normalized.

Normalized values have all components in the range [0, 1].

◆ operator*() [1/2]

CVarColor icmm::CVarColor::operator* ( const CVarColor color) const
inline

Definition at line 309 of file CVarColor.h.

◆ operator*() [2/2]

CVarColor icmm::CVarColor::operator* ( double  value) const
inline

◆ operator*=() [1/2]

const CVarColor & icmm::CVarColor::operator*= ( const CVarColor color)

◆ operator*=() [2/2]

const CVarColor & icmm::CVarColor::operator*= ( double  value)
inline

Definition at line 357 of file CVarColor.h.

References imath::CVarVector::operator*=().

◆ operator+()

CVarColor icmm::CVarColor::operator+ ( const CVarColor color) const
inline

Definition at line 289 of file CVarColor.h.

◆ operator+=()

const CVarColor & icmm::CVarColor::operator+= ( const CVarColor color)

◆ operator-()

CVarColor icmm::CVarColor::operator- ( const CVarColor color) const
inline

Definition at line 299 of file CVarColor.h.

◆ operator-=()

const CVarColor & icmm::CVarColor::operator-= ( const CVarColor color)

◆ operator/() [1/2]

CVarColor icmm::CVarColor::operator/ ( const CVarColor color) const
inline

Definition at line 319 of file CVarColor.h.

◆ operator/() [2/2]

CVarColor icmm::CVarColor::operator/ ( double  value) const
inline

◆ operator/=() [1/2]

const CVarColor & icmm::CVarColor::operator/= ( const CVarColor color)

◆ operator/=() [2/2]

const CVarColor & icmm::CVarColor::operator/= ( double  value)
inline

Definition at line 365 of file CVarColor.h.

References imath::CVarVector::operator/=().

◆ operator=()

CVarColor & icmm::CVarColor::operator= ( const CVarColor color)

◆ Serialize()

virtual bool icmm::CVarColor::Serialize ( iser::IArchive archive)
overridevirtual

Load or store state of this object as a archive stream.

Type of operation is depending on archive type.

See also
iser::IArchive

Implements iser::ISerializable.


The documentation for this class was generated from the following file: