~ubuntu-branches/debian/sid/osgearth/sid

« back to all changes in this revision

Viewing changes to src/osgEarth/MaskLayer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pirmin Kalberer
  • Date: 2011-07-14 22:13:36 UTC
  • Revision ID: james.westby@ubuntu.com-20110714221336-94igk9rskxveh794
Tags: upstream-2.0+dfsg
ImportĀ upstreamĀ versionĀ 2.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*-c++-*- */
 
2
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 
3
 * Copyright 2008-2010 Pelican Mapping
 
4
 * http://osgearth.org
 
5
 *
 
6
 * osgEarth is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 
18
 */
 
19
#include <osgEarth/MaskLayer>
 
20
#include <osgEarth/Map>
 
21
 
 
22
using namespace osgEarth;
 
23
 
 
24
#define MASK_MODEL_DRIVER "feature_stencil"
 
25
 
 
26
MaskLayer::MaskLayer( const ConfigOptions& options )
 
27
{
 
28
    // just in case the caller did not ref the parameter:
 
29
    //osg::ref_ptr<const DriverOptions> tempHold = options;
 
30
 
 
31
    // copy the input options and set some special settings:
 
32
    Config conf = options.getConfig();
 
33
    conf.update( "mask", "true" );
 
34
    conf.update( "inverted", "true" );
 
35
    conf.update( "extrusion_distance", "100000" );
 
36
    _driverOptions = DriverConfigOptions( conf );
 
37
    _driverOptions.setDriver( MASK_MODEL_DRIVER );
 
38
}
 
39
 
 
40
void
 
41
MaskLayer::initialize( const std::string& referenceURI, const Map* map )
 
42
{
 
43
    _referenceURI = referenceURI;
 
44
 
 
45
    if ( !_modelSource.valid() )
 
46
    {
 
47
        _modelSource = ModelSourceFactory::create( _driverOptions );
 
48
    }
 
49
 
 
50
    if ( _modelSource.valid() )
 
51
    {
 
52
        _modelSource->initialize( _referenceURI, map );
 
53
    }
 
54
}
 
55
 
 
56
osg::Node*
 
57
MaskLayer::getOrCreateNode( ProgressCallback* progress )
 
58
{
 
59
    osg::Node* result = 0L;
 
60
 
 
61
    if ( _modelSource.valid() )
 
62
    {
 
63
        result = _modelSource->createNode( progress );
 
64
 
 
65
        // a hack to immediately update-traverse this node so it can generate its 
 
66
        // MaskNodes. Otherwise MapNode will not be able to apply it.
 
67
        if ( result )
 
68
        {
 
69
            osg::NodeVisitor nv( osg::NodeVisitor::UPDATE_VISITOR, osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
 
70
            result->accept( nv );
 
71
        }
 
72
    }
 
73
 
 
74
    return result;
 
75
}
 
76
 
 
77
Config
 
78
MaskLayer::getConfig() const
 
79
{
 
80
    Config conf = _driverOptions.getConfig();
 
81
    conf.key() = "mask";
 
82
    conf.remove( "driver" );
 
83
    return conf;
 
84
}