From 17756d53f839ab922456a7ff7b56e614d1851d41 Mon Sep 17 00:00:00 2001 From: Glenn Waldron Date: Thu, 10 Oct 2024 14:49:21 -0400 Subject: [PATCH] FeatureImage: add simple point rasterization (with demo) --- src/osgEarth/FeatureRasterizer.cpp | 23 ++++++++++++++++ src/osgEarth/Geometry | 43 +++++++++++++++++++++++------- src/osgEarth/Geometry.cpp | 26 +++++++++--------- tests/feature_rasterize.earth | 16 ++++++++++- 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/src/osgEarth/FeatureRasterizer.cpp b/src/osgEarth/FeatureRasterizer.cpp index 34a7ccdb66..c754467cea 100644 --- a/src/osgEarth/FeatureRasterizer.cpp +++ b/src/osgEarth/FeatureRasterizer.cpp @@ -723,6 +723,7 @@ FeatureRasterizer::render_blend2d( _inverted = true; // find the symbology: + const PointSymbol* masterPoint = style.get(); const LineSymbol* masterLine = style.getSymbol(); const PolygonSymbol* masterPoly = style.getSymbol(); const CoverageSymbol* masterCov = style.getSymbol(); @@ -865,6 +866,28 @@ FeatureRasterizer::render_blend2d( } } + if (masterPoint) + { + float width = masterPoint->size().value(); + + ctx.setFillStyle(BLRgba( + masterPoint->fill()->color().r(), masterPoint->fill()->color().g(), masterPoint->fill()->color().b(), masterPoint->fill()->color().a())); + + for (const auto& feature : features) + { + feature->getGeometry()->forEachPart([&](const Geometry* part) + { + for (auto& p : *part) + { + double x = frame.xf * (p.x() - frame.xmin); + double y = frame.yf * (p.y() - frame.ymin); + y = ctx.targetHeight() - y; + ctx.fillCircle(x, y, width / 2.0); + } + }); + } + } + if (masterText || masterSkin) { // Sort the features based their location. We do this to ensure that features collected in a metatiling diff --git a/src/osgEarth/Geometry b/src/osgEarth/Geometry index 95e00e1208..813ecc5b28 100644 --- a/src/osgEarth/Geometry +++ b/src/osgEarth/Geometry @@ -256,17 +256,18 @@ namespace osgEarth //! Whether a closed geometry contains the 2D point virtual bool contains2D(double x, double y) const { return false; } - //! Iterate over all the parts of a geometry - void forEachPart(const std::function& func) { forEachPart(true, func); } - //! Iterate over all the parts of a geometry - void forEachPart(bool includePolygonHoles, const std::function& func); + //! Iterate over all the parts of a geometry (signature = void(Geometry* part)) + template + inline void forEachPart(bool includePolygonHoles, CALLABLE&& func); + template + inline void forEachPart(CALLABLE&& func) { forEachPart(true, func); }; - //! Iterate over all the parts of a geometry - void forEachPart(const std::function& func) const { forEachPart(true, func); } - - //! Iterate over all the parts of a geometry - void forEachPart(bool includePolygonHoles, const std::function& func) const; + //! Iterate over all the parts of a CONST geometry (signature = void(const Geometry* part)) + template + inline void forEachPart(bool includePolygonHoles, CALLABLE&& func) const; + template + inline void forEachPart(CALLABLE&& func) const { forEachPart(true, func); }; public: inline Type getType() const { return _type; } @@ -560,7 +561,9 @@ namespace osgEarth const Geometry* next(); //! Visits each part and calls a user-defined functor - inline void forEach(const std::function& func) { + //! Signature = void(const Geometry* part) + template + inline void forEach(CALLABLE&& func) { //const std::function& func) { while (hasMore()) func(next()); } @@ -620,6 +623,26 @@ namespace osgEarth bool _closeLoop; Segment _current; }; + + + + //! Iterate over all the parts of a geometry + template + inline void Geometry::forEachPart(bool includePolygonHoles, CALLABLE&& func) + { + GeometryIterator i(this, includePolygonHoles); + i.forEach(func); + } + + //! Iterate over all the parts of a geometry + template + inline void Geometry::forEachPart(bool includePolygonHoles, CALLABLE&& func) const + { + ConstGeometryIterator i(this, includePolygonHoles); + i.forEach(func); + } + + } // namespace osgEarth diff --git a/src/osgEarth/Geometry.cpp b/src/osgEarth/Geometry.cpp index 957f925762..ca0a6fc41d 100644 --- a/src/osgEarth/Geometry.cpp +++ b/src/osgEarth/Geometry.cpp @@ -696,19 +696,19 @@ Geometry::close() push_back( front() ); } -void -Geometry::forEachPart(bool includePolygonHoles, const std::function& func) -{ - GeometryIterator i(this, includePolygonHoles); - i.forEach(func); -} - -void -Geometry::forEachPart(bool includePolygonHoles, const std::function& func) const -{ - ConstGeometryIterator i(this, includePolygonHoles); - i.forEach(func); -} +//void +//Geometry::forEachPart(bool includePolygonHoles, const std::function& func) +//{ +// GeometryIterator i(this, includePolygonHoles); +// i.forEach(func); +//} +// +//void +//Geometry::forEachPart(bool includePolygonHoles, const std::function& func) const +//{ +// ConstGeometryIterator i(this, includePolygonHoles); +// i.forEach(func); +//} //---------------------------------------------------------------------------- diff --git a/tests/feature_rasterize.earth b/tests/feature_rasterize.earth index d41d881eea..e6e5a543f7 100644 --- a/tests/feature_rasterize.earth +++ b/tests/feature_rasterize.earth @@ -10,7 +10,7 @@ FeatureImage - rasterizes feature data into an image layer. ../data/world.shp - + world-data