qCC_db  version 2.5.4 (Qt) - 19 Apr 2014
 All Classes Functions Variables Typedefs Enumerations Enumerator Pages
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

typedef QSharedPointer
< ccColorScale
Shared
 Shared pointer type.
 
- Public Types inherited from ccSerializableObject
enum  DeserializationFlags { DF_POINT_COORDS_64_BITS = 1, DF_SCALAR_VAL_32_BITS = 2 }
 Deserialization flags (bit-field) More...
 

Public Member Functions

 ccColorScale (QString name, QString uuid=QString())
 Default constructor. More...
 
virtual ~ccColorScale ()
 Destructor.
 
const QString & getName () const
 Returns name.
 
void setName (const QString &name)
 Sets name.
 
QString getUuid () const
 Returns unique ID.
 
void setUuid (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.
 
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 colorType * getColorByValue (double value, const colorType *outOfRangeColor=0) const
 Returns color by value. More...
 
const colorType * getColorByRelativePos (double relativePos, const colorType *outOfRangeColor=0) const
 Returns color by relative position in scale. More...
 
const colorType * getColorByRelativePos (double relativePos, unsigned steps, const colorType *outOfRangeColor=0) const
 Returns color by relative position in scale with a given 'resolution'. More...
 
const colorType * getColorByIndex (unsigned index) const
 Returns color by index. More...
 
virtual bool isSerializable () const
 Returns whether object is serializable of not.
 
virtual bool toFile (QFile &out) const
 Saves data to binay stream. More...
 
virtual bool fromFile (QFile &in, short dataVersion, int flags)
 Loads data from binay stream. More...
 
- Public Member Functions inherited from ccSerializableObject
virtual ~ccSerializableObject ()
 Desctructor.
 

Static Public Member Functions

static ccColorScale::Shared Create (QString name)
 Creates a new color scale (with auto-generated unique id) 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.
 
static const unsigned DEFAULT_STEPS = 256
 Default number of steps for display.
 
static const 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.
 
colorType m_rgbaScale [MAX_STEPS *4]
 Internal representation (RGBA)
 
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...
 

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 vald 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 intervale.

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

Constructor & Destructor Documentation

ccColorScale::ccColorScale ( QString  name,
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

void ccColorScale::clear ( )

Clears all steps.

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

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

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

Warning: color scale is relative by default.

bool ccColorScale::fromFile ( QFile &  in,
short  dataVersion,
int  flags 
)
virtual

Loads data from binay stream.

Parameters
ininput file (already opened)
dataVersionfile version
flagsdeserialization flags (see ccSerializableObject::DeserializationFlags)
Returns
success

Reimplemented from ccSerializableObject.

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

Get absolute scale boundaries.

Warning: only valid with absolute scales!

const colorType* 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
const colorType* ccColorScale::getColorByRelativePos ( double  relativePos,
const colorType *  outOfRangeColor = 0 
) 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
const colorType* ccColorScale::getColorByRelativePos ( double  relativePos,
unsigned  steps,
const colorType *  outOfRangeColor = 0 
) 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
const colorType* ccColorScale::getColorByValue ( double  value,
const colorType *  outOfRangeColor = 0 
) 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
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.

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

Adds a step.

Scale must not be locked.

bool ccColorScale::isRelative ( ) const
inline

Returns whether scale is relative or absoute.

Relative means that internal 'values' are percentage.

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.

int ccColorScale::stepCount ( ) const
inline

Returns the current number of steps.

A valid scale should always have at least 2 steps!

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

Saves data to binay stream.

Parameters
outoutput file (already opened)
Returns
success

Reimplemented from ccSerializableObject.

void ccColorScale::update ( )

Updates internal representation.

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

Member Data Documentation

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!

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: