openscenegraph
osgTerrain/Locator
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGTERRAIN_LOCATOR
15#define OSGTERRAIN_LOCATOR 1
16
17#include <osg/Object>
18#include <osg/Vec3d>
19#include <osg/CoordinateSystemNode>
20
21#include <osgTerrain/Export>
22
23namespace osgTerrain {
24
25class OSGTERRAIN_EXPORT Locator : public osg::Object
26{
27 public:
28
29 Locator();
30
31 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
32 Locator(const Locator&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
33
34 META_Object(osgTerrain, Locator);
35
36 /** CoordinateSystemType provides the classification of the type coordinate system represented.*/
37 enum CoordinateSystemType
38 {
39 /** GEOCENTRIC coordinate systems are ones mapped to the around the ellipsoid, i.e. whole earth.*/
40 GEOCENTRIC,
41
42 /** GEOGRAPHIC coordinate systems are ones mapped to latitude and longitude.*/
43 GEOGRAPHIC,
44
45 /** PROJECTED coordinate systems are ones projected to a local projected coordinate system i.e. UTMs.*/
46 PROJECTED
47 };
48
49 /** Set the CoordinatesSyetemType.
50 * Note, the user must keep the CoordinateSystemString consistent with the type of the CoordinateSystem.*/
51 void setCoordinateSystemType(CoordinateSystemType type) { _coordinateSystemType = type; }
52
53 /** Get the CoordinatesSyetemType.*/
54 CoordinateSystemType getCoordinateSystemType() const { return _coordinateSystemType; }
55
56 /** Set the coordinate system format string. Typical values would be WKT, PROJ4, USGS etc.*/
57 void setFormat(const std::string& format) { _format = format; }
58
59 /** Get the coordinate system format string.*/
60 const std::string& getFormat() const { return _format; }
61
62 /** Set the CoordinateSystem reference string, should be stored in a form consistent with the Format.*/
63 void setCoordinateSystem(const std::string& cs) { _cs = cs; }
64
65 /** Get the CoordinateSystem reference string.*/
66 const std::string& getCoordinateSystem() const { return _cs; }
67
68
69 /** Set EllipsoidModel to describe the model used to map lat, long and height into geocentric XYZ and back. */
70 void setEllipsoidModel(osg::EllipsoidModel* ellipsode) { _ellipsoidModel = ellipsode; }
71
72 /** Get the EllipsoidModel.*/
73 osg::EllipsoidModel* getEllipsoidModel() { return _ellipsoidModel.get(); }
74
75 /** Get the const EllipsoidModel.*/
76 const osg::EllipsoidModel* getEllipsoidModel() const { return _ellipsoidModel.get(); }
77
78
79 /** Set the transformation from local coordinates to model coordinates.*/
80 void setTransform(const osg::Matrixd& transform) { _transform = transform; _inverse.invert(_transform); }
81
82 /** Set the transformation from local coordinates to model coordinates.*/
83 const osg::Matrixd& getTransform() const { return _transform; }
84
85 /** Set the extents of the local coords.*/
86 void setTransformAsExtents(double minX, double minY, double maxX, double maxY);
87
88
89 virtual bool orientationOpenGL() const;
90
91 virtual bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const;
92
93 virtual bool convertModelToLocal(const osg::Vec3d& world, osg::Vec3d& local) const;
94
95 static bool convertLocalCoordBetween(const Locator& source, const osg::Vec3d& sourceNDC,
96 const Locator& destination, osg::Vec3d& destinationNDC)
97 {
98 osg::Vec3d model;
99 if (!source.convertLocalToModel(sourceNDC, model)) return false;
100 if (!destination.convertModelToLocal(model, destinationNDC)) return false;
101 return true;
102 }
103
104 bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
105
106 void setDefinedInFile(bool flag) { _definedInFile = flag; }
107 bool getDefinedInFile() const { return _definedInFile; }
108
109 void setTransformScaledByResolution(bool scaledByResolution) { _transformScaledByResolution = scaledByResolution; }
110 bool getTransformScaledByResolution() const { return _transformScaledByResolution; }
111
112 protected:
113
114 virtual ~Locator();
115
116 CoordinateSystemType _coordinateSystemType;
117
118 std::string _format;
119 std::string _cs;
120 osg::ref_ptr<osg::EllipsoidModel> _ellipsoidModel;
121
122 osg::Matrixd _transform;
123 osg::Matrixd _inverse;
124
125 bool _definedInFile;
126 bool _transformScaledByResolution;
127
128};
129
130}
131
132#endif