ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccColorScale Class Reference

Color scale. More...

#include <ecvColorScale.h>

Inheritance diagram for ccColorScale:
Collaboration diagram for ccColorScale:

Classes

struct  Label
 Color scale label (value + optional text) More...
 

Public Types

typedef QSharedPointer< ccColorScaleShared
 Shared pointer type. More...
 
using LabelSet = std::set< Label >
 Type of a list of custom labels. More...
 
- Public Types inherited from ccSerializableObject
enum  DeserializationFlags { DF_POINT_COORDS_64_BITS , DF_SCALAR_VAL_32_BITS = 2 }
 Deserialization flags (bit-field) More...
 
typedef QMultiMap< unsigned, unsigned > LoadedIDMap
 Map of loaded unique IDs (old ID --> new ID) More...
 

Public Member Functions

 ccColorScale (const QString &name, const QString &uuid=QString())
 Default constructor. More...
 
virtual ~ccColorScale ()
 Destructor. More...
 
ccColorScale::Shared copy (const QString &uuid=QString()) const
 Creates a copy of this color scale (with a specified unique id) More...
 
const QString & getName () const
 Returns name. More...
 
void setName (const QString &name)
 Sets name. More...
 
QString getUuid () const
 Returns unique ID. More...
 
void setUuid (QString uuid)
 Sets unique ID. More...
 
void generateNewUuid ()
 Generates a new unique ID. More...
 
bool isRelative () const
 Returns whether scale is relative or absoute. More...
 
void setRelative ()
 Sets scale as relative. More...
 
void setAbsolute (double minVal, double maxVal)
 Sets scale as absolute. More...
 
void getAbsoluteBoundaries (double &minVal, double &maxVal) const
 Get absolute scale boundaries. More...
 
bool isLocked () const
 Returns whether scale is locked or not. More...
 
void setLocked (bool state)
 Sets whether scale is locked or not. More...
 
LabelSetcustomLabels ()
 Returns the list of custom labels (if any) More...
 
const LabelSetcustomLabels () const
 Returns the list of custom labels (if any - const version) More...
 
void setCustomLabels (const LabelSet &labels)
 Sets the list of custom labels (only if the scale is absolute) More...
 
int stepCount () const
 Returns the current number of steps. More...
 
ccColorScaleElementstep (int index)
 Access to a given step. More...
 
const ccColorScaleElementstep (int index) const
 Access to a given step (const) More...
 
void insert (const ccColorScaleElement &step, bool autoUpdate=true)
 Adds a step. More...
 
void remove (int index, bool autoUpdate=true)
 Deletes a given step. More...
 
void clear ()
 Clears all steps. More...
 
void update ()
 Updates internal representation. More...
 
double getRelativePosition (double value) const
 
const ecvColor::RgbgetColorByValue (double value, const ecvColor::Rgb *outOfRangeColor=nullptr) const
 Returns color by value. More...
 
const ecvColor::RgbgetColorByRelativePos (double relativePos, const ecvColor::Rgb *outOfRangeColor=nullptr) const
 Returns color by relative position in scale. More...
 
const ecvColor::RgbgetColorByRelativePos (double relativePos, unsigned steps, const ecvColor::Rgb *outOfRangeColor=nullptr) const
 Returns color by relative position in scale with a given 'resolution'. More...
 
const ecvColor::RgbgetColorByIndex (unsigned index) const
 Returns color by index. More...
 
bool saveAsXML (QString filename) const
 Saves this color scale as an XML file. More...
 
bool isSerializable () const override
 Returns whether object is serializable of not. More...
 
bool toFile (QFile &out, short dataVersion) const override
 Saves data to binary stream. More...
 
short minimumFileVersion () const override
 Returns the minimum file version required to save this instance. More...
 
