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

Primitive for representation of HSV (Hue, Saturation, Value) color values. More...

#include <CHsv.h>

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

Public Types

enum  ComponentIndex { CI_HUE , CI_SATURATION , CI_VALUE , CI_LAST = CI_VALUE }
 
typedef TComposedColor< 3 > BaseClass
 
- Public Types inherited from icmm::TComposedColor< 3 >
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

 CHsv (double h=0.0, double s=0.0, double v=0.0)
 
 CHsv (const CHsv &color)
 
 CHsv (const imath::CVarVector &vector)
 
double GetHue () const
 
void SetHue (double value)
 
double GetSaturation () const
 
void SetSaturation (double value)
 
double GetValue () const
 
void SetValue (double value)
 
virtual bool Serialize (iser::IArchive &archive) override
 Load or store state of this object as a archive stream.
 
CHsv operator+ (const CHsv &color) const
 
CHsv operator- (const CHsv &color) const
 
CHsv operator* (const CHsv &color) const
 
CHsv operator/ (const CHsv &color) const
 
CHsv operator* (double value) const
 
CHsv operator/ (double value) const
 
CHsvoperator= (const CHsv &color)
 
const CHsvoperator+= (const CHsv &color)
 
const CHsvoperator-= (const CHsv &color)
 
const CHsvoperator*= (const CHsv &color)
 
const CHsvoperator/= (const CHsv &color)
 
const CHsvoperator*= (double value)
 
const CHsvoperator/= (double value)
 
- Public Member Functions inherited from icmm::TComposedColor< 3 >
 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* (double value) const
 
TComposedColor< Size > operator/ (const TComposedColor< Size > &color) 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*= (double value)
 
const TComposedColor< Size > & operator/= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator/= (double value)
 
- 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

Primitive for representation of HSV (Hue, Saturation, Value) color values.

Purpose

CHsv represents colors in the HSV color model, which is more intuitive for human color selection than RGB. HSV separates color (hue) from intensity (value) and colorfulness (saturation), making it easier to create color pickers, adjust brightness, or perform color-based image processing.

HSV Color Model

HSV consists of three cylindrical coordinates:

Usage Examples

// Example 1: Creating HSV colors
icmm::CHsv red(0.0, 1.0, 1.0); // Pure red
icmm::CHsv yellow(0.167, 1.0, 1.0); // Pure yellow
icmm::CHsv green(0.333, 1.0, 1.0); // Pure green
icmm::CHsv cyan(0.5, 1.0, 1.0); // Pure cyan
icmm::CHsv blue(0.667, 1.0, 1.0); // Pure blue
icmm::CHsv magenta(0.833, 1.0, 1.0); // Pure magenta
icmm::CHsv pastelBlue(0.667, 0.3, 0.9); // Low saturation = pastel
icmm::CHsv darkRed(0.0, 1.0, 0.3); // Low value = dark
icmm::CHsv gray(0.0, 0.0, 0.5); // Zero saturation = gray
// Example 2: Accessing and modifying components
icmm::CHsv color;
color.SetHue(0.5); // Cyan hue
color.SetSaturation(0.7); // Fairly saturated
color.SetValue(0.9); // Bright
double h = color.GetHue();
double s = color.GetSaturation();
double v = color.GetValue();
// Example 3: Adjusting brightness
icmm::CHsv AdjustBrightness(const icmm::CHsv& color, double factor)
{
icmm::CHsv result = color;
result.SetValue(color.GetValue() * factor);
// Clamp to [0, 1]
if (result.GetValue() > 1.0) result.SetValue(1.0);
if (result.GetValue() < 0.0) result.SetValue(0.0);
return result;
}
icmm::CHsv original(0.667, 0.8, 0.6); // Blue
icmm::CHsv brighter = AdjustBrightness(original, 1.5);
icmm::CHsv darker = AdjustBrightness(original, 0.5);
// Example 4: Adjusting saturation
icmm::CHsv ChangeSaturation(const icmm::CHsv& color, double newSat)
{
icmm::CHsv result = color;
result.SetSaturation(qBound(0.0, newSat, 1.0));
return result;
}
// Make more vivid
icmm::CHsv vivid = ChangeSaturation(original, 1.0);
// Make more pastel
icmm::CHsv pastel = ChangeSaturation(original, 0.3);
// Make grayscale
icmm::CHsv gray = ChangeSaturation(original, 0.0);
// Example 5: Hue rotation (color shift)
icmm::CHsv RotateHue(const icmm::CHsv& color, double rotation)
{
icmm::CHsv result = color;
double newHue = color.GetHue() + rotation;
// Wrap around [0, 1)
while (newHue >= 1.0) newHue -= 1.0;
while (newHue < 0.0) newHue += 1.0;
result.SetHue(newHue);
return result;
}
icmm::CHsv red(0.0, 1.0, 1.0);
icmm::CHsv complementary = RotateHue(red, 0.5); // Cyan (opposite)
icmm::CHsv analogous = RotateHue(red, 0.083); // Orange (nearby)
// Example 6: Creating color harmonies
QList<icmm::CHsv> CreateTriadicHarmony(const icmm::CHsv& base)
{
QList<icmm::CHsv> colors;
colors.append(base);
colors.append(RotateHue(base, 1.0 / 3.0)); // 120 degrees
colors.append(RotateHue(base, 2.0 / 3.0)); // 240 degrees
return colors;
}
// Example 7: RGB to HSV conversion
icmm::CHsv ConvertRgbToHsv(const icmm::CRgb& rgb)
{
// Use transformation for conversion
// (actual implementation uses color transformation)
// ...
}
// Example 8: Color wheel generation
QList<icmm::CHsv> GenerateColorWheel(int steps)
{
QList<icmm::CHsv> colors;
for (int i = 0; i < steps; ++i) {
double hue = static_cast<double>(i) / steps;
colors.append(icmm::CHsv(hue, 1.0, 1.0));
}
return colors;
}
// Example 9: Creating a color picker
icmm::CHsv SelectColorFromWheel(double angle, // 0-360 degrees
double distance, // 0-1 from center
double brightness) // 0-1
{
double hue = angle / 360.0;
double saturation = distance;
double value = brightness;
return icmm::CHsv(hue, saturation, value);
}
Primitive for representation of HSV (Hue, Saturation, Value) color values.
Definition CHsv.h:182
double GetValue() const
Definition CHsv.h:277
double GetHue() const
Definition CHsv.h:253
void SetValue(double value)
Definition CHsv.h:283
double GetSaturation() const
Definition CHsv.h:265
void SetHue(double value)
Definition CHsv.h:259
void SetSaturation(double value)
Definition CHsv.h:271
Concrete RGB color model implementation.
Primitive for representation of RGB color values.
Definition CRgb.h:168

