Skip to content

Commit

Permalink
Added support for "pixel-size-on-screen" rendering to feature model /…
Browse files Browse the repository at this point in the history
… tiled feature model.
  • Loading branch information
Daniel Allen committed Sep 27, 2023
1 parent e2969c7 commit b6dc7d1
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/osgEarth/FeatureDisplayLayout
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ namespace osgEarth
optional<float>& minRange() { return _minRange; }
const optional<float>& minRange() const { return _minRange; }

/**
* Whether features are loaded based on range. If not, pixels on screen
* is used. Default = range
*/
optional<bool>& useRange() { return _useRange; }
const optional<bool>& useRange() const { return _useRange; }

/**
* When using pixel size on screen instead of range, this specifies the maximum
* number of pixels at which to display the feature at a given LOD
*/
optional<float>& maxPixels() { return _maxPixels;}
const optional<float>& maxPixels() const { return _maxPixels;}

/**
* When using pixel size on screen instead of range, this specifies the minimum
* number of pixels at which to display the feature at a given LOD
*/
optional<float>& minPixels() { return _minPixels; }
const optional<float>& minPixels() const { return _minPixels; }

/**
* Whether to crop geometry to fit within the cell extents when chopping
* a feature level up into grid cells. By default, this is false, meaning
Expand Down Expand Up @@ -184,6 +205,9 @@ namespace osgEarth
optional<float> _tileSizeFactor;
optional<float> _minRange;
optional<float> _maxRange;
optional<float> _minPixels;
optional<float> _maxPixels;
optional<bool> _useRange;
optional<bool> _cropFeatures;
optional<float> _priorityOffset;
optional<float> _priorityScale;
Expand Down
9 changes: 9 additions & 0 deletions src/osgEarth/FeatureDisplayLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ FeatureDisplayLayout::FeatureDisplayLayout( const Config& conf ) :
_tileSizeFactor( 3.5f ),
_minRange ( 0.0f ),
_maxRange ( 0.0f ),
_minPixels ( 0.0f ),
_maxPixels ( 0.0f ),
_useRange ( true ),
_cropFeatures ( false ),
_priorityOffset( 0.0f ),
_priorityScale ( 1.0f ),
Expand All @@ -91,6 +94,9 @@ FeatureDisplayLayout::fromConfig( const Config& conf )
conf.get( "min_expiry_time", _minExpiryTime );
conf.get( "min_range", _minRange );
conf.get( "max_range", _maxRange );
conf.get( "min_pixels", _minPixels);
conf.get( "max_pixels", _maxPixels);
conf.get( "use_range", _useRange);
conf.get("paged", _paged);
ConfigSet children = conf.children( "level" );
for( ConfigSet::const_iterator i = children.begin(); i != children.end(); ++i )
Expand All @@ -109,6 +115,9 @@ FeatureDisplayLayout::getConfig() const
conf.set( "min_expiry_time", _minExpiryTime );
conf.set( "min_range", _minRange );
conf.set( "max_range", _maxRange );
conf.set( "min_pixels", _minPixels );
conf.set( "max_pixels", _maxPixels );
conf.set( "use_range", _useRange );
conf.set("paged", _paged);
for( Levels::const_iterator i = _levels.begin(); i != _levels.end(); ++i )
conf.add( i->second.getConfig() );
Expand Down
16 changes: 14 additions & 2 deletions src/osgEarth/FeatureModelGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,20 @@ namespace
p->setLoadFunction(func);
p->setCenter(bs.center());
p->setRadius(bs.radius());
p->setMinRange(minRange);
p->setMaxRange(maxRange);
if( layout.useRange().get() )
{
p->setMinRange(minRange);
p->setMaxRange(maxRange);
}
else
{
if( layout.minPixels().isSet() )
p->setMinPixels(layout.minPixels().get());

if( layout.maxPixels().isSet() )
p->setMaxPixels(layout.maxPixels().get());
}

p->setPriorityScale(layout.priorityScale().get());
p->setSceneGraphCallbacks(sgCallbacks);
return p;
Expand Down
4 changes: 4 additions & 0 deletions src/osgEarth/SimplePager
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace osgEarth { namespace Util
float getPriorityOffset() const { return _priorityOffset; }
void setPriorityOffset(float value) { _priorityOffset = value; }

void setMinPixel(float value) { _minPixel = value; _useRange = false; }

void setEnableCancelation(bool value);
bool getEnableCancelation() const;

Expand Down Expand Up @@ -120,6 +122,8 @@ namespace osgEarth { namespace Util

bool _additive;
double _rangeFactor;
bool _useRange;
float _minPixel;
unsigned int _minLevel;
unsigned int _maxLevel;
osg::ref_ptr<const Profile> _profile;
Expand Down
9 changes: 7 additions & 2 deletions src/osgEarth/SimplePager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ SimplePager::SimplePager(const osgEarth::Map* map, const osgEarth::Profile* prof
_map(map),
_profile( profile ),
_rangeFactor( 6.0 ),
_useRange(true),
_minPixel(0.0),
_additive(false),
_minLevel(0),
_maxLevel(30),
Expand Down Expand Up @@ -235,8 +237,11 @@ SimplePager::createPagedNode(const TileKey& key, ProgressCallback* progress)
loadRange = (float)(tileRadius * _rangeFactor);
pagedNode->setRefinePolicy(_additive ? REFINE_ADD : REFINE_REPLACE);
}

pagedNode->setMaxRange(loadRange);

if (_useRange)
pagedNode->setMaxRange(loadRange);
else
pagedNode->setMinPixels(_minPixel);

//OE_INFO << "PagedNode2: key="<<key.str()<<" hasChildren=" << hasChildren << ", range=" << loadRange << std::endl;

Expand Down
4 changes: 4 additions & 0 deletions src/osgEarth/TiledFeatureModelLayer
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace osgEarth
Options(const ConfigOptions& options);
OE_OPTION_LAYER(FeatureSource, featureSource);
OE_OPTION(bool, additive);
OE_OPTION(float, minPixel);
virtual Config getConfig() const;
protected: // LayerOptions
virtual void mergeConfig(const Config& conf);
Expand Down Expand Up @@ -79,6 +80,9 @@ namespace osgEarth
void setAdditive(const bool& value);
const bool& getAdditive() const;

void setMinPixel(const float& value);
const float& getMinPixel() const;

//! Forces a rebuild on this FeatureModelLayer.
void dirty();

Expand Down
10 changes: 10 additions & 0 deletions src/osgEarth/TiledFeatureModelLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ GeometryCompilerOptions(options)
void TiledFeatureModelLayer::Options::fromConfig(const Config& conf)
{
additive().setDefault(false);
minPixel().setDefault(512.0);

conf.get("additive", additive());
conf.get("min_pixel", minPixel());

featureSource().get(conf, "features");
}

Expand All @@ -65,6 +68,7 @@ TiledFeatureModelLayer::Options::getConfig() const
conf.merge(gcConf);

conf.set("additive", additive());
conf.set("min_pixel", minPixel());

featureSource().set(conf, "features");

Expand All @@ -82,6 +86,7 @@ void TiledFeatureModelLayer::Options::mergeConfig(const Config& conf)
OE_LAYER_PROPERTY_IMPL(TiledFeatureModelLayer, bool, AlphaBlending, alphaBlending);
OE_LAYER_PROPERTY_IMPL(TiledFeatureModelLayer, bool, EnableLighting, enableLighting);
OE_LAYER_PROPERTY_IMPL(TiledFeatureModelLayer, bool, Additive, additive);
OE_LAYER_PROPERTY_IMPL(TiledFeatureModelLayer, float, MinPixel, minPixel);

TiledFeatureModelLayer::~TiledFeatureModelLayer()
{
Expand Down Expand Up @@ -267,6 +272,11 @@ TiledFeatureModelLayer::create()
fmg->setOwnerName(getName());
fmg->setFilterChain(chain.get());
fmg->setAdditive(*_options->additive());
if (_options->minPixel().isSet())
{
fmg->setMinPixel(_options->minPixel().get());
}

fmg->build();

_root->removeChildren(0, _root->getNumChildren());
Expand Down

0 comments on commit b6dc7d1

Please sign in to comment.