[drape] draw real area geometry

This commit is contained in:
ExMix 2014-01-28 19:10:17 +03:00 committed by Alex Zolotarev
parent c3da8aee90
commit 51ed0b0a9f
3 changed files with 133 additions and 94 deletions

View file

@ -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);
}

View file

@ -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<m2::PointF> & 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<m2::PointF> & m_triangles;
};
class ApplyAreaFeature
{
public:
ApplyAreaFeature(EngineContext & context,
TileKey tileKey,
vector<m2::PointF> & 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<MapShape>(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<m2::PointF> 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<area_tess_points> functor_t;
vector<m2::PointF> 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<di::AreaInfo> & 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();
}
}
}

View file

@ -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<m2::PointF> 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<m2::PointF> 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<FeatureID> & ids, vector<df::FeatureInfo> const & src)
@ -127,22 +58,18 @@ namespace df
vector<size_t> 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<MapShape>(CreateFakeShape1()));
context.InsertShape(m_key, MovePointer<MapShape>(CreateFakeShape2()));
context.InsertShape(m_key, MovePointer<MapShape>(CreateFakeLine1()));
context.InsertShape(m_key, MovePointer<MapShape>(CreateFakeLine2()));
}
vector<FeatureID> 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<FeatureID> 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)