16 #include <QSharedPointer>
74 typedef QSharedPointer<ccColorScale>
Shared;
99 static const unsigned MIN_STEPS = 2;
104 static const unsigned DEFAULT_STEPS = 256;
109 static const unsigned MAX_STEPS = 1024;
112 inline const QString&
getName()
const {
return m_name; }
149 Label(
double v,
const QString& t) : value(v), text(t) {}
155 return value < otherLabel.
value;
171 m_customLabels = labels;
184 return m_steps[index];
196 void remove(
int index,
bool autoUpdate =
true);
216 assert(m_updated && !m_relative);
217 return (value - m_absoluteMinValue) / m_absoluteRange;
229 assert(m_updated && !m_relative);
230 double relativePos = getRelativePosition(value);
231 return (relativePos >= 0.0 && relativePos <= 1.0
232 ? getColorByRelativePos(relativePos)
245 if (relativePos >= 0.0 && relativePos <= 1.0)
246 return &getColorByIndex(
247 static_cast<unsigned>(relativePos * (MAX_STEPS - 1)));
249 return outOfRangeColor;
263 if (relativePos >= 0.0 && relativePos <= 1.0) {
266 (
static_cast<unsigned>((relativePos * steps) * 65535.0)) >>
268 return &getColorByIndex((index * (MAX_STEPS - 1)) / steps);
270 return outOfRangeColor;
279 assert(m_updated && index < MAX_STEPS);
280 return m_rgbaScale[index];
290 bool toFile(QFile& out,
short dataVersion)
const override;
Color scale element: one value + one color.
const QColor & getColor() const
Returns color.
ccColorScaleElement()
Default constructor.
double m_relativePos
Step (relative) position.
ccColorScaleElement(double relativePos, QColor color)
Constructor from a (relative) position and a color.
double getRelativePos() const
Returns step position (relative to scale boundaries)
static bool IsSmaller(const ccColorScaleElement &e1, const ccColorScaleElement &e2)
Comparison operator between two color scale elements.
void setRelativePos(double pos)
Sets associated value (relative to scale boundaries)
void setColor(QColor color)
Sets color.
bool saveAsXML(QString filename) const
Saves this color scale as an XML file.
ccColorScaleElement & step(int index)
Access to a given step.
static Shared LoadFromXML(QString filename)
Loads a color scale from an XML file.
QString getUuid() const
Returns unique ID.
void setRelative()
Sets scale as relative.
LabelSet & customLabels()
Returns the list of custom labels (if any)
void setAbsolute(double minVal, double maxVal)
Sets scale as absolute.
void update()
Updates internal representation.
void setLocked(bool state)
Sets whether scale is locked or not.
QList< ccColorScaleElement > m_steps
Elements.
const QString & getName() const
Returns name.
bool m_relative
Whether scale is relative or not.
bool toFile(QFile &out, short dataVersion) const override
Saves data to binary stream.
const ecvColor::Rgb & getColorByIndex(unsigned index) const
Returns color by index.
bool isRelative() const
Returns whether scale is relative or absoute.
ccColorScale(const QString &name, const QString &uuid=QString())
Default constructor.
bool m_locked
Whether scale is locked or not.
void remove(int index, bool autoUpdate=true)
Deletes a given step.
double getRelativePosition(double value) const
static ccColorScale::Shared Create(const QString &name)
Creates a new color scale (with auto-generated unique id)
bool fromFile(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads data from binary stream.
bool isSerializable() const override
Returns whether object is serializable of not.
short minimumFileVersion() const override
Returns the minimum file version required to save this instance.
const LabelSet & customLabels() const
Returns the list of custom labels (if any - const version)
void getAbsoluteBoundaries(double &minVal, double &maxVal) const
Get absolute scale boundaries.
void insert(const ccColorScaleElement &step, bool autoUpdate=true)
Adds a step.
const ecvColor::Rgb * getColorByRelativePos(double relativePos, const ecvColor::Rgb *outOfRangeColor=nullptr) const
Returns color by relative position in scale.
void generateNewUuid()
Generates a new unique ID.
double m_absoluteMinValue
'Absolute' minimum value
double m_absoluteRange
'Absolute' range
int stepCount() const
Returns the current number of steps.
ccColorScale::Shared copy(const QString &uuid=QString()) const
Creates a copy of this color scale (with a specified unique id)
const ccColorScaleElement & step(int index) const
Access to a given step (const)
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'.
QSharedPointer< ccColorScale > Shared
Shared pointer type.
void clear()
Clears all steps.
const ecvColor::Rgb * getColorByValue(double value, const ecvColor::Rgb *outOfRangeColor=nullptr) const
Returns color by value.
void sort()
Sort elements.
virtual ~ccColorScale()
Destructor.
void setUuid(QString uuid)
Sets unique ID.
LabelSet m_customLabels
List of custom labels.
void setName(const QString &name)
Sets name.
std::set< Label > LabelSet
Type of a list of custom labels.
bool m_updated
Internal representation validity.
bool isLocked() const
Returns whether scale is locked or not.
void setCustomLabels(const LabelSet &labels)
Sets the list of custom labels (only if the scale is absolute)
Serializable object interface.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
constexpr Rgb black(0, 0, 0)
Color scale label (value + optional text)
Label(double v, const QString &t)
bool operator<(const Label &otherLabel) const