![]() |
ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
|
Color scale. More...
#include <ecvColorScale.h>
Classes | |
| struct | Label |
| Color scale label (value + optional text) More... | |
Public Types | |
| typedef QSharedPointer< ccColorScale > | Shared |
| 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... | |
| LabelSet & | customLabels () |
| Returns the list of custom labels (if any) More... | |
| const LabelSet & | customLabels () 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... | |
| ccColorScaleElement & | step (int index) |
| Access to a given step. More... | |
| const ccColorScaleElement & | step (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::Rgb * | getColorByValue (double value, const ecvColor::Rgb *outOfRangeColor=nullptr) const |
| Returns color by value. More... | |
| const ecvColor::Rgb * | getColorByRelativePos (double relativePos, const ecvColor::Rgb *outOfRangeColor=nullptr) const |
| Returns color by relative position in scale. More... | |
| const ecvColor::Rgb * | getColorByRelativePos (double relativePos, unsigned steps, const ecvColor::Rgb *outOfRangeColor=nullptr) const |
| Returns color by relative position in scale with a given 'resolution'. More... | |
| const ecvColor::Rgb & | getColorByIndex (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< ccColorScaleElement > | m_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... | |
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).
| using ccColorScale::LabelSet = std::set<Label> |
Type of a list of custom labels.
| typedef QSharedPointer<ccColorScale> ccColorScale::Shared |
Shared pointer type.
| 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). |
References generateNewUuid(), and m_uuid.
Referenced by copy(), Create(), and LoadFromXML().
|
virtual |
Destructor.
| void ccColorScale::clear | ( | ) |
Clears all steps.
There should be at least 2 steps for the scale to be valid! Scale must not be locked.
References m_locked, m_name, m_steps, m_updated, and CVLog::Warning().
Referenced by define_ccColorScale().
| ccColorScale::Shared ccColorScale::copy | ( | const QString & | uuid = QString() | ) | const |
Creates a copy of this color scale (with a specified unique id)
References ccColorScale(), m_absoluteMinValue, m_absoluteRange, m_customLabels, m_locked, m_name, m_relative, m_steps, and CVLog::Warning().
|
static |
Creates a new color scale (with auto-generated unique id)
Warning: color scale is relative by default.
References ccColorScale(), and name.
Referenced by ccColorScaleEditorDialog::copyCurrentScale(), ccColorScaleEditorDialog::createNewScale(), and ccEntityAction::setColorGradient().
|
inline |
Returns the list of custom labels (if any)
Referenced by define_ccColorScale().
|
inline |
Returns the list of custom labels (if any - const version)
|
overridevirtual |
Loads data from binary stream.
| in | input file (already opened) |
| dataVersion | file version (for version-specific deserialization) |
| flags | deserialization flags (see ccSerializableObject::DeserializationFlags) |
| oldToNewIDMap | map to link old IDs with new IDs |
Note: When implementing, use dataVersion checks to handle differentversions:
Reimplemented from ccSerializableObject.
| void ccColorScale::generateNewUuid | ( | ) |
Generates a new unique ID.
References m_uuid.
Referenced by ccColorScale(), and define_ccColorScale().
| void ccColorScale::getAbsoluteBoundaries | ( | double & | minVal, |
| double & | maxVal | ||
| ) | const |
Get absolute scale boundaries.
Warning: only valid with absolute scales!
References m_absoluteMinValue, and m_absoluteRange.
|
inline |
Returns color by index.
| index | color index in m_rgbaScale array (must be below MAX_STEPS) |
Referenced by define_ccColorScale().
|
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] |
Referenced by define_ccColorScale().
|
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] |
Referenced by define_ccColorScale().
|
inline |
Returns name.
Referenced by define_ccColorScale(), saveAsXML(), and update().
|
inline |
Returns relative position of a given value (wrt to scale absolute min and max) Warning: only valid with absolute scales! Use 'getColorByRelativePos' otherwise.
Referenced by define_ccColorScale().
|
inline |
Returns unique ID.
Referenced by define_ccColorScale(), and saveAsXML().
| void ccColorScale::insert | ( | const ccColorScaleElement & | step, |
| bool | autoUpdate = true |
||
| ) |
Adds a step.
Scale must not be locked.
References m_locked, m_name, m_steps, m_updated, MIN_STEPS, step(), update(), and CVLog::Warning().
Referenced by define_ccColorScale().
|
inline |
Returns whether scale is locked or not.
Referenced by define_ccColorScale().
|
inline |
Returns whether scale is relative or absoute.
Relative means that internal 'values' are percentage.
Referenced by define_ccColorScale(), and saveAsXML().
|
inlineoverridevirtual |
Returns whether object is serializable of not.
Reimplemented from ccSerializableObject.
|
static |
Loads a color scale from an XML file.
References ccColorScale(), CVLog::Error(), filename, name, CVLog::Print(), rgb, s_xmlACloudViewer(), s_xmlCloudCompare(), s_xmlColorScaleData(), s_xmlColorScaleProperties(), s_xmlColorScaleTitle(), s_xmlColorScaleVer, version, and CVLog::Warning().
Referenced by define_ccColorScale(), ccColorScaleEditorDialog::importScale(), and CommandSFColorScale::process().
|
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:
Implements ccSerializableObject.
References m_customLabels.
| 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.
References m_locked, m_name, m_steps, m_updated, update(), and CVLog::Warning().
Referenced by define_ccColorScale().
| bool ccColorScale::saveAsXML | ( | QString | filename | ) | const |
Saves this color scale as an XML file.
References color, CVLog::Error(), filename, ccColorScaleElement::getColor(), getName(), ccColorScaleElement::getRelativePos(), getUuid(), isRelative(), m_absoluteMinValue, m_absoluteRange, m_customLabels, m_steps, s_xmlACloudViewer(), s_xmlColorScaleData(), s_xmlColorScaleProperties(), s_xmlColorScaleTitle(), and s_xmlColorScaleVer.
Referenced by define_ccColorScale().
| void ccColorScale::setAbsolute | ( | double | minVal, |
| double | maxVal | ||
| ) |
Sets scale as absolute.
References e, m_absoluteMinValue, m_absoluteRange, and m_relative.
Referenced by define_ccColorScale().
|
inline |
Sets the list of custom labels (only if the scale is absolute)
Referenced by define_ccColorScale().
|
inline |
Sets whether scale is locked or not.
Referenced by define_ccColorScale().
|
inline |
|
inline |
Sets scale as relative.
Referenced by define_ccColorScale().
|
inline |
Sets unique ID.
Referenced by define_ccColorScale().
|
protected |
|
inline |
Access to a given step.
Referenced by define_ccColorScale(), and insert().
|
inline |
Access to a given step (const)
|
inline |
Returns the current number of steps.
A valid scale should always have at least 2 steps!
Referenced by define_ccColorScale(), and update().
|
overridevirtual |
Saves data to binary stream.
| out | output file (already opened) |
| dataVersion | target file version (for forward/backward compatibility) |
Reimplemented from ccSerializableObject.
| void ccColorScale::update | ( | ) |
Updates internal representation.
Must be called at least once after any modification (before using this scale).
References ecvColor::black(), getName(), m_rgbaScale, m_steps, m_updated, ecvColor::MAX, MAX_STEPS, MIN_STEPS, sort(), stepCount(), CVLog::Warning(), Tuple3Tpl< Type >::x, Tuple3Tpl< Type >::y, and Tuple3Tpl< Type >::z.
Referenced by define_ccColorScale(), insert(), and remove().
|
static |
Default number of steps for display.
Referenced by ccScalarField::ccScalarField(), and define_ccColorScale().
|
protected |
'Absolute' minimum value
Only used if scale is 'absolute' (i.e. not relative). 'Absolute' should not be taken in its mathematical meaning!
Referenced by copy(), getAbsoluteBoundaries(), saveAsXML(), and setAbsolute().
|
protected |
'Absolute' range
Only used if scale is 'absolute' (i.e. not relative). 'Absolute' should not be taken in its mathematical meaning!
Referenced by copy(), getAbsoluteBoundaries(), saveAsXML(), and setAbsolute().
|
protected |
List of custom labels.
Referenced by copy(), minimumFileVersion(), and saveAsXML().
|
protected |
|
protected |
Whether scale is relative or not.
Referenced by copy(), and setAbsolute().
|
protected |
Internal representation (RGB)
Referenced by update().
|
protected |
|
protected |
|
protected |
Unique ID.
Referenced by ccColorScale(), and generateNewUuid().
|
static |
Maximum number of steps (internal representation)
Referenced by ccPropertiesTreeDelegate::createEditor(), define_ccColorScale(), DistanceMapGenerationDlg::DistanceMapGenerationDlg(), ccScalarField::setColorRampSteps(), ccRenderingTools::ShowDepthBuffer(), StereogramDialog::StereogramDialog(), and update().
|
static |
Minimum number of steps.
Referenced by ccPropertiesTreeDelegate::createEditor(), define_ccColorScale(), DistanceMapGenerationDlg::DistanceMapGenerationDlg(), insert(), StereogramDialog::onDensityColorStepsChanged(), ccScalarField::setColorRampSteps(), StereogramDialog::StereogramDialog(), and update().