[mapguide-commits] r9526 - sandbox/jng/mvt/Common/Renderers
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Fri May 31 07:10:44 PDT 2019
Author: jng
Date: 2019-05-31 07:10:44 -0700 (Fri, 31 May 2019)
New Revision: 9526
Modified:
sandbox/jng/mvt/Common/Renderers/MVTRenderer.cpp
sandbox/jng/mvt/Common/Renderers/MVTRenderer.h
Log:
pimpl-ize MVTRenderer so vtzero headers don't leak out to consumers
Modified: sandbox/jng/mvt/Common/Renderers/MVTRenderer.cpp
===================================================================
--- sandbox/jng/mvt/Common/Renderers/MVTRenderer.cpp 2019-05-31 13:06:39 UTC (rev 9525)
+++ sandbox/jng/mvt/Common/Renderers/MVTRenderer.cpp 2019-05-31 14:10:44 UTC (rev 9526)
@@ -18,6 +18,7 @@
#include "MVTRenderer.h"
#include "RS_FeatureReader.h"
#include "UnicodeString.h"
+#include <vtzero/builder.hpp>
// =========================== MVTRenderer overview =============================== //
//
@@ -28,7 +29,7 @@
//
// - Create a new vtzero::layer_builder instance on every StartLayer(). Push any
// current instance to the internal list for cleanup
-// - Clear and fill the internal property map on every StartFeature() call
+// - Stash the RS_FeatureReader pointer on every StartFeature() call (we need this for writing properties)
// - For every ProcessXXX() call
// - Create a vtzero::feature_builder instance
// - Write the line buffer coordinates to this builder
@@ -42,11 +43,189 @@
//
// ================================================================================ //
+struct MVTRenderer::MVTImpl {
+ MVTImpl(MVTRenderer* parent)
+ : m_tileBuilder(new vtzero::tile_builder())
+ , m_activeLayerBuilder(nullptr)
+ , m_parent(parent)
+ { }
+
+ ~MVTImpl()
+ {
+ for (auto lb : m_prevLayerBuilder)
+ {
+ delete lb;
+ }
+ m_prevLayerBuilder.clear();
+ delete m_tileBuilder;
+ }
+
+ void SetActiveLayerBuilder(const std::string& name)
+ {
+ m_activeLayerBuilder = new vtzero::layer_builder(*m_tileBuilder, name);
+ }
+
+ void ClearActiveLayerBuilder()
+ {
+ m_prevLayerBuilder.push_back(m_activeLayerBuilder);
+ m_activeLayerBuilder = nullptr;
+ }
+
+ static void AddActiveFeatureProperties(RS_FeatureReader* activeFeature, vtzero::feature_builder* builder)
+ {
+ int count;
+ auto propNames = activeFeature->GetPropNames(count);
+ for (int i = 0; i < count; i++)
+ {
+ auto name = propNames[i];
+ std::string mbName;
+ UnicodeString::WideCharToMultiByte(name, mbName);
+ auto propType = activeFeature->GetPropertyType(name);
+ switch (propType)
+ {
+ case FdoDataType_Boolean:
+ builder->add_property(mbName, vtzero::bool_value_type(activeFeature->GetBoolean(name)));
+ break;
+ case FdoDataType_Byte:
+ builder->add_property(mbName, vtzero::int_value_type(activeFeature->GetByte(name)));
+ break;
+ case FdoDataType_DateTime:
+ {
+ auto dt = activeFeature->GetAsString(name);
+ std::string sDt;
+ UnicodeString::WideCharToMultiByte(dt, sDt);
+ builder->add_property(mbName, vtzero::string_value_type(sDt));
+ break;
+ }
+ case FdoDataType_Decimal:
+ case FdoDataType_Double:
+ builder->add_property(mbName, vtzero::double_value_type(activeFeature->GetDouble(name)));
+ break;
+ case FdoDataType_Int16:
+ builder->add_property(mbName, vtzero::int_value_type(activeFeature->GetInt16(name)));
+ break;
+ case FdoDataType_Int32:
+ builder->add_property(mbName, vtzero::int_value_type(activeFeature->GetInt32(name)));
+ break;
+ case FdoDataType_Int64:
+ builder->add_property(mbName, vtzero::int_value_type(activeFeature->GetInt64(name)));
+ break;
+ case FdoDataType_Single:
+ builder->add_property(mbName, vtzero::float_value_type(activeFeature->GetSingle(name)));
+ break;
+ case FdoDataType_String:
+ {
+ auto s = activeFeature->GetString(name);
+ std::string sVal;
+ UnicodeString::WideCharToMultiByte(s, sVal);
+ builder->add_property(mbName, vtzero::string_value_type(sVal));
+ break;
+ }
+ case FdoDataType_BLOB: //Not handled
+ case FdoDataType_CLOB:
+ break;
+ }
+ }
+ }
+
+ void ProcessPolygon(RS_FeatureReader* activeFeature, LineBuffer * lb)
+ {
+ vtzero::polygon_feature_builder builder(*m_activeLayerBuilder);
+
+ if (lb->cntr_count() == 1)
+ {
+ auto numPoints = lb->point_count();
+ builder.add_ring(numPoints);
+ for (auto i = 0; i < numPoints; i++)
+ {
+ auto x = lb->x_coord(i);
+ auto y = lb->y_coord(i);
+
+ double tx;
+ double ty;
+ m_parent->WorldToScreenPoint(x, y, tx, ty);
+
+ builder.set_point(static_cast<int>(tx), static_cast<int>(ty));
+ }
+ }
+ else //MultiPolygon
+ {
+
+ }
+
+ AddActiveFeatureProperties(activeFeature, &builder);
+ builder.commit();
+ }
+
+ void ProcessPolyline(RS_FeatureReader* activeFeature, LineBuffer * lb)
+ {
+ vtzero::linestring_feature_builder builder(*m_activeLayerBuilder);
+
+ if (lb->cntr_count() == 1)
+ {
+ auto numPoints = lb->cntr_size(0);
+ auto pointOffset = lb->contour_start_point(0);
+ for (auto i = 0; i < numPoints; i++)
+ {
+ auto x = lb->x_coord(i + pointOffset);
+ auto y = lb->y_coord(i + pointOffset);
+
+ double tx;
+ double ty;
+ m_parent->WorldToScreenPoint(x, y, tx, ty);
+
+ builder.set_point(static_cast<int>(tx), static_cast<int>(ty));
+ }
+ }
+ else //MultiLineString
+ {
+
+ }
+
+ AddActiveFeatureProperties(activeFeature, &builder);
+ builder.commit();
+ }
+
+ void ProcessMarker(RS_FeatureReader* activeFeature, LineBuffer * lb)
+ {
+ vtzero::point_feature_builder builder(*m_activeLayerBuilder);
+
+ if (lb->point_count() == 1)
+ {
+ auto x = lb->x_coord(0);
+ auto y = lb->y_coord(0);
+
+ double tx;
+ double ty;
+ m_parent->WorldToScreenPoint(x, y, tx, ty);
+
+ builder.set_point(static_cast<int>(tx), static_cast<int>(ty));
+ }
+ else //MultiPoint
+ {
+
+ }
+
+ AddActiveFeatureProperties(activeFeature, &builder);
+ builder.commit();
+ }
+
+ void GetMVTContent(std::string& buffer)
+ {
+ m_tileBuilder->serialize(buffer);
+ }
+
+private:
+ vtzero::tile_builder* m_tileBuilder;
+ vtzero::layer_builder* m_activeLayerBuilder;
+ std::vector<vtzero::layer_builder*> m_prevLayerBuilder;
+ MVTRenderer* m_parent;
+};
+
const int MVT_SIZE = 4096;
MVTRenderer::MVTRenderer()
- : m_tileBuilder(new vtzero::tile_builder())
- , m_activeLayerBuilder(nullptr)
+ : m_impl(new MVTRenderer::MVTImpl(this)) //MVTImpl only stashes this pointer in its ctor, nothing is called on it yet
, m_mapInfo(nullptr)
, m_layerInfo(nullptr)
, m_fcInfo(nullptr)
@@ -57,14 +236,7 @@
}
MVTRenderer::~MVTRenderer()
-{
- for (auto lb : m_prevLayerBuilder)
- {
- delete lb;
- }
- m_prevLayerBuilder.clear();
- delete m_tileBuilder;
-}
+{ }
//Called by the stylizer when rendering is about to begin on the map
void MVTRenderer::StartMap(RS_MapUIInfo * mapInfo, RS_Bounds & extents, double mapScale, double dpi, double metersPerUnit, CSysTransformer * xformToLL)
@@ -122,7 +294,7 @@
std::string name;
UnicodeString::WideCharToMultiByte(m_layerInfo->name().c_str(), name);
- m_activeLayerBuilder = new vtzero::layer_builder(*m_tileBuilder, name);
+ m_impl->SetActiveLayerBuilder(name);
}
//Called by the stylizer when rendering is about to begin on the map for the layer indicated by StartLayer()
@@ -132,8 +304,7 @@
m_layerInfo = nullptr;
m_fcInfo = nullptr;
- m_prevLayerBuilder.push_back(m_activeLayerBuilder);
- m_activeLayerBuilder = nullptr;
+ m_impl->ClearActiveLayerBuilder();
}
//Called by the stylizer when rendering is about to begin on the map for the given feature
@@ -145,61 +316,13 @@
//Entry point for polygon rendering. Perform any pre-rendering operations.
void MVTRenderer::ProcessPolygon(LineBuffer * lb, RS_FillStyle & fill)
{
- vtzero::polygon_feature_builder builder(*m_activeLayerBuilder);
-
- if (lb->cntr_count() == 1)
- {
- auto numPoints = lb->point_count();
- builder.add_ring(numPoints);
- for (auto i = 0; i < numPoints; i++)
- {
- auto x = lb->x_coord(i);
- auto y = lb->y_coord(i);
-
- double tx;
- double ty;
- WorldToScreenPoint(x, y, tx, ty);
-
- builder.set_point(static_cast<int>(tx), static_cast<int>(ty));
- }
- }
- else //MultiPolygon
- {
-
- }
-
- AddActiveFeatureProperties(&builder);
- builder.commit();
+ m_impl->ProcessPolygon(m_activeFeature, lb);
}
//Entry point for polyline rendering. Perform any pre-rendering operations.
void MVTRenderer::ProcessPolyline(LineBuffer * lb, RS_LineStroke & lsym)
{
- vtzero::linestring_feature_builder builder(*m_activeLayerBuilder);
-
- if (lb->cntr_count() == 1)
- {
- auto numPoints = lb->cntr_size(0);
- auto pointOffset = lb->contour_start_point(0);
- for (auto i = 0; i < numPoints; i++)
- {
- auto x = lb->x_coord(i + pointOffset);
- auto y = lb->y_coord(i + pointOffset);
-
- double tx;
- double ty;
- WorldToScreenPoint(x, y, tx, ty);
-
- builder.set_point(static_cast<int>(tx), static_cast<int>(ty));
- }
- }
- else //MultiLineString
- {
-
- }
-
- AddActiveFeatureProperties(&builder);
- builder.commit();
+ m_impl->ProcessPolyline(m_activeFeature, lb);
}
//Entry point for raster/image rendering. Perform any pre-rendering operations.
@@ -213,26 +336,7 @@
//Entry point for marker rendering. Perform any pre-rendering operations.
void MVTRenderer::ProcessMarker(LineBuffer * lb, RS_MarkerDef & mdef, bool allowOverpost, RS_Bounds * bounds)
{
- vtzero::point_feature_builder builder(*m_activeLayerBuilder);
-
- if (lb->point_count() == 1)
- {
- auto x = lb->x_coord(0);
- auto y = lb->y_coord(0);
-
- double tx;
- double ty;
- WorldToScreenPoint(x, y, tx, ty);
-
- builder.set_point(static_cast<int>(tx), static_cast<int>(ty));
- }
- else //MultiPoint
- {
-
- }
-
- AddActiveFeatureProperties(&builder);
- builder.commit();
+ m_impl->ProcessMarker(m_activeFeature, lb);
}
//Entry point for label group rendering.
@@ -406,62 +510,5 @@
void MVTRenderer::GetMVTContent(std::string& buffer)
{
- m_tileBuilder->serialize(buffer);
-}
-
-void MVTRenderer::AddActiveFeatureProperties(vtzero::feature_builder* builder)
-{
- int count;
- auto propNames = m_activeFeature->GetPropNames(count);
- for (int i = 0; i < count; i++)
- {
- auto name = propNames[i];
- std::string mbName;
- UnicodeString::WideCharToMultiByte(name, mbName);
- auto propType = m_activeFeature->GetPropertyType(name);
- switch (propType)
- {
- case FdoDataType_Boolean:
- builder->add_property(mbName, vtzero::bool_value_type(m_activeFeature->GetBoolean(name)));
- break;
- case FdoDataType_Byte:
- builder->add_property(mbName, vtzero::int_value_type(m_activeFeature->GetByte(name)));
- break;
- case FdoDataType_DateTime:
- {
- auto dt = m_activeFeature->GetAsString(name);
- std::string sDt;
- UnicodeString::WideCharToMultiByte(dt, sDt);
- builder->add_property(mbName, vtzero::string_value_type(sDt));
- break;
- }
- case FdoDataType_Decimal:
- case FdoDataType_Double:
- builder->add_property(mbName, vtzero::double_value_type(m_activeFeature->GetDouble(name)));
- break;
- case FdoDataType_Int16:
- builder->add_property(mbName, vtzero::int_value_type(m_activeFeature->GetInt16(name)));
- break;
- case FdoDataType_Int32:
- builder->add_property(mbName, vtzero::int_value_type(m_activeFeature->GetInt32(name)));
- break;
- case FdoDataType_Int64:
- builder->add_property(mbName, vtzero::int_value_type(m_activeFeature->GetInt64(name)));
- break;
- case FdoDataType_Single:
- builder->add_property(mbName, vtzero::float_value_type(m_activeFeature->GetSingle(name)));
- break;
- case FdoDataType_String:
- {
- auto s = m_activeFeature->GetString(name);
- std::string sVal;
- UnicodeString::WideCharToMultiByte(s, sVal);
- builder->add_property(mbName, vtzero::string_value_type(sVal));
- break;
- }
- case FdoDataType_BLOB: //Not handled
- case FdoDataType_CLOB:
- break;
- }
- }
+ m_impl->GetMVTContent(buffer);
}
\ No newline at end of file
Modified: sandbox/jng/mvt/Common/Renderers/MVTRenderer.h
===================================================================
--- sandbox/jng/mvt/Common/Renderers/MVTRenderer.h 2019-05-31 13:06:39 UTC (rev 9525)
+++ sandbox/jng/mvt/Common/Renderers/MVTRenderer.h 2019-05-31 14:10:44 UTC (rev 9526)
@@ -20,7 +20,6 @@
#include "Renderers.h"
#include "SE_Renderer.h"
-#include <vtzero/builder.hpp>
#include <vector>
// A renderer that produces Mapbox Vector Tiles (MVT)
@@ -74,13 +73,11 @@
RENDERERS_API void GetMVTContent(std::string& buffer);
private:
- void AddActiveFeatureProperties(vtzero::feature_builder* builder);
+ struct MVTImpl;
+ std::unique_ptr<MVTImpl> m_impl;
+
RS_FeatureReader* m_activeFeature;
- vtzero::tile_builder* m_tileBuilder;
- vtzero::layer_builder* m_activeLayerBuilder;
- std::vector<vtzero::layer_builder*> m_prevLayerBuilder;
-
// map/layer/feature info
RS_MapUIInfo* m_mapInfo;
RS_LayerUIInfo* m_layerInfo;
More information about the mapguide-commits
mailing list