diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2017-08-05 15:01:46 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2017-08-07 15:11:09 +0300 |
commit | 26f348e47f45ebaa2a3def023d84b105ad8600c2 (patch) | |
tree | 38f8dae145e78beb3b5fcf17bb3773c8d616f61d /mapshot | |
parent | 0cb5cd6f0d7a875e6b71ad02a4da76ec403de8e6 (diff) |
Moved obsolete watch renderer to own library
Diffstat (limited to 'mapshot')
-rw-r--r-- | mapshot/CMakeLists.txt | 57 | ||||
-rw-r--r-- | mapshot/mapshot.cpp | 114 | ||||
-rw-r--r-- | mapshot/mapshot.pro | 8 |
3 files changed, 161 insertions, 18 deletions
diff --git a/mapshot/CMakeLists.txt b/mapshot/CMakeLists.txt new file mode 100644 index 0000000000..55c2eefaaa --- /dev/null +++ b/mapshot/CMakeLists.txt @@ -0,0 +1,57 @@ +project(mapshot_tool) + +include_directories( + . + ${OMIM_ROOT}/3party/glm + ${OMIM_ROOT}/3party/gflags/src +) + +set( + SRC + mapshot.cpp +) + +omim_add_executable(${PROJECT_NAME} ${SRC}) + +omim_link_libraries( + ${PROJECT_NAME} + map + software_renderer + drape_frontend + routing + search + storage + tracking + traffic + routing_common + ugc + indexer + drape + partners_api + local_ads + platform + editor + geometry + coding + base + freetype + expat + gflags + icu + agg + jansson + protobuf + osrm + stats_client + minizip + succinct + pugixml + oauthcpp + opening_hours + stb_image + sdf_image + ${LIBZ} +) + +link_opengl(${PROJECT_NAME}) +link_qt5_core(${PROJECT_NAME}) diff --git a/mapshot/mapshot.cpp b/mapshot/mapshot.cpp index 90035447b2..1f9aae1d62 100644 --- a/mapshot/mapshot.cpp +++ b/mapshot/mapshot.cpp @@ -1,5 +1,11 @@ #include "map/framework.hpp" +#include "software_renderer/cpu_drawer.hpp" +#include "software_renderer/feature_processor.hpp" +#include "software_renderer/frame_image.hpp" + +#include "drape_frontend/visual_params.hpp" + #include "geometry/mercator.hpp" #include "base/string_utils.hpp" @@ -52,31 +58,110 @@ Place ParsePlace(string const & src) return p; } +string FilenameSeq(string const & path) +{ + static size_t counter = 0; + stringstream filename; + filename << path << "mapshot" << setw(6) << setfill('0') << counter++ << ".png"; + return filename.str(); +} + +unique_ptr<software_renderer::CPUDrawer> cpuDrawer; + +bool IsFrameRendererInitialized() +{ + return cpuDrawer != nullptr; +} + +void InitFrameRenderer(float visualScale) +{ + using namespace software_renderer; + + if (cpuDrawer == nullptr) + { + string resPostfix = df::VisualParams::GetResourcePostfix(visualScale); + cpuDrawer = make_unique_dp<CPUDrawer>(CPUDrawer::Params(resPostfix, visualScale)); + } +} + +void ReleaseFrameRenderer() +{ + if (IsFrameRendererInitialized()) + cpuDrawer.reset(); +} + +/// @param center - map center in Mercator +/// @param zoomModifier - result zoom calculate like "base zoom" + zoomModifier +/// if we are have search result "base zoom" calculate that my position and search result +/// will be see with some bottom clamp. +/// if we are't have search result "base zoom" == scales::GetUpperComfortScale() - 1 +/// @param pxWidth - result image width. +/// It must be equal render buffer width. For retina it's equal 2.0 * displayWidth +/// @param pxHeight - result image height. +/// It must be equal render buffer height. For retina it's equal 2.0 * displayHeight +/// @param symbols - configuration for symbols on the frame +/// @param image [out] - result image +void DrawFrame(Framework & framework, + m2::PointD const & center, int zoomModifier, + uint32_t pxWidth, uint32_t pxHeight, + software_renderer::FrameSymbols const & symbols, + software_renderer::FrameImage & image) +{ + ASSERT(IsFrameRendererInitialized(), ()); + + int resultZoom = -1; + ScreenBase screen = cpuDrawer->CalculateScreen(center, zoomModifier, pxWidth, pxHeight, symbols, resultZoom); + ASSERT_GREATER(resultZoom, 0, ()); + + uint32_t const bgColor = drule::rules().GetBgColor(resultZoom); + cpuDrawer->BeginFrame(pxWidth, pxHeight, dp::Extract(bgColor, 255 - (bgColor >> 24))); + + m2::RectD renderRect = m2::RectD(0, 0, pxWidth, pxHeight); + m2::RectD selectRect; + m2::RectD clipRect; + double const inflationSize = 24 * cpuDrawer->GetVisualScale(); + screen.PtoG(m2::Inflate(renderRect, inflationSize, inflationSize), clipRect); + screen.PtoG(renderRect, selectRect); + + uint32_t const tileSize = static_cast<uint32_t>(df::CalculateTileSize(pxWidth, pxHeight)); + int const drawScale = df::GetDrawTileScale(screen, tileSize, cpuDrawer->GetVisualScale()); + software_renderer::FeatureProcessor doDraw(make_ref(cpuDrawer), clipRect, screen, drawScale); + + int const upperScale = scales::GetUpperScale(); + + framework.GetIndex().ForEachInRect(doDraw, selectRect, min(upperScale, drawScale)); + + cpuDrawer->Flush(); + //cpuDrawer->DrawMyPosition(screen.GtoP(center)); + + if (symbols.m_showSearchResult) + { + if (!screen.PixelRect().IsPointInside(screen.GtoP(symbols.m_searchResult))) + cpuDrawer->DrawSearchArrow(ang::AngleTo(center, symbols.m_searchResult)); + else + cpuDrawer->DrawSearchResult(screen.GtoP(symbols.m_searchResult)); + } + + cpuDrawer->EndFrame(image); +} + void RenderPlace(Framework & framework, Place const & place, string const & filename) { - df::watch::FrameImage frame; - df::watch::FrameSymbols sym; + software_renderer::FrameImage frame; + software_renderer::FrameSymbols sym; sym.m_showSearchResult = false; // If you are interested why, look at CPUDrawer::CalculateScreen. // It is almost UpperComfortScale but there is some magic involved. int constexpr kMagicBaseScale = 17; - framework.DrawWatchFrame(MercatorBounds::FromLatLon(place.lat, place.lon), place.zoom - kMagicBaseScale, - place.width, place.height, sym, frame); + DrawFrame(framework, MercatorBounds::FromLatLon(place.lat, place.lon), + place.zoom - kMagicBaseScale, place.width, place.height, sym, frame); ofstream file(filename.c_str()); file.write(reinterpret_cast<char const *>(frame.m_data.data()), frame.m_data.size()); file.close(); } - -string FilenameSeq(string const & path) -{ - static size_t counter = 0; - stringstream filename; - filename << path << "mapshot" << setw(6) << setfill('0') << counter++ << ".png"; - return filename.str(); -} } // namespace int main(int argc, char * argv[]) @@ -114,7 +199,7 @@ int main(int argc, char * argv[]) // This magic constant was determined in several attempts. // It is a scale level, basically, dpi factor. 1 means 90 or 96, it seems, // and with 1.1 the map looks subjectively better. - f.InitWatchFrameRenderer(1.1 /* visualScale */); + InitFrameRenderer(1.1 /* visualScale */); if (!FLAGS_place.empty()) processPlace(FLAGS_place); @@ -125,11 +210,12 @@ int main(int argc, char * argv[]) processPlace(line); } - f.ReleaseWatchFrameRenderer(); + ReleaseFrameRenderer(); return 0; } catch (exception & e) { + ReleaseFrameRenderer(); cerr << e.what() << endl; } return 1; diff --git a/mapshot/mapshot.pro b/mapshot/mapshot.pro index 2ca6b64693..d4cc968064 100644 --- a/mapshot/mapshot.pro +++ b/mapshot/mapshot.pro @@ -1,10 +1,10 @@ # mapshot binary ROOT_DIR = .. -DEPENDENCIES = map drape_frontend routing search storage tracking traffic routing_common ugc indexer \ - drape partners_api local_ads platform editor geometry coding base \ - freetype expat gflags jansson protobuf osrm stats_client minizip succinct \ - pugixml opening_hours stb_image sdf_image icu +DEPENDENCIES = map drape_frontend software_renderer routing search storage tracking traffic \ + routing_common ugc indexer drape partners_api local_ads platform editor geometry \ + coding base freetype expat gflags jansson protobuf osrm stats_client minizip succinct \ + pugixml opening_hours stb_image sdf_image icu agg include($$ROOT_DIR/common.pri) |