qCC_db version 2.13.alpha (Qt) - 31 May 2022
CloudCompare 3D entities
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ccColorScale Class Reference

Color scale. More...

#include <ccColorScale.h>

Inheritance diagram for ccColorScale:
Inheritance graph
[legend]
Collaboration diagram for ccColorScale:
Collaboration graph
[legend]

Public Types

using Shared = QSharedPointer< ccColorScale >
 Shared pointer type.
 
using LabelSet = std::set< double >
 Type of a list of custom labels.
 
- Public Types inherited from ccSerializableObject
enum  DeserializationFlags { DF_POINT_COORDS_64_BITS = 1 , 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)
 

Public Member Functions

 ccColorScale (const QString &name, const QString &uuid=QString())
 Default constructor. More...
 
 ~ccColorScale () override=default
 Destructor.
 
ccColorScale::Shared copy (const QString &uuid=QString()) const
 Creates a copy of this color scale (with a specified unique id)
 
const QString & getName () const
 Returns name.
 
void setName (const QString &name)
 Sets name.
 
const QString & getUuid () const
 Returns unique ID.
 
void setUuid (const QString &uuid)
 Sets unique ID.
 
void generateNewUuid ()
 Generates a new unique ID.
 
bool isRelative () const
 Returns whether scale is relative or absoute. More...
 
void setRelative ()
 Sets scale as relative.
 
void setAbsolute (double minVal, double maxVal)
 Sets scale as absolute.
 
void getAbsoluteBoundaries (double &minVal, double &maxVal) const
 Get absolute scale boundaries. More...
 
bool isLocked () const
 Returns whether scale is locked or not.
 
void setLocked (bool state)
 Sets whether scale is locked or not.
 
LabelSetcustomLabels ()
 Returns the list of custom labels (if any)
 
const LabelSetcustomLabels () const
 Returns the list of custom labels (if any - const version)
 
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.
 
const ccColorScaleElementstep (int index) const
 Access to a given step (const)
 
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
 Returns relative position of a given value (wrt to scale absolute min and max) More...
 
const ccColor::RgbgetColorByValue (double value, const ccColor::Rgb *outOfRangeColor=nullptr) const
 Returns color by value. More...
 
const ccColor::RgbgetColorByRelativePos (double relativePos, const ccColor::Rgb *outOfRangeColor=nullptr) const
 Returns color by relative position in scale. More...
 
const ccColor::RgbgetColorByRelativePos (double relativePos, unsigned steps, const ccColor::Rgb *outOfRangeColor=nullptr) const
 Returns color by relative position in scale with a given 'resolution'. More...
 
const ccColor::RgbgetColorByIndex (unsigned index) const
 Returns color by index. More...
 
bool saveAsXML (const QString &filename) const
 Saves this color scale as an XML file.
 
bool isSerializable () const override
 Returns whether object is serializable of not. More...
 
bool toFile (QFile &out) const override
 Saves data to binary stream. 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.
 
virtual bool isSerializable () const
 Returns whether object is serializable of not. More...
 
virtual bool toFile (QFile &out) const
 Saves data to binary stream. More...
 
virtual bool fromFile (QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap)
 Loads data from binary stream. 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 (const QString &filename)
 Loads a color scale from an XML file.
 
- 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 constexpr unsigned MIN_STEPS = 2
 Minimum number of steps.
 
static constexpr unsigned DEFAULT_STEPS = 256
 Default number of steps for display.
 
static constexpr unsigned MAX_STEPS = 1024
 Maximum number of steps (internal representation)
 

Protected Member Functions

void sort ()
 Sort elements.
 

Protected Attributes

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

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, an array of interpolated colors is maintained internally. Be sure that the 'refresh' method has been called after any modification of the scale steps (position or color).

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).

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.

◆ Create()

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.

◆ 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
flagsdeserialization flags (see ccSerializableObject::DeserializationFlags)
oldToNewIDMapmap to link old IDs with new IDs
Returns
success

Reimplemented from ccSerializableObject.

◆ getAbsoluteBoundaries()

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

Get absolute scale boundaries.

Warning: only valid with absolute scales!

◆ getColorByIndex()

const ccColor::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

◆ getColorByRelativePos() [1/2]

const ccColor::Rgb * ccColorScale::getColorByRelativePos ( double  relativePos,
const ccColor::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

◆ getColorByRelativePos() [2/2]

const ccColor::Rgb * ccColorScale::getColorByRelativePos ( double  relativePos,
unsigned  steps,
const ccColor::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

◆ getColorByValue()

const ccColor::Rgb * ccColorScale::getColorByValue ( double  value,
const ccColor::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

◆ 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.

◆ insert()

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

Adds a step.

Scale must not be locked.

◆ isRelative()

bool ccColorScale::isRelative ( ) const
inline

Returns whether scale is relative or absoute.

Relative means that internal 'values' are percentage.

◆ isSerializable()

bool ccColorScale::isSerializable ( ) const
inlineoverridevirtual

Returns whether object is serializable of not.

Reimplemented from 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.

◆ 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)

◆ stepCount()

int ccColorScale::stepCount ( ) const
inline

Returns the current number of steps.

A valid scale should always have at least 2 steps!

◆ toFile()

bool ccColorScale::toFile ( QFile &  out) const
overridevirtual

Saves data to binary stream.

Parameters
outoutput file (already opened)
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).

Member Data Documentation

◆ 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!

◆ 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!


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