Locator 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifndef OSGTERRAIN_LOCATOR
  14. #define OSGTERRAIN_LOCATOR 1
  15. #include <osg/Object>
  16. #include <osg/Vec3d>
  17. #include <osg/CoordinateSystemNode>
  18. #include <osgTerrain/Export>
  19. namespace osgTerrain {
  20. class OSGTERRAIN_EXPORT Locator : public osg::Object
  21. {
  22. public:
  23. Locator();
  24. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  25. Locator(const Locator&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  26. META_Object(osgTerrain, Locator);
  27. /** CoordinateSystemType provides the classification of the type coordinate system represented.*/
  28. enum CoordinateSystemType
  29. {
  30. /** GEOCENTRIC coordinate systems are ones mapped to the around the ellipsoid, i.e. whole earth.*/
  31. GEOCENTRIC,
  32. /** GEOGRAPHIC coordinate systems are ones mapped to latitude and longitude.*/
  33. GEOGRAPHIC,
  34. /** PROJECTED coordinate systems are ones projected to a local projected coordinate system i.e. UTMs.*/
  35. PROJECTED
  36. };
  37. /** Set the CoordinatesSyetemType.
  38. * Note, the user must keep the CoordinateSystemString consistent with the type of the CoordinateSystem.*/
  39. void setCoordinateSystemType(CoordinateSystemType type) { _coordinateSystemType = type; }
  40. /** Get the CoordinatesSyetemType.*/
  41. CoordinateSystemType getCoordinateSystemType() const { return _coordinateSystemType; }
  42. /** Set the coordinate system format string. Typical values would be WKT, PROJ4, USGS etc.*/
  43. void setFormat(const std::string& format) { _format = format; }
  44. /** Get the coordinate system format string.*/
  45. const std::string& getFormat() const { return _format; }
  46. /** Set the CoordinateSystem reference string, should be stored in a form consistent with the Format.*/
  47. void setCoordinateSystem(const std::string& cs) { _cs = cs; }
  48. /** Get the CoordinateSystem reference string.*/
  49. const std::string& getCoordinateSystem() const { return _cs; }
  50. /** Set EllipsoidModel to describe the model used to map lat, long and height into geocentric XYZ and back. */
  51. void setEllipsoidModel(osg::EllipsoidModel* ellipsode) { _ellipsoidModel = ellipsode; }
  52. /** Get the EllipsoidModel.*/
  53. osg::EllipsoidModel* getEllipsoidModel() { return _ellipsoidModel.get(); }
  54. /** Get the const EllipsoidModel.*/
  55. const osg::EllipsoidModel* getEllipsoidModel() const { return _ellipsoidModel.get(); }
  56. /** Set the transformation from local coordinates to model coordinates.*/
  57. void setTransform(const osg::Matrixd& transform) { _transform = transform; _inverse.invert(_transform); }
  58. /** Set the transformation from local coordinates to model coordinates.*/
  59. const osg::Matrixd& getTransform() const { return _transform; }
  60. /** Set the extents of the local coords.*/
  61. void setTransformAsExtents(double minX, double minY, double maxX, double maxY);
  62. virtual bool orientationOpenGL() const;
  63. virtual bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const;
  64. virtual bool convertModelToLocal(const osg::Vec3d& world, osg::Vec3d& local) const;
  65. static bool convertLocalCoordBetween(const Locator& source, const osg::Vec3d& sourceNDC,
  66. const Locator& destination, osg::Vec3d& destinationNDC)
  67. {
  68. osg::Vec3d model;
  69. if (!source.convertLocalToModel(sourceNDC, model)) return false;
  70. if (!destination.convertModelToLocal(model, destinationNDC)) return false;
  71. return true;
  72. }
  73. bool computeLocalBounds(Locator& source, osg::Vec3d& bottomLeft, osg::Vec3d& topRight) const;
  74. void setDefinedInFile(bool flag) { _definedInFile = flag; }
  75. bool getDefinedInFile() const { return _definedInFile; }
  76. void setTransformScaledByResolution(bool scaledByResolution) { _transformScaledByResolution = scaledByResolution; }
  77. bool getTransformScaledByResolution() const { return _transformScaledByResolution; }
  78. protected:
  79. virtual ~Locator();
  80. CoordinateSystemType _coordinateSystemType;
  81. std::string _format;
  82. std::string _cs;
  83. osg::ref_ptr<osg::EllipsoidModel> _ellipsoidModel;
  84. osg::Matrixd _transform;
  85. osg::Matrixd _inverse;
  86. bool _definedInFile;
  87. bool _transformScaledByResolution;
  88. };
  89. }
  90. #endif