Exemple #1
0
osg::Node*
LocalizedNode::applyAltitudePolicy(osg::Node* node, const Style& style)
{
    AnnotationUtils::AltitudePolicy ap;
    AnnotationUtils::getAltitudePolicy( style, ap );

    // Draped (projected) geometry
    if ( ap.draping )
    {
        DrapeableNode* drapable = new DrapeableNode( getMapNode() );
        drapable->addChild( node );
        node = drapable;
    }

    // gw - not sure whether is makes sense to support this for LocalizedNode
    // GPU-clamped geometry
    else if ( ap.gpuClamping )
    {
        ClampableNode* clampable = new ClampableNode( getMapNode() );
        clampable->addChild( node );
        node = clampable;

        const RenderSymbol* render = style.get<RenderSymbol>();
        if ( render && render->depthOffset().isSet() )
        {
            clampable->depthOffset() = *render->depthOffset();
        }
    }

    // scenegraph-clamped geometry
    else if ( ap.sceneClamping )
    {
        // save for later when we need to reclamp the mesh on the CPU
        _altitude = style.get<AltitudeSymbol>();

        // activate the terrain callback:
        setCPUAutoClamping( true );
    }

    return node;
}
Exemple #2
0
void
FeatureNode::init()
{
    // if there's a decoration, clear it out first.
    this->clearDecoration();
    _attachPoint = 0L;

    // if there is existing geometry, kill it
    this->removeChildren( 0, this->getNumChildren() );

    if ( !getMapNode() )
        return;

    if ( !_feature.valid() )
        return;

    // compilation options.
    GeometryCompilerOptions options = _options;
    
    // figure out what kind of altitude manipulation we need to perform.
    AnnotationUtils::AltitudePolicy ap;
    AnnotationUtils::getAltitudePolicy( *_feature->style(), ap );

    // If we're doing auto-clamping on the CPU, shut off compiler map clamping
    // clamping since it would be redundant.
    // TODO: I think this is OBE now that we have "scene" clamping technique..
    if ( ap.sceneClamping )
    {
        options.ignoreAltitudeSymbol() = true;
    }

    // prep the compiler:
    GeometryCompiler compiler( options );
    Session* session = new Session( getMapNode()->getMap() );
    GeoExtent extent(_feature->getSRS(), _feature->getGeometry()->getBounds());
    osg::ref_ptr<FeatureProfile> profile = new FeatureProfile( extent );
    FilterContext context( session, profile.get(), extent );

    // Clone the Feature before rendering as the GeometryCompiler and it's filters can change the coordinates
    // of the geometry when performing localization or converting to geocentric.
    osg::ref_ptr< Feature > clone = new Feature(*_feature.get(), osg::CopyOp::DEEP_COPY_ALL);

    osg::Node* node = compiler.compile( clone.get(), *clone->style(), context );
    if ( node )
    {
        if ( _feature->style().isSet() &&
            AnnotationUtils::styleRequiresAlphaBlending( *_feature->style() ) &&
            _feature->style()->get<ExtrusionSymbol>() )
        {
            node = AnnotationUtils::installTwoPassAlpha( node );
        }

        _attachPoint = new osg::Group();
        _attachPoint->addChild( node );

        // Draped (projected) geometry
        if ( ap.draping )
        {
            DrapeableNode* d = new DrapeableNode( getMapNode() );
            d->addChild( _attachPoint );
            this->addChild( d );
        }

        // GPU-clamped geometry
        else if ( ap.gpuClamping )
        {
            ClampableNode* clampable = new ClampableNode( getMapNode() );
            clampable->addChild( _attachPoint );
            this->addChild( clampable );

            const RenderSymbol* render = _feature->style()->get<RenderSymbol>();
            if ( render && render->depthOffset().isSet() )
            {
                clampable->depthOffset() = *render->depthOffset();
            }
        }

        else 
        {
            this->addChild( _attachPoint );

            // CPU-clamped geometry?
            if ( ap.sceneClamping )
            {
                // save for later when we need to reclamp the mesh on the CPU
                _altitude = _feature->style()->get<AltitudeSymbol>();

                // The polytope will ensure we only clamp to intersecting tiles:
                _feature->getWorldBoundingPolytope( getMapNode()->getMapSRS(), _featurePolytope );

                // activate the terrain callback:
                setCPUAutoClamping( true );

                // set default lighting based on whether we are extruding:
                setLightingIfNotSet( _feature->style()->has<ExtrusionSymbol>() );

                // do an initial clamp to get started.
                clampMesh( getMapNode()->getTerrain()->getGraph() );
            }
        }
    }
}