qCC_db version 2.13.alpha (Qt) - 31 May 2022
CloudCompare 3D entities
|
Color scale. More...
#include <ccColorScale.h>
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. | |
LabelSet & | customLabels () |
Returns the list of custom labels (if any) | |
const LabelSet & | customLabels () 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... | |
ccColorScaleElement & | step (int index) |
Access to a given step. | |
const ccColorScaleElement & | step (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::Rgb * | getColorByValue (double value, const ccColor::Rgb *outOfRangeColor=nullptr) const |
Returns color by value. More... | |
const ccColor::Rgb * | getColorByRelativePos (double relativePos, const ccColor::Rgb *outOfRangeColor=nullptr) const |
Returns color by relative position in scale. More... | |
const ccColor::Rgb * | getColorByRelativePos (double relativePos, unsigned steps, const ccColor::Rgb *outOfRangeColor=nullptr) const |
Returns color by relative position in scale with a given 'resolution'. More... | |
const ccColor::Rgb & | getColorByIndex (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... | |
Protected Member Functions | |
void | sort () |
Sort elements. | |
Protected Attributes | |
QString | m_name |
Name. | |
QString | m_uuid |
Unique ID. | |
QList< ccColorScaleElement > | m_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. | |
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).
ccColorScale::ccColorScale | ( | const QString & | name, |
const QString & | uuid = QString() |
||
) |
Default constructor.
name | scale name |
uuid | UUID (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). |
void ccColorScale::clear | ( | ) |
Clears all steps.
There should be at least 2 steps for the scale to be valid! Scale must not be locked.
|
static |
Creates a new color scale (with auto-generated unique id)
Warning: color scale is relative by default.
|
overridevirtual |
Loads data from binary stream.
in | input file (already opened) |
dataVersion | file version |
flags | deserialization flags (see ccSerializableObject::DeserializationFlags) |
oldToNewIDMap | map to link old IDs with new IDs |
Reimplemented from ccSerializableObject.
void ccColorScale::getAbsoluteBoundaries | ( | double & | minVal, |
double & | maxVal | ||
) | const |
Get absolute scale boundaries.
Warning: only valid with absolute scales!
|
inline |
Returns color by index.
index | color index in m_rgbaScale array (must be below MAX_STEPS) |
|
inline |
Returns color by relative position in scale.
relativePos | relative position (should be in [0;1]) |
outOfRangeColor | default color to return if relativePos if out of [0;1] |
|
inline |
Returns color by relative position in scale with a given 'resolution'.
relativePos | relative position (must be between 0 and 1!) |
steps | desired resolution (must be greater than 1 and smaller than MAX_STEPS) |
outOfRangeColor | default color to return if relativePos if out of [0;1] |
|
inline |
Returns color by value.
Warning: only valid with absolute scales!
value | value |
outOfRangeColor | default color to return if relativePos if out of [0;1] |
|
inline |
Returns relative position of a given value (wrt to scale absolute min and max)
Warning: only valid with absolute scales! Use 'getColorByRelativePos' otherwise.
void ccColorScale::insert | ( | const ccColorScaleElement & | step, |
bool | autoUpdate = true |
||
) |
Adds a step.
Scale must not be locked.
|
inline |
Returns whether scale is relative or absoute.
Relative means that internal 'values' are percentage.
|
inlineoverridevirtual |
Returns whether object is serializable of not.
Reimplemented from ccSerializableObject.
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.
|
inline |
Sets the list of custom labels (only if the scale is absolute)
|
inline |
Returns the current number of steps.
A valid scale should always have at least 2 steps!
|
overridevirtual |
Saves data to binary stream.
out | output file (already opened) |
Reimplemented from ccSerializableObject.
void ccColorScale::update | ( | ) |
Updates internal representation.
Must be called at least once after any modification (before using this scale).
|
protected |
'Absolute' minimum value
Only used if scale is 'absolute' (i.e. not relative). 'Absolute' should not be taken in its mathematical meaning!
|
protected |
'Absolute' range
Only used if scale is 'absolute' (i.e. not relative). 'Absolute' should not be taken in its mathematical meaning!