bool fromFile (QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
 Loads data from binary stream. More...
 
- Public Member Functions inherited from ccSerializableObject
virtual ~ccSerializableObject ()=default
 Destructor. More...
 

Static Public Member Functions

static ccColorScale::Shared Create (const QString &name)
 Creates a new color scale (with auto-generated unique id) More...
 
static Shared LoadFromXML (QString filename)
 Loads a color scale from an XML file. More...
 
- Static Public Member Functions inherited from ccSerializableObject
static bool WriteError ()
 Sends a custom error message (write error) and returns 'false'. More...
 
static bool ReadError ()
 Sends a custom error message (read error) and returns 'false'. More...
 
static bool MemoryError ()
 Sends a custom error message (not enough memory) and returns 'false'. More...
 
static bool CorruptError ()
 Sends a custom error message (corrupted file) and returns 'false'. More...
 

Static Public Attributes

static const unsigned MIN_STEPS = 2
 Minimum number of steps. More...
 
static const unsigned DEFAULT_STEPS = 256
 Default number of steps for display. More...
 
static const unsigned MAX_STEPS = 1024
 Maximum number of steps (internal representation) More...
 

Protected Member Functions

void sort ()
 Sort elements. More...
 

Protected Attributes

QString m_name
 Name. More...
 
QString m_uuid
 Unique ID. More...
 
QList< ccColorScaleElementm_steps
 Elements. More...
 
ecvColor::Rgb m_rgbaScale [MAX_STEPS]
 Internal representation (RGB) More...
 
bool m_updated
 Internal representation validity. More...
 
bool m_relative
 Whether scale is relative or not. More...
 
bool m_locked
 Whether scale is locked or not. More...
 
double m_absoluteMinValue
 'Absolute' minimum value More...
 
double m_absoluteRange
 'Absolute' range More...
 
LabelSet m_customLabels
 List of custom labels. More...
 

Detailed Description

Color scale.

A color scale is defined by several 'steps' corresponding to given colors. The color between each step is linearly interpolated. A valid color scale must have at least 2 steps, one at relative position 0.0 (scale start) and one at relative position 1.0 (scale end). Steps can't be defined outside this interval.

For faster access, a array of interpolated colors is maintained internally. Be sure that the 'refresh' method has been called after any modification(s) of the scale steps (position or color).

Definition at line 71 of file ecvColorScale.h.

Member Typedef Documentation

◆ LabelSet

using ccColorScale::LabelSet = std::set<Label>

Type of a list of custom labels.

Definition at line 160 of file ecvColorScale.h.

◆ Shared

typedef QSharedPointer<ccColorScale> ccColorScale::Shared

Shared pointer type.

Definition at line 74 of file ecvColorScale.h.

Constructor & Destructor Documentation

◆ ccColorScale()

ccColorScale::ccColorScale ( const QString &  name,
const QString &  uuid = QString() 
)

Default constructor.

Parameters
namescale name
uuidUUID (automatically generated if none is provided) Scale are 'relative' by default (can be changed afterwards, see setAbsolute). On construction they already have the two extreme steps defined (at position 0.0 and 1.0).

◆ ~ccColorScale()

virtual ccColorScale::~ccColorScale ( )
virtual

Destructor.

Member Function Documentation

◆ clear()

void ccColorScale::clear ( )

Clears all steps.

There should be at least 2 steps for the scale to be valid! Scale must not be locked.

Referenced by define_ccColorScale().

◆ copy()

ccColorScale::Shared ccColorScale::copy ( const QString &  uuid = QString()) const

Creates a copy of this color scale (with a specified unique id)

◆ Create()

static ccColorScale::Shared ccColorScale::Create ( const QString &  name)
static

Creates a new color scale (with auto-generated unique id)

Warning: color scale is relative by default.

Referenced by ccColorScaleEditorDialog::copyCurrentScale(), ccColorScaleEditorDialog::createNewScale(), and ccEntityAction::setColorGradient().

◆ customLabels() [1/2]

LabelSet& ccColorScale::customLabels ( )
inline

Returns the list of custom labels (if any)

Definition at line 163 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ customLabels() [2/2]

const LabelSet& ccColorScale::customLabels ( ) const
inline

Returns the list of custom labels (if any - const version)

Definition at line 165 of file ecvColorScale.h.

◆ fromFile()

bool ccColorScale::fromFile ( QFile &  in,
short  dataVersion,
int  flags,
LoadedIDMap oldToNewIDMap 
)
overridevirtual

Loads data from binary stream.

Parameters
ininput file (already opened)
dataVersionfile version (for version-specific deserialization)
flagsdeserialization flags (see ccSerializableObject::DeserializationFlags)
oldToNewIDMapmap to link old IDs with new IDs
Returns
success
Note: When implementing, use dataVersion checks to handle different
versions:
  • if (dataVersion >= X) { read new field } else { use default value } This ensures forward compatibility with older file formats.

Reimplemented from ccSerializableObject.

◆ generateNewUuid()

void ccColorScale::generateNewUuid ( )

Generates a new unique ID.

Referenced by define_ccColorScale().

◆ getAbsoluteBoundaries()

void ccColorScale::getAbsoluteBoundaries ( double &  minVal,
double &  maxVal 
) const

Get absolute scale boundaries.

Warning: only valid with absolute scales!

◆ getColorByIndex()

const ecvColor::Rgb& ccColorScale::getColorByIndex ( unsigned  index) const
inline

Returns color by index.

Parameters
indexcolor index in m_rgbaScale array (must be below MAX_STEPS)
Returns
corresponding color

Definition at line 278 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ getColorByRelativePos() [1/2]

const ecvColor::Rgb* ccColorScale::getColorByRelativePos ( double  relativePos,
const ecvColor::Rgb outOfRangeColor = nullptr 
) const
inline

Returns color by relative position in scale.

Parameters
relativePosrelative position (should be in [0;1])
outOfRangeColordefault color to return if relativePos if out of [0;1]
Returns
corresponding color

Definition at line 241 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ getColorByRelativePos() [2/2]

const ecvColor::Rgb* ccColorScale::getColorByRelativePos ( double  relativePos,
unsigned  steps,
const ecvColor::Rgb outOfRangeColor = nullptr 
) const
inline

Returns color by relative position in scale with a given 'resolution'.

Parameters
relativePosrelative position (must be between 0 and 1!)
stepsdesired resolution (must be greater than 1 and smaller than MAX_STEPS)
outOfRangeColordefault color to return if relativePos if out of [0;1]
Returns
corresponding color

Definition at line 258 of file ecvColorScale.h.

◆ getColorByValue()

const ecvColor::Rgb* ccColorScale::getColorByValue ( double  value,
const ecvColor::Rgb outOfRangeColor = nullptr 
) const
inline

Returns color by value.

Warning: only valid with absolute scales!

Parameters
valuevalue
outOfRangeColordefault color to return if relativePos if out of [0;1]
Returns
corresponding color

Definition at line 226 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ getName()

const QString& ccColorScale::getName ( ) const
inline

Returns name.

Definition at line 112 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ getRelativePosition()

double ccColorScale::getRelativePosition ( double  value) const
inline

Returns relative position of a given value (wrt to scale absolute min and max) Warning: only valid with absolute scales! Use 'getColorByRelativePos' otherwise.

Definition at line 215 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ getUuid()

QString ccColorScale::getUuid ( ) const
inline

Returns unique ID.

Definition at line 117 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ insert()

void ccColorScale::insert ( const ccColorScaleElement step,
bool  autoUpdate = true 
)

Adds a step.

Scale must not be locked.

Referenced by define_ccColorScale().

◆ isLocked()

bool ccColorScale::isLocked ( ) const
inline

Returns whether scale is locked or not.

Definition at line 140 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ isRelative()

bool ccColorScale::isRelative ( ) const
inline

Returns whether scale is relative or absoute.

Relative means that internal 'values' are percentage.

Definition at line 126 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ isSerializable()

bool ccColorScale::isSerializable ( ) const
inlineoverridevirtual

Returns whether object is serializable of not.

Reimplemented from ccSerializableObject.

Definition at line 289 of file ecvColorScale.h.

◆ LoadFromXML()

static Shared ccColorScale::LoadFromXML ( QString  filename)
static

Loads a color scale from an XML file.

Referenced by define_ccColorScale(), ccColorScaleEditorDialog::importScale(), and CommandSFColorScale::process().

◆ minimumFileVersion()

short ccColorScale::minimumFileVersion ( ) const
overridevirtual

Returns the minimum file version required to save this instance.

To be overridden by subclasses to indicate their minimum required version. This enables the system to determine:

  • Forward compatibility: newer software can read older files (dataVersion check in fromFile)
  • Backward compatibility: determine minimum version needed to save current data
    Returns
    minimum file version required for this object

Implements ccSerializableObject.

◆ remove()

void ccColorScale::remove ( int  index,
bool  autoUpdate = true 
)

Deletes a given step.

The first and last index shouldn't be deleted! Scale must not be locked.

Referenced by define_ccColorScale().

◆ saveAsXML()

bool ccColorScale::saveAsXML ( QString  filename) const

Saves this color scale as an XML file.

Referenced by define_ccColorScale().

◆ setAbsolute()

void ccColorScale::setAbsolute ( double  minVal,
double  maxVal 
)

Sets scale as absolute.

Referenced by define_ccColorScale().

◆ setCustomLabels()

void ccColorScale::setCustomLabels ( const LabelSet labels)
inline

Sets the list of custom labels (only if the scale is absolute)

Warning
May throw std::bad_alloc exception)

