Skip to content

Commit

Permalink
Fix issues cropping and geometry cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Jan 23, 2025
1 parent b2cf598 commit a2024fc
Show file tree
Hide file tree
Showing 16 changed files with 447 additions and 358 deletions.
62 changes: 41 additions & 21 deletions src/osgEarth/BuildGeometryFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ namespace
if (auto cropped = geometry->crop(&boundary))
{
// Use an iterator since crop could return a multi-polygon
GeometryIterator gi(cropped.get(), false);
GeometryIterator gi(cropped, false);
while (gi.hasMore())
{
Geometry* geom = gi.next();
Expand Down Expand Up @@ -1798,15 +1798,11 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )
// Split features across the dateline if necessary
if (context.getOutputSRS() && !context.getOutputSRS()->isGeographic())
{
for(FeatureList::iterator itr = input.begin(); itr != input.end(); ++itr)
for(auto& feature : input)
{
osg::ref_ptr<Feature> f = new Feature(*itr->get());
f->splitAcrossAntimeridian();
splitFeatures.emplace_back(f);
//Feature* f = itr->clone(); // itr->get();
//FeatureList tmpSplit;
//f->splitAcrossDateLine(tmpSplit);
//splitFeatures.insert(splitFeatures.end(), tmpSplit.begin(), tmpSplit.end());
auto* clone = new Feature(*feature.get());
clone->splitAcrossAntimeridian();
splitFeatures.emplace_back(clone);
}
}
else
Expand All @@ -1815,6 +1811,8 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )
std::copy(input.begin(), input.end(), std::back_inserter(splitFeatures));
}

osg::ref_ptr<osg::Group> polysGroup, linesGroup, pointsGroup, meshesGroup;

for(FeatureList::iterator i = splitFeatures.begin(); i != splitFeatures.end(); ++i)
{
Feature* f = i->get();
Expand Down Expand Up @@ -1872,10 +1870,10 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )

if ( has_polysymbol )
{
if (f->getGeometry()->getType() == Geometry::TYPE_TRIMESH)
meshes.push_back(f);
else
polygons.push_back( f );
//if (f->getGeometry()->getType() == Geometry::TYPE_TRIMESH)
// meshes.push_back(f);
//else
polygons.push_back( f );
}

if (has_linesymbol)
Expand Down Expand Up @@ -1927,7 +1925,10 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )
GenerateNormals gen;
geode->accept(gen);

result->addChild( geode.get() );
if (!polysGroup.valid())
polysGroup = new osg::Group();

polysGroup->addChild( geode.get() );
}
}

Expand All @@ -1937,12 +1938,13 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )
bool twosided = polygons.size() > 0 ? false : true;
osg::ref_ptr< osg::Group > lines = processPolygonizedLines(polygonizedLines, twosided, context,
false);

if (lines->getNumChildren() > 0)
{
result->addChild( lines.get() );
}
if (!linesGroup.valid())
linesGroup = new osg::Group();

linesGroup->addChild( lines.get() );
}
}

if ( wireLines.size() > 0 )
Expand All @@ -1952,7 +1954,9 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )

if (lines->getNumChildren() > 0)
{
result->addChild( lines.get() );
if (!meshesGroup.valid())
meshesGroup = new osg::Group();
meshesGroup->addChild( lines.get() );
}

}
Expand All @@ -1965,7 +1969,9 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )

if ( group->getNumChildren() > 0 )
{
result->addChild(group.get());
if (!linesGroup.valid())
linesGroup = new osg::Group();
linesGroup->addChild(group.get());
}
}

Expand All @@ -1977,7 +1983,9 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )

if ( group->getNumChildren() > 0 )
{
result->addChild(group.get());
if (!pointsGroup.valid())
pointsGroup = new osg::Group();
pointsGroup->addChild(group.get());
}
}

Expand All @@ -1987,10 +1995,22 @@ BuildGeometryFilter::push( FeatureList& input, FilterContext& context )

if (group->getNumChildren() > 0)
{
result->addChild(group.get());
if (!meshesGroup.valid())
meshesGroup = new osg::Group();
meshesGroup->addChild(group.get());
}
}

if (polysGroup.valid())
result->addChild(polysGroup.get());
if (linesGroup.valid())
result->addChild(linesGroup.get());
if (pointsGroup.valid())
result->addChild(pointsGroup.get());
if (meshesGroup.valid())
result->addChild(meshesGroup.get());


//// indicate that geometry contains clamping attributes
if (_style.has<AltitudeSymbol>() &&
_style.get<AltitudeSymbol>()->technique() == AltitudeSymbol::TECHNIQUE_GPU)
Expand Down
22 changes: 8 additions & 14 deletions src/osgEarth/ConvertTypeFilter
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,24 @@ namespace osgEarth { namespace Util
static bool isSupported() { return true; }

public:
ConvertTypeFilter();
ConvertTypeFilter( const Geometry::Type& toType );
ConvertTypeFilter( const ConvertTypeFilter& rhs );
ConvertTypeFilter() = default;
ConvertTypeFilter(const ConvertTypeFilter&) = default;

ConvertTypeFilter( const Config& conf );
ConvertTypeFilter(const Geometry::Type& toType);
ConvertTypeFilter(const Config& conf);

/**
* Serialize this FeatureFilter
*/
virtual Config getConfig() const;

virtual ~ConvertTypeFilter() { }
//!Serialize this FeatureFilter
Config getConfig() const override;

public:
Geometry::Type& toType() {
return _toType; }
const Geometry::Type& toType() const {
return _toType; }
return _toType.value(); }

public:
virtual FilterContext push( FeatureList& input, FilterContext& context );

protected:
Geometry::Type _toType;
optional<Geometry::Type> _toType = Geometry::TYPE_UNKNOWN;
};
} }

Expand Down
53 changes: 22 additions & 31 deletions src/osgEarth/ConvertTypeFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,28 @@ using namespace osgEarth::Util;
OSGEARTH_REGISTER_SIMPLE_FEATUREFILTER(convert, ConvertTypeFilter)


ConvertTypeFilter::ConvertTypeFilter() :
_toType( Geometry::TYPE_UNKNOWN )
{
//NOP
}

ConvertTypeFilter::ConvertTypeFilter( const Geometry::Type& toType ) :
_toType( toType )
ConvertTypeFilter::ConvertTypeFilter(const Geometry::Type& toType) :
_toType(toType)
{
// NOP
}

ConvertTypeFilter::ConvertTypeFilter( const ConvertTypeFilter& rhs ) :
_toType( rhs._toType )
{
//NOP
}

ConvertTypeFilter::ConvertTypeFilter( const Config& conf):
_toType( Geometry::TYPE_UNKNOWN )
ConvertTypeFilter::ConvertTypeFilter(const Config& conf)
{
if (conf.key() == "convert")
{
optional<Geometry::Type> type = Geometry::TYPE_POINTSET;
conf.get( "type", "point", type, Geometry::TYPE_POINTSET );
conf.get( "type", "line", type, Geometry::TYPE_LINESTRING );
conf.get( "type", "polygon", type, Geometry::TYPE_POLYGON );
_toType = *type;
conf.get("type", "point", _toType, Geometry::TYPE_POINTSET);
conf.get("type", "line", _toType, Geometry::TYPE_LINESTRING);
conf.get("type", "polygon", _toType, Geometry::TYPE_POLYGON);
}
}

Config ConvertTypeFilter::getConfig() const
{
Config config("convert");
optional<Geometry::Type> type(_toType);
type = _toType;
config.set("type", "point", type, Geometry::TYPE_POINTSET);
config.set("type", "line", type, Geometry::TYPE_LINESTRING);
config.set("type", "polygon", type, Geometry::TYPE_POLYGON);

config.set("type", "point", _toType, Geometry::TYPE_POINTSET);
config.set("type", "line", _toType, Geometry::TYPE_LINESTRING);
config.set("type", "polygon", _toType, Geometry::TYPE_POLYGON);
return config;
}

Expand All @@ -76,13 +58,22 @@ ConvertTypeFilter::push( FeatureList& input, FilterContext& context )
return context;
}

if (_toType == Geometry::TYPE_UNKNOWN)
{
return context;
}

bool ok = true;
for( FeatureList::iterator i = input.begin(); i != input.end(); ++i )
for (auto& feature : input)
{
Feature* input = i->get();
if ( input && input->getGeometry() && input->getGeometry()->getComponentType() != _toType )
if (feature && feature->getGeometry() && feature->getGeometry()->getComponentType() != _toType.value())
{
input->setGeometry( input->getGeometry()->cloneAs(_toType) );
auto cloned = feature->getGeometry()->cloneAs(_toType.value());
if (cloned)
{
OE_SOFT_ASSERT(cloned->isValid());
feature->setGeometry(cloned);
}
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/osgEarth/CropFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,12 @@ CropFilter::push( FeatureList& input, FilterContext& context )
// then move on to the cropping operation:
else
{
if (auto cropped = featureGeom->crop(&poly))
osg::ref_ptr<Geometry> cropped = featureGeom->crop(&poly);
if (cropped.valid() && cropped->isValid())
{
if (cropped->isValid())
{
feature->setGeometry(cropped.get());
keepFeature = true;
newExtent.expandToInclude(GeoExtent(newExtent.getSRS(), cropped->getBounds()));
}
feature->setGeometry(cropped);
keepFeature = true;
newExtent.expandToInclude(GeoExtent(newExtent.getSRS(), cropped->getBounds()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarth/Feature
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace osgEarth
Feature(const Feature& rhs);

//! Contruct a feature (move)
Feature(Feature&& rhs);
//Feature(Feature&& rhs);

public:

Expand Down
27 changes: 15 additions & 12 deletions src/osgEarth/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,28 +207,30 @@ Feature::Feature(Geometry* geom, const SpatialReference* srs, const Style& style
dirty();
}

Feature::Feature(const Feature& rhs) : //, const osg::CopyOp& copyOp) :
Feature::Feature(const Feature& rhs) :
_fid(rhs._fid),
_attrs(rhs._attrs),
_style(rhs._style),
_geoInterp(rhs._geoInterp),
_srs(rhs._srs.get())
{
OE_SOFT_ASSERT(rhs._geom.valid());

if (rhs._geom.valid())
_geom = rhs._geom->clone();

dirty();
}

Feature::Feature(Feature&& rhs) // : osg::Object(rhs)
{
_fid = std::move(rhs._fid);
_attrs = std::move(rhs._attrs);
_style = std::move(rhs._style);
_geoInterp = std::move(rhs._geoInterp);
_geom = std::move(rhs._geom);
_cachedExtent = std::move(rhs._cachedExtent);
}
//Feature::Feature(Feature&& rhs) // : osg::Object(rhs)
//{
// _fid = std::move(rhs._fid);
// _attrs = std::move(rhs._attrs);
// _style = std::move(rhs._style);
// _geoInterp = std::move(rhs._geoInterp);
// _geom = std::move(rhs._geom);
// _cachedExtent = std::move(rhs._cachedExtent);
//}

Feature::~Feature()
{
Expand Down Expand Up @@ -267,6 +269,7 @@ Feature::setSRS( const SpatialReference* srs )
void
Feature::setGeometry( Geometry* geom )
{
OE_HARD_ASSERT(geom != nullptr);
_geom = geom;
dirty();
}
Expand Down Expand Up @@ -786,8 +789,8 @@ void Feature::transform( const SpatialReference* srs )
void
Feature::splitAcrossAntimeridian()
{
// If the feature is geodetic, try to split it across the dateline.
if (getSRS() && getSRS()->isGeodetic())
// If the feature is geodetic, try to split it across the dateline.
if (getSRS() && getSRS()->isGeodetic() && getGeometry())
{
auto* split_geom = getGeometry()->splitAcrossAntimeridian();
setGeometry(split_geom);
Expand Down
7 changes: 4 additions & 3 deletions src/osgEarth/FeatureRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,8 @@ FeatureRasterizer::render_agglite(
{
Geometry* geometry = feature->getGeometry();

if (auto cropped = geometry->crop(&cropPoly))
osg::ref_ptr<Geometry> cropped = geometry->crop(&cropPoly);
if (cropped.valid())
{
if (covValue.isSet())
{
Expand All @@ -1208,8 +1209,8 @@ FeatureRasterizer::render_agglite(
{
Geometry* geometry = feature->getGeometry();

osg::ref_ptr<Geometry> croppedGeometry;
if (auto cropped = geometry->crop(&cropPoly))
osg::ref_ptr<Geometry> cropped = geometry->crop(&cropPoly);
if (cropped.valid())
{
if (covValue.isSet())
{
Expand Down
Loading

0 comments on commit a2024fc

Please sign in to comment.