From 51ed0b0a9f497c3a80156a0b532b7c1c27f4406a Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 28 Jan 2014 19:10:17 +0300 Subject: [PATCH] [drape] draw real area geometry --- drape_frontend/frontend_renderer.cpp | 4 +- drape_frontend/rule_drawer.cpp | 134 ++++++++++++++++++++++++--- drape_frontend/tile_info.cpp | 89 ++---------------- 3 files changed, 133 insertions(+), 94 deletions(-) diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 2d1fd6c18e..1a27d119f5 100644 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -152,7 +152,7 @@ namespace df #endif m_viewport.Apply(); - GLFunctions::glClearColor(0.65f, 0.65f, 0.65f, 1.f); + GLFunctions::glClearColor(0.93f, 0.93f, 0.86f, 1.f); GLFunctions::glClear(); for_each(m_renderData.begin(), m_renderData.end(), bind(&FrontendRenderer::RenderPartImpl, this, _1)); @@ -174,7 +174,7 @@ namespace df float m[4*4]; - OrthoMatrix(m, 0.0f, w, h, 0.0f, -2.f, 2.f); + OrthoMatrix(m, 0.0f, w, h, 0.0f, -20000.0f, 20000.0f); m_generalUniforms.SetMatrix4x4Value("projection", m); } diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index 5646a7e1a8..f73defb3ee 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -2,16 +2,23 @@ #include "stylist.hpp" #include "shape_view_params.hpp" #include "engine_context.hpp" +#include "vizualization_params.hpp" #include "line_shape.hpp" +#include "area_shape.hpp" #include "../indexer/drules_include.hpp" #include "../indexer/feature.hpp" +#include "../indexer/feature_algo.hpp" +#include "../indexer/drawing_rules.hpp" #include "../map/geometry_processors.hpp" #include "../base/assert.hpp" +#include "../std/vector.hpp" +#include "../std/bind.hpp" + namespace df { namespace @@ -21,13 +28,11 @@ namespace df return Extract(src, 255 - (src >> 24)); } - // ==================================================== // void Extract(::LineDefProto const * lineRule, - double visualScale, df::LineViewParams & params) { params.m_color = ToDrapeColor(lineRule->color()); - params.m_width = max(lineRule->width() * visualScale, 1.0); + params.m_width = max(lineRule->width() * df::VizualizationParams::GetVisualScale(), 1.0); switch(lineRule->cap()) { @@ -55,6 +60,112 @@ namespace df } } + // ============================================= // + + namespace + { + class TrianglesFunctor + { + public: + TrianglesFunctor(ScreenBase const & convertor, vector & triangles) + : m_convertor(convertor) + , m_triangles(triangles) + { + } + + void operator()(m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3) + { + m2::PointF points[3] = { m_convertor.GtoP(p1), m_convertor.GtoP(p2), m_convertor.GtoP(p3) }; + m2::RectF r(points[0], points[1]); + r.Add(points[2]); + + double const eps = 1.0; + if (r.SizeX() < eps && r.SizeY() < 1.0) + return; + + m_triangles.push_back(points[0]); + m_triangles.push_back(points[1]); + m_triangles.push_back(points[2]); + } + + private: + ScreenBase const & m_convertor; + vector & m_triangles; + }; + + class ApplyAreaFeature + { + public: + ApplyAreaFeature(EngineContext & context, + TileKey tileKey, + vector & triangles) + : m_context(context) + , m_tileKey(tileKey) + , m_triangles(triangles) + , m_hasCenter(false) + { + } + + void SetCenter(m2::PointF const & center) { m_center = center; } + + void ProcessRule(Stylist::rule_wrapper_t const & rule) + { + drule::BaseRule const * pRule = rule.first; + double const depth = rule.second; + + AreaRuleProto const * areaRule = pRule->GetArea(); + + if (areaRule) + { + AreaShape * shape = new AreaShape(ToDrapeColor(areaRule->color()), depth); + for (size_t i = 0; i < m_triangles.size(); i += 3) + shape->AddTriangle(m_triangles[i], m_triangles[i + 1], m_triangles[i + 2]); + + m_context.InsertShape(m_tileKey, MovePointer(shape)); + } + else + { + SymbolRuleProto const * symRule = pRule->GetSymbol(); + if (symRule) + { + m_symbolDepth = depth; + m_symbolRule = symRule; + } + + CircleRuleProto const * circleRule = pRule->GetCircle(); + if (circleRule) + { + m_circleDepth = depth; + m_circleRule = circleRule; + } + } + } + + void Finish() + { + if (!m_hasCenter) + return; + + // TODO + // create symbol or circle of symbol with circle + } + + private: + EngineContext & m_context; + TileKey m_tileKey; + vector m_triangles; + bool m_hasCenter; + m2::PointF m_center; + + double m_symbolDepth; + double m_circleDepth; + CircleRuleProto const * m_circleRule; + SymbolRuleProto const * m_symbolRule; + }; + } + + // ==================================================== // + RuleDrawer::RuleDrawer(drawer_callback_fn const & fn, const TileKey & tileKey, EngineContext & context) : m_callback(fn) , m_tileKey(tileKey) @@ -88,18 +199,19 @@ namespace df } #endif - using namespace gp; if (s.AreaStyleExists()) { - typedef filter_screenpts_adapter functor_t; + vector triangles; - functor_t::params p; - p.m_convertor = & m_geometryConvertor; - p.m_rect = & m_globalRect; + TrianglesFunctor fun(m_geometryConvertor, triangles); + f.ForEachTriangleRef(fun, m_tileKey.m_zoomLevel); - functor_t fun(p); - f.ForEachTriangleExRef(fun, m_tileKey.m_zoomLevel); - list & info = fun.m_points; + ApplyAreaFeature apply(m_context, m_tileKey, triangles); + if (s.PointStyleExists()) + apply.SetCenter(feature::GetCenter(f, m_tileKey.m_zoomLevel)); + + s.ForEachRule(bind(&ApplyAreaFeature::ProcessRule, &apply, _1)); + apply.Finish(); } } } diff --git a/drape_frontend/tile_info.cpp b/drape_frontend/tile_info.cpp index f7ce5e8fd6..262dbe8dd1 100644 --- a/drape_frontend/tile_info.cpp +++ b/drape_frontend/tile_info.cpp @@ -3,81 +3,12 @@ #include "stylist.hpp" #include "rule_drawer.hpp" -#include "line_shape.hpp" -#include "area_shape.hpp" -#include "engine_context.hpp" - #include "../map/feature_vec_model.hpp" #include "../std/bind.hpp" namespace { - df::AreaShape * CreateFakeShape1() - { - df::AreaShape * shape = new df::AreaShape(Extract(0xFFEEAABB), 0.3f); - shape->AddTriangle(m2::PointF(50.0f, 50.0f), - m2::PointF(100.0f, 50.0f), - m2::PointF(50.0f, 100.0f)); - - shape->AddTriangle(m2::PointF(100.0f, 50.0f), - m2::PointF(50.0f, 100.0f), - m2::PointF(100.0f, 100.0f)); - return shape; - } - - df::AreaShape * CreateFakeShape2() - { - df::AreaShape * shape = new df::AreaShape(Extract(0xFF66AAFF), 0.0f); - shape->AddTriangle(m2::PointF(0.0f, 50.0f), - m2::PointF(50.0f, 150.0f), - m2::PointF(50.0f, 0.0f)); - - shape->AddTriangle(m2::PointF(50.0f, 0.0f), - m2::PointF(50.0f, 150.0f), - m2::PointF(150.0f, 50.0f)); - return shape; - } - - df::LineShape * CreateFakeLine1() - { - vector points; - const float magn = 40; - - for (float x = -4*math::pi; x <= 4*math::pi; x+= math::pi/32) - points.push_back(m2::PointF(50 * x + 100.0, magn*sinf(x) + 200.0)); - - df::LineViewParams params; - params.m_color = Extract(0xFFFF0000); - params.m_width = 4.0f; - - return new df::LineShape(points, 0.0f, params); - } - - df::LineShape * CreateFakeLine2() - { - vector points; - points.push_back(m2::PointF(0,0)); - points.push_back(m2::PointF(0,0)); // to check for zero-normal - points.push_back(m2::PointF(4,0)); - points.push_back(m2::PointF(8,4)); - points.push_back(m2::PointF(4,4)); - points.push_back(m2::PointF(0,4)); - points.push_back(m2::PointF(0,0)); - - for (size_t i = 0; i < points.size(); ++i) - { - m2::PointF p = points[i] * 100; - points[i] = p + m2::PointF(100.0, 300.0); - } - - df::LineViewParams params; - params.m_color = Extract(0xFF00FF00); - params.m_width = 2.0f; - - return new df::LineShape(points, 0.5f, params); - } - struct IDsAccumulator { IDsAccumulator(vector & ids, vector const & src) @@ -127,22 +58,18 @@ namespace df vector indexes; RequestFeatures(memIndex, indexes); - if (!indexes.empty() && m_key == TileKey(0,0,3)) + // TODO remove m_key == TileKey(1, 0, 3) when tile position on + // display will be calculated in frontend_renderer + if (!indexes.empty() && m_key == TileKey(1,0,3)) { context.BeginReadTile(m_key); - { - context.InsertShape(m_key, MovePointer(CreateFakeShape1())); - context.InsertShape(m_key, MovePointer(CreateFakeShape2())); - context.InsertShape(m_key, MovePointer(CreateFakeLine1())); - context.InsertShape(m_key, MovePointer(CreateFakeLine2())); - } + vector featuresToRead; + for_each(indexes.begin(), indexes.end(), IDsAccumulator(featuresToRead, m_featureInfo)); + + RuleDrawer drawer(bind(&TileInfo::InitStylist, this, _1 ,_2), m_key, context); + model.ReadFeatures(drawer, featuresToRead); context.EndReadTile(m_key); } -// vector featuresToRead; -// for_each(indexes.begin(), indexes.end(), IDsAccumulator(featuresToRead, m_featureInfo)); - -// RuleDrawer drawer(bind(&TileInfo::InitStylist, this, _1 ,_2), context); -// model.ReadFeatures(drawer, featuresToRead); } void TileInfo::Cancel(MemoryFeatureIndex & memIndex)