Definition at line 170 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ setLocked()

void ccColorScale::setLocked ( bool  state)
inline

Sets whether scale is locked or not.

Definition at line 143 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ setName()

void ccColorScale::setName ( const QString &  name)
inline

Sets name.

Definition at line 114 of file ecvColorScale.h.

References name.

Referenced by define_ccColorScale().

◆ setRelative()

void ccColorScale::setRelative ( )
inline

Sets scale as relative.

Definition at line 129 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ setUuid()

void ccColorScale::setUuid ( QString  uuid)
inline

Sets unique ID.

Definition at line 119 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ sort()

void ccColorScale::sort ( )
protected

Sort elements.

◆ step() [1/2]

ccColorScaleElement& ccColorScale::step ( int  index)
inline

Access to a given step.

Definition at line 180 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ step() [2/2]

const ccColorScaleElement& ccColorScale::step ( int  index) const
inline

Access to a given step (const)

Definition at line 183 of file ecvColorScale.h.

◆ stepCount()

int ccColorScale::stepCount ( ) const
inline

Returns the current number of steps.

A valid scale should always have at least 2 steps!

Definition at line 177 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ toFile()

bool ccColorScale::toFile ( QFile &  out,
short  dataVersion 
) const
overridevirtual

Saves data to binary stream.

Parameters
outoutput file (already opened)
dataVersiontarget file version (for forward/backward compatibility)
Returns
success

Reimplemented from ccSerializableObject.

◆ update()

void ccColorScale::update ( )

Updates internal representation.

Must be called at least once after any modification (before using this scale).

Referenced by define_ccColorScale().

Member Data Documentation

◆ DEFAULT_STEPS

const unsigned ccColorScale::DEFAULT_STEPS = 256
static

Default number of steps for display.

Warning
Never pass a 'constant initializer' by reference

Definition at line 104 of file ecvColorScale.h.

Referenced by define_ccColorScale().

◆ m_absoluteMinValue

double ccColorScale::m_absoluteMinValue
protected

'Absolute' minimum value

Only used if scale is 'absolute' (i.e. not relative). 'Absolute' should not be taken in its mathematical meaning!

Definition at line 326 of file ecvColorScale.h.

◆ m_absoluteRange

double ccColorScale::m_absoluteRange
protected

'Absolute' range

Only used if scale is 'absolute' (i.e. not relative). 'Absolute' should not be taken in its mathematical meaning!

Definition at line 332 of file ecvColorScale.h.

◆ m_customLabels

LabelSet ccColorScale::m_customLabels
protected

List of custom labels.

Definition at line 335 of file ecvColorScale.h.

◆ m_locked

bool ccColorScale::m_locked
protected

Whether scale is locked or not.

Definition at line 320 of file ecvColorScale.h.

◆ m_name

QString ccColorScale::m_name
protected

Name.

Definition at line 302 of file ecvColorScale.h.

◆ m_relative

bool ccColorScale::m_relative
protected

Whether scale is relative or not.

Definition at line 317 of file ecvColorScale.h.

◆ m_rgbaScale

ecvColor::Rgb ccColorScale::m_rgbaScale[MAX_STEPS]
protected

Internal representation (RGB)

Definition at line 311 of file ecvColorScale.h.

◆ m_steps

QList<ccColorScaleElement> ccColorScale::m_steps
protected

Elements.

Definition at line 308 of file ecvColorScale.h.

◆ m_updated

bool ccColorScale::m_updated
protected

Internal representation validity.

Definition at line 314 of file ecvColorScale.h.

◆ m_uuid

QString ccColorScale::m_uuid
protected

Unique ID.

Definition at line 305 of file ecvColorScale.h.

◆ MAX_STEPS

const unsigned ccColorScale::MAX_STEPS = 1024
static

Maximum number of steps (internal representation)

Warning
Never pass a 'constant initializer' by reference

Definition at line 109 of file ecvColorScale.h.

Referenced by ccPropertiesTreeDelegate::createEditor(), define_ccColorScale(), DistanceMapGenerationDlg::DistanceMapGenerationDlg(), and StereogramDialog::StereogramDialog().

◆ MIN_STEPS

const unsigned ccColorScale::MIN_STEPS = 2
static

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