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

« back to all changes in this revision

Viewing changes to src/osgEarthUtil/ObjectPlacer

  • 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
#ifndef OSGEARTHUTIL_OBJECT_PLACER
 
20
#define OSGEARTHUTIL_OBJECT_PLACER
 
21
 
 
22
#include <osgEarthUtil/Common>
 
23
#include <osgEarth/MapNode>
 
24
#include <osg/Node>
 
25
#include <osg/Matrix>
 
26
#include <osgUtil/IntersectionVisitor>
 
27
 
 
28
namespace osgEarth { namespace Util
 
29
{
 
30
    /**
 
31
     * Convenience utilities for placing an object on an osgEarth terrain map
 
32
     * using latitude/longitude coordinates.
 
33
     */
 
34
    class OSGEARTHUTIL_EXPORT ObjectPlacer
 
35
    {
 
36
    public:
 
37
        /**
 
38
         * Constructs a new placer.
 
39
         *
 
40
         * @param terrain
 
41
         *      The scene graph containing the osgEarth::Map node.
 
42
         * @param traversalMask
 
43
         *      Mask to use when intersecting the terrain.
 
44
         * @param clamp
 
45
         *      Whether the class should attempt to calculate the placement 
 
46
         *      position so that it sits exactly on the terrain skin.
 
47
         *      Warning: this does not yet work properly for maps that don't
 
48
         *      report a maximum resolution (like most of the commercial providers).
 
49
         * @param maxLevel
 
50
         *      Maximum level of detail to which to search for high resolution terrain.
 
51
         */
 
52
        ObjectPlacer(
 
53
            osg::Node* terrain,
 
54
            int  traversalMask =~0,
 
55
            bool clamp        =false,
 
56
            int  maxLevel     =20);
 
57
 
 
58
        /**
 
59
         * Creates a double-precision matrix that will transform geometry to the
 
60
         * specified map location. In a geocentric map, the matrix will also rotate
 
61
         * into the tangent plane.
 
62
         *
 
63
         * @param lat_degrees, lon_degrees
 
64
         *      Location on the map for which to generate a matrix
 
65
         * @param height
 
66
         *      Height above the terrain (in local units)
 
67
         * @param out_result
 
68
         *      Receives the resulting matrix; only valid if the method returns TRUE.
 
69
         * @return
 
70
         *      True if the method succesfully created the output matrix; false if not
 
71
         *      (e.g., the input location was outside the extents of the terrain map).
 
72
         */
 
73
        bool createPlacerMatrix(
 
74
            double lat_degrees,
 
75
            double lon_degrees,
 
76
            double height,
 
77
            osg::Matrixd& out_result ) const;
 
78
 
 
79
        /**
 
80
         * Creates a new node graph that positions the input node at a specified map
 
81
         * location. The resulting node will contain the input node as a child.
 
82
         *
 
83
         * @param node
 
84
         *      Node to position at the specified location
 
85
         * @param lat_degrees, lon_degrees
 
86
         *      Position on the map at which to place the node
 
87
         * @param height
 
88
         *      Height above the terrain (in local units)
 
89
         * @return
 
90
         *      A node graph representing the newly placed node. The input node will be
 
91
         *      a child in the new graph. NULL if the placement failed for some reason.
 
92
         */
 
93
        osg::Node* placeNode(
 
94
            osg::Node* node,
 
95
            double lat_degrees,
 
96
            double lon_degrees,
 
97
            double height ) const;
 
98
 
 
99
    private:
 
100
        osg::ref_ptr<osgEarth::MapNode> _mapNode;
 
101
        osg::ref_ptr<osg::CoordinateSystemNode> _csn;
 
102
        osg::ref_ptr<osgUtil::IntersectionVisitor::ReadCallback> _readCallback;
 
103
        int _traversalMask;
 
104
        bool _clamp;
 
105
 
 
106
        bool clampGeocentric(osg::CoordinateSystemNode* csn, double lat_rad, double lon_rad, osg::Vec3d& out) const;
 
107
        bool clampProjected(osg::CoordinateSystemNode* csn, double x, double y, osg::Vec3d& out) const;
 
108
    };
 
109
 
 
110
} } // namespace osgEarth::Util
 
111
 
 
112
#endif // OSGEARTHUTIL_OBJECT_PLACER