WS30: Improved vegetation constraints

Unlike the elevation constraints, the vegetation constraints
don't need to be global.  So no need for mutexes.  Big speed up.
next
Stuart Buchanan 3 years ago
parent 8cc3c15712
commit d1e9134a89

@ -61,6 +61,7 @@ VPBTechnique::VPBTechnique()
setFilterBias(0);
setFilterWidth(0.1);
setFilterMatrixAs(GAUSSIAN);
_vegetationConstraintGroup = new osg::Group();
}
VPBTechnique::VPBTechnique(const SGReaderWriterOptions* options)
@ -69,6 +70,7 @@ VPBTechnique::VPBTechnique(const SGReaderWriterOptions* options)
setFilterWidth(0.1);
setFilterMatrixAs(GAUSSIAN);
setOptions(options);
_vegetationConstraintGroup = new osg::Group();
}
VPBTechnique::VPBTechnique(const VPBTechnique& gt,const osg::CopyOp& copyop):
@ -78,6 +80,7 @@ VPBTechnique::VPBTechnique(const VPBTechnique& gt,const osg::CopyOp& copyop):
setFilterWidth(gt._filterWidth);
setFilterMatrix(gt._filterMatrix);
setOptions(gt._options);
_vegetationConstraintGroup = new osg::Group();
}
VPBTechnique::~VPBTechnique()
@ -2283,21 +2286,24 @@ osg::Vec3d VPBTechnique::checkAgainstElevationConstraints(osg::Vec3d origin, osg
// intersection with the constraint model.
void VPBTechnique::addVegetationConstraint(osg::ref_ptr<osg::Node> constraint)
{
const std::lock_guard<std::mutex> lock(VPBTechnique::_vegetationConstraintMutex); // Lock the _vegetationConstraintGroup for this scope
_vegetationConstraintGroup->addChild(constraint.get());
}
// Remove a previously added constraint. E.g on model unload.
void VPBTechnique::removeVegetationConstraint(osg::ref_ptr<osg::Node> constraint)
{
const std::lock_guard<std::mutex> lock(VPBTechnique::_vegetationConstraintMutex); // Lock the _vegetationConstraintGroup for this scope
_vegetationConstraintGroup->removeChild(constraint.get());
}
// Remove all the constraints, which will still be referenced by the terrain tile itself.
void VPBTechnique::clearVegetationConstraints()
{
_vegetationConstraintGroup->removeChildren(0, _vegetationConstraintGroup->getNumChildren());
}
// Check a given vertex against any vegetation constraints E.g. to ensure we don't get trees sprouting from roads or runways.
bool VPBTechnique::checkAgainstVegetationConstraints(osg::Vec3d origin, osg::Vec3d vertex)
{
const std::lock_guard<std::mutex> lock(VPBTechnique::_vegetationConstraintMutex); // Lock the _vegetationConstraintGroup for this scope
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector;
intersector = new osgUtil::LineSegmentIntersector(origin, vertex);
osgUtil::IntersectionVisitor visitor(intersector.get());
@ -2308,9 +2314,7 @@ bool VPBTechnique::checkAgainstVegetationConstraints(osg::Vec3d origin, osg::Vec
void VPBTechnique::clearConstraints()
{
const std::lock_guard<std::mutex> elock(VPBTechnique::_elevationConstraintMutex); // Lock the _elevationConstraintGroup for this scope
const std::lock_guard<std::mutex> vlock(VPBTechnique::_vegetationConstraintMutex); // Lock the _vegetationConstraintGroup for this scope
_elevationConstraintGroup = new osg::Group();
_vegetationConstraintGroup = new osg::Group();
}
void VPBTechnique::addLineFeatureList(SGBucket bucket, LineFeatureBinList roadList)

@ -91,16 +91,12 @@ class VPBTechnique : public TerrainTechnique
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
// Elevation constraints ensure that the terrain mesh is placed underneath objects such as airports
// Elevation constraints ensure that the terrain mesh is placed underneath objects such as airports.
// As airports are generated in a separate loading thread, these are static.
static void addElevationConstraint(osg::ref_ptr<osg::Node> constraint);
static void removeElevationConstraint(osg::ref_ptr<osg::Node> constraint);
static osg::Vec3d checkAgainstElevationConstraints(osg::Vec3d origin, osg::Vec3d vertex, float vertex_gap);
// Vegetation constraints ensure that trees don't grow in roads
static void addVegetationConstraint(osg::ref_ptr<osg::Node> constraint);
static void removeVegetationConstraint(osg::ref_ptr<osg::Node> constraint);
static bool checkAgainstVegetationConstraints(osg::Vec3d origin, osg::Vec3d vertex);
static void clearConstraints();
// LineFeatures and AreaFeatures are draped over the underlying mesh.
@ -178,6 +174,13 @@ class VPBTechnique : public TerrainTechnique
virtual osg::Vec3d getMeshIntersection(BufferData& buffer, Locator* masterLocator, osg::Vec3d pt, osg::Vec3d up);
// Vegetation constraints ensure that trees don't grow in roads. Unlike the elevation constraints,
// we only use these internally and during generation of this particular tile.
virtual void addVegetationConstraint(osg::ref_ptr<osg::Node> constraint);
virtual void removeVegetationConstraint(osg::ref_ptr<osg::Node> constraint);
virtual bool checkAgainstVegetationConstraints(osg::Vec3d origin, osg::Vec3d vertex);
virtual void clearVegetationConstraints();
OpenThreads::Mutex _writeBufferMutex;
osg::ref_ptr<BufferData> _currentBufferData;
osg::ref_ptr<BufferData> _newBufferData;
@ -189,12 +192,11 @@ class VPBTechnique : public TerrainTechnique
osg::Matrix3 _filterMatrix;
osg::ref_ptr<osg::Uniform> _filterMatrixUniform;
osg::ref_ptr<SGReaderWriterOptions> _options;
osg::ref_ptr<osg::Group> _vegetationConstraintGroup;
inline static osg::ref_ptr<osg::Group> _elevationConstraintGroup = new osg::Group();
inline static std::mutex _elevationConstraintMutex; // protects the _elevationConstraintGroup;
inline static osg::ref_ptr<osg::Group> _vegetationConstraintGroup = new osg::Group();
inline static std::mutex _vegetationConstraintMutex; // protects the _vegetationConstraintGroup;
typedef std::pair<SGBucket, LineFeatureBinList> BucketLineFeatureBinList;
typedef std::pair<SGBucket, AreaFeatureBinList> BucketAreaFeatureBinList;

Loading…
Cancel
Save