osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/HeightFieldUtils

Go to the documentation of this file.
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 #ifndef OSGEARTH_HEIGHTFIELDUTILS_H
00020 #define OSGEARTH_HEIGHTFIELDUTILS_H
00021 
00022 #include <osgEarth/Common>
00023 #include <osg/Shape>
00024 #include <osg/CoordinateSystemNode>
00025 #include <osg/ClusterCullingCallback>
00026 #include <osgTerrain/ValidDataOperator>
00027 
00028 namespace osgEarth
00029 {
00030 #define NO_DATA_VALUE -FLT_MAX
00031 
00035     enum OSGEARTH_EXPORT ElevationInterpolation
00036     {
00037         INTERP_AVERAGE,
00038         INTERP_NEAREST,
00039         INTERP_BILINEAR,
00040         INTERP_TRIANGULATE
00041     };
00042 
00046     enum OSGEARTH_EXPORT ElevationSamplePolicy
00047     {
00048         SAMPLE_FIRST_VALID,
00049         SAMPLE_HIGHEST,
00050         SAMPLE_LOWEST,
00051         SAMPLE_AVERAGE
00052     };
00053 
00054     class OSGEARTH_EXPORT HeightFieldUtils
00055     {
00056     public:
00060         static float getHeightAtPixel(
00061             const osg::HeightField* hf, 
00062             double c, double r, 
00063             ElevationInterpolation interpoltion = INTERP_BILINEAR);
00064         
00068         static float getHeightAtLocation(
00069             const osg::HeightField* hf, 
00070             double x, double y, 
00071             double llx, double lly,
00072             double dx, double dy,
00073             ElevationInterpolation interpolation = INTERP_BILINEAR);
00074 
00080         static float getHeightAtNormalizedLocation(
00081             const osg::HeightField* hf,
00082             double nx, double ny,
00083             ElevationInterpolation interp = INTERP_BILINEAR);
00084 
00090         static void scaleHeightFieldToDegrees( osg::HeightField* hf );
00091 
00095         static osg::HeightField* createSubSample(
00096             osg::HeightField* input, const class GeoExtent& inputEx,
00097             const class GeoExtent& outputEx,
00098             ElevationInterpolation interpolation = INTERP_BILINEAR);
00099 
00104         static osg::HeightField* resizeHeightField(
00105             osg::HeightField* input,
00106             int newX,
00107             int newY,
00108             ElevationInterpolation interp = INTERP_BILINEAR );
00109         
00115         static osg::ClusterCullingCallback* createClusterCullingCallback(
00116             osg::HeightField*    grid, 
00117             osg::EllipsoidModel* em, 
00118             float verticalScale =1.0f );
00119     };
00120 
00124     struct OSGEARTH_EXPORT CompositeValidValueOperator : public osgTerrain::ValidDataOperator
00125     {
00126         typedef std::vector<osg::ref_ptr<osgTerrain::ValidDataOperator> > ValidDataOperatorList;
00127         ValidDataOperatorList& getOperators() { return _operators;}
00128 
00129         virtual bool operator() (float value) const
00130         {
00131             for (ValidDataOperatorList::const_iterator itr = _operators.begin(); itr != _operators.end(); ++itr)
00132             {
00133                 if (!(*itr->get())(value)) return false;
00134             }
00135             return true;
00136         }
00137 
00138         ValidDataOperatorList _operators;
00139     };
00140 
00144     struct OSGEARTH_EXPORT ReplaceInvalidDataOperator : public osg::Referenced
00145     {
00146         ReplaceInvalidDataOperator();
00147 
00148         virtual void operator()(osg::HeightField* heightField);
00149 
00150         osgTerrain::ValidDataOperator* getValidDataOperator() { return _validDataOperator.get(); }
00151         void setValidDataOperator(osgTerrain::ValidDataOperator* validDataOperator) { _validDataOperator = validDataOperator; }
00152 
00153         float getReplaceWith() { return _replaceWith; }
00154         void setReplaceWith( float replaceWith ) { _replaceWith = replaceWith; }
00155 
00156         osg::ref_ptr<osgTerrain::ValidDataOperator> _validDataOperator;
00157         float _replaceWith;
00158     };
00159 
00163     struct OSGEARTH_EXPORT FillNoDataOperator : public osg::Referenced
00164     {
00165         FillNoDataOperator();
00166 
00167         virtual void operator()(osg::HeightField* heightField);
00168 
00169         osgTerrain::ValidDataOperator* getValidDataOperator() { return _validDataOperator.get(); }
00170         void setValidDataOperator(osgTerrain::ValidDataOperator* validDataOperator) { _validDataOperator = validDataOperator; }
00171 
00172         float getDefaultValue() { return _defaultValue; }
00173         void setDefaultValue(float defaultValue) { _defaultValue = defaultValue; }
00174 
00175         osg::ref_ptr<osgTerrain::ValidDataOperator> _validDataOperator;
00176 
00177         float _defaultValue;
00178     };
00179 }
00180 
00181 #endif //OSGEARTH_HEIGHTFIELDUTILS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines