ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
icmm::TComposedColor< Size > Class Template Reference

Generic fixed-size color implementation template. More...

#include <TComposedColor.h>

Inheritance diagram for icmm::TComposedColor< Size >:
imath::TVector< Size, Element > iser::ISerializable istd::IChangeable istd::IPolymorphic

Public Types

typedef imath::TVector< Size > BaseClass
 
typedef BaseClass::Elements Elements
 
- Public Types inherited from imath::TVector< Size, Element >
typedef Element ElementType
 
typedef Element Elements[Size]
 
- 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

 TComposedColor ()
 
 TComposedColor (const BaseClass &value)
 
 TComposedColor (const imath::CVarVector &vector)
 
 TComposedColor (const TComposedColor< Size > &color)=default
 
void GetRounded (const imath::IDoubleManip &manipulator, TComposedColor< Size > &result)
 Get color after components value rounding with specified precision.
 
bool IsRoundedEqual (const TComposedColor< Size > &color, const imath::IDoubleManip &manipulator) const
 Check if two values are equal after rounding.
 
bool IsSimilar (const TComposedColor< Size > &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 (TComposedColor< Size > &result) const
 Get normalized color.
 
TComposedColor< Size > operator+ (const TComposedColor< Size > &color) const
 
TComposedColor< Size > operator- (const TComposedColor< Size > &color) const
 
TComposedColor< Size > operator* (const TComposedColor< Size > &color) const
 
TComposedColor< Size > operator/ (const TComposedColor< Size > &color) const
 
TComposedColor< Size > operator* (double value) const
 
TComposedColor< Size > operator/ (double value) const
 
const TComposedColor< Size > & operator= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator= (double colorValue)
 
const TComposedColor< Size > & operator+= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator-= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator*= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator/= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator*= (double value)
 
const TComposedColor< Size > & operator/= (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::TVector< Size, Element >
 TVector ()
 Creates an uninitialized vector.
 
 TVector (const TVector< Size, Element > &vector)
 Creates a copy of another vector.
 
 TVector (std::initializer_list< Element > values)
 Creates a vector from an initializer list.
 
const Element & GetElement (int i) const
 Gets the element at the specified index (read-only).
 
Element & GetElementRef (int i)
 Gets a reference to the element at the specified index (read-write).
 
void SetElement (int i, const Element &value)
 Sets the element at the specified index.
 
void SetAllElements (const Element &value)
 Sets all elements to the same value.
 
void Reset ()
 Sets all coordinates to zero.
 
void Clear ()
 Sets all coordinates to zero.
 
const TVector< Size, Element >::ElementsGetElements () const
 Get read-only access to internal element container.
 
TVector< Size, Element >::ElementsGetElementsRef ()
 Get access to internal element container.
 
void Translate (const TVector< Size, Element > &vector)
 Translates (adds) another vector to this vector.
 
TVector< Size, Element > GetTranslated (const TVector< Size, Element > &vector)
 Returns a new vector that is the translation of this vector.
 
void GetTranslated (const TVector< Size, Element > &vector, TVector< Size, Element > &result)
 Computes the translated vector and stores it in the result parameter.
 
void ScaledCumulate (const TVector< Size, Element > &vector, Element scale)
 Adds a scaled vector to this vector.
 
bool IsNull (Element tolerance=I_BIG_EPSILON) const
 Checks if this vector is null (all elements approximately zero).
 
Element GetDotProduct (const TVector< Size, Element > &vector) const
 Calculates the dot product with another vector.
 
Element GetLength2 () const
 Calculates the squared Euclidean length of the vector.
 
Element GetLength () const
 Calculates the Euclidean length (magnitude) of the vector.
 
Element GetDistance2 (const TVector< Size, Element > &vector) const
 Calculates the squared distance to another vector.
 
Element GetDistance (const TVector< Size, Element > &vector) const
 Calculates the Euclidean distance to another vector.
 
Element GetElementsSum () const
 Calculates the sum of all vector elements.
 
bool Normalize (Element length=1.0)
 Normalizes the vector to a specified length.
 
bool GetNormalized (TVector< Size, Element > &result, Element length=1.0) const
 Returns a normalized copy of this vector with specified length.
 
void GetMinimal (const TVector< Size, Element > &vector, TVector< Size, Element > &result) const
 Get vector with minimal elements values.
 
void GetMaximal (const TVector< Size, Element > &vector, TVector< Size, Element > &result) const
 Get vector with maximal elements values.
 
bool Serialize (iser::IArchive &archive)
 Serialize this vector to specified archive.
 
bool operator== (const TVector< Size, Element > &vector) const
 
bool operator!= (const TVector< Size, Element > &vector) const
 
bool operator< (const TVector< Size, Element > &vector) const
 
bool operator> (const TVector< Size, Element > &vector) const
 
bool operator<= (const TVector< Size, Element > &vector) const
 
bool operator>= (const TVector< Size, Element > &vector) const
 
TVector< Size, Element > & operator= (const TVector< Size, Element > &vector)=default
 
TVector< Size, Element > operator- () const
 
TVector< Size, Element > operator+ (const TVector< Size, Element > &vector) const
 
TVector< Size, Element > operator- (const TVector< Size, Element > &vector) const
 
TVector< Size, Element > operator* (Element scalar) const
 
TVector< Size, Element > operator/ (Element scalar) const
 
TVector< Size, Element > & operator+= (const TVector< Size, Element > &vector)
 
TVector< Size, Element > & operator-= (const TVector< Size, Element > &vector)
 
TVector< Size, Element > & operator*= (Element scalar)
 
TVector< Size, Element > & operator/= (Element scalar)
 
const Element & operator[] (int i) const
 
Element & 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 imath::TVector< Size, Element >
static int GetElementsCount ()
 Get number of elements.
 
static bool SetElementsCount (int count)
 Set number of elements.
 
static const TVector< Size, Element > & GetZero ()
 Get vector with all coordinates set to 0.
 
- 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.
 
- Protected Attributes inherited from imath::TVector< Size, Element >
Elements m_elements
 

Detailed Description

template<int Size>
class icmm::TComposedColor< Size >

Generic fixed-size color implementation template.

Purpose

TComposedColor is a template base class for fixed-size color representations. It combines the mathematical vector operations of TVector with color-specific functionality like normalization, rounding, and serialization. This class serves as the foundation for CRgb, CHsv, CCmyk, CLab, and other fixed-size color classes.

Design

TComposedColor<Size> inherits from TVector<Size> and adds:

Usage Examples

// Example 1: TComposedColor as base for custom colors
// (CRgb, CHsv, etc. inherit from TComposedColor)
class CMyCustomColor : public icmm::TComposedColor<5>
{
public:
CMyCustomColor(double c1 = 0, double c2 = 0, double c3 = 0,
double c4 = 0, double c5 = 0)
{
SetElement(0, c1);
SetElement(1, c2);
SetElement(2, c3);
SetElement(3, c4);
SetElement(4, c5);
}
};
// Example 2: Normalization (clamping to [0,1])
icmm::CRgb rgb(1.5, -0.2, 0.8); // Out of range values
if (!rgb.IsNormalized()) {
rgb.Normalize(); // Now (1.0, 0.0, 0.8)
}
// Example 3: Fuzzy comparison
icmm::CRgb color1(0.5, 0.5, 0.5);
icmm::CRgb color2(0.501, 0.499, 0.502);
bool similar = color1.IsSimilar(color2, 0.01); // true
bool exact = (color1 == color2); // false (if == is implemented)
// Example 4: Color arithmetic (inherited from TComposedColor)
icmm::CRgb a(0.8, 0.3, 0.2);
icmm::CRgb b(0.2, 0.5, 0.7);
// Component-wise operations
icmm::CRgb sum = a + b; // {1.0, 0.8, 0.9}
icmm::CRgb diff = a - b; // {0.6, -0.2, -0.5}
icmm::CRgb product = a * b; // {0.16, 0.15, 0.14}
icmm::CRgb scaled = a * 0.5; // {0.4, 0.15, 0.1}
// Example 5: Serialization
void SaveColor(const icmm::TComposedColor<3>& color,
const QString& filename)
{
ifile::CFileWriteArchive archive(filename);
if (archive.IsOpen()) {
copy.Serialize(archive);
}
}
void LoadColor(icmm::TComposedColor<3>& color,
const QString& filename)
{
ifile::CFileReadArchive archive(filename);
if (archive.IsOpen()) {
color.Serialize(archive);
}
}
// Example 6: Getting normalized copy
icmm::CRgb hdrColor(2.0, 1.5, 0.8); // HDR values
icmm::CRgb sdrColor;
hdrColor.GetNormalized(sdrColor); // sdrColor = (1.0, 1.0, 0.8)
// hdrColor unchanged
// Example 7: Conversion from CVarVector
varVec.SetElement(0, 0.5);
varVec.SetElement(1, 0.6);
varVec.SetElement(2, 0.7);
icmm::TComposedColor<3> color(varVec); // Convert to fixed-size
Primitive for representation of RGB color values.
Definition CRgb.h:168
Generic fixed-size color implementation template.
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
void GetNormalized(TComposedColor< Size > &result) const
Get normalized color.
Simple implementation of archive reading from own ACF format binary file.
Simple implementation of archive writing to own ACF format binary file.
Implementation of variable-size mathematical vector with double precision elements.
Definition CVarVector.h:110

Inheritance Hierarchy

TComposedColor serves as the base for:

Best Practices

Note
Template parameter Size determines the number of color components at compile time, enabling optimizations not possible with CVarColor.
See also
icmm::CVarColor, icmm::CRgb, icmm::CHsv, icmm::CCmyk, icmm::CLab, imath::TVector, iser::ISerializable

Definition at line 141 of file TComposedColor.h.

Member Typedef Documentation

◆ BaseClass

template<int Size>
typedef imath::TVector<Size> icmm::TComposedColor< Size >::BaseClass

Definition at line 144 of file TComposedColor.h.

◆ Elements

template<int Size>
typedef BaseClass::Elements icmm::TComposedColor< Size >::Elements

Definition at line 145 of file TComposedColor.h.

Constructor & Destructor Documentation

◆ TComposedColor() [1/4]

template<int Size>
icmm::TComposedColor< Size >::TComposedColor ( )
inline

Definition at line 216 of file TComposedColor.h.

◆ TComposedColor() [2/4]

template<int Size>
icmm::TComposedColor< Size >::TComposedColor ( const BaseClass value)
inline

Definition at line 223 of file TComposedColor.h.

◆ TComposedColor() [3/4]

template<int Size>
icmm::TComposedColor< Size >::TComposedColor ( const imath::CVarVector vector)
inlineexplicit

Definition at line 230 of file TComposedColor.h.

References imath::CVarVector::GetElementsCount().

◆ TComposedColor() [4/4]

template<int Size>
icmm::TComposedColor< Size >::TComposedColor ( const TComposedColor< Size > &  color)
default

Member Function Documentation

◆ GetNormalized()

template<int Size>
void icmm::TComposedColor< Size >::GetNormalized ( TComposedColor< Size > &  result) const

Get normalized color.

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

Definition at line 469 of file TComposedColor.h.

References icmm::TComposedColor< Size >::Normalize().

◆ GetRounded()

template<int Size>
void icmm::TComposedColor< Size >::GetRounded ( const imath::IDoubleManip manipulator,
TComposedColor< Size > &  result 
)

Get color after components value rounding with specified precision.

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

Definition at line 430 of file TComposedColor.h.

References imath::TIValueManip< ValueType >::GetRounded().

◆ IsNormalized()

template<int Size>
bool icmm::TComposedColor< Size >::IsNormalized ( ) const
inline

Check if this color value is normalized.

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

Definition at line 251 of file TComposedColor.h.

◆ IsRoundedEqual()

template<int Size>
bool icmm::TComposedColor< Size >::IsRoundedEqual ( const TComposedColor< Size > &  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.

Definition at line 439 of file TComposedColor.h.

References imath::TIValueManip< ValueType >::AreValuesEqual().

◆ IsSimilar()

template<int Size>
bool icmm::TComposedColor< Size >::IsSimilar ( const TComposedColor< Size > &  color,
double  tolerance = I_BIG_EPSILON 
) const
inline

Allows to compare two colors with tolerance.

Definition at line 244 of file TComposedColor.h.

◆ Normalize()

template<int Size>
void icmm::TComposedColor< Size >::Normalize ( )

Make this color to be normalized.

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

Definition at line 452 of file TComposedColor.h.

Referenced by icmm::TComposedColor< Size >::GetNormalized().

◆ operator*() [1/2]

template<int Size>
TComposedColor< Size > icmm::TComposedColor< Size >::operator* ( const TComposedColor< Size > &  color) const
inline

Definition at line 292 of file TComposedColor.h.

◆ operator*() [2/2]

template<int Size>
TComposedColor< Size > icmm::TComposedColor< Size >::operator* ( double  value) const
inline

Definition at line 318 of file TComposedColor.h.

◆ operator*=() [1/2]

template<int Size>
const TComposedColor< Size > & icmm::TComposedColor< Size >::operator*= ( const TComposedColor< Size > &  color)
inline

Definition at line 384 of file TComposedColor.h.

◆ operator*=() [2/2]

template<int Size>
const TComposedColor< Size > & icmm::TComposedColor< Size >::operator*= ( double  value)
inline

Definition at line 410 of file TComposedColor.h.

◆ operator+()

template<int Size>
TComposedColor< Size > icmm::TComposedColor< Size >::operator+ ( const TComposedColor< Size > &  color) const
inline

Definition at line 266 of file TComposedColor.h.

◆ operator+=()

template<int Size>
const TComposedColor< Size > & icmm::TComposedColor< Size >::operator+= ( const TComposedColor< Size > &  color)
inline

Definition at line 366 of file TComposedColor.h.

◆ operator-()

template<int Size>
TComposedColor< Size > icmm::TComposedColor< Size >::operator- ( const TComposedColor< Size > &  color) const
inline

Definition at line 279 of file TComposedColor.h.

◆ operator-=()

template<int Size>
const TComposedColor< Size > & icmm::TComposedColor< Size >::operator-= ( const TComposedColor< Size > &  color)
inline

Definition at line 375 of file TComposedColor.h.

◆ operator/() [1/2]

template<int Size>
TComposedColor< Size > icmm::TComposedColor< Size >::operator/ ( const TComposedColor< Size > &  color) const
inline

Definition at line 305 of file TComposedColor.h.

◆ operator/() [2/2]

template<int Size>
TComposedColor< Size > icmm::TComposedColor< Size >::operator/ ( double  value) const
inline

Definition at line 331 of file TComposedColor.h.

◆ operator/=() [1/2]

template<int Size>
const TComposedColor< Size > & icmm::TComposedColor< Size >::operator/= ( const TComposedColor< Size > &  color)
inline

Definition at line 397 of file TComposedColor.h.

◆ operator/=() [2/2]

template<int Size>
const TComposedColor< Size > & icmm::TComposedColor< Size >::operator/= ( double  value)
inline

Definition at line 419 of file TComposedColor.h.

◆ operator=() [1/2]

template<int Size>
const TComposedColor< Size > & icmm::TComposedColor< Size >::operator= ( const TComposedColor< Size > &  color)
inline

Definition at line 344 of file TComposedColor.h.

◆ operator=() [2/2]

template<int Size>
const TComposedColor< Size > & icmm::TComposedColor< Size >::operator= ( double  colorValue)
inline

Definition at line 355 of file TComposedColor.h.

◆ Serialize()

template<int Size>
bool icmm::TComposedColor< Size >::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.

Reimplemented in icmm::CCmy, icmm::CCmyk, icmm::CHsv, icmm::CLab, and icmm::CRgb.

Definition at line 480 of file TComposedColor.h.

References iser::IArchive::BeginMultiTag(), iser::IArchive::BeginTag(), iser::IArchive::EndTag(), iser::IArchive::IsStoring(), NULL, iser::IArchive::Process(), iser::CArchiveTag::TT_LEAF, and iser::CArchiveTag::TT_MULTIPLE.


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