Skip to content

Commit

Permalink
GroundCoverFeatureGenerator: fix bug causing the first billboard to a…
Browse files Browse the repository at this point in the history
…lways be chosen; add ability to pass through billboard symbol properties as feature attributes
  • Loading branch information
gwaldron committed Apr 14, 2020
1 parent 6a5ee86 commit d9b0810
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ usage(const char* name, const std::string& error)
<< "Error: " << error
<< "\nUsage:"
<< "\n" << name << " file.earth"
<< "\n --layer layername ; name of GroundCover layer"
<< "\n --extents swlong swlat nelong nelat ; extents in degrees"
<< "\n --out out.shp ; output features"
<< "\n --layer layername ; name of GroundCover layer"
<< "\n --extents swlong swlat nelong nelat ; extents in degrees"
<< "\n --out out.shp ; output features"
<< "\n --include-billboard-property <name> ; include billboard property name as attribute (optional)"
<< std::endl;

return -1;
Expand Down Expand Up @@ -105,6 +106,14 @@ struct App
outSchema["elevation"] = ATTRTYPE_DOUBLE;
outSchema["width"] = ATTRTYPE_DOUBLE;
outSchema["height"] = ATTRTYPE_DOUBLE;

std::string prop;
while(arguments.read("--include-billboard-property", prop))
{
featureGen.addBillboardPropertyName(prop);
outSchema[prop] = ATTRTYPE_STRING;
}

outfs = new OGRFeatureSource();
outfs->setOGRDriver("ESRI Shapefile");
outfs->setURL(outfile);
Expand Down
4 changes: 4 additions & 0 deletions src/osgEarthSplat/GroundCoverFeatureGenerator
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ namespace osgEarth { namespace Splat
//! Sets the groundcover layer from which to generate features (required)
void setLayer(GroundCoverLayer* layer);

//! Adds a property name to store as a feature attribute
void addBillboardPropertyName(const std::string& name);

//! Returns the status of the generator - call this to
//! see if there are any setup errors before calling getFeatures.
const Status& getStatus() const;
Expand All @@ -68,6 +71,7 @@ namespace osgEarth { namespace Splat
osg::ref_ptr<LandCoverDictionary> _lcdict;
osg::ref_ptr<osg::Texture> _noiseTexture;
CreateTileManifest _manifest;
std::vector<std::string> _propNames;

void initialize();
};
Expand Down
23 changes: 22 additions & 1 deletion src/osgEarthSplat/GroundCoverFeatureGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace
float width;
float height;
float sizeVariation;
Config billboardConfig;
};

typedef std::vector<BillboardLUTEntry> BillboardLUT;
Expand All @@ -90,6 +91,8 @@ namespace
BillboardLUTEntry entry;
if (bb->_symbol.valid())
{
entry.billboardConfig = bb->_symbol->getConfig();
OE_INFO << entry.billboardConfig.toJSON(false) << std::endl;
entry.width = bb->_symbol->width().get();
entry.height = bb->_symbol->height().get();
entry.sizeVariation = bb->_symbol->sizeVariation().get();
Expand Down Expand Up @@ -142,6 +145,12 @@ GroundCoverFeatureGenerator::setLayer(GroundCoverLayer* layer)
initialize();
}

void
GroundCoverFeatureGenerator::addBillboardPropertyName(const std::string& name)
{
_propNames.push_back(name);
}

const Status&
GroundCoverFeatureGenerator::getStatus() const
{
Expand Down Expand Up @@ -439,13 +448,25 @@ GroundCoverFeatureGenerator::getFeatures(const TileKey& key, FeatureList& output
if (biome)
{
BillboardLUT& bblut = biomeLUT[biome];
unsigned index = (unsigned)clamp(noise[NOISE_RANDOM], 0.0, 0.9999999) * (float)(bblut.size());
unsigned index = (unsigned)(clamp(noise[NOISE_RANDOM], 0.0, 0.9999999) * (float)(bblut.size()));
BillboardLUTEntry& bb = bblut[index];
float sizeScale = bb.sizeVariation * (noise[NOISE_RANDOM_2] * 2.0 - 1.0);
float width = bb.width + bb.width*sizeScale;
float height = bb.height + bb.height*sizeScale;
feature->set("width", width);
feature->set("height", height);

// Store any pass-thru properties
for(std::vector<std::string>::const_iterator i = _propNames.begin();
i != _propNames.end();
++i)
{
std::string value = bb.billboardConfig.value(*i);
if (!value.empty())
{
feature->set(*i, value);
}
}
}

output.push_back(feature.get());
Expand Down

0 comments on commit d9b0810

Please sign in to comment.