From ad4497c90994e75dd918e09a201a87ef85d6504c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 27 Jun 2014 16:19:43 +0200 Subject: [PATCH] reorganize properties --- include/llmr/map/source.hpp | 1 + include/llmr/renderer/painter.hpp | 6 +- include/llmr/renderer/prerendered_texture.hpp | 2 +- include/llmr/style/class_properties.hpp | 121 ++++++++ include/llmr/style/function_properties.hpp | 45 +++ include/llmr/style/properties.hpp | 290 ------------------ include/llmr/style/rasterize_properties.hpp | 26 ++ include/llmr/style/style.hpp | 3 + include/llmr/style/style_properties.hpp | 122 ++++++++ include/llmr/style/types.hpp | 4 + include/llmr/util/transition.hpp | 2 +- src/renderer/painter_composite.cpp | 1 + ...properties.cpp => function_properties.cpp} | 13 +- src/style/style.cpp | 1 - src/style/style_parser.cpp | 1 - src/style/style_properties.cpp | 13 + 16 files changed, 344 insertions(+), 307 deletions(-) create mode 100644 include/llmr/style/class_properties.hpp create mode 100644 include/llmr/style/function_properties.hpp delete mode 100644 include/llmr/style/properties.hpp create mode 100644 include/llmr/style/rasterize_properties.hpp create mode 100644 include/llmr/style/style_properties.hpp rename src/style/{properties.cpp => function_properties.cpp} (75%) create mode 100644 src/style/style_properties.cpp diff --git a/include/llmr/map/source.hpp b/include/llmr/map/source.hpp index 93dabdc7c..0d6ef864f 100644 --- a/include/llmr/map/source.hpp +++ b/include/llmr/map/source.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index 1b1d231ca..3a5f73270 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -25,6 +25,7 @@ #include #include +#include namespace llmr { @@ -40,6 +41,9 @@ class IconBucket; class TextBucket; class RasterBucket; +struct FillProperties; +struct CompositeProperties; + class LayerDescription; class RasterTileData; diff --git a/include/llmr/renderer/prerendered_texture.hpp b/include/llmr/renderer/prerendered_texture.hpp index b109e397c..6ca3cd540 100644 --- a/include/llmr/renderer/prerendered_texture.hpp +++ b/include/llmr/renderer/prerendered_texture.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace llmr { diff --git a/include/llmr/style/class_properties.hpp b/include/llmr/style/class_properties.hpp new file mode 100644 index 000000000..92f7fa3f4 --- /dev/null +++ b/include/llmr/style/class_properties.hpp @@ -0,0 +1,121 @@ +#ifndef LLMR_STYLE_CLASS_PROPERTIES +#define LLMR_STYLE_CLASS_PROPERTIES + +#include +#include +#include + + +#include + +namespace llmr { + +enum class ClassPropertyKey { + FillEnabled, + FillAntialias, + FillOpacity, + FillColor, + FillOutlineColor, + FillTranslate, // for transitions only + FillTranslateX, + FillTranslateY, + FillTranslateAnchor, + FillImage, + + LineEnabled, + LineOpacity, + LineColor, + LineTranslate, // for transitions only + LineTranslateX, + LineTranslateY, + LineTranslateAnchor, + LineWidth, + LineOffset, + LineBlur, + LineDashArray, // for transitions only + LineDashLand, + LineDashGap, + LineImage, + + IconEnabled, + IconOpacity, + IconRotate, + IconRotateAnchor, + + TextEnabled, + TextOpacity, + TextSize, + TextColor, + TextHaloColor, + TextHaloWidth, + TextHaloBlur, + + CompositeEnabled, + CompositeOpacity, + + RasterSpin, + RasterBrightnessLow, + RasterBrightnessHigh, + RasterSaturation, + RasterContrast, + RasterFade, + + BackgroundColor +}; + +typedef util::variant< + FunctionProperty, + TranslateAnchorType, + RotateAnchorType, + Color, + std::string, + bool +> ClassPropertyValue; + + +struct ClassPropertyTransition { + uint16_t duration = 0; + uint16_t delay = 0; +}; + +class ClassProperties { +public: + inline ClassProperties() {} + inline ClassProperties(ClassProperties &&properties) + : properties(std::move(properties.properties)) {} + + template + inline const T *get(ClassPropertyKey key) const { + const auto it = properties.find(key); + if (it != properties.end() && it->second.is()) { + return ::std::addressof(it->second.get()); + } else { + return nullptr; + } + } + inline const ClassPropertyTransition *getTransition(ClassPropertyKey key) const { + const auto it = transitions.find(key); + if (it != transitions.end()) { + return ::std::addressof(it->second); + } else { + return nullptr; + } + } + + template + inline void set(Args&& ...args) { + properties.emplace(::std::forward(args)...); + } + template + inline void setTransition(Args&& ...args) { + transitions.emplace(::std::forward(args)...); + } + +public: + std::map properties; + std::map transitions; +}; + +} + +#endif diff --git a/include/llmr/style/function_properties.hpp b/include/llmr/style/function_properties.hpp new file mode 100644 index 000000000..970d617d0 --- /dev/null +++ b/include/llmr/style/function_properties.hpp @@ -0,0 +1,45 @@ +#ifndef LLMR_STYLE_FUNCTION_PROPERTIES +#define LLMR_STYLE_FUNCTION_PROPERTIES + +#include + +namespace llmr { + +namespace functions { + +float null(float z, const std::vector&); +float constant(float z, const std::vector& values); +float min(float z, const std::vector& values); +float max(float z, const std::vector& values); +float stops(float z, const std::vector& values); +float linear(float z, const std::vector& values); +float exponential(float z, const std::vector& values); + +} + +struct FunctionProperty { + typedef float (*fn)(float z, const std::vector& values); + + fn function; + std::vector values; + + inline FunctionProperty() : function(&functions::null) {} + + inline FunctionProperty(const FunctionProperty &property) + : function(property.function), values(property.values) {} + inline FunctionProperty(FunctionProperty &&property) + : function(property.function), values(std::move(property.values)) {} + + + inline void operator=(const FunctionProperty &rhs) { + function = rhs.function; + values = rhs.values; + } + + inline FunctionProperty(float value) : function(&functions::constant), values(1, value) {} + template inline T evaluate(float z) const { return function(z, values); } +}; + +} + +#endif diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp deleted file mode 100644 index 32ef18760..000000000 --- a/include/llmr/style/properties.hpp +++ /dev/null @@ -1,290 +0,0 @@ -#ifndef LLMR_STYLE_PROPERTIES -#define LLMR_STYLE_PROPERTIES - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -namespace llmr { - -// Stores a premultiplied color, with all four channels ranging from 0..1 -typedef std::array Color; - -struct ClassPropertyTransition { - uint16_t duration = 0; - uint16_t delay = 0; -}; - -enum class Property { - Null = 1, - Constant = 2, - Stops = 3, - Linear = 4 -}; -namespace functions { - -float null(float z, const std::vector&); -float constant(float z, const std::vector& values); -float min(float z, const std::vector& values); -float max(float z, const std::vector& values); -float stops(float z, const std::vector& values); -float linear(float z, const std::vector& values); -float exponential(float z, const std::vector& values); - -} - -struct FunctionProperty { - typedef float (*fn)(float z, const std::vector& values); - - fn function; - std::vector values; - - inline FunctionProperty() : function(&functions::null) {} - - inline FunctionProperty(const FunctionProperty &property) - : function(property.function), values(property.values) {} - inline FunctionProperty(FunctionProperty &&property) - : function(property.function), values(std::move(property.values)) {} - - - inline void operator=(const FunctionProperty &rhs) { - function = rhs.function; - values = rhs.values; - } - - inline FunctionProperty(float value) : function(&functions::constant), values(1, value) {} - template inline T evaluate(float z) const { return function(z, values); } -}; - -enum class ClassPropertyKey { - FillEnabled, - FillAntialias, - FillOpacity, - FillColor, - FillOutlineColor, - FillTranslate, // for transitions only - FillTranslateX, - FillTranslateY, - FillTranslateAnchor, - FillImage, - - LineEnabled, - LineOpacity, - LineColor, - LineTranslate, // for transitions only - LineTranslateX, - LineTranslateY, - LineTranslateAnchor, - LineWidth, - LineOffset, - LineBlur, - LineDashArray, // for transitions only - LineDashLand, - LineDashGap, - LineImage, - - IconEnabled, - IconOpacity, - IconRotate, - IconRotateAnchor, - - TextEnabled, - TextOpacity, - TextSize, - TextColor, - TextHaloColor, - TextHaloWidth, - TextHaloBlur, - - CompositeEnabled, - CompositeOpacity, - - RasterSpin, - RasterBrightnessLow, - RasterBrightnessHigh, - RasterSaturation, - RasterContrast, - RasterFade, - - BackgroundColor -}; - -typedef util::variant< - FunctionProperty, - TranslateAnchorType, - RotateAnchorType, - Color, - std::string, - bool -> ClassPropertyValue; - -class ClassProperties { -public: - inline ClassProperties() {} - inline ClassProperties(ClassProperties &&properties) - : properties(std::move(properties.properties)) {} - - template - inline const T *get(ClassPropertyKey key) const { - const auto it = properties.find(key); - if (it != properties.end() && it->second.is()) { - return ::std::addressof(it->second.get()); - } else { - return nullptr; - } - } - inline const ClassPropertyTransition *getTransition(ClassPropertyKey key) const { - const auto it = transitions.find(key); - if (it != transitions.end()) { - return ::std::addressof(it->second); - } else { - return nullptr; - } - } - - template - inline void set(Args&& ...args) { - properties.emplace(::std::forward(args)...); - } - template - inline void setTransition(Args&& ...args) { - transitions.emplace(::std::forward(args)...); - } - -public: - std::map properties; - std::map transitions; -}; - -struct PrerenderProperties { - float buffer = 1.0f / 32.0f; - uint16_t size = 256; - uint16_t blur = 0; -}; - -struct FillProperties { - FillProperties() {} - bool enabled = true; - bool antialias = true; - float opacity = 1.0f; - Color fill_color = {{ 0, 0, 0, 1 }}; - Color stroke_color = {{ 0, 0, 0, -1 }}; - std::array translate = {{ 0, 0 }}; - TranslateAnchorType translateAnchor = TranslateAnchorType::Default; - std::string image; - - inline bool isVisible() const { - return enabled && opacity > 0 && (fill_color[3] > 0 || stroke_color[3] > 0); - } -}; - -struct LineProperties { - inline LineProperties() {} - bool enabled = true; - float opacity = 1.0f; - Color color = {{ 0, 0, 0, 1 }}; - std::array translate = {{ 0, 0 }}; - TranslateAnchorType translateAnchor = TranslateAnchorType::Default; - float width = 0; - float offset = 0; - float blur = 0; - std::array dash_array = {{ 1, -1 }}; - std::string image; - - inline bool isVisible() const { - return enabled && opacity > 0 && color[3] > 0 && width > 0; - } -}; - -struct IconProperties { - inline IconProperties() {} - bool enabled = true; - float opacity = 1.0f; - float rotate = 0.0f; - RotateAnchorType rotate_anchor = RotateAnchorType::Default; - - inline bool isVisible() const { - return enabled && opacity > 0; - } -}; - -struct TextProperties { - inline TextProperties() {} - bool enabled = true; - float opacity = 1.0f; - float size = 12.0f; - Color color = {{ 0, 0, 0, 1 }}; - Color halo_color = {{ 1, 1, 1, 0.75 }}; - float halo_width = 0.25f; - float halo_blur = 1.0f; - - inline bool isVisible() const { - return enabled && opacity > 0 && (color[3] > 0 || halo_color[3] > 0) && size > 0; - } -}; - -struct CompositeProperties { - inline CompositeProperties() {} - bool enabled = true; - float opacity = 1.0f; - - inline bool isVisible() const { - return enabled && opacity > 0; - } -}; - -struct RasterProperties { - inline RasterProperties() {} - bool enabled = true; - float opacity = 1.0f; - float spin = 0.0f; - std::array brightness = {{ 0, 1 }}; - float saturation = 0.0f; - float contrast = 0.0f; - float fade = 0.0f; - - inline bool isVisible() const { - return enabled && opacity > 0; - } -}; - -struct BackgroundProperties { - inline BackgroundProperties() {} - Color color = {{ 1, 1, 1, 1 }}; -}; - -typedef util::variant< - FillProperties, - LineProperties, - IconProperties, - TextProperties, - CompositeProperties, - RasterProperties, - BackgroundProperties, - std::false_type -> StyleProperties; - -template -const T &defaultStyleProperties(); - -class RasterizeProperties { -public: - boost::optional enabled; - boost::optional buffer; - boost::optional size; - boost::optional blur; -}; - -} - -#endif diff --git a/include/llmr/style/rasterize_properties.hpp b/include/llmr/style/rasterize_properties.hpp new file mode 100644 index 000000000..f085a7bdd --- /dev/null +++ b/include/llmr/style/rasterize_properties.hpp @@ -0,0 +1,26 @@ +#ifndef LLMR_STYLE_RASTERIZE_PROPERTIES +#define LLMR_STYLE_RASTERIZE_PROPERTIES + +#include + +#include + +namespace llmr { + +struct PrerenderProperties { + float buffer = 1.0f / 32.0f; + uint16_t size = 256; + uint16_t blur = 0; +}; + +class RasterizeProperties { +public: + boost::optional enabled; + boost::optional buffer; + boost::optional size; + boost::optional blur; +}; + +} + +#endif diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index fd5f7e222..f2b4cd492 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include #include #include diff --git a/include/llmr/style/style_properties.hpp b/include/llmr/style/style_properties.hpp new file mode 100644 index 000000000..71758563a --- /dev/null +++ b/include/llmr/style/style_properties.hpp @@ -0,0 +1,122 @@ +#ifndef LLMR_STYLE_STYLE_PROPERTIES +#define LLMR_STYLE_STYLE_PROPERTIES + +#include +#include +#include + +#include +#include +#include +#include + +namespace llmr { + +struct FillProperties { + FillProperties() {} + bool enabled = true; + bool antialias = true; + float opacity = 1.0f; + Color fill_color = {{ 0, 0, 0, 1 }}; + Color stroke_color = {{ 0, 0, 0, -1 }}; + std::array translate = {{ 0, 0 }}; + TranslateAnchorType translateAnchor = TranslateAnchorType::Default; + std::string image; + + inline bool isVisible() const { + return enabled && opacity > 0 && (fill_color[3] > 0 || stroke_color[3] > 0); + } +}; + +struct LineProperties { + inline LineProperties() {} + bool enabled = true; + float opacity = 1.0f; + Color color = {{ 0, 0, 0, 1 }}; + std::array translate = {{ 0, 0 }}; + TranslateAnchorType translateAnchor = TranslateAnchorType::Default; + float width = 0; + float offset = 0; + float blur = 0; + std::array dash_array = {{ 1, -1 }}; + std::string image; + + inline bool isVisible() const { + return enabled && opacity > 0 && color[3] > 0 && width > 0; + } +}; + +struct IconProperties { + inline IconProperties() {} + bool enabled = true; + float opacity = 1.0f; + float rotate = 0.0f; + RotateAnchorType rotate_anchor = RotateAnchorType::Default; + + inline bool isVisible() const { + return enabled && opacity > 0; + } +}; + +struct TextProperties { + inline TextProperties() {} + bool enabled = true; + float opacity = 1.0f; + float size = 12.0f; + Color color = {{ 0, 0, 0, 1 }}; + Color halo_color = {{ 1, 1, 1, 0.75 }}; + float halo_width = 0.25f; + float halo_blur = 1.0f; + + inline bool isVisible() const { + return enabled && opacity > 0 && (color[3] > 0 || halo_color[3] > 0) && size > 0; + } +}; + +struct CompositeProperties { + inline CompositeProperties() {} + bool enabled = true; + float opacity = 1.0f; + + inline bool isVisible() const { + return enabled && opacity > 0; + } +}; + +struct RasterProperties { + inline RasterProperties() {} + bool enabled = true; + float opacity = 1.0f; + float spin = 0.0f; + std::array brightness = {{ 0, 1 }}; + float saturation = 0.0f; + float contrast = 0.0f; + float fade = 0.0f; + + inline bool isVisible() const { + return enabled && opacity > 0; + } +}; + +struct BackgroundProperties { + inline BackgroundProperties() {} + Color color = {{ 1, 1, 1, 1 }}; +}; + +typedef util::variant< + FillProperties, + LineProperties, + IconProperties, + TextProperties, + CompositeProperties, + RasterProperties, + BackgroundProperties, + std::false_type +> StyleProperties; + +template +const T &defaultStyleProperties(); + +} + +#endif diff --git a/include/llmr/style/types.hpp b/include/llmr/style/types.hpp index f10a0f3dc..95365947f 100644 --- a/include/llmr/style/types.hpp +++ b/include/llmr/style/types.hpp @@ -2,9 +2,13 @@ #define LLMR_STYLE_TYPES #include +#include namespace llmr { +// Stores a premultiplied color, with all four channels ranging from 0..1 +typedef std::array Color; + enum class BucketType : uint8_t { None, Fill, diff --git a/include/llmr/util/transition.hpp b/include/llmr/util/transition.hpp index 3085b3455..fbf33d10f 100644 --- a/include/llmr/util/transition.hpp +++ b/include/llmr/util/transition.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace llmr { namespace util { diff --git a/src/renderer/painter_composite.cpp b/src/renderer/painter_composite.cpp index af3fd8e32..4ed507667 100644 --- a/src/renderer/painter_composite.cpp +++ b/src/renderer/painter_composite.cpp @@ -1,4 +1,5 @@ #include +#include #include diff --git a/src/style/properties.cpp b/src/style/function_properties.cpp similarity index 75% rename from src/style/properties.cpp rename to src/style/function_properties.cpp index 4f0649b22..eaaa2ad6f 100644 --- a/src/style/properties.cpp +++ b/src/style/function_properties.cpp @@ -1,8 +1,5 @@ -#include -#include +#include - -#include #include namespace llmr { @@ -86,12 +83,4 @@ float functions::exponential(float z, const std::vector& values) { return std::fmin(std::fmax(min, val + std::pow(1.75, (z - z_base)) * slope), max); } -template<> const FillProperties &defaultStyleProperties() { static const FillProperties p; return p; } -template<> const LineProperties &defaultStyleProperties() { static const LineProperties p; return p; } -template<> const IconProperties &defaultStyleProperties() { static const IconProperties p; return p; } -template<> const TextProperties &defaultStyleProperties() { static const TextProperties p; return p; } -template<> const CompositeProperties &defaultStyleProperties() { static const CompositeProperties p; return p; } -template<> const RasterProperties &defaultStyleProperties() { static const RasterProperties p; return p; } -template<> const BackgroundProperties &defaultStyleProperties() { static const BackgroundProperties p; return p; } - } diff --git a/src/style/style.cpp b/src/style/style.cpp index 64cdfd659..d6d7a7291 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 5d5737567..7bb05ecc6 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/src/style/style_properties.cpp b/src/style/style_properties.cpp new file mode 100644 index 000000000..f2b5af651 --- /dev/null +++ b/src/style/style_properties.cpp @@ -0,0 +1,13 @@ +#include + +namespace llmr { + +template<> const FillProperties &defaultStyleProperties() { static const FillProperties p; return p; } +template<> const LineProperties &defaultStyleProperties() { static const LineProperties p; return p; } +template<> const IconProperties &defaultStyleProperties() { static const IconProperties p; return p; } +template<> const TextProperties &defaultStyleProperties() { static const TextProperties p; return p; } +template<> const CompositeProperties &defaultStyleProperties() { static const CompositeProperties p; return p; } +template<> const RasterProperties &defaultStyleProperties() { static const RasterProperties p; return p; } +template<> const BackgroundProperties &defaultStyleProperties() { static const BackgroundProperties p; return p; } + +}