HSV Advantages

HSV vs RGB

Best Practices

Note
Component values are normalized to [0, 1] range where:
  • Hue: 0.0-1.0 represents 0 degrees-360 degrees
  • Saturation: 0.0 (gray) to 1.0 (pure color)
  • Value: 0.0 (black) to 1.0 (bright)
See also
icmm::TComposedColor, icmm::CRgb, icmm::CHsvToRgbTransformation, icmm::CRgbToHsvTranformation

Definition at line 181 of file CHsv.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 184 of file CHsv.h.

Member Enumeration Documentation

◆ ComponentIndex

Enumerator
CI_HUE 
CI_SATURATION 
CI_VALUE 
CI_LAST 

Definition at line 186 of file CHsv.h.

Constructor & Destructor Documentation

◆ CHsv() [1/3]

icmm::CHsv::CHsv ( double  h = 0.0,
double  s = 0.0,
double  v = 0.0 
)
inline

Definition at line 231 of file CHsv.h.

References CI_HUE, CI_SATURATION, CI_VALUE, and imath::TVector< Size, Element >::SetElement().

◆ CHsv() [2/3]

icmm::CHsv::CHsv ( const CHsv color)
inline

Definition at line 239 of file CHsv.h.

◆ CHsv() [3/3]

icmm::CHsv::CHsv ( const imath::CVarVector vector)
inline

Definition at line 245 of file CHsv.h.

Member Function Documentation

◆ GetHue()

double icmm::CHsv::GetHue ( ) const
inline

Definition at line 253 of file CHsv.h.

References CI_HUE, and imath::TVector< Size, Element >::GetElement().

◆ GetSaturation()

double icmm::CHsv::GetSaturation ( ) const
inline

Definition at line 265 of file CHsv.h.

References CI_SATURATION, and imath::TVector< Size, Element >::GetElement().

◆ GetValue()

double icmm::CHsv::GetValue ( ) const
inline

Definition at line 277 of file CHsv.h.

References CI_VALUE, and imath::TVector< Size, Element >::GetElement().

◆ operator*() [1/2]

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

Definition at line 311 of file CHsv.h.

◆ operator*() [2/2]

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

Definition at line 331 of file CHsv.h.

◆ operator*=() [1/2]

const CHsv & icmm::CHsv::operator*= ( const CHsv color)
inline

Definition at line 375 of file CHsv.h.

References icmm::TComposedColor< 3 >::operator*=().

◆ operator*=() [2/2]

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

Definition at line 391 of file CHsv.h.

References icmm::TComposedColor< 3 >::operator*=().

◆ operator+()

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

Definition at line 291 of file CHsv.h.

◆ operator+=()

const CHsv & icmm::CHsv::operator+= ( const CHsv color)
inline

Definition at line 359 of file CHsv.h.

References icmm::TComposedColor< 3 >::operator+=().

◆ operator-()

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

Definition at line 301 of file CHsv.h.

◆ operator-=()

const CHsv & icmm::CHsv::operator-= ( const CHsv color)
inline

Definition at line 367 of file CHsv.h.

References icmm::TComposedColor< 3 >::operator-=().

◆ operator/() [1/2]

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

Definition at line 321 of file CHsv.h.

◆ operator/() [2/2]

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

Definition at line 341 of file CHsv.h.

◆ operator/=() [1/2]

const CHsv & icmm::CHsv::operator/= ( const CHsv color)
inline

Definition at line 383 of file CHsv.h.

References icmm::TComposedColor< 3 >::operator/=().

◆ operator/=() [2/2]

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

Definition at line 399 of file CHsv.h.

References icmm::TComposedColor< 3 >::operator/=().

◆ operator=()

CHsv & icmm::CHsv::operator= ( const CHsv color)
inline

Definition at line 351 of file CHsv.h.

References icmm::TComposedColor< 3 >::operator=().

◆ Serialize()

virtual bool icmm::CHsv::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

Reimplemented from icmm::TComposedColor< 3 >.

◆ SetHue()

void icmm::CHsv::SetHue ( double  value)
inline

Definition at line 259 of file CHsv.h.

References CI_HUE, and imath::TVector< Size, Element >::SetElement().

◆ SetSaturation()

void icmm::CHsv::SetSaturation ( double  value)
inline

Definition at line 271 of file CHsv.h.

References CI_SATURATION, and imath::TVector< Size, Element >::SetElement().

◆ SetValue()

void icmm::CHsv::SetValue ( double  value)
inline

Definition at line 283 of file CHsv.h.

References CI_VALUE, and imath::TVector< Size, Element >::SetElement().


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