1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSGTERRAIN_LOCATOR
15#define OSGTERRAIN_LOCATOR 1
19#include <osg/CoordinateSystemNode>
21#include <osgTerrain/Export>
25class OSGTERRAIN_EXPORT Locator : public osg::Object
31 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
32 Locator(const Locator&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
34 META_Object(osgTerrain, Locator);
36 /** CoordinateSystemType provides the classification of the type coordinate system represented.*/
37 enum CoordinateSystemType
39 /** GEOCENTRIC coordinate systems are ones mapped to the around the ellipsoid, i.e. whole earth.*/
42 /** GEOGRAPHIC coordinate systems are ones mapped to latitude and longitude.*/
45 /** PROJECTED coordinate systems are ones projected to a local projected coordinate system i.e. UTMs.*/
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; }
53 /** Get the CoordinatesSyetemType.*/
54 CoordinateSystemType getCoordinateSystemType() const { return _coordinateSystemType; }
56 /** Set the coordinate system format string. Typical values would be WKT, PROJ4, USGS etc.*/
57 void setFormat(const std::string& format) { _format = format; }
59 /** Get the coordinate system format string.*/
60 const std::string& getFormat() const { return _format; }
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; }
65 /** Get the CoordinateSystem reference string.*/
66 const std::string& getCoordinateSystem() const { return _cs; }
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; }
72 /** Get the EllipsoidModel.*/
73 osg::EllipsoidModel* getEllipsoidModel() { return _ellipsoidModel.get(); }
75 /** Get the const EllipsoidModel.*/
76 const osg::EllipsoidModel* getEllipsoidModel() const { return _ellipsoidModel.get(); }
79 /** Set the transformation from local coordinates to model coordinates.*/
80 void setTransform(const osg::Matrixd& transform) { _transform = transform; _inverse.invert(_transform); }
82 /** Set the transformation from local coordinates to model coordinates.*/
83 const osg::Matrixd& getTransform() const { return _transform; }
85 /** Set the extents of the local coords.*/
86 void setTransformAsExtents(double minX, double minY, double maxX, double maxY);
89 virtual bool orientationOpenGL() const;
91 virtual bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const;
93 virtual bool convertModelToLocal(const osg::Vec3d& world, osg::Vec3d& local) const;
95 static bool convertLocalCoordBetween(const Locator& source, const osg::Vec3d& sourceNDC,
96 const Locator& destination, osg::Vec3d& destinationNDC)
99 if (!source.convertLocalToModel(sourceNDC, model)) return false;
100 if (!destination.convertModelToLocal(model, destinationNDC)) return false;
104 bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
106 void setDefinedInFile(bool flag) { _definedInFile = flag; }
107 bool getDefinedInFile() const { return _definedInFile; }
109 void setTransformScaledByResolution(bool scaledByResolution) { _transformScaledByResolution = scaledByResolution; }
110 bool getTransformScaledByResolution() const { return _transformScaledByResolution; }
116 CoordinateSystemType _coordinateSystemType;
120 osg::ref_ptr<osg::EllipsoidModel> _ellipsoidModel;
122 osg::Matrixd _transform;
123 osg::Matrixd _inverse;
126 bool _transformScaledByResolution;