Moved tesselator from indexer_tool to geometry

This commit is contained in:
Alex Zolotarev 2011-01-28 18:51:27 +02:00 committed by Alex Zolotarev
parent 0a193f6121
commit 7bf7b8ac91
5 changed files with 73 additions and 19 deletions

View file

@ -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 \

View file

@ -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<m2::PointD> points_t;
void TesselateInterior( points_t const & bound, list<points_t> 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<points_t>::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));

View file

@ -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<m2::PointD> points_t;
void TesselateInterior(points_t const & bound, list<points_t> 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<points_t> const & holes = fb.GetHoles();
tesselator::holes_container const & holes = fb.GetHoles();
if (holes.empty() && holder.TryToMakeStrip(points))
continue;
list<points_t> simpleHoles;
for (list<points_t>::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);

View file

@ -21,7 +21,6 @@ SOURCES += \
data_generator.cpp \
feature_generator.cpp \
feature_sorter.cpp \
tesselator.cpp \
update_generator.cpp \
grid_generator.cpp \
statistics.cpp \

View file

@ -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<m2::PointD> points_t;
void TesselateInterior(points_t const & bound, list<points_t> const & holes,
points_t & triangles);
}
namespace kml
{
typedef vector<Region> PolygonsContainerT;
@ -86,6 +96,39 @@ namespace kml
}
};
m2::PointU MercatorPointToPointU(m2::PointD const & pt)
{
typedef CellIdConverter<MercatorBounds, RectId> CellIdConverterType;
uint32_t const ix = static_cast<uint32_t>(CellIdConverterType::XToCellIdX(pt.x));
uint32_t const iy = static_cast<uint32_t>(CellIdConverterType::YToCellIdY(pt.y));
return m2::PointU(ix, iy);
}
class AreaFeature : public FeatureType
{
public:
template <class IterT>
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<feature::points_t> 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<int64_t> ids;
// ids = covering::CoverFeature(ft, -1);
// // debug output
// set<int64_t> 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)
{