From 7bf7b8ac9138687ea4f3da43431b3747a74a11f2 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Fri, 28 Jan 2011 18:51:27 +0200 Subject: [PATCH] Moved tesselator from indexer_tool to geometry --- geometry/geometry.pro | 2 + .../indexer_tool => geometry}/tesselator.cpp | 14 ++--- indexer/indexer_tool/feature_sorter.cpp | 18 +++--- indexer/indexer_tool/indexer_tool.pro | 1 - indexer/indexer_tool/kml_parser.cpp | 57 +++++++++++++++++++ 5 files changed, 73 insertions(+), 19 deletions(-) rename {indexer/indexer_tool => geometry}/tesselator.cpp (80%) diff --git a/geometry/geometry.pro b/geometry/geometry.pro index 1181efbe46..13606ae28e 100644 --- a/geometry/geometry.pro +++ b/geometry/geometry.pro @@ -12,6 +12,7 @@ include($$ROOT_DIR/common.pri) SOURCES += \ screenbase.cpp \ packer.cpp \ + tesselator.cpp \ HEADERS += \ rect2d.hpp \ @@ -30,3 +31,4 @@ HEADERS += \ tree4d.hpp \ polygon.hpp \ region2d.hpp \ + tesselator.hpp \ diff --git a/indexer/indexer_tool/tesselator.cpp b/geometry/tesselator.cpp similarity index 80% rename from indexer/indexer_tool/tesselator.cpp rename to geometry/tesselator.cpp index da344d0bd5..67819579a8 100644 --- a/indexer/indexer_tool/tesselator.cpp +++ b/geometry/tesselator.cpp @@ -1,10 +1,10 @@ -#include "../../base/SRC_FIRST.hpp" +#include "tesselator.hpp" -#include "../cell_id.hpp" +#include "../base/assert.hpp" #include "../../3party/sgitess/interface.h" -namespace feature +namespace tesselator { struct AddTessPointF { @@ -17,10 +17,8 @@ namespace feature } }; - typedef vector points_t; - - void TesselateInterior( points_t const & bound, list const & holes, - points_t & triangles) + void TesselateInterior(points_container const & bound, holes_container const & holes, + points_container & triangles) { tess::VectorDispatcher disp; tess::Tesselator tess; @@ -33,7 +31,7 @@ namespace feature for_each(bound.begin(), bound.end(), AddTessPointF(tess)); tess.endContour(); - for (list::const_iterator it = holes.begin(); it != holes.end(); ++it) + for (holes_container::const_iterator it = holes.begin(); it != holes.end(); ++it) { tess.beginContour(); for_each(it->begin(), it->end(), AddTessPointF(tess)); diff --git a/indexer/indexer_tool/feature_sorter.cpp b/indexer/indexer_tool/feature_sorter.cpp index b1f2788f91..a0dc6dfd89 100644 --- a/indexer/indexer_tool/feature_sorter.cpp +++ b/indexer/indexer_tool/feature_sorter.cpp @@ -10,6 +10,7 @@ #include "../../indexer/cell_id.hpp" #include "../../geometry/polygon.hpp" +#include "../../geometry/tesselator.hpp" #include "../../platform/platform.hpp" @@ -71,9 +72,6 @@ namespace namespace feature { - typedef vector points_t; - void TesselateInterior(points_t const & bound, list const & holes, points_t & triangles); - class FeaturesCollector2 : public FeaturesCollector { FilesContainerW m_writer; @@ -303,7 +301,7 @@ namespace feature if (fb.IsDrawableInRange(i > 0 ? g_arrScales[i-1] + 1 : 0, g_arrScales[i])) { // simplify and serialize geometry - points_t points; + tesselator::points_container points; SimplifyPoints(holder.GetSourcePoints(), points, g_arrScales[i]); if (isLine) @@ -313,15 +311,15 @@ namespace feature { // simplify and serialize triangles - list const & holes = fb.GetHoles(); + tesselator::holes_container const & holes = fb.GetHoles(); if (holes.empty() && holder.TryToMakeStrip(points)) continue; - list simpleHoles; - for (list::const_iterator iH = holes.begin(); iH != holes.end(); ++iH) + tesselator::holes_container simpleHoles; + for (tesselator::holes_container::const_iterator iH = holes.begin(); iH != holes.end(); ++iH) { - simpleHoles.push_back(points_t()); + simpleHoles.push_back(tesselator::points_container()); SimplifyPoints(*iH, simpleHoles.back(), g_arrScales[i]); @@ -329,8 +327,8 @@ namespace feature simpleHoles.pop_back(); } - points_t triangles; - feature::TesselateInterior(points, simpleHoles, triangles); + tesselator::points_container triangles; + tesselator::TesselateInterior(points, simpleHoles, triangles); if (!triangles.empty()) holder.AddTriangles(triangles, i); diff --git a/indexer/indexer_tool/indexer_tool.pro b/indexer/indexer_tool/indexer_tool.pro index 84cb89caa6..eb214ee7b9 100644 --- a/indexer/indexer_tool/indexer_tool.pro +++ b/indexer/indexer_tool/indexer_tool.pro @@ -21,7 +21,6 @@ SOURCES += \ data_generator.cpp \ feature_generator.cpp \ feature_sorter.cpp \ - tesselator.cpp \ update_generator.cpp \ grid_generator.cpp \ statistics.cpp \ diff --git a/indexer/indexer_tool/kml_parser.cpp b/indexer/indexer_tool/kml_parser.cpp index 891553c1d0..8ed7db55c2 100644 --- a/indexer/indexer_tool/kml_parser.cpp +++ b/indexer/indexer_tool/kml_parser.cpp @@ -8,9 +8,12 @@ #include "../../coding/file_reader.hpp" #include "../../geometry/rect2d.hpp" +#include "../../geometry/cellid.hpp" #include "../../indexer/cell_id.hpp" #include "../../indexer/mercator.hpp" +#include "../../indexer/feature.hpp" +#include "../../indexer/covering.hpp" #include "../../std/fstream.hpp" @@ -20,6 +23,13 @@ #define MIN_SIMPLIFIED_POINTS_COUNT 4 +namespace feature +{ + typedef vector points_t; + void TesselateInterior(points_t const & bound, list const & holes, + points_t & triangles); +} + namespace kml { typedef vector PolygonsContainerT; @@ -86,6 +96,39 @@ namespace kml } }; + m2::PointU MercatorPointToPointU(m2::PointD const & pt) + { + typedef CellIdConverter CellIdConverterType; + uint32_t const ix = static_cast(CellIdConverterType::XToCellIdX(pt.x)); + uint32_t const iy = static_cast(CellIdConverterType::YToCellIdY(pt.y)); + return m2::PointU(ix, iy); + } + + class AreaFeature : public FeatureType + { + public: + template + AreaFeature(IterT beg, IterT end) + { + // manually fill bordering geometry points + m_bPointsParsed = true; + for (IterT it = beg; it != end; ++it) + { + m_Points.push_back(*it); + m_LimitRect.Add(*it); + } + + // manually fill triangles points + m_bTrianglesParsed = true; + list const holes; + feature::points_t points(beg, end); + feature::points_t triangles; + feature::TesselateInterior(points, holes, triangles); + CHECK(!triangles.empty(), ("Tesselation unsuccessfull?")); + for (size_t i = 0; i < triangles.size(); ++i) + m_Triangles.push_back(triangles[i]); + } + }; void KmlParser::Pop(string const & element) { if (element == "Placemark") @@ -107,6 +150,20 @@ namespace kml size_t const numPoints = points.size(); if (numPoints > 3 && points[numPoints - 1] == points[0]) { +// // create feature for country's polygon +// AreaFeature ft(points.begin(), points.end()); +// // get polygon covering (cellids) +// vector ids; +// ids = covering::CoverFeature(ft, -1); +// // debug output +// set ids8; +// for (size_t i = 0; i < ids.size(); ++i) +// { +// int64_t a = ids[i] >> (2 * 11); +// if (ids8.insert(a).second) +// LOG(LINFO, (RectId::FromInt64(a).ToString())); +// } +// LOG(LINFO, ("Total cellids:", ids8.size())); // second, simplify points if necessary if (m_level > 0) {