From 88e362729ddf3f5bb9149c153e7620a5620eb2bd Mon Sep 17 00:00:00 2001 From: ExMix Date: Mon, 13 Apr 2015 12:48:47 +0300 Subject: [PATCH] [drape] track rendering --- drape_frontend/backend_renderer.cpp | 5 + drape_frontend/frontend_renderer.cpp | 52 +++------ drape_frontend/frontend_renderer.hpp | 5 +- drape_frontend/render_group.cpp | 22 +--- drape_frontend/render_group.hpp | 9 +- drape_frontend/user_mark_shapes.cpp | 116 +++++++++++++------- drape_frontend/user_mark_shapes.hpp | 2 +- drape_frontend/user_marks_provider.hpp | 16 +-- map/bookmark.cpp | 74 +++++++------ map/bookmark.hpp | 14 +-- map/bookmark_manager.cpp | 5 +- map/map_tests/bookmarks_test.cpp | 6 +- map/route_track.cpp | 34 ------ map/route_track.hpp | 21 +--- map/track.cpp | 143 +++++-------------------- map/track.hpp | 92 ++++------------ map/user_mark_container.cpp | 10 +- map/user_mark_container.hpp | 4 +- std/iterator.hpp | 4 +- 19 files changed, 223 insertions(+), 411 deletions(-) diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index 2e7b6d9a1b..899d940ba4 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -127,6 +127,11 @@ void BackendRenderer::AcceptMessage(dp::RefPointer message) { UpdateUserMarkLayerMessage * msg = df::CastMessage(message); TileKey const & key = msg->GetKey(); + + m_commutator->PostMessage(ThreadsCommutator::RenderThread, + dp::MovePointer(new ClearUserMarkLayerMessage(key)), + MessagePriority::Normal); + m_batchersPool->ReserveBatcher(key); UserMarksProvider const * marksProvider = msg->StartProcess(); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 66b43315f7..6c4dcfbd4e 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -102,29 +102,6 @@ void FrontendRenderer::AfterDrawFrame() } #endif -unique_ptr const & FrontendRenderer::FindUserMarkRenderGroup(TileKey const & tileKey, bool createIfNeed) -{ - auto it = find_if(m_userMarkRenderGroups.begin(), m_userMarkRenderGroups.end(), [&tileKey](unique_ptr const & g) - { - return g->GetTileKey() == tileKey; - }); - - if (it != m_userMarkRenderGroups.end()) - { - ASSERT((*it).get() != nullptr, ()); - return *it; - } - - if (createIfNeed) - { - m_userMarkRenderGroups.emplace_back(new UserMarkRenderGroup(dp::GLState(0, dp::GLState::UserMarkLayer), tileKey)); - return m_userMarkRenderGroups.back(); - } - - static unique_ptr emptyRenderGroup; - return emptyRenderGroup; -} - void FrontendRenderer::AcceptMessage(dp::RefPointer message) { switch (message->GetType()) @@ -144,11 +121,7 @@ void FrontendRenderer::AcceptMessage(dp::RefPointer message) bucket.Destroy(); } else - { - unique_ptr const & group = FindUserMarkRenderGroup(key, true); - ASSERT(group.get() != nullptr, ()); - group->SetRenderBucket(state, bucket.Move()); - } + m_userMarkRenderGroups.push_back(new UserMarkRenderGroup(state, key, bucket.Move())); break; } @@ -202,25 +175,26 @@ void FrontendRenderer::AcceptMessage(dp::RefPointer message) case Message::ClearUserMarkLayer: { TileKey const & tileKey = df::CastMessage(message)->GetKey(); - auto it = find_if(m_userMarkRenderGroups.begin(), m_userMarkRenderGroups.end(), [&tileKey](unique_ptr const & g) + auto const functor = [&tileKey](unique_ptr const & g) { return g->GetTileKey() == tileKey; - }); + }; - if (it != m_userMarkRenderGroups.end()) - { - ASSERT((*it).get() != nullptr, ()); - m_userMarkRenderGroups.erase(it); - } + auto const iter = remove_if(m_userMarkRenderGroups.begin(), + m_userMarkRenderGroups.end(), + functor); + m_userMarkRenderGroups.erase(iter, m_userMarkRenderGroups.end()); break; } case Message::ChangeUserMarkLayerVisibility: { ChangeUserMarkLayerVisibilityMessage * m = df::CastMessage(message); - unique_ptr const & group = FindUserMarkRenderGroup(m->GetKey(), true); - ASSERT(group.get() != nullptr, ()); - group->SetIsVisible(m->IsVisible()); + TileKey const & key = m->GetKey(); + if (m->IsVisible()) + m_userMarkVisibility.insert(key); + else + m_userMarkVisibility.erase(key); break; } case Message::GuiLayerRecached: @@ -371,7 +345,7 @@ void FrontendRenderer::RenderScene() for (unique_ptr const & group : m_userMarkRenderGroups) { ASSERT(group.get() != nullptr, ()); - if (group->IsVisible()) + if (m_userMarkVisibility.find(group->GetTileKey()) != m_userMarkVisibility.end()) { dp::GLState const & state = group->GetState(); dp::RefPointer program = m_gpuProgramManager->GetProgram(state.GetProgramIndex()); diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp index ccf135c83a..d39baea4a1 100755 --- a/drape_frontend/frontend_renderer.hpp +++ b/drape_frontend/frontend_renderer.hpp @@ -71,9 +71,6 @@ private: void ResolveTileKeys(int tileScale); int GetCurrentZoomLevel() const; - //TODO(@kuznetsov): return new ref-pointer here - unique_ptr const & FindUserMarkRenderGroup(TileKey const & tileKey, bool createIfNeed); - private: class Routine : public threads::IRoutine { @@ -117,6 +114,8 @@ private: vector> m_renderGroups; vector> m_deferredRenderGroups; vector> m_userMarkRenderGroups; + set m_userMarkVisibility; + dp::MasterPointer m_guiRenderer; dp::MasterPointer m_myPositionMark; diff --git a/drape_frontend/render_group.cpp b/drape_frontend/render_group.cpp index fc02c9d5bc..97c6237ce4 100755 --- a/drape_frontend/render_group.cpp +++ b/drape_frontend/render_group.cpp @@ -96,9 +96,11 @@ bool RenderGroupComparator::operator()(unique_ptr const & l, unique return false; } -UserMarkRenderGroup::UserMarkRenderGroup(dp::GLState const & state, TileKey const & tileKey) +UserMarkRenderGroup::UserMarkRenderGroup(dp::GLState const & state, + TileKey const & tileKey, + dp::TransferPointer bucket) : TBase(state, tileKey) - , m_isVisible(true) + , m_renderBucket(bucket) { } @@ -107,22 +109,6 @@ UserMarkRenderGroup::~UserMarkRenderGroup() m_renderBucket.Destroy(); } -void UserMarkRenderGroup::SetIsVisible(bool isVisible) -{ - m_isVisible = isVisible; -} - -bool UserMarkRenderGroup::IsVisible() -{ - return m_isVisible && !m_renderBucket.IsNull(); -} - -void UserMarkRenderGroup::SetRenderBucket(dp::GLState const & state, dp::TransferPointer bucket) -{ - m_state = state; - m_renderBucket = dp::MasterPointer(bucket); -} - void UserMarkRenderGroup::Render(ScreenBase const & screen) { if (!m_renderBucket.IsNull()) diff --git a/drape_frontend/render_group.hpp b/drape_frontend/render_group.hpp index 5b068cf4f3..abb81a5ff4 100755 --- a/drape_frontend/render_group.hpp +++ b/drape_frontend/render_group.hpp @@ -81,18 +81,13 @@ class UserMarkRenderGroup : public BaseRenderGroup typedef BaseRenderGroup TBase; public: - UserMarkRenderGroup(dp::GLState const & state, TileKey const & tileKey); + UserMarkRenderGroup(dp::GLState const & state, TileKey const & tileKey, + dp::TransferPointer bucket); ~UserMarkRenderGroup(); - void SetIsVisible(bool isVisible); - bool IsVisible(); - - void Clear(); - void SetRenderBucket(dp::GLState const & state, dp::TransferPointer bucket); void Render(ScreenBase const & screen); private: - bool m_isVisible; dp::MasterPointer m_renderBucket; }; diff --git a/drape_frontend/user_mark_shapes.cpp b/drape_frontend/user_mark_shapes.cpp index 6a631b6038..95d0589598 100644 --- a/drape_frontend/user_mark_shapes.cpp +++ b/drape_frontend/user_mark_shapes.cpp @@ -1,9 +1,13 @@ #include "user_mark_shapes.hpp" +#include "line_shape.hpp" + #include "../drape/utils/vertex_decl.hpp" #include "../drape/shader_def.hpp" #include "../drape/attribute_provider.hpp" +#include "../geometry/spline.hpp" + namespace df { @@ -37,53 +41,47 @@ bool IsUserMarkLayer(TileKey const & tileKey) namespace { - template - void AlignFormingNormals(TCreateVector const & fn, dp::Anchor anchor, - dp::Anchor first, dp::Anchor second, - glsl::vec2 & firstNormal, glsl::vec2 & secondNormal) - { - firstNormal = fn(); - secondNormal = -firstNormal; - if ((anchor & second) != 0) - { - firstNormal *= 2; - secondNormal = glsl::vec2(0.0, 0.0); - } - else if ((anchor & first) != 0) - { - firstNormal = glsl::vec2(0.0, 0.0); - secondNormal *= 2; - } - } - void AlignHorizontal(float halfWidth, dp::Anchor anchor, - glsl::vec2 & left, glsl::vec2 & right) +template +void AlignFormingNormals(TCreateVector const & fn, dp::Anchor anchor, + dp::Anchor first, dp::Anchor second, + glsl::vec2 & firstNormal, glsl::vec2 & secondNormal) +{ + firstNormal = fn(); + secondNormal = -firstNormal; + if ((anchor & second) != 0) { - AlignFormingNormals([&halfWidth]{ return glsl::vec2(-halfWidth, 0.0f); }, anchor, dp::Left, dp::Right, left, right); + firstNormal *= 2; + secondNormal = glsl::vec2(0.0, 0.0); } - - void AlignVertical(float halfHeight, dp::Anchor anchor, - glsl::vec2 & up, glsl::vec2 & down) + else if ((anchor & first) != 0) { - AlignFormingNormals([&halfHeight]{ return glsl::vec2(0.0f, -halfHeight); }, anchor, dp::Top, dp::Bottom, up, down); + firstNormal = glsl::vec2(0.0, 0.0); + secondNormal *= 2; } } -void CacheUserMarks(UserMarksProvider const * provider, - dp::RefPointer batcher, - dp::RefPointer textures) +void AlignHorizontal(float halfWidth, dp::Anchor anchor, + glsl::vec2 & left, glsl::vec2 & right) { - size_t markCount = provider->GetPointCount(); + AlignFormingNormals([&halfWidth]{ return glsl::vec2(-halfWidth, 0.0f); }, anchor, dp::Left, dp::Right, left, right); +} + +void AlignVertical(float halfHeight, dp::Anchor anchor, + glsl::vec2 & up, glsl::vec2 & down) +{ + AlignFormingNormals([&halfHeight]{ return glsl::vec2(0.0f, -halfHeight); }, anchor, dp::Top, dp::Bottom, up, down); +} + +void CacheUserPoints(UserMarksProvider const * provider, + dp::RefPointer batcher, + dp::RefPointer textures) +{ + size_t markCount = provider->GetUserPointCount(); if (markCount == 0) return; - uint32_t vertexCount = 4 * markCount; // 4 vertex per quad - uint32_t indexCount = 6 * markCount; // 6 index on one quad - - uint32_t savedIndSize = batcher->GetIndexBufferSize(); - uint32_t savedVerSize = batcher->GetVertexBufferSize(); - batcher->SetIndexBufferSize(indexCount); - batcher->SetVertexBufferSize(vertexCount); + uint32_t vertexCount = dp::Batcher::VertexPerQuad * markCount; // 4 vertex per quad buffer_vector buffer; buffer.reserve(vertexCount); @@ -119,12 +117,52 @@ void CacheUserMarks(UserMarksProvider const * provider, dp::GLState state(gpu::TEXTURING_PROGRAM, dp::GLState::UserMarkLayer); state.SetColorTexture(region.GetTexture()); + dp::AttributeProvider attribProvider(1, buffer.size()); attribProvider.InitStream(0, gpu::SolidTexturingVertex::GetBindingInfo(), dp::MakeStackRefPointer(buffer.data())); - batcher->InsertListOfStrip(state, dp::MakeStackRefPointer(&attribProvider), 4); - batcher->SetIndexBufferSize(savedIndSize); - batcher->SetVertexBufferSize(savedVerSize); + batcher->InsertListOfStrip(state, dp::MakeStackRefPointer(&attribProvider), dp::Batcher::VertexPerQuad); +} + +void CacheUserLines(UserMarksProvider const * provider, + dp::RefPointer batcher, + dp::RefPointer textures) +{ + for (size_t i = 0; i < provider->GetUserLineCount(); ++i) + { + UserLineMark const * line = provider->GetUserLineMark(i); + size_t pointCount = line->GetPointCount(); + + vector points; + points.reserve(pointCount); + for (size_t i = 0; i < pointCount; ++i) + points.push_back(line->GetPoint(i)); + + m2::SharedSpline spline(points); + + for (size_t layerIndex = 0; layerIndex < line->GetLayerCount(); ++layerIndex) + { + LineViewParams params; + params.m_baseGtoPScale = 1.0f; + params.m_cap = dp::RoundCap; + params.m_join = dp::RoundJoin; + params.m_color = line->GetColor(layerIndex); + params.m_depth = line->GetLayerDepth(layerIndex); + params.m_width = line->GetWidth(layerIndex); + + LineShape(spline, params).Draw(batcher, textures); + } + } +} + +} // namespace + +void CacheUserMarks(UserMarksProvider const * provider, + dp::RefPointer batcher, + dp::RefPointer textures) +{ + CacheUserPoints(provider, batcher, textures); + CacheUserLines(provider, batcher, textures); } } // namespace df diff --git a/drape_frontend/user_mark_shapes.hpp b/drape_frontend/user_mark_shapes.hpp index e12c755c63..734e34a8f6 100644 --- a/drape_frontend/user_mark_shapes.hpp +++ b/drape_frontend/user_mark_shapes.hpp @@ -15,7 +15,7 @@ namespace df TileKey GetSearchTileKey(); TileKey GetApiTileKey(); TileKey GetBookmarkTileKey(size_t categoryIndex); - bool IsUserMarkLayer(const TileKey & tileKey); + bool IsUserMarkLayer(TileKey const & tileKey); void CacheUserMarks(UserMarksProvider const * provider, dp::RefPointer batcher, dp::RefPointer textures); diff --git a/drape_frontend/user_marks_provider.hpp b/drape_frontend/user_marks_provider.hpp index a5eabba7e8..224ee544be 100644 --- a/drape_frontend/user_marks_provider.hpp +++ b/drape_frontend/user_marks_provider.hpp @@ -26,13 +26,14 @@ class UserLineMark public: virtual ~UserLineMark() {} - virtual dp::Color const & GetColor() const = 0; - virtual float GetWidth() const = 0; + virtual size_t GetLayerCount() const = 0; + virtual dp::Color const & GetColor(size_t layerIndex) const = 0; + virtual float GetWidth(size_t layerIndex) const = 0; + virtual float GetLayerDepth(size_t layerIndex) const = 0; /// Line geometry enumeration - virtual bool HasPoint() const = 0; - virtual m2::PointD const & GetCurrentPoint() const = 0; - virtual void Advance() const = 0; + virtual size_t GetPointCount() const = 0; + virtual m2::PointD const & GetPoint(size_t pointIndex) const = 0; }; class UserMarksProvider @@ -45,14 +46,13 @@ public: bool IsDirty() const; virtual bool IsDrawable() const = 0; - virtual size_t GetPointCount() const = 0; + virtual size_t GetUserPointCount() const = 0; /// never store UserPointMark reference virtual UserPointMark const * GetUserPointMark(size_t index) const = 0; - virtual size_t GetLineCount() const = 0; + virtual size_t GetUserLineCount() const = 0; /// never store UserLineMark reference virtual UserLineMark const * GetUserLineMark(size_t index) const = 0; - virtual void EndRead(); void IncrementCounter(); diff --git a/map/bookmark.cpp b/map/bookmark.cpp index cd098f2182..9bbf0e034d 100644 --- a/map/bookmark.cpp +++ b/map/bookmark.cpp @@ -8,9 +8,6 @@ #include "base/scope_guard.hpp" - -#include "graphics/depth_constants.hpp" - #include "indexer/mercator.hpp" #include "coding/file_reader.hpp" @@ -26,10 +23,10 @@ #include "base/stl_add.hpp" #include "base/string_utils.hpp" -#include "std/fstream.hpp" #include "std/algorithm.hpp" #include "std/auto_ptr.hpp" - +#include "std/fstream.hpp" +#include "std/iterator.hpp" Bookmark::Bookmark(m2::PointD const & ptOrg, UserMarkContainer * container) : TBase(ptOrg, container) @@ -135,14 +132,15 @@ void Bookmark::SetScale(double scale) ////////////////////////////////////////////////////////////////// -void BookmarkCategory::AddTrack(Track & track) +void BookmarkCategory::AddTrack(unique_ptr && track) { - m_tracks.push_back(track.CreatePersistent()); + SetDirty(); + m_tracks.push_back(move(track)); } Track const * BookmarkCategory::GetTrack(size_t index) const { - return (index < m_tracks.size() ? m_tracks[index] : 0); + return (index < m_tracks.size() ? m_tracks[index].get() : 0); } BookmarkCategory::BookmarkCategory(string const & name, Framework & framework) @@ -156,32 +154,29 @@ BookmarkCategory::~BookmarkCategory() ClearTracks(); } +size_t BookmarkCategory::GetUserLineCount() const +{ + return m_tracks.size(); +} + +df::UserLineMark const * BookmarkCategory::GetUserLineMark(size_t index) const +{ + ASSERT_LESS(index, m_tracks.size(), ()); + return m_tracks[index].get(); +} + void BookmarkCategory::ClearTracks() { - DeleteRange(m_tracks, DeleteFunctor()); -} - -namespace -{ - -template void DeleteItem(vector & v, size_t i) -{ - if (i < v.size()) - { - delete v[i]; - v.erase(v.begin() + i); - } - else - { - LOG(LWARNING, ("Trying to delete non-existing item at index", i)); - } -} - + m_tracks.clear(); } void BookmarkCategory::DeleteTrack(size_t index) { - DeleteItem(m_tracks, index); + RequestController(); + SetDirty(); + ASSERT_LESS(index, m_tracks.size(), ()); + m_tracks.erase(next(m_tracks.begin(), index)); + ReleaseController(); } namespace @@ -307,7 +302,10 @@ namespace { m2::PointD pt; if (ParsePoint(*cortegeIter, coordSeparator, pt)) - m_points.Add(pt); + { + if (m_points.GetSize() == 0 || !(pt - m_points.Back()).IsAlmostZero()) + m_points.Add(pt); + } ++cortegeIter; } } @@ -417,14 +415,12 @@ namespace } else if (GEOMETRY_TYPE_LINE == m_geometryType) { - Track track(m_points); - track.SetName(m_name); - - Track::TrackOutline trackOutline { 5.0f, m_trackColor }; - track.AddOutline(&trackOutline, 1); + Track::Params params; + params.m_colors.push_back({ 5.0f, m_trackColor }); + params.m_name = m_name; /// @todo Add description, style, timestamp - m_category.AddTrack(track); + m_category.AddTrack(make_unique(m_points, params)); } } Reset(); @@ -710,7 +706,7 @@ void BookmarkCategory::SaveToKML(ostream & s) // GetBookmarksCount() - 1, i.e. to the last bookmark in the // bookmarks list. for (size_t count = 0, i = GetUserMarkCount() - 1; - count < GetUserMarkCount(); ++count, --i) + count < GetUserPointCount(); ++count, --i) { Bookmark const * bm = static_cast(GetUserMark(i)); s << " \n"; @@ -758,8 +754,10 @@ void BookmarkCategory::SaveToKML(ostream & s) SaveStringWithCDATA(s, track->GetName()); s << "\n"; + ASSERT_GREATER(track->GetLayerCount(), 0, ()); + s << "\n"; diff --git a/map/bookmark.hpp b/map/bookmark.hpp index f813d72c46..da5a4ec4e3 100644 --- a/map/bookmark.hpp +++ b/map/bookmark.hpp @@ -115,11 +115,7 @@ private: class BookmarkCategory : public UserMarkContainer { typedef UserMarkContainer TBase; - /// @name Data - //@{ - /// TODO move track into UserMarkContainer as a IDrawable custom data - vector m_tracks; - //@} + vector> m_tracks; string m_name; /// Stores file name from which category was loaded @@ -149,14 +145,18 @@ public: BookmarkCategory(string const & name, Framework & framework); ~BookmarkCategory(); + ////////////////////////////////////////////////////////////////////// + size_t GetUserLineCount() const override; + df::UserLineMark const * GetUserLineMark(size_t index) const override; + ////////////////////////////////////////////////////////////////////// + static string GetDefaultType(); void ClearTracks(); /// @name Tracks routine. //@{ - /// @note Move semantics is used here. - void AddTrack(Track & track); + void AddTrack(unique_ptr && track); Track const * GetTrack(size_t index) const; inline size_t GetTracksCount() const { return m_tracks.size(); } void DeleteTrack(size_t index); diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 6c0a120ff0..b917b65218 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -234,10 +234,9 @@ void BookmarkManager::UserMarksReleaseController(UserMarksController & controlle FindUserMarksContainer(controller.GetType())->ReleaseController(); } -void BookmarkManager::SetRouteTrack(RouteTrack & track) +void BookmarkManager::SetRouteTrack(unique_ptr && track) { - m_routeTrack.reset(); - m_routeTrack.reset(track.CreatePersistent()); + m_routeTrack = move(track); } void BookmarkManager::ResetRouteTrack() diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index 02e258231c..b44278ef5a 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -661,7 +661,8 @@ UNIT_TEST(TrackParsingTest_1) Track const * track = cat->GetTrack(i); TEST_EQUAL(names[i], track->GetName(), ()); TEST(fabs(track->GetLengthMeters() - length[i]) < 1.0E-6, (track->GetLengthMeters(), length[i])); - TEST_EQUAL(col[i], track->GetMainColor(), ()); + TEST_GREATER(track->GetLayerCount(), 0, ()); + TEST_EQUAL(col[i], track->GetColor(0), ()); } } @@ -675,6 +676,7 @@ UNIT_TEST(TrackParsingTest_2) TEST_EQUAL(cat->GetTracksCount(), 1, ()); Track const * track = cat->GetTrack(0); TEST_EQUAL(track->GetName(), "XY", ()); - TEST_EQUAL(track->GetMainColor(), dp::Color(57, 255, 32, 255), ()); + TEST_GREATER(track->GetLayerCount(), 0, ()); + TEST_EQUAL(track->GetColor(0), dp::Color(57, 255, 32, 255), ()); } diff --git a/map/route_track.cpp b/map/route_track.cpp index 1030186d45..ef6434953b 100644 --- a/map/route_track.cpp +++ b/map/route_track.cpp @@ -169,11 +169,6 @@ bool MergeArrows(vector & ptsCurrentTurn, vector const & } } -RouteTrack::~RouteTrack() -{ - DeleteClosestSegmentDisplayList(); -} - /* void RouteTrack::CreateDisplayListArrows(graphics::Screen * dlScreen, MatrixT const & matrix, double visualScale) const { @@ -291,13 +286,6 @@ void RouteTrack::CreateDisplayListArrows(graphics::Screen * dlScreen, MatrixT co // dlScreen->endFrame(); //} -RouteTrack * RouteTrack::CreatePersistent() -{ - RouteTrack * p = new RouteTrack(); - Swap(*p); - return p; -} - void RouteTrack::DeleteClosestSegmentDisplayList() const { // delete m_closestSegmentDL; @@ -335,25 +323,3 @@ void RouteTrack::AddClosingSymbol(bool isBeginSymbol, string const & symbolName, // for_each(m_endSymbols.begin(), m_endSymbols.end(), symDrawer); // } //} - -void RouteTrack::Swap(RouteTrack & rhs) -{ -// Track::Swap(rhs); -// swap(m_beginSymbols, rhs.m_beginSymbols); -// swap(m_endSymbols, rhs.m_endSymbols); -// m_turnsGeom.swap(rhs.m_turnsGeom); - -// rhs.m_relevantMatchedInfo.Reset(); -// m_relevantMatchedInfo.Reset(); -} - -//void RouteTrack::CleanUp() const -//{ -// Track::CleanUp(); -// DeleteClosestSegmentDisplayList(); -//} - -//bool RouteTrack::HasDisplayLists() const -//{ -// return Track::HasDisplayLists() && m_closestSegmentDL != nullptr; -//} diff --git a/map/route_track.hpp b/map/route_track.hpp index ba4fe9a222..f441f773ff 100644 --- a/map/route_track.hpp +++ b/map/route_track.hpp @@ -9,19 +9,8 @@ class RouteTrack : public Track { - RouteTrack & operator=(RouteTrack const &) = delete; - RouteTrack(RouteTrack const &) = delete; public: - RouteTrack() {} - explicit RouteTrack(PolylineD const & polyline) : Track(polyline) {} - virtual ~RouteTrack(); -// virtual void CreateDisplayList(graphics::Screen * dlScreen, MatrixT const & matrix, bool isScaleChanged, -// int drawScale, double visualScale, -// location::RouteMatchingInfo const & matchingInfo) const; -// virtual void Draw(graphics::Screen * pScreen, MatrixT const & matrix) const; - virtual RouteTrack * CreatePersistent(); -// virtual void CleanUp() const; -// virtual bool HasDisplayLists() const; + explicit RouteTrack(PolylineD const & polyline) : Track(polyline, Params()) {} void AddClosingSymbol(bool isBeginSymbol, string const & symbolName, dp::Anchor pos, double depth); @@ -29,13 +18,7 @@ public: void SetArrowColor(graphics::Color color) { m_arrowColor = color; } private: - //void CreateDisplayListSymbols(graphics::Screen * dlScreen, PointContainerT const & pts) const; - - //void CreateDisplayListArrows(graphics::Screen * dlScreen, MatrixT const & matrix, double visualScale) const; void DeleteClosestSegmentDisplayList() const; - //bool HasClosestSegmentDisplayList() const { return m_closestSegmentDL != nullptr; } - //void SetClosestSegmentDisplayList(graphics::DisplayList * dl) const { m_closestSegmentDL = dl; } - void Swap(RouteTrack & rhs); struct ClosingSymbol { @@ -50,8 +33,6 @@ private: vector m_endSymbols; mutable location::RouteMatchingInfo m_relevantMatchedInfo; - /// @TODO UVR - //mutable graphics::DisplayList * m_closestSegmentDL = nullptr; }; bool ClipArrowBodyAndGetArrowDirection(vector & ptsTurn, pair & arrowDirection, diff --git a/map/track.cpp b/map/track.cpp index 8ca8096a91..c2ae2e1aa2 100644 --- a/map/track.cpp +++ b/map/track.cpp @@ -3,104 +3,26 @@ #include "indexer/mercator.hpp" #include "drape/color.hpp" -#include "drape/drape_global.hpp" -#include "geometry/distance.hpp" -#include "geometry/simplification.hpp" #include "geometry/distance_on_sphere.hpp" -#include "base/timer.hpp" -#include "base/logging.hpp" - -#include "platform/location.hpp" - - -Track::~Track() +Track::Track(Track::PolylineD const & polyline, Track::Params const & p) + : m_polyline(polyline) + , m_params(p) { - ///@TODO UVR - //DeleteDisplayList(); + ASSERT_GREATER(m_polyline.GetSize(), 1, ()); } -Track * Track::CreatePersistent() +string const & Track::GetName() const { - Track * p = new Track(); - Swap(*p); - return p; + return m_params.m_name; } -float Track::GetMainWidth() const +m2::RectD const & Track::GetLimitRect() const { - ASSERT(!m_outlines.empty(), ()); - return m_outlines.back().m_lineWidth; + return m_polyline.GetLimitRect(); } -dp::Color const & Track::GetMainColor() const -{ - ASSERT(!m_outlines.empty(), ()); - return m_outlines.back().m_color; -} - -///@TODO UVR -//void Track::DeleteDisplayList() const -//{ -// if (m_dList) -// { -// delete m_dList; -// m_dList = nullptr; -// } -//} - -void Track::AddOutline(TrackOutline const * outline, size_t arraySize) -{ - m_outlines.reserve(m_outlines.size() + arraySize); - for_each(outline, outline + arraySize, MakeBackInsertFunctor(m_outlines)); - sort(m_outlines.begin(), m_outlines.end(), [] (TrackOutline const & l, TrackOutline const & r) - { - return l.m_lineWidth > r.m_lineWidth; - }); -} - -///@TODO UVR -//void Track::Draw(graphics::Screen * pScreen, MatrixT const & matrix) const -//{ -// pScreen->drawDisplayList(m_dList, matrix); -//} - -///@TODO UVR -//void Track::CreateDisplayListPolyline(graphics::Screen * dlScreen, PointContainerT const & pts) const -//{ -// double baseDepthTrack = graphics::tracksDepth - 10 * m_outlines.size(); -// for (TrackOutline const & outline : m_outlines) -// { -// graphics::Pen::Info const outlineInfo(outline.m_color, outline.m_lineWidth); -// uint32_t const outlineId = dlScreen->mapInfo(outlineInfo); -// dlScreen->drawPath(pts.data(), pts.size(), 0, outlineId, baseDepthTrack); -// baseDepthTrack += 10; -// } -//} - -///@TODO UVR -//void Track::CreateDisplayList(graphics::Screen * dlScreen, MatrixT const & matrix, bool isScaleChanged, -// int, double, location::RouteMatchingInfo const &) const -//{ -// if (HasDisplayLists() && !isScaleChanged) -// return; - -// DeleteDisplayList(); - -// m_dList = dlScreen->createDisplayList(); -// dlScreen->beginFrame(); -// dlScreen->setDisplayList(m_dList); - -// PointContainerT pts; -// pts.reserve(m_polyline.GetSize()); -// TransformAndSymplifyPolyline(m_polyline, matrix, GetMainWidth(), pts); -// CreateDisplayListPolyline(dlScreen, pts); - -// dlScreen->setDisplayList(0); -// dlScreen->endFrame(); -//} - double Track::GetLengthMeters() const { double res = 0.0; @@ -120,39 +42,32 @@ double Track::GetLengthMeters() const return res; } -void Track::Swap(Track & rhs) +size_t Track::GetLayerCount() const { - ///@TODO UVR - //swap(m_rect, rhs.m_rect); - //swap(m_outlines, rhs.m_outlines); - //m_name.swap(rhs.m_name); - //m_polyline.Swap(rhs.m_polyline); - - //DeleteDisplayList(); - //rhs.DeleteDisplayList(); + return m_params.m_colors.size(); } -///@TODO UVR -//void Track::CleanUp() const -//{ -// DeleteDisplayList(); -//} - -//bool Track::HasDisplayLists() const -//{ -// return m_dList != nullptr; -//} - -void TransformPolyline(Track::PolylineD const & polyline, MatrixT const & matrix, PointContainerT & pts) +dp::Color const & Track::GetColor(size_t layerIndex) const { - pts.resize(polyline.GetSize()); - transform(polyline.Begin(), polyline.End(), pts.begin(), DoLeftProduct(matrix)); + return m_params.m_colors[layerIndex].m_color; } -void TransformAndSymplifyPolyline(Track::PolylineD const & polyline, MatrixT const & matrix, double width, PointContainerT & pts) +float Track::GetWidth(size_t layerIndex) const { - PointContainerT pts1(polyline.GetSize()); - TransformPolyline(polyline, matrix, pts1); - SimplifyDP(pts1.begin(), pts1.end(), width, - m2::DistanceToLineSquare(), MakeBackInsertFunctor(pts)); + return m_params.m_colors[layerIndex].m_lineWidth; +} + +float Track::GetLayerDepth(size_t layerIndex) const +{ + return 0 + layerIndex * 10; +} + +size_t Track::GetPointCount() const +{ + return m_polyline.GetSize(); +} + +m2::PointD const & Track::GetPoint(size_t pointIndex) const +{ + return m_polyline.GetPoint(pointIndex); } diff --git a/map/track.hpp b/map/track.hpp index 3ebd0865ef..14b1cba913 100644 --- a/map/track.hpp +++ b/map/track.hpp @@ -1,64 +1,24 @@ #pragma once -#include "drape/drape_global.hpp" +#include "drape_frontend/user_marks_provider.hpp" #include "drape/color.hpp" #include "geometry/polyline2d.hpp" -#include "geometry/screenbase.hpp" - -#include "std/noncopyable.hpp" #include "base/buffer_vector.hpp" +#include "base/macros.hpp" - -class Navigator; namespace location { class RouteMatchingInfo; } -template class DoLeftProduct +class Track : public df::UserLineMark { - T const & m_t; + DISALLOW_COPY_AND_MOVE(Track) + public: - DoLeftProduct(T const & t) : m_t(t) {} - template X operator() (X const & x) const { return x * m_t; } -}; - -typedef math::Matrix MatrixT; -typedef buffer_vector PointContainerT; - -class Track : private noncopyable -{ -public: - typedef m2::PolylineD PolylineD; - - Track() {} - virtual ~Track(); - - explicit Track(PolylineD const & polyline) - : m_polyline(polyline) - { - ASSERT_GREATER(polyline.GetSize(), 1, ()); - - m_rect = m_polyline.GetLimitRect(); - } - - /// @note Move semantics is used here. - virtual Track * CreatePersistent(); - float GetMainWidth() const; - dp::Color const & GetMainColor() const; - - - /// @TODO UVR - //virtual void Draw(graphics::Screen * pScreen, MatrixT const & matrix) const; - //virtual void CreateDisplayList(graphics::Screen * dlScreen, MatrixT const & matrix, bool isScaleChanged, - // int, double, location::RouteMatchingInfo const &) const; - //virtual void CleanUp() const; - //virtual bool HasDisplayLists() const; - - /// @name Simple Getters-Setter - //@{ + using PolylineD = m2::PolylineD; struct TrackOutline { @@ -66,35 +26,29 @@ public: dp::Color m_color; }; - void AddOutline(TrackOutline const * outline, size_t arraySize); + struct Params + { + buffer_vector m_colors; + string m_name; + }; - string const & GetName() const { return m_name; } - void SetName(string const & name) { m_name = name; } + explicit Track(PolylineD const & polyline, Params const & p); + string const & GetName() const; PolylineD const & GetPolyline() const { return m_polyline; } - m2::RectD const & GetLimitRect() const { return m_rect; } - //@} + m2::RectD const & GetLimitRect() const; double GetLengthMeters() const; -protected: -/// @TODO UVR -// graphics::DisplayList * GetDisplayList() const { return m_dList; } -// void SetDisplayList(graphics::DisplayList * dl) const { m_dList = dl; } -// void CreateDisplayListPolyline(graphics::Screen * dlScreen, PointContainerT const & pts2) const; - void Swap(Track & rhs); -// void DeleteDisplayList() const; + size_t GetLayerCount() const override; + dp::Color const & GetColor(size_t layerIndex) const override; + float GetWidth(size_t layerIndex) const override; + float GetLayerDepth(size_t layerIndex) const override; + + /// Line geometry enumeration + size_t GetPointCount() const override; + m2::PointD const & GetPoint(size_t pointIndex) const override; private: - string m_name; - - vector m_outlines; PolylineD m_polyline; - m2::RectD m_rect; - - ///@TODO UVR - //mutable graphics::DisplayList * m_dList = nullptr; + Params m_params; }; - -void TransformPolyline(Track::PolylineD const & polyline, MatrixT const & matrix, PointContainerT & pts); -void TransformAndSymplifyPolyline(Track::PolylineD const & polyline, MatrixT const & matrix, - double width, PointContainerT & pts); diff --git a/map/user_mark_container.cpp b/map/user_mark_container.cpp index 9e87840f98..de97a6499c 100644 --- a/map/user_mark_container.cpp +++ b/map/user_mark_container.cpp @@ -148,16 +148,16 @@ void UserMarkContainer::ReleaseController() if (IsDirty()) { - if (GetUserMarkCount() == 0) + if (GetUserPointCount() == 0 && GetUserLineCount() == 0) engine->ClearUserMarksLayer(key); else engine->UpdateUserMarksLayer(key, this); } } -size_t UserMarkContainer::GetPointCount() const +size_t UserMarkContainer::GetUserPointCount() const { - return GetUserMarkCount(); + return m_userMarks.size(); } df::UserPointMark const * UserMarkContainer::GetUserPointMark(size_t index) const @@ -165,7 +165,7 @@ df::UserPointMark const * UserMarkContainer::GetUserPointMark(size_t index) cons return GetUserMark(index); } -size_t UserMarkContainer::GetLineCount() const +size_t UserMarkContainer::GetUserLineCount() const { return 0; } @@ -201,7 +201,7 @@ UserMark * UserMarkContainer::CreateUserMark(m2::PointD const & ptOrg) size_t UserMarkContainer::GetUserMarkCount() const { - return m_userMarks.size(); + return GetUserPointCount(); } UserMark const * UserMarkContainer::GetUserMark(size_t index) const diff --git a/map/user_mark_container.hpp b/map/user_mark_container.hpp index 9eccb34e21..cab51d1a93 100644 --- a/map/user_mark_container.hpp +++ b/map/user_mark_container.hpp @@ -64,10 +64,10 @@ public: //////////////////////////////////////////////////////////// /// Render info - virtual size_t GetPointCount() const; + virtual size_t GetUserPointCount() const; virtual df::UserPointMark const * GetUserPointMark(size_t index) const; - virtual size_t GetLineCount() const; + virtual size_t GetUserLineCount() const; virtual df::UserLineMark const * GetUserLineMark(size_t index) const; //////////////////////////////////////////////////////////// diff --git a/std/iterator.hpp b/std/iterator.hpp index 6fb9c08133..d72f99eed1 100644 --- a/std/iterator.hpp +++ b/std/iterator.hpp @@ -6,6 +6,7 @@ #include +using std::advance; using std::back_insert_iterator; using std::back_inserter; using std::begin; @@ -14,9 +15,8 @@ using std::end; using std::insert_iterator; using std::istream_iterator; using std::iterator_traits; +using std::next; using std::reverse_iterator; -using std::begin; -using std::end; #ifdef DEBUG_NEW #define new DEBUG_NEW