diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-09-15 13:04:36 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-09-27 11:53:44 +0300 |
commit | 06cf7a28debe3d2c922e8d7114f06c154356e360 (patch) | |
tree | 6a7846556ff2579d12325efdc1f99bfd2b364bad /drape_frontend | |
parent | 1a1ebbcbe99a80210049bea08045da3ea7835d91 (diff) |
Added line simplification
Diffstat (limited to 'drape_frontend')
-rw-r--r-- | drape_frontend/apply_feature_functors.cpp | 12 | ||||
-rw-r--r-- | drape_frontend/apply_feature_functors.hpp | 3 | ||||
-rw-r--r-- | drape_frontend/area_shape.cpp | 17 | ||||
-rw-r--r-- | drape_frontend/line_shape.cpp | 133 | ||||
-rw-r--r-- | drape_frontend/line_shape.hpp | 3 | ||||
-rw-r--r-- | drape_frontend/rule_drawer.cpp | 11 | ||||
-rw-r--r-- | drape_frontend/shape_view_params.hpp | 1 |
7 files changed, 142 insertions, 38 deletions
diff --git a/drape_frontend/apply_feature_functors.cpp b/drape_frontend/apply_feature_functors.cpp index 4acaa2810c..b5982bca70 100644 --- a/drape_frontend/apply_feature_functors.cpp +++ b/drape_frontend/apply_feature_functors.cpp @@ -37,6 +37,9 @@ double const kMinVisibleFontSize = 8.0; string const kStarSymbol = "★"; string const kPriceSymbol = "$"; +int const kLineSimplifyLevelStart = 10; +int const kLineSimplifyLevelEnd = 12; + dp::Color ToDrapeColor(uint32_t src) { return dp::Extract(src, 255 - (src >> 24)); @@ -107,8 +110,7 @@ private: }; #endif -void Extract(::LineDefProto const * lineRule, - df::LineViewParams & params) +void Extract(::LineDefProto const * lineRule, df::LineViewParams & params) { float const scale = df::VisualParams::Instance().GetVisualScale(); params.m_color = ToDrapeColor(lineRule->color()); @@ -612,11 +614,12 @@ void ApplyAreaFeature::ProcessRule(Stylist::TRuleWrapper const & rule) ApplyLineFeature::ApplyLineFeature(m2::PointD const & tileCenter, double currentScaleGtoP, TInsertShapeFn const & insertShape, FeatureID const & id, m2::RectD const & clipRect, int minVisibleScale, uint8_t rank, - CaptionDescription const & captions, bool simplify, size_t pointsCount) + CaptionDescription const & captions, int zoomLevel, size_t pointsCount) : TBase(tileCenter, insertShape, id, minVisibleScale, rank, captions) , m_currentScaleGtoP(currentScaleGtoP) , m_sqrScale(math::sqr(m_currentScaleGtoP)) - , m_simplify(simplify) + , m_simplify(zoomLevel >= kLineSimplifyLevelStart && zoomLevel <= kLineSimplifyLevelEnd) + , m_zoomLevel(zoomLevel) , m_initialPointsCount(pointsCount) , m_shieldDepth(0.0) , m_shieldRule(nullptr) @@ -727,6 +730,7 @@ void ApplyLineFeature::ProcessRule(Stylist::TRuleWrapper const & rule) params.m_minVisibleScale = m_minVisibleScale; params.m_rank = m_rank; params.m_baseGtoPScale = m_currentScaleGtoP; + params.m_zoomLevel = m_zoomLevel; for (auto const & spline : m_clippedSplines) m_insertShape(make_unique_dp<LineShape>(spline, params)); diff --git a/drape_frontend/apply_feature_functors.hpp b/drape_frontend/apply_feature_functors.hpp index c41d4ff9a9..a88792e0e4 100644 --- a/drape_frontend/apply_feature_functors.hpp +++ b/drape_frontend/apply_feature_functors.hpp @@ -137,7 +137,7 @@ public: ApplyLineFeature(m2::PointD const & tileCenter, double currentScaleGtoP, TInsertShapeFn const & insertShape, FeatureID const & id, m2::RectD const & clipRect, int minVisibleScale, uint8_t rank, - CaptionDescription const & captions, bool simplify, size_t pointsCount); + CaptionDescription const & captions, int zoomLevel, size_t pointsCount); void operator() (m2::PointD const & point); bool HasGeometry() const; @@ -151,6 +151,7 @@ private: double m_sqrScale; m2::PointD m_lastAddedPoint; bool m_simplify; + int m_zoomLevel; size_t m_initialPointsCount; double m_shieldDepth; ShieldRuleProto const * m_shieldRule; diff --git a/drape_frontend/area_shape.cpp b/drape_frontend/area_shape.cpp index d6ab5b0b65..57d82f80f3 100644 --- a/drape_frontend/area_shape.cpp +++ b/drape_frontend/area_shape.cpp @@ -7,11 +7,21 @@ #include "drape/texture_manager.hpp" #include "drape/utils/vertex_decl.hpp" +#include "indexer/map_style_reader.hpp" + #include "base/buffer_vector.hpp" #include "base/logging.hpp" #include "std/algorithm.hpp" +namespace +{ + +float const kLightOutlineColorFactor = 0.8; +float const kDarkOutlineColorFactor = 1.4; + +} // namespace + namespace df { @@ -24,10 +34,13 @@ AreaShape::AreaShape(vector<m2::PointD> && triangleList, BuildingOutline && buil void AreaShape::Draw(ref_ptr<dp::Batcher> batcher, ref_ptr<dp::TextureManager> textures) const { + auto const style = GetStyleReader().GetCurrentStyle(); + float const colorFactor = (style == MapStyleDark) ? kDarkOutlineColorFactor : kLightOutlineColorFactor; + dp::TextureManager::ColorRegion region; textures->GetColorRegion(m_params.m_color, region); dp::TextureManager::ColorRegion outlineRegion; - textures->GetColorRegion(m_params.m_color * 0.75, outlineRegion); + textures->GetColorRegion(m_params.m_color * colorFactor, outlineRegion); ASSERT_EQUAL(region.GetTexture(), outlineRegion.GetTexture(), ()); if (m_params.m_is3D) @@ -111,7 +124,7 @@ void AreaShape::DrawArea3D(ref_ptr<dp::Batcher> batcher, m2::PointD const & colo vertexes.emplace_back(gpu::Area3dVertex(glsl::vec3(endPt, -m_params.m_posZ), normal, uv)); } - glsl::vec3 normal(0.0f, 0.0f, -1.0f); + glsl::vec3 const normal(0.0f, 0.0f, -1.0f); for (auto const & vertex : m_vertexes) { glsl::vec2 const pt = glsl::ToVec2(ConvertToLocal(vertex, m_params.m_tileCenter, kShapeCoordScalar)); diff --git a/drape_frontend/line_shape.cpp b/drape_frontend/line_shape.cpp index 8130117f56..4f92d2e266 100644 --- a/drape_frontend/line_shape.cpp +++ b/drape_frontend/line_shape.cpp @@ -1,14 +1,18 @@ #include "drape_frontend/line_shape.hpp" #include "drape_frontend/line_shape_helper.hpp" +#include "drape_frontend/visual_params.hpp" -#include "drape/utils/vertex_decl.hpp" +#include "drape/attribute_provider.hpp" +#include "drape/batcher.hpp" #include "drape/glsl_types.hpp" #include "drape/glsl_func.hpp" #include "drape/shader_def.hpp" -#include "drape/attribute_provider.hpp" -#include "drape/batcher.hpp" +#include "drape/support_manager.hpp" #include "drape/texture_manager.hpp" +#include "drape/utils/vertex_decl.hpp" + +#include "indexer/scales.hpp" #include "base/logging.hpp" @@ -263,6 +267,36 @@ private: TCapBuffer m_capGeometry; }; +class SimpleSolidLineBuilder : public BaseLineBuilder<gpu::AreaVertex> +{ + using TBase = BaseLineBuilder<gpu::AreaVertex>; + +public: + using BuilderParams = BaseBuilderParams; + + SimpleSolidLineBuilder(BuilderParams const & params, size_t pointsInSpline, int lineWidth) + : TBase(params, pointsInSpline, 0) + , m_lineWidth(lineWidth) + {} + + dp::GLState GetState() override + { + dp::GLState state(gpu::AREA_OUTLINE_PROGRAM, dp::GLState::GeometryLayer); + state.SetColorTexture(m_params.m_color.GetTexture()); + state.SetDrawAsLine(true); + state.SetLineWidth(m_lineWidth); + return state; + } + + void SubmitVertex(glsl::vec3 const & pivot) + { + m_geometry.emplace_back(V(pivot, m_colorCoord)); + } + +private: + int m_lineWidth; +}; + class DashedLineBuilder : public BaseLineBuilder<gpu::DashedLineVertex> { using TBase = BaseLineBuilder<gpu::DashedLineVertex>; @@ -313,6 +347,7 @@ private: LineShape::LineShape(m2::SharedSpline const & spline, LineViewParams const & params) : m_params(params) , m_spline(spline) + , m_isSimple(false) { ASSERT_GREATER(m_spline->GetPath().size(), 1, ()); } @@ -415,11 +450,44 @@ void LineShape::Construct<SolidLineBuilder>(SolidLineBuilder & builder) const } } +// Specialization optimized for simple solid lines. +template <> +void LineShape::Construct<SimpleSolidLineBuilder>(SimpleSolidLineBuilder & builder) const +{ + vector<m2::PointD> const & path = m_spline->GetPath(); + ASSERT_GREATER(path.size(), 1, ()); + + // Build geometry. + for (size_t i = 0; i < path.size(); ++i) + { + glsl::vec2 const p = glsl::ToVec2(ConvertToLocal(path[i], m_params.m_tileCenter, kShapeCoordScalar)); + builder.SubmitVertex(glsl::vec3(p, m_params.m_depth)); + } +} + +bool LineShape::CanBeSimplified(int & lineWidth) const +{ + // Disable simplification for world map. + if (m_params.m_zoomLevel > 0 && m_params.m_zoomLevel <= scales::GetUpperCountryScale()) + return false; + + static float width = min(2.5f, static_cast<float>(dp::SupportManager::Instance().GetMaxLineWidth())); + if (m_params.m_width <= width) + { + lineWidth = max(1, static_cast<int>(m_params.m_width)); + return true; + } + + lineWidth = 1; + return false; +} + void LineShape::Prepare(ref_ptr<dp::TextureManager> textures) const { + float const pxHalfWidth = m_params.m_width / 2.0f; + dp::TextureManager::ColorRegion colorRegion; textures->GetColorRegion(m_params.m_color, colorRegion); - float const pxHalfWidth = m_params.m_width / 2.0f; auto commonParamsBuilder = [&](BaseBuilderParams & p) { @@ -432,12 +500,25 @@ void LineShape::Prepare(ref_ptr<dp::TextureManager> textures) const if (m_params.m_pattern.empty()) { - SolidLineBuilder::BuilderParams p; - commonParamsBuilder(p); + int lineWidth = 1; + m_isSimple = CanBeSimplified(lineWidth); + if (m_isSimple) + { + SimpleSolidLineBuilder::BuilderParams p; + commonParamsBuilder(p); - auto builder = make_unique<SolidLineBuilder>(p, m_spline->GetPath().size()); - Construct<SolidLineBuilder>(*builder); - m_lineShapeInfo = move(builder); + auto builder = make_unique<SimpleSolidLineBuilder>(p, m_spline->GetPath().size(), lineWidth); + Construct<SimpleSolidLineBuilder>(*builder); + m_lineShapeInfo = move(builder); + } + else + { + SolidLineBuilder::BuilderParams p; + commonParamsBuilder(p); + auto builder = make_unique<SolidLineBuilder>(p, m_spline->GetPath().size()); + Construct<SolidLineBuilder>(*builder); + m_lineShapeInfo = move(builder); + } } else { @@ -463,25 +544,31 @@ void LineShape::Draw(ref_ptr<dp::Batcher> batcher, ref_ptr<dp::TextureManager> t ASSERT(m_lineShapeInfo != nullptr, ()); dp::GLState state = m_lineShapeInfo->GetState(); - dp::AttributeProvider provider(1, m_lineShapeInfo->GetLineSize()); provider.InitStream(0, m_lineShapeInfo->GetBindingInfo(), m_lineShapeInfo->GetLineData()); - batcher->InsertListOfStrip(state, make_ref(&provider), dp::Batcher::VertexPerQuad); - - size_t joinSize = m_lineShapeInfo->GetJoinSize(); - if (joinSize > 0) + if (!m_isSimple) { - dp::AttributeProvider joinsProvider(1, joinSize); - joinsProvider.InitStream(0, m_lineShapeInfo->GetBindingInfo(), m_lineShapeInfo->GetJoinData()); - batcher->InsertTriangleList(state, make_ref(&joinsProvider)); - } + batcher->InsertListOfStrip(state, make_ref(&provider), dp::Batcher::VertexPerQuad); - size_t capSize = m_lineShapeInfo->GetCapSize(); - if (capSize > 0) + size_t const joinSize = m_lineShapeInfo->GetJoinSize(); + if (joinSize > 0) + { + dp::AttributeProvider joinsProvider(1, joinSize); + joinsProvider.InitStream(0, m_lineShapeInfo->GetBindingInfo(), m_lineShapeInfo->GetJoinData()); + batcher->InsertTriangleList(state, make_ref(&joinsProvider)); + } + + size_t const capSize = m_lineShapeInfo->GetCapSize(); + if (capSize > 0) + { + dp::AttributeProvider capProvider(1, capSize); + capProvider.InitStream(0, m_lineShapeInfo->GetCapBindingInfo(), m_lineShapeInfo->GetCapData()); + batcher->InsertListOfStrip(m_lineShapeInfo->GetCapState(), make_ref(&capProvider), dp::Batcher::VertexPerQuad); + } + } + else { - dp::AttributeProvider capProvider(1, capSize); - capProvider.InitStream(0, m_lineShapeInfo->GetCapBindingInfo(), m_lineShapeInfo->GetCapData()); - batcher->InsertListOfStrip(m_lineShapeInfo->GetCapState(), make_ref(&capProvider), dp::Batcher::VertexPerQuad); + batcher->InsertLineStrip(state, make_ref(&provider)); } } diff --git a/drape_frontend/line_shape.hpp b/drape_frontend/line_shape.hpp index b1f583e645..fee0c814ec 100644 --- a/drape_frontend/line_shape.hpp +++ b/drape_frontend/line_shape.hpp @@ -45,9 +45,12 @@ private: template <typename TBuilder> void Construct(TBuilder & builder) const; + bool CanBeSimplified(int & lineWidth) const; + LineViewParams m_params; m2::SharedSpline m_spline; mutable unique_ptr<ILineShapeInfo> m_lineShapeInfo; + mutable bool m_isSimple; }; } // namespace df diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index 84ad111adc..ce9fa8fe10 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -44,9 +44,6 @@ df::BaseApplyFeature::HotelData ExtractHotelData(FeatureType const & f) namespace df { -int const kLineSimplifyLevelStart = 10; -int const kLineSimplifyLevelEnd = 12; - RuleDrawer::RuleDrawer(TDrawerCallback const & fn, TCheckCancelledCallback const & checkCancelled, TIsCountryLoadedByNameFn const & isLoadedFn, @@ -237,11 +234,9 @@ void RuleDrawer::operator()(FeatureType const & f) } else if (s.LineStyleExists()) { - ApplyLineFeature apply(m_globalRect.Center(), m_currentScaleGtoP, - insertShape, f.GetID(), m_globalRect, minVisibleScale, - f.GetRank(), s.GetCaptionDescription(), - zoomLevel >= kLineSimplifyLevelStart && zoomLevel <= kLineSimplifyLevelEnd, - f.GetPointsCount()); + ApplyLineFeature apply(m_globalRect.Center(), m_currentScaleGtoP, insertShape, f.GetID(), + m_globalRect, minVisibleScale, f.GetRank(), s.GetCaptionDescription(), + zoomLevel, f.GetPointsCount()); f.ForEachPoint(apply, zoomLevel); if (CheckCancelled()) diff --git a/drape_frontend/shape_view_params.hpp b/drape_frontend/shape_view_params.hpp index f5c084c288..6341e80829 100644 --- a/drape_frontend/shape_view_params.hpp +++ b/drape_frontend/shape_view_params.hpp @@ -63,6 +63,7 @@ struct LineViewParams : CommonViewParams dp::LineJoin m_join; buffer_vector<uint8_t, 8> m_pattern; float m_baseGtoPScale = 1.0f; + int m_zoomLevel = -1; }; struct TextViewParams : CommonViewParams |