/usr/include/osgEarth/HeightFieldUtils is in libosgearth-dev 2.5.0+dfsg-8build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | /* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2013 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_HEIGHTFIELDUTILS_H
#define OSGEARTH_HEIGHTFIELDUTILS_H
#include <osgEarth/Common>
#include <osgEarth/GeoData>
#include <osg/Shape>
#include <osg/CoordinateSystemNode>
#include <osg/ClusterCullingCallback>
#include <osgTerrain/ValidDataOperator>
namespace osgEarth
{
struct HeightFieldNeighborhood
{
osg::ref_ptr<osg::HeightField> _center;
osg::ref_ptr<osg::HeightField> _neighbors[8];
osg::HeightField* getNeighbor(int xoffset, int yoffset) const {
if ( xoffset == 0 && yoffset == 0 ) return _center.get();
int index = 3*(yoffset+1)+(xoffset+1);
if (index > 4) index--;
return _neighbors[index].get();
}
void setNeighbor(int xoffset, int yoffset, osg::HeightField* hf) {
if ( xoffset == 0 && yoffset == 0 ) {
_center = hf;
}
else {
int index = 3*(yoffset+1)+(xoffset+1);
if (index > 4) index--;
_neighbors[index] = hf;
}
}
void getNeighborForNormalizedLocation(double nx, double ny, osg::ref_ptr<osg::HeightField>& hf, double& out_nx, double& out_ny) const {
int xoffset = nx < 0.0 ? -1 : nx > 1.0 ? 1 : 0;
int yoffset = ny < 0.0 ? 1 : ny > 1.0 ? -1 : 0;
if ( xoffset != 0 || yoffset != 0 )
hf = getNeighbor(xoffset, yoffset);
else
hf = _center.get();
out_nx = nx < 0.0 ? 1.0+nx : nx > 1.0 ? nx-1.0 : nx;
out_ny = ny < 0.0 ? 1.0+ny : ny > 1.0 ? ny-1.0 : ny;
}
};
class OSGEARTH_EXPORT HeightFieldUtils
{
public:
/**
* Gets the interpolated height value at the specified fractional pixel position.
*/
static float getHeightAtPixel(
const osg::HeightField* hf,
double c, double r,
ElevationInterpolation interpoltion = INTERP_BILINEAR);
/**
* Gets the height value at the specified column and row, but instead of reading
* the actual height, interpolates a height based on the neighbors.
*/
static bool getInterpolatedHeight(
const osg::HeightField* hf,
unsigned c, unsigned r,
float& out_height,
ElevationInterpolation interpoltion = INTERP_BILINEAR);
/**
* Gets the interpolated height value at the specific geolocation.
*/
static float getHeightAtLocation(
const osg::HeightField* hf,
double x, double y,
double llx, double lly,
double dx, double dy,
ElevationInterpolation interpolation = INTERP_BILINEAR);
/**
* Gets the interpolated elevation at the specified "normalized unit location".
* i.e., nx => [0.0, 1.0], ny => [0.0, 1.0] where 0.0 and 1.0 are the opposing
* endposts of the heightfield.
*/
static float getHeightAtNormalizedLocation(
const osg::HeightField* hf,
double nx, double ny,
ElevationInterpolation interp = INTERP_BILINEAR);
/**
* Gets the interpolated elevation at the specified "normalized unit location".
* i.e., nx => [-1.0...2.0], ny => [-1.0...2.0] since it can query neighbors
* as well.
*/
static float getHeightAtNormalizedLocation(
const HeightFieldNeighborhood& hood,
double nx, double ny,
ElevationInterpolation interp = INTERP_BILINEAR);
/**
* Gets the normal vector at the specified "normalized unit location".
* i.e., nx => [0.0, 1.0], ny => [0.0, 1.0] where 0.0 and 1.0 are the opposing
* endposts of the heightfield.
*/
static bool getNormalAtNormalizedLocation(
const osg::HeightField* hf,
double nx, double ny,
osg::Vec3& output,
ElevationInterpolation interp = INTERP_BILINEAR);
/**
* Scales all the height values in a heightfield from scalar units to "linear degrees".
* The only purpose of this is to show reasonable height values in a projected
* Plate Carre map (in which vertical units are not well defined).
*/
static void scaleHeightFieldToDegrees( osg::HeightField* hf );
/**
* Creates a heightfield containing MSL heights for the specified extent.
* If the SRS (in GeoExtent) has a vertical datum, the height values will be those of
* its reference geoid. If there is no vertical datum, we assume that MSL == the reference
* ellipsoid, and all the HF values will be zero.
*/
static osg::HeightField* createReferenceHeightField(
const GeoExtent& ex,
unsigned numCols,
unsigned numRows );
/**
* Subsamples a heightfield to the specified extent.
*/
static osg::HeightField* createSubSample(
osg::HeightField* input,
const GeoExtent& inputEx,
const GeoExtent& outputEx,
ElevationInterpolation interpolation = INTERP_BILINEAR);
/**
* Resizes a heightfield, keeping the corner values the same and
* resampling the internal posts.
*/
static osg::HeightField* resampleHeightField(
osg::HeightField* input,
const GeoExtent& inputEx,
int newX,
int newY,
ElevationInterpolation interp = INTERP_BILINEAR );
/**
* Resolves any "invalid" height values in the hieghtfield, replacing them
* with valid values from a Geoid (or zero if no geoid).
*/
static void resolveInvalidHeights(
osg::HeightField* grid,
const GeoExtent& extent,
float invalidValue,
const Geoid* geoid );
/**
* Creates a new cluster culler based on a heightfield.
* Cluster cullers are for geocentric maps only, and therefore requires
* the ellipsoid model.
*/
static osg::NodeCallback* createClusterCullingCallback(
osg::HeightField* grid,
const osg::EllipsoidModel* em,
float verticalScale =1.0f );
};
/**
* A collection of ValidDataOperators. All operators must pass to be considered valid.
*/
struct OSGEARTH_EXPORT CompositeValidValueOperator : public osgTerrain::ValidDataOperator
{
typedef std::vector<osg::ref_ptr<osgTerrain::ValidDataOperator> > ValidDataOperatorList;
ValidDataOperatorList& getOperators() { return _operators;}
virtual bool operator() (float value) const
{
for (ValidDataOperatorList::const_iterator itr = _operators.begin(); itr != _operators.end(); ++itr)
{
if (!(*itr->get())(value)) return false;
}
return true;
}
ValidDataOperatorList _operators;
};
/**
* Visitor that replaces "invalid" data values with a known value.
*/
struct OSGEARTH_EXPORT ReplaceInvalidDataOperator : public osg::Referenced
{
ReplaceInvalidDataOperator();
virtual void operator()(osg::HeightField* heightField);
osgTerrain::ValidDataOperator* getValidDataOperator() { return _validDataOperator.get(); }
void setValidDataOperator(osgTerrain::ValidDataOperator* validDataOperator) { _validDataOperator = validDataOperator; }
float getReplaceWith() { return _replaceWith; }
void setReplaceWith( float replaceWith ) { _replaceWith = replaceWith; }
osg::ref_ptr<osgTerrain::ValidDataOperator> _validDataOperator;
float _replaceWith;
};
/**
* Visitor that replaces "invalid" data values with a default value.
*/
struct OSGEARTH_EXPORT FillNoDataOperator : public osg::Referenced
{
FillNoDataOperator();
virtual void operator()(osg::HeightField* heightField);
osgTerrain::ValidDataOperator* getValidDataOperator() { return _validDataOperator.get(); }
void setValidDataOperator(osgTerrain::ValidDataOperator* validDataOperator) { _validDataOperator = validDataOperator; }
float getDefaultValue() { return _defaultValue; }
void setDefaultValue(float defaultValue) { _defaultValue = defaultValue; }
osg::ref_ptr<osgTerrain::ValidDataOperator> _validDataOperator;
float _defaultValue;
};
}
#endif //OSGEARTH_HEIGHTFIELDUTILS_H
|