osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #include <osgEarth/LocalTangentPlane> 00021 #include <osg/Math> 00022 #include <osg/Notify> 00023 #include <sstream> 00024 #include <algorithm> 00025 00026 using namespace osgEarth; 00027 00028 #define LC "[LTP] " 00029 00030 // -------------------------------------------------------------------------- 00031 00032 LTPSpatialReference::LTPSpatialReference( void* handle, const osg::Vec3d& worldPointLLA ) : 00033 SpatialReference( handle, false ), 00034 _worldPointLLA ( worldPointLLA ) 00035 { 00036 //todo, set proper init string 00037 } 00038 00039 void 00040 LTPSpatialReference::_init() 00041 { 00042 SpatialReference::_init(); 00043 00044 _is_user_defined = true; 00045 _is_contiguous = true; 00046 _is_ltp = true; 00047 _is_geographic = false; 00048 _name = "ENU Local Tangent Plane"; 00049 00050 // set up the LTP matrixes. 00051 00052 getEllipsoid()->computeLocalToWorldTransformFromLatLongHeight( 00053 osg::DegreesToRadians(_worldPointLLA.y()), 00054 osg::DegreesToRadians(_worldPointLLA.x()), 00055 _worldPointLLA.z(), 00056 _local2world); 00057 00058 _world2local.invert( _local2world ); 00059 } 00060 00061 bool 00062 LTPSpatialReference::preTransform(double& x, double& y, double& z, void* context) const 00063 { 00064 osg::Vec3d world = osg::Vec3d(x,y,z) * _local2world; 00065 double lat, lon, height; 00066 getEllipsoid()->convertXYZToLatLongHeight(world.x(), world.y(), world.z(), lat, lon, height); 00067 x = osg::RadiansToDegrees(lon); 00068 y = osg::RadiansToDegrees(lat); 00069 z = height; 00070 return true; 00071 } 00072 00073 bool 00074 LTPSpatialReference::postTransform(double& x, double& y, double& z, void* context) const 00075 { 00076 osg::Vec3d world; 00077 getEllipsoid()->convertLatLongHeightToXYZ( 00078 osg::DegreesToRadians(y), osg::DegreesToRadians(x), z, 00079 world.x(), world.y(), world.z() ); 00080 osg::Vec3d local = world * _world2local; 00081 x = local.x(), y = local.y(), z = local.z(); 00082 return true; 00083 } 00084 00085 bool 00086 LTPSpatialReference::_isEquivalentTo( const SpatialReference* srs ) const 00087 { 00088 return 00089 srs->isLTP() && 00090 _worldPointLLA == static_cast<const LTPSpatialReference*>(srs)->_worldPointLLA ; 00091 // todo: check the reference ellipsoids 00092 }