+ apply mapnik coding convention
This commit is contained in:
parent
5b3b42bbc3
commit
179740a331
2 changed files with 113 additions and 81 deletions
|
@ -74,10 +74,13 @@ public:
|
||||||
//! \param[in] value The stop value
|
//! \param[in] value The stop value
|
||||||
//! \param[in] mode The stop mode
|
//! \param[in] mode The stop mode
|
||||||
//! \param[in] color The stop color
|
//! \param[in] color The stop color
|
||||||
colorizer_stop(const float value = 0, const colorizer_mode mode = COLORIZER_INHERIT, const color& _color = color(0,0,0,0), const std::string& label="");
|
colorizer_stop(float value = 0,
|
||||||
|
colorizer_mode mode = COLORIZER_INHERIT,
|
||||||
|
color const& _color = color(0,0,0,0),
|
||||||
|
std::string const& label="");
|
||||||
|
|
||||||
//! \brief Copy constructor
|
//! \brief Copy constructor
|
||||||
colorizer_stop(const colorizer_stop& stop);
|
colorizer_stop(colorizer_stop const& stop);
|
||||||
|
|
||||||
//! \brief Destructor
|
//! \brief Destructor
|
||||||
~colorizer_stop();
|
~colorizer_stop();
|
||||||
|
@ -85,39 +88,39 @@ public:
|
||||||
|
|
||||||
//! \brief Set the stop value
|
//! \brief Set the stop value
|
||||||
//! \param[in] value The stop value
|
//! \param[in] value The stop value
|
||||||
inline void set_value(const float value) { value_ = value; };
|
inline void set_value(float value) { value_ = value; };
|
||||||
|
|
||||||
//! \brief Get the stop value
|
//! \brief Get the stop value
|
||||||
//! \return The stop value
|
//! \return The stop value
|
||||||
inline float get_value(void) const {return value_; };
|
inline float get_value() const {return value_; };
|
||||||
|
|
||||||
|
|
||||||
//! \brief Set the stop mode
|
//! \brief Set the stop mode
|
||||||
//! \param[in] mode The stop mode
|
//! \param[in] mode The stop mode
|
||||||
inline void set_mode(const colorizer_mode mode) { mode_ = mode; };
|
inline void set_mode(colorizer_mode mode) { mode_ = mode; };
|
||||||
inline void set_mode_enum(const colorizer_mode_enum mode) { set_mode(mode); };
|
inline void set_mode_enum(colorizer_mode_enum mode) { set_mode(mode); };
|
||||||
|
|
||||||
//! \brief Get the stop mode
|
//! \brief Get the stop mode
|
||||||
//! \return The stop mode
|
//! \return The stop mode
|
||||||
inline colorizer_mode get_mode(void) const { return mode_; };
|
inline colorizer_mode get_mode() const { return mode_; };
|
||||||
inline colorizer_mode_enum get_mode_enum(void) const { return get_mode(); };
|
inline colorizer_mode_enum get_mode_enum() const { return get_mode(); };
|
||||||
|
|
||||||
|
|
||||||
//! \brief set the stop color
|
//! \brief set the stop color
|
||||||
//! \param[in] the stop color
|
//! \param[in] the stop color
|
||||||
inline void set_color(const color& _color) { color_ = _color; };
|
inline void set_color(color const& _color) { color_ = _color; };
|
||||||
|
|
||||||
//! \brief get the stop color
|
//! \brief get the stop color
|
||||||
//! \return The stop color
|
//! \return The stop color
|
||||||
inline const color& get_color(void) const {return color_; };
|
inline color const& get_color() const {return color_; };
|
||||||
|
|
||||||
//! \brief set the stop label
|
//! \brief set the stop label
|
||||||
//! \param[in] the stop label
|
//! \param[in] the stop label
|
||||||
inline void set_label(const std::string& label) { label_ = label; };
|
inline void set_label(std::string const& label) { label_ = label; };
|
||||||
|
|
||||||
//! \brief get the stop label
|
//! \brief get the stop label
|
||||||
//! \return The stop label
|
//! \return The stop label
|
||||||
inline const std::string& get_label(void) const {return label_; };
|
inline std::string const& get_label() const {return label_; };
|
||||||
|
|
||||||
|
|
||||||
//! \brief Equality operator
|
//! \brief Equality operator
|
||||||
|
@ -143,7 +146,7 @@ typedef std::vector<colorizer_stop> colorizer_stops;
|
||||||
class MAPNIK_DECL raster_colorizer {
|
class MAPNIK_DECL raster_colorizer {
|
||||||
public:
|
public:
|
||||||
//! \brief Constructor
|
//! \brief Constructor
|
||||||
raster_colorizer(colorizer_mode mode = COLORIZER_LINEAR, const color& _color = color(0,0,0,0));
|
raster_colorizer(colorizer_mode mode = COLORIZER_LINEAR, color const& _color = color(0,0,0,0));
|
||||||
|
|
||||||
//! \brief Destructor
|
//! \brief Destructor
|
||||||
~raster_colorizer();
|
~raster_colorizer();
|
||||||
|
@ -153,28 +156,33 @@ public:
|
||||||
//!
|
//!
|
||||||
//! This can not be set as INHERIT, if you do, LINEAR will be used instead.
|
//! This can not be set as INHERIT, if you do, LINEAR will be used instead.
|
||||||
//! \param[in] mode The default mode
|
//! \param[in] mode The default mode
|
||||||
void set_default_mode(const colorizer_mode mode) { default_mode_ = (mode == COLORIZER_INHERIT) ? COLORIZER_LINEAR:(colorizer_mode_enum)mode; };
|
|
||||||
void set_default_mode_enum(const colorizer_mode_enum mode) { set_default_mode(mode); };
|
void set_default_mode(colorizer_mode mode)
|
||||||
|
{
|
||||||
|
default_mode_ = (mode == COLORIZER_INHERIT) ? COLORIZER_LINEAR:(colorizer_mode_enum)mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_default_mode_enum(colorizer_mode_enum mode) { set_default_mode(mode); };
|
||||||
|
|
||||||
//! \brief Get the default mode
|
//! \brief Get the default mode
|
||||||
//! \return The default mode
|
//! \return The default mode
|
||||||
colorizer_mode get_default_mode(void) const {return default_mode_; };
|
colorizer_mode get_default_mode() const {return default_mode_; };
|
||||||
colorizer_mode_enum get_default_mode_enum(void) const {return get_default_mode(); };
|
colorizer_mode_enum get_default_mode_enum() const {return get_default_mode(); };
|
||||||
|
|
||||||
//! \brief Set the default color
|
//! \brief Set the default color
|
||||||
//! \param[in] color The default color
|
//! \param[in] color The default color
|
||||||
void set_default_color(const color& color) { default_color_ = color; };
|
void set_default_color(color const& color) { default_color_ = color; };
|
||||||
|
|
||||||
//! \brief Get the default color
|
//! \brief Get the default color
|
||||||
//! \return The default color
|
//! \return The default color
|
||||||
const color& get_default_color(void) const {return default_color_; };
|
color const& get_default_color() const {return default_color_; };
|
||||||
|
|
||||||
|
|
||||||
//! \brief Add a stop
|
//! \brief Add a stop
|
||||||
//!
|
//!
|
||||||
//! \param[in] stop The stop to add
|
//! \param[in] stop The stop to add
|
||||||
//! \return True if added, false if error
|
//! \return True if added, false if error
|
||||||
bool add_stop(const colorizer_stop & stop);
|
bool add_stop(colorizer_stop const& stop);
|
||||||
|
|
||||||
//! \brief Set the list of stops
|
//! \brief Set the list of stops
|
||||||
//! \param[in] stops The list of stops
|
//! \param[in] stops The list of stops
|
||||||
|
@ -182,14 +190,14 @@ public:
|
||||||
|
|
||||||
//! \brief Get the list of stops
|
//! \brief Get the list of stops
|
||||||
//! \return The list of stops
|
//! \return The list of stops
|
||||||
const colorizer_stops& get_stops(void) const {return stops_; };
|
colorizer_stops const& get_stops() const {return stops_; };
|
||||||
|
|
||||||
|
|
||||||
//! \brief Colorize a raster
|
//! \brief Colorize a raster
|
||||||
//!
|
//!
|
||||||
//! \param[in, out] raster A raster stored in float32 single channel format, which gets colorized in place.
|
//! \param[in, out] raster A raster stored in float32 single channel format, which gets colorized in place.
|
||||||
//! \param[in] properties belonging to the feature, used to find 'NODATA' information if available
|
//! \param[in] properties belonging to the feature, used to find 'NODATA' information if available
|
||||||
void colorize(raster_ptr const& raster,const std::map<std::string,value> &Props) const;
|
void colorize(raster_ptr const& raster,std::map<std::string,value> const& Props) const;
|
||||||
|
|
||||||
|
|
||||||
//! \brief Perform the translation of input to output
|
//! \brief Perform the translation of input to output
|
||||||
|
@ -205,7 +213,7 @@ public:
|
||||||
|
|
||||||
//! \brief Get the epsilon value for exact mode
|
//! \brief Get the epsilon value for exact mode
|
||||||
//! \return The epsilon value
|
//! \return The epsilon value
|
||||||
inline float get_epsilon(void) const { return epsilon_; };
|
inline float get_epsilon() const { return epsilon_; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
colorizer_stops stops_; //!< The vector of stops
|
colorizer_stops stops_; //!< The vector of stops
|
||||||
|
|
|
@ -40,8 +40,10 @@ static const char *colorizer_mode_strings[] = {
|
||||||
IMPLEMENT_ENUM( colorizer_mode, colorizer_mode_strings )
|
IMPLEMENT_ENUM( colorizer_mode, colorizer_mode_strings )
|
||||||
|
|
||||||
|
|
||||||
colorizer_stop::colorizer_stop(const float value/* = 0*/, const colorizer_mode mode/* = COLORIZER_INHERIT*/, const color& _color/* = color(0,0,0,0)*/, const std::string& label/* ) ""*/)
|
colorizer_stop::colorizer_stop(float value, colorizer_mode mode,
|
||||||
: value_(value)
|
color const& _color,
|
||||||
|
std::string const& label)
|
||||||
|
: value_(value)
|
||||||
, mode_(mode)
|
, mode_(mode)
|
||||||
, color_(_color)
|
, color_(_color)
|
||||||
, label_(label)
|
, label_(label)
|
||||||
|
@ -49,7 +51,7 @@ colorizer_stop::colorizer_stop(const float value/* = 0*/, const colorizer_mode m
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
colorizer_stop::colorizer_stop(const colorizer_stop& stop)
|
colorizer_stop::colorizer_stop(colorizer_stop const& stop)
|
||||||
: value_(stop.value_)
|
: value_(stop.value_)
|
||||||
, mode_(stop.mode_)
|
, mode_(stop.mode_)
|
||||||
, color_(stop.color_)
|
, color_(stop.color_)
|
||||||
|
@ -84,7 +86,7 @@ std::string colorizer_stop::to_string() const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
raster_colorizer::raster_colorizer(colorizer_mode mode/* = COLORIZER_LINEAR*/, const color& _color/* = color(0,0,0,0)*/)
|
raster_colorizer::raster_colorizer(colorizer_mode mode, color const& _color)
|
||||||
: default_mode_(mode)
|
: default_mode_(mode)
|
||||||
, default_color_(_color)
|
, default_color_(_color)
|
||||||
, epsilon_(std::numeric_limits<float>::epsilon())
|
, epsilon_(std::numeric_limits<float>::epsilon())
|
||||||
|
@ -96,10 +98,13 @@ raster_colorizer::~raster_colorizer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool raster_colorizer::add_stop(const colorizer_stop & stop) {
|
bool raster_colorizer::add_stop(colorizer_stop const& stop)
|
||||||
|
{
|
||||||
//make sure stops are added in order of value
|
//make sure stops are added in order of value
|
||||||
if(stops_.size()) {
|
if(stops_.size())
|
||||||
if(stop.get_value() <= stops_.back().get_value()) {
|
{
|
||||||
|
if(stop.get_value() <= stops_.back().get_value())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +114,7 @@ bool raster_colorizer::add_stop(const colorizer_stop & stop) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void raster_colorizer::colorize(raster_ptr const& raster,const std::map<std::string,value> &Props) const
|
void raster_colorizer::colorize(raster_ptr const& raster, std::map<std::string,value> const& Props) const
|
||||||
{
|
{
|
||||||
unsigned *imageData = raster->data_.getData();
|
unsigned *imageData = raster->data_.getData();
|
||||||
|
|
||||||
|
@ -118,7 +123,7 @@ void raster_colorizer::colorize(raster_ptr const& raster,const std::map<std::str
|
||||||
bool hasNoData = false;
|
bool hasNoData = false;
|
||||||
float noDataValue = 0;
|
float noDataValue = 0;
|
||||||
|
|
||||||
const std::map<std::string,value>::const_iterator fi = Props.find("NODATA");
|
std::map<std::string,value>::const_iterator fi = Props.find("NODATA");
|
||||||
if (fi != Props.end())
|
if (fi != Props.end())
|
||||||
{
|
{
|
||||||
hasNoData = true;
|
hasNoData = true;
|
||||||
|
@ -141,11 +146,13 @@ inline unsigned interpolate(unsigned start, unsigned end, float fraction)
|
||||||
return static_cast<unsigned>(fraction * ((float)end - (float)start) + start);
|
return static_cast<unsigned>(fraction * ((float)end - (float)start) + start);
|
||||||
}
|
}
|
||||||
|
|
||||||
color raster_colorizer::get_color(float value) const {
|
color raster_colorizer::get_color(float value) const
|
||||||
|
{
|
||||||
int stopCount = stops_.size();
|
int stopCount = stops_.size();
|
||||||
|
|
||||||
//use default color if no stops
|
//use default color if no stops
|
||||||
if(stopCount == 0) {
|
if(stopCount == 0)
|
||||||
|
{
|
||||||
return default_color_;
|
return default_color_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,31 +160,41 @@ color raster_colorizer::get_color(float value) const {
|
||||||
int stopIdx = -1;
|
int stopIdx = -1;
|
||||||
bool foundStopIdx = false;
|
bool foundStopIdx = false;
|
||||||
|
|
||||||
for(int i=0; i<stopCount; i++) {
|
for(int i=0; i<stopCount; ++i)
|
||||||
if(value < stops_[i].get_value()) {
|
{
|
||||||
|
if(value < stops_[i].get_value())
|
||||||
|
{
|
||||||
stopIdx = i-1;
|
stopIdx = i-1;
|
||||||
foundStopIdx = true;
|
foundStopIdx = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!foundStopIdx) {
|
|
||||||
|
if(!foundStopIdx)
|
||||||
|
{
|
||||||
stopIdx = stopCount-1;
|
stopIdx = stopCount-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//2 - Find the next stop
|
//2 - Find the next stop
|
||||||
int nextStopIdx = stopIdx + 1;
|
int nextStopIdx = stopIdx + 1;
|
||||||
if(nextStopIdx >= stopCount) { //there is no next stop
|
if(nextStopIdx >= stopCount)
|
||||||
|
{
|
||||||
|
//there is no next stop
|
||||||
nextStopIdx = stopCount - 1;
|
nextStopIdx = stopCount - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//3 - Work out the mode
|
//3 - Work out the mode
|
||||||
colorizer_mode stopMode;
|
colorizer_mode stopMode;
|
||||||
if( stopIdx == -1 ) { //before the first stop
|
if( stopIdx == -1 )
|
||||||
|
{
|
||||||
|
//before the first stop
|
||||||
stopMode = default_mode_;
|
stopMode = default_mode_;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
stopMode = stops_[stopIdx].get_mode();
|
stopMode = stops_[stopIdx].get_mode();
|
||||||
if(stopMode == COLORIZER_INHERIT) {
|
if(stopMode == COLORIZER_INHERIT)
|
||||||
|
{
|
||||||
stopMode = default_mode_;
|
stopMode = default_mode_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,27 +205,32 @@ color raster_colorizer::get_color(float value) const {
|
||||||
float stopValue = 0;
|
float stopValue = 0;
|
||||||
float nextStopValue = 0;
|
float nextStopValue = 0;
|
||||||
color outputColor = get_default_color();
|
color outputColor = get_default_color();
|
||||||
if(stopIdx == -1) {
|
if(stopIdx == -1)
|
||||||
|
{
|
||||||
stopColor = default_color_;
|
stopColor = default_color_;
|
||||||
nextStopColor = stops_[nextStopIdx].get_color();
|
nextStopColor = stops_[nextStopIdx].get_color();
|
||||||
stopValue = value;
|
stopValue = value;
|
||||||
nextStopValue = stops_[nextStopIdx].get_value();
|
nextStopValue = stops_[nextStopIdx].get_value();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
stopColor = stops_[stopIdx].get_color();
|
stopColor = stops_[stopIdx].get_color();
|
||||||
nextStopColor = stops_[nextStopIdx].get_color();
|
nextStopColor = stops_[nextStopIdx].get_color();
|
||||||
stopValue = stops_[stopIdx].get_value();
|
stopValue = stops_[stopIdx].get_value();
|
||||||
nextStopValue = stops_[nextStopIdx].get_value();
|
nextStopValue = stops_[nextStopIdx].get_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(stopMode) {
|
switch(stopMode)
|
||||||
|
{
|
||||||
case COLORIZER_LINEAR:
|
case COLORIZER_LINEAR:
|
||||||
{
|
{
|
||||||
//deal with this separately so we don't have to worry about div0
|
//deal with this separately so we don't have to worry about div0
|
||||||
if(nextStopValue == stopValue) {
|
if(nextStopValue == stopValue)
|
||||||
|
{
|
||||||
outputColor = stopColor;
|
outputColor = stopColor;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
float fraction = (value - stopValue) / (nextStopValue - stopValue);
|
float fraction = (value - stopValue) / (nextStopValue - stopValue);
|
||||||
|
|
||||||
unsigned r = interpolate(stopColor.red(), nextStopColor.red(),fraction);
|
unsigned r = interpolate(stopColor.red(), nextStopColor.red(),fraction);
|
||||||
|
@ -230,10 +252,12 @@ color raster_colorizer::get_color(float value) const {
|
||||||
case COLORIZER_EXACT:
|
case COLORIZER_EXACT:
|
||||||
default:
|
default:
|
||||||
//approximately equal (within epsilon)
|
//approximately equal (within epsilon)
|
||||||
if(fabs(value - stopValue) < epsilon_) {
|
if(fabs(value - stopValue) < epsilon_)
|
||||||
|
{
|
||||||
outputColor = stopColor;
|
outputColor = stopColor;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
outputColor = default_color_;
|
outputColor = default_color_;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -250,7 +274,7 @@ color raster_colorizer::get_color(float value) const {
|
||||||
std::clog << "\tnextStopColor: " << nextStopColor.to_string() << "\n";
|
std::clog << "\tnextStopColor: " << nextStopColor.to_string() << "\n";
|
||||||
std::clog << "\tstopMode: " << stopMode.as_string() << "\n";
|
std::clog << "\tstopMode: " << stopMode.as_string() << "\n";
|
||||||
std::clog << "\toutputColor: " << outputColor.to_string() << "\n";
|
std::clog << "\toutputColor: " << outputColor.to_string() << "\n";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return outputColor;
|
return outputColor;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue