Fixed simplified traffic color scheme

This commit is contained in:
r.kuznetsov 2017-05-31 16:32:19 +03:00
parent ec3436e9cf
commit 7f5ea2277f
4 changed files with 63 additions and 59 deletions

View file

@ -11,16 +11,12 @@
#include "drape/glsl_types.hpp"
#include "drape/texture_manager.hpp"
#include "indexer/map_style_reader.hpp"
#include "base/logging.hpp"
namespace df
{
namespace
{
float const kLeftSide = 1.0f;
float const kCenter = 0.0f;
float const kRightSide = -1.0f;
@ -33,9 +29,9 @@ void GetArrowTextureRegion(ref_ptr<dp::TextureManager> textures, dp::TextureMana
textures->GetSymbolRegion("route-arrow", region);
}
vector<m2::PointD> CalculatePoints(m2::PolylineD const & polyline, double start, double end)
std::vector<m2::PointD> CalculatePoints(m2::PolylineD const & polyline, double start, double end)
{
vector<m2::PointD> result;
std::vector<m2::PointD> result;
result.reserve(polyline.GetSize() / 4);
auto addIfNotExist = [&result](m2::PointD const & pnt)
@ -44,7 +40,7 @@ vector<m2::PointD> CalculatePoints(m2::PolylineD const & polyline, double start,
result.push_back(pnt);
};
vector<m2::PointD> const & path = polyline.GetPoints();
std::vector<m2::PointD> const & path = polyline.GetPoints();
double len = 0;
bool started = false;
for (size_t i = 0; i + 1 < path.size(); i++)
@ -81,8 +77,9 @@ vector<m2::PointD> CalculatePoints(m2::PolylineD const & polyline, double start,
return result;
}
void GenerateJoinsTriangles(glsl::vec3 const & pivot, vector<glsl::vec2> const & normals, glsl::vec4 const & color,
glsl::vec2 const & length, bool isLeft, RouteShape::TGeometryBuffer & joinsGeometry)
void GenerateJoinsTriangles(glsl::vec3 const & pivot, std::vector<glsl::vec2> const & normals,
glsl::vec4 const & color, glsl::vec2 const & length, bool isLeft,
RouteShape::TGeometryBuffer & joinsGeometry)
{
float const kEps = 1e-5;
size_t const trianglesCount = normals.size() / 3;
@ -110,8 +107,8 @@ glsl::vec2 GetUV(m2::RectF const & texRect, glsl::vec2 const & uv)
return GetUV(texRect, uv.x, uv.y);
}
void GenerateArrowsTriangles(glsl::vec4 const & pivot, vector<glsl::vec2> const & normals,
m2::RectF const & texRect, vector<glsl::vec2> const & uv,
void GenerateArrowsTriangles(glsl::vec4 const & pivot, std::vector<glsl::vec2> const & normals,
m2::RectF const & texRect, std::vector<glsl::vec2> const & uv,
bool normalizedUV, RouteShape::TArrowGeometryBuffer & joinsGeometry)
{
size_t const trianglesCount = normals.size() / 3;
@ -128,15 +125,15 @@ void GenerateArrowsTriangles(glsl::vec4 const & pivot, vector<glsl::vec2> const
} // namespace
void RouteShape::PrepareGeometry(vector<m2::PointD> const & path, m2::PointD const & pivot,
vector<glsl::vec4> const & segmentsColors,
void RouteShape::PrepareGeometry(std::vector<m2::PointD> const & path, m2::PointD const & pivot,
std::vector<glsl::vec4> const & segmentsColors,
TGeometryBuffer & geometry, TGeometryBuffer & joinsGeometry,
double & outputLength)
{
ASSERT(path.size() > 1, ());
// Construct segments.
vector<LineSegment> segments;
std::vector<LineSegment> segments;
segments.reserve(path.size() - 1);
ConstructLineSegments(path, segmentsColors, segments);
@ -199,7 +196,7 @@ void RouteShape::PrepareGeometry(vector<m2::PointD> const & path, m2::PointD con
float widthScalar = segments[i].m_hasLeftJoin[EndPoint] ? segments[i].m_rightWidthScalar[EndPoint].x :
segments[i].m_leftWidthScalar[EndPoint].x;
vector<glsl::vec2> normals;
std::vector<glsl::vec2> normals;
normals.reserve(24);
GenerateJoinNormals(dp::RoundJoin, n1, n2, 1.0f, segments[i].m_hasLeftJoin[EndPoint],
widthScalar, normals);
@ -211,7 +208,7 @@ void RouteShape::PrepareGeometry(vector<m2::PointD> const & path, m2::PointD con
// Generate caps.
if (i == 0)
{
vector<glsl::vec2> normals;
std::vector<glsl::vec2> normals;
normals.reserve(24);
GenerateCapNormals(dp::RoundCap, segments[i].m_leftNormals[StartPoint],
segments[i].m_rightNormals[StartPoint], -segments[i].m_tangent,
@ -223,7 +220,7 @@ void RouteShape::PrepareGeometry(vector<m2::PointD> const & path, m2::PointD con
if (i == static_cast<int>(segments.size()) - 1)
{
vector<glsl::vec2> normals;
std::vector<glsl::vec2> normals;
normals.reserve(24);
GenerateCapNormals(dp::RoundCap, segments[i].m_leftNormals[EndPoint],
segments[i].m_rightNormals[EndPoint], segments[i].m_tangent,
@ -237,20 +234,20 @@ void RouteShape::PrepareGeometry(vector<m2::PointD> const & path, m2::PointD con
}
}
void RouteShape::PrepareArrowGeometry(vector<m2::PointD> const & path, m2::PointD const & pivot,
void RouteShape::PrepareArrowGeometry(std::vector<m2::PointD> const & path, m2::PointD const & pivot,
m2::RectF const & texRect, float depthStep, float depth,
TArrowGeometryBuffer & geometry, TArrowGeometryBuffer & joinsGeometry)
{
ASSERT(path.size() > 1, ());
// Construct segments.
vector<LineSegment> segments;
std::vector<LineSegment> segments;
segments.reserve(path.size() - 1);
ConstructLineSegments(path, vector<glsl::vec4>(), segments);
ConstructLineSegments(path, std::vector<glsl::vec4>(), segments);
m2::RectF tr = texRect;
tr.setMinX(texRect.minX() * (1.0 - kArrowTailSize) + texRect.maxX() * kArrowTailSize);
tr.setMaxX(texRect.minX() * kArrowHeadSize + texRect.maxX() * (1.0 - kArrowHeadSize));
tr.setMinX(static_cast<float>(texRect.minX() * (1.0 - kArrowTailSize) + texRect.maxX() * kArrowTailSize));
tr.setMaxX(static_cast<float>(texRect.minX() * kArrowHeadSize + texRect.maxX() * (1.0 - kArrowHeadSize)));
// Build geometry.
float const depthInc = depthStep / (segments.size() + 1);
@ -300,9 +297,9 @@ void RouteShape::PrepareArrowGeometry(vector<m2::PointD> const & path, m2::Point
segments[i].m_leftWidthScalar[EndPoint].x;
int const kAverageSize = 24;
vector<glsl::vec2> normals;
std::vector<glsl::vec2> normals;
normals.reserve(kAverageSize);
vector<glsl::vec2> uv;
std::vector<glsl::vec2> uv;
uv.reserve(kAverageSize);
GenerateJoinNormals(dp::RoundJoin, n1, n2, 1.0f, segments[i].m_hasLeftJoin[EndPoint],
@ -316,14 +313,14 @@ void RouteShape::PrepareArrowGeometry(vector<m2::PointD> const & path, m2::Point
// Generate arrow head.
if (i == segments.size() - 1)
{
vector<glsl::vec2> normals =
std::vector<glsl::vec2> normals =
{
segments[i].m_rightNormals[EndPoint],
segments[i].m_leftNormals[EndPoint],
kArrowHeadFactor * segments[i].m_tangent
};
float const u = 1.0f - kArrowHeadSize;
vector<glsl::vec2> uv = { glsl::vec2(u, 1.0f), glsl::vec2(u, 0.0f), glsl::vec2(1.0f, 0.5f) };
float const u = 1.0f - static_cast<float>(kArrowHeadSize);
std::vector<glsl::vec2> uv = { glsl::vec2(u, 1.0f), glsl::vec2(u, 0.0f), glsl::vec2(1.0f, 0.5f) };
glsl::vec4 const headPivot = glsl::vec4(glsl::ToVec2(endPt), depth, 1.0);
depth += depthInc;
GenerateArrowsTriangles(headPivot, normals, texRect, uv, true /* normalizedUV */, joinsGeometry);
@ -336,11 +333,11 @@ void RouteShape::PrepareArrowGeometry(vector<m2::PointD> const & path, m2::Point
glsl::vec2 const n2 = segments[i].m_rightNormals[StartPoint];
glsl::vec2 const n3 = (n1 - kArrowTailFactor * segments[i].m_tangent);
glsl::vec2 const n4 = (n2 - kArrowTailFactor * segments[i].m_tangent);
vector<glsl::vec2> normals = { n2, n4, n1, n1, n4, n3 };
std::vector<glsl::vec2> normals = { n2, n4, n1, n1, n4, n3 };
m2::RectF t = texRect;
t.setMaxX(tr.minX());
vector<glsl::vec2> uv =
std::vector<glsl::vec2> uv =
{
glsl::ToVec2(t.RightBottom()),
glsl::ToVec2(t.LeftBottom()),
@ -395,7 +392,8 @@ void RouteShape::CacheRouteSign(ref_ptr<dp::TextureManager> mng, RouteSignData &
}
void RouteShape::CacheRouteArrows(ref_ptr<dp::TextureManager> mng, m2::PolylineD const & polyline,
vector<ArrowBorders> const & borders, RouteArrowsData & routeArrowsData)
std::vector<ArrowBorders> const & borders,
RouteArrowsData & routeArrowsData)
{
TArrowGeometryBuffer geometry;
TArrowGeometryBuffer joinsGeometry;
@ -410,7 +408,7 @@ void RouteShape::CacheRouteArrows(ref_ptr<dp::TextureManager> mng, m2::PolylineD
for (ArrowBorders const & b : borders)
{
depth -= depthStep;
vector<m2::PointD> points = CalculatePoints(polyline, b.m_startDistance, b.m_endDistance);
std::vector<m2::PointD> points = CalculatePoints(polyline, b.m_startDistance, b.m_endDistance);
ASSERT_LESS_OR_EQUAL(points.size(), polyline.GetSize(), ());
PrepareArrowGeometry(points, routeArrowsData.m_pivot, region.GetTexRect(), depthStep,
depth, geometry, joinsGeometry);
@ -423,12 +421,13 @@ void RouteShape::CacheRouteArrows(ref_ptr<dp::TextureManager> mng, m2::PolylineD
void RouteShape::CacheRoute(ref_ptr<dp::TextureManager> textures, RouteData & routeData)
{
vector<glsl::vec4> segmentsColors;
std::vector<glsl::vec4> segmentsColors;
segmentsColors.reserve(routeData.m_traffic.size());
for (auto const & speedGroup : routeData.m_traffic)
for (auto speedGroup : routeData.m_traffic)
{
dp::Color const color = df::GetColorConstant(TrafficGenerator::GetColorBySpeedGroup(speedGroup,
true /* route */));
speedGroup = TrafficGenerator::CheckColorsSimplification(speedGroup);
auto const colorConstant = TrafficGenerator::GetColorBySpeedGroup(speedGroup, true /* route */);
dp::Color const color = df::GetColorConstant(colorConstant);
float const alpha = (speedGroup == traffic::SpeedGroup::G4 ||
speedGroup == traffic::SpeedGroup::G5 ||
speedGroup == traffic::SpeedGroup::Unknown) ? 0.0f : 1.0f;
@ -479,5 +478,4 @@ void RouteShape::BatchGeometry(dp::GLState const & state, ref_ptr<void> geometry
}
}
}
} // namespace df
} // namespace df

View file

@ -13,11 +13,10 @@
#include "geometry/polyline2d.hpp"
#include "std/vector.hpp"
#include <vector>
namespace df
{
double const kArrowSize = 0.0008;
// Constants below depend on arrow texture.
@ -28,9 +27,9 @@ double const kArrowHeadTextureWidth = 32.0;
double const kArrowTailTextureWidth = 4.0;
double const kArrowHeadSize = kArrowHeadTextureWidth / kArrowTextureWidth;
float const kArrowHeadFactor = 2.0 * kArrowHeadTextureWidth / kArrowTextureHeight;
float const kArrowHeadFactor = static_cast<float>(2.0 * kArrowHeadTextureWidth / kArrowTextureHeight);
double const kArrowTailSize = kArrowTailTextureWidth / kArrowTextureWidth;
float const kArrowTailFactor = 2.0 * kArrowTailTextureWidth / kArrowTextureHeight;
float const kArrowTailFactor = static_cast<float>(2.0 * kArrowTailTextureWidth / kArrowTextureHeight);
double const kArrowHeightFactor = kArrowTextureHeight / kArrowBodyHeight;
double const kArrowAspect = kArrowTextureWidth / kArrowTextureHeight;
@ -52,7 +51,7 @@ struct RoutePattern
struct RouteRenderProperty
{
dp::GLState m_state;
vector<drape_ptr<dp::RenderBucket>> m_buckets;
std::vector<drape_ptr<dp::RenderBucket>> m_buckets;
RouteRenderProperty() : m_state(0, dp::GLState::GeometryLayer) {}
};
@ -67,10 +66,10 @@ struct RouteData
{
int m_routeIndex;
m2::PolylineD m_sourcePolyline;
vector<double> m_sourceTurns;
std::vector<double> m_sourceTurns;
m2::PointD m_pivot;
df::ColorConstant m_color;
vector<traffic::SpeedGroup> m_traffic;
std::vector<traffic::SpeedGroup> m_traffic;
double m_length;
RouteRenderProperty m_route;
RoutePattern m_pattern;
@ -104,19 +103,20 @@ public:
static void CacheRoute(ref_ptr<dp::TextureManager> textures, RouteData & routeData);
static void CacheRouteSign(ref_ptr<dp::TextureManager> mng, RouteSignData & routeSignData);
static void CacheRouteArrows(ref_ptr<dp::TextureManager> mng, m2::PolylineD const & polyline,
vector<ArrowBorders> const & borders, RouteArrowsData & routeArrowsData);
std::vector<ArrowBorders> const & borders,
RouteArrowsData & routeArrowsData);
private:
static void PrepareGeometry(vector<m2::PointD> const & path, m2::PointD const & pivot,
vector<glsl::vec4> const & segmentsColors,
static void PrepareGeometry(std::vector<m2::PointD> const & path, m2::PointD const & pivot,
std::vector<glsl::vec4> const & segmentsColors,
TGeometryBuffer & geometry, TGeometryBuffer & joinsGeometry,
double & outputLength);
static void PrepareArrowGeometry(vector<m2::PointD> const & path, m2::PointD const & pivot,
static void PrepareArrowGeometry(std::vector<m2::PointD> const & path, m2::PointD const & pivot,
m2::RectF const & texRect, float depthStep, float depth,
TArrowGeometryBuffer & geometry, TArrowGeometryBuffer & joinsGeometry);
TArrowGeometryBuffer & geometry,
TArrowGeometryBuffer & joinsGeometry);
static void BatchGeometry(dp::GLState const & state, ref_ptr<void> geometry, uint32_t geomSize,
ref_ptr<void> joinsGeometry, uint32_t joinsGeomSize,
dp::BindingInfo const & bindingInfo, RouteRenderProperty & property);
};
} // namespace df
} // namespace df

View file

@ -345,7 +345,17 @@ void TrafficGenerator::SetSimplifiedColorSchemeEnabled(bool enabled)
}
// static
df::ColorConstant TrafficGenerator::GetColorBySpeedGroup(traffic::SpeedGroup const & speedGroup, bool route)
traffic::SpeedGroup TrafficGenerator::CheckColorsSimplification(traffic::SpeedGroup speedGroup)
{
traffic::SpeedGroup group = speedGroup;
// In simplified color scheme we reduce amount of speed groups visually.
if (m_simplifiedColorScheme && speedGroup == traffic::SpeedGroup::G4)
group = traffic::SpeedGroup::G3;
return group;
}
// static
df::ColorConstant TrafficGenerator::GetColorBySpeedGroup(traffic::SpeedGroup speedGroup, bool route)
{
size_t constexpr kSpeedGroupsCount = static_cast<size_t>(traffic::SpeedGroup::Count);
static array<df::ColorConstant, kSpeedGroupsCount> const kColorMap
@ -372,12 +382,7 @@ df::ColorConstant TrafficGenerator::GetColorBySpeedGroup(traffic::SpeedGroup con
"TrafficUnknown",
}};
traffic::SpeedGroup group = speedGroup;
// In simplified color scheme we reduce amount of speed groups visually.
if (m_simplifiedColorScheme && speedGroup == traffic::SpeedGroup::G4)
group = traffic::SpeedGroup::G3;
size_t const index = static_cast<size_t>(group);
size_t const index = static_cast<size_t>(CheckColorsSimplification(speedGroup));
ASSERT_LESS(index, kSpeedGroupsCount, ());
return route ? kColorMapRoute[index] : kColorMap[index];
}

View file

@ -148,7 +148,8 @@ public:
void InvalidateTexturesCache();
static void SetSimplifiedColorSchemeEnabled(bool enabled);
static df::ColorConstant GetColorBySpeedGroup(traffic::SpeedGroup const & speedGroup, bool route);
static traffic::SpeedGroup CheckColorsSimplification(traffic::SpeedGroup speedGroup);
static df::ColorConstant GetColorBySpeedGroup(traffic::SpeedGroup speedGroup, bool route);
private:
struct TrafficBatcherKey