|
osgEarth 2.1.1
|
Collaboration diagram for ClusterVisitor:Public Member Functions | |
| ClusterVisitor (const FeatureList &features, const MarkerSymbol *symbol, FeaturesToNodeFilter *f2n, FilterContext &cx) | |
| void | apply (osg::Geode &geode) |
Private Attributes | |
| const FeatureList & | _features |
| FilterContext | _cx |
| const MarkerSymbol * | _symbol |
| FeaturesToNodeFilter * | _f2n |
Definition at line 178 of file SubstituteModelFilter.cpp.
| ClusterVisitor::ClusterVisitor | ( | const FeatureList & | features, |
| const MarkerSymbol * | symbol, | ||
| FeaturesToNodeFilter * | f2n, | ||
| FilterContext & | cx | ||
| ) | [inline] |
| void ClusterVisitor::apply | ( | osg::Geode & | geode | ) | [inline] |
Definition at line 191 of file SubstituteModelFilter.cpp.
{
bool makeECEF = _cx.getSession()->getMapInfo().isGeocentric();
const SpatialReference* srs = _cx.profile()->getSRS();
NumericExpression scaleEx = *_symbol->scale();
osg::Matrixd scaleMatrix;
// save the geode's drawables..
osg::Geode::DrawableList old_drawables = geode.getDrawableList();
// ..and clear out the drawables list.
geode.removeDrawables( 0, geode.getNumDrawables() );
// foreach each drawable that was originally in the geode...
for( osg::Geode::DrawableList::iterator i = old_drawables.begin(); i != old_drawables.end(); i++ )
{
osg::Geometry* originalDrawable = dynamic_cast<osg::Geometry*>( i->get() );
if ( !originalDrawable )
continue;
// go through the list of input features...
for( FeatureList::const_iterator j = _features.begin(); j != _features.end(); j++ )
{
const Feature* feature = j->get();
if ( _symbol->scale().isSet() )
{
double scale = feature->eval( scaleEx );
scaleMatrix.makeScale( scale, scale, scale );
}
ConstGeometryIterator gi( feature->getGeometry(), false );
while( gi.hasMore() )
{
const Geometry* geom = gi.next();
for( Geometry::const_iterator k = geom->begin(); k != geom->end(); ++k )
{
osg::Vec3d point = *k;
osg::Matrixd mat;
if ( makeECEF )
{
osg::Matrixd rotation;
ECEF::transformAndGetRotationMatrix( srs, point, point, rotation );
mat = rotation * scaleMatrix * osg::Matrixd::translate(point) * _f2n->world2local();
}
else
{
mat = scaleMatrix * osg::Matrixd::translate(point) * _f2n->world2local();
}
// clone the source drawable once for each input feature.
osg::ref_ptr<osg::Geometry> newDrawable = osg::clone(
originalDrawable,
osg::CopyOp::DEEP_COPY_ARRAYS | osg::CopyOp::DEEP_COPY_PRIMITIVES );
osg::Vec3Array* verts = dynamic_cast<osg::Vec3Array*>( newDrawable->getVertexArray() );
if ( verts )
{
for( osg::Vec3Array::iterator v = verts->begin(); v != verts->end(); ++v )
{
(*v).set( (*v) * mat );
}
// add the new cloned, translated drawable back to the geode.
geode.addDrawable( newDrawable.get() );
}
}
}
}
}
geode.dirtyBound();
MeshConsolidator::run( geode );
// merge the geometry. Not sure this is necessary
osgUtil::Optimizer opt;
opt.optimize( &geode, osgUtil::Optimizer::MERGE_GEOMETRY | osgUtil::Optimizer::SHARE_DUPLICATE_STATE );
osg::NodeVisitor::apply( geode );
}
Here is the call graph for this function:FilterContext ClusterVisitor::_cx [private] |
Definition at line 279 of file SubstituteModelFilter.cpp.
FeaturesToNodeFilter* ClusterVisitor::_f2n [private] |
Definition at line 282 of file SubstituteModelFilter.cpp.
const FeatureList& ClusterVisitor::_features [private] |
Definition at line 278 of file SubstituteModelFilter.cpp.
const MarkerSymbol* ClusterVisitor::_symbol [private] |
Definition at line 280 of file SubstituteModelFilter.cpp.
1.7.3