35 static ossimTrace traceDebug(
"ossimH5GridModel:debug");
37 static const std::string CROSSES_DATELINE_KW =
"crosses_dateline";
38 static const std::string GROUND_POLYGON_KW =
"ground_polygon";
39 static const std::string WKT_FOOTPRINT_KW =
"wkt_footprint";
46 m_crossesDateline(false),
57 H5::DataSet* lonDataSet,
62 if ( latDataSet && lonDataSet )
76 H5::DataSpace latDataSpace = latDataSet->getSpace();
77 H5::DataSpace lonDataSpace = lonDataSet->getSpace();
78 const ossim_int32 LAT_DIM_COUNT = latDataSpace.getSimpleExtentNdims();
79 const ossim_int32 LON_DIM_COUNT = lonDataSpace.getSimpleExtentNdims();
82 if ( ( LAT_DIM_COUNT == 2 ) && ( LON_DIM_COUNT == 2 ) )
92 std::vector<hsize_t> latDimsOut(LAT_DIM_COUNT);
93 latDataSpace.getSimpleExtentDims( &latDimsOut.front(), 0 );
94 std::vector<hsize_t> lonDimsOut(LON_DIM_COUNT);
95 lonDataSpace.getSimpleExtentDims( &lonDimsOut.front(), 0 );
98 if ( (ROWS <= latDimsOut[0] ) && (ROWS <= lonDimsOut[0] ) &&
99 (COLS <= latDimsOut[1] ) && (COLS <= lonDimsOut[1] ) )
104 ossimDpt dspacing (GRID_SIZE, GRID_SIZE);
110 if ( ROWS % GRID_SIZE) ++gridRows;
111 if ( COLS % GRID_SIZE) ++gridCols;
113 ossimIpt gridSize (gridCols, gridRows);
125 std::vector<hsize_t> inputCount(LAT_DIM_COUNT);
126 std::vector<hsize_t> inputOffset(LAT_DIM_COUNT);
129 inputOffset[1] = validRect.
ul().
x;
132 inputCount[1] = (hsize_t)COLS;
136 std::vector<hsize_t> outputCount(OUT_DIM_COUNT);
139 outputCount[2] = COLS;
142 std::vector<hsize_t> outputOffset(OUT_DIM_COUNT);
161 H5::DataType latDataType = latDataSet->getDataType();
162 H5::DataType lonDataType = lonDataSet->getDataType();
165 H5::DataSpace bufferDataSpace( OUT_DIM_COUNT, &outputCount.front());
166 bufferDataSpace.selectHyperslab( H5S_SELECT_SET,
167 &outputCount.front(),
168 &outputOffset.front() );
171 vector<ossim_float32> latValue(COLS);
172 vector<ossim_float32> lonValue(COLS);
183 inputOffset[0] = row + validRect.
ul().
y;
185 latDataSpace.selectHyperslab( H5S_SELECT_SET,
187 &inputOffset.front() );
188 lonDataSpace.selectHyperslab( H5S_SELECT_SET,
190 &inputOffset.front() );
193 latDataSet->read( &(latValue.front()), latDataType,
194 bufferDataSpace, latDataSpace );
195 lonDataSet->read( &(lonValue.front()), lonDataType,
196 bufferDataSpace, lonDataSpace );
201 endian->
swap( &(latValue.front()), COLS );
202 endian->
swap( &(lonValue.front()), COLS );
218 if ( (latValue[col] > NULL_VALUE)&&(lonValue[col] > NULL_VALUE) )
224 if ( lon < 0.0 ) lon += 360;
230 "ossimH5GridModel::setGridNodes encountered nans!";
244 if ( ( lat1 > NULL_VALUE ) && ( lat2 > NULL_VALUE ) )
250 lat = lat2 + latSpacing;
255 "ossimH5GridModel::setGridNodes encountered nans!";
259 if ( ( lon1 > NULL_VALUE ) && ( lon2 > NULL_VALUE ) )
265 lon = lon2 + lonSpacing;
276 "ossimH5GridModel::setGridNodes encountered nans!";
281 cout <<
"lat1: " << lat1 <<
" lat2 " << lat2
282 <<
" lon1 " << lon1 <<
" lon2 " << lon2
292 cout <<
"x,y,col,row,lat,lon:" <<
x <<
"," <<
y <<
"," 293 << col <<
"," << row <<
"," 314 if ( ( lon1 > NULL_VALUE ) && ( lon2 > NULL_VALUE ) )
320 lon = lon2 + lonSpacing;
331 "ossimH5GridModel::setGridNodes encountered nans!";
335 if ( ( lat1 > NULL_VALUE ) && ( lat2 > NULL_VALUE ) )
340 lat = lat2 + latSpacing;
345 "ossimH5GridModel::setGridNodes encountered nans!";
350 hsize_t col =
x*GRID_SIZE;
351 cout <<
"lat1: " << lat1 <<
" lat2 " << lat2
352 <<
" lon1 " << lon1 <<
" lon2 " << lon2
353 <<
"\nx,y,col,row,lat,lon:" <<
x <<
"," <<
y <<
"," 354 << col <<
"," << row <<
"," << lat <<
"," << lon <<
"\n";
368 latDataSpace.close();
369 lonDataSpace.close();
374 *latDataSet,*lonDataSet, validRect );
408 std::string myPrefix = ( prefix ? prefix:
"" );
413 kwl.
addPair( myPrefix,CROSSES_DATELINE_KW, value,
true );
418 kwl.
addPair( myPrefix, WKT_FOOTPRINT_KW, value,
true );
424 std::string polyPrefix = myPrefix;
425 polyPrefix += GROUND_POLYGON_KW;
437 seedPrefix +=
"seed_projection.";
449 std::string myPrefix = ( prefix ? prefix:
"" );
452 std::string key =
"type";
453 std::string value = kwl.
findKey( myPrefix, key );
458 if ( ( value ==
"ossimH5GridModel" ) || ( value ==
"ossimHdfGridModel" ) )
464 std::string seedPrefix = myPrefix;
465 seedPrefix +=
"seed_projection.";
466 value = kwl.
findKey( seedPrefix, key );
471 createProjection(kwl, seedPrefix.c_str());
475 value = kwl.
findKey( myPrefix, CROSSES_DATELINE_KW );
482 std::string polyPrefix = myPrefix;
483 polyPrefix += GROUND_POLYGON_KW;
490 value =
"ossimCoarseGridModel";
491 myKwl.
addPair( myPrefix, key, value,
true );
511 static const double PIXEL_THRESHOLD = .1;
512 static const int MAX_NUM_ITERATIONS = 20;
553 double height = worldPoint.
hgt;
577 double dlat_du, dlat_dv, dlon_du, dlon_dv;
578 double delta_lat, delta_lon, delta_u, delta_v;
589 ip_du.
u = ip.
u + 1.0;
592 ip_dv.
v = ip.
v + 1.0;
618 if ( gp.
lon < 0.0 ) gp.
lon += 360.0;
619 if ( gp_du.
lon < 0.0 ) gp_du.
lon += 360.0;
620 if ( gp_dv.
lon < 0.0 ) gp_dv.
lon += 360.0;
623 dlat_du = gp_du.
lat - gp.
lat;
624 dlon_du = gp_du.
lon - gp.
lon;
625 dlat_dv = gp_dv.
lat - gp.
lat;
626 dlon_dv = gp_dv.
lon - gp.
lon;
632 delta_lat = wdp.
lat - gp.
lat;
633 delta_lon = wdp.
lon - gp.
lon;
636 inverse_norm = dlat_dv*dlon_du - dlat_du*dlon_dv;
640 delta_u = (-dlon_dv*delta_lat + dlat_dv*delta_lon)/inverse_norm;
641 delta_v = ( dlon_du*delta_lat - dlat_du*delta_lon)/inverse_norm;
653 <<
"\ngp_du: " << gp_du
654 <<
"\ngp_dv: " << gp_dv
655 <<
"\ndelta_lat: " << delta_lat
656 <<
"\ndelta_lon: " << delta_lon
657 <<
"\ndelta_u: " << delta_u
658 <<
"\ndelta_v: " << delta_v
662 done = ((fabs(delta_u) < PIXEL_THRESHOLD)&&
663 (fabs(delta_v) < PIXEL_THRESHOLD));
666 }
while ( (!done) && (iters < MAX_NUM_ITERATIONS));
674 if (iters >= MAX_NUM_ITERATIONS)
676 std::cout <<
"MAX ITERATION!!!" << std::endl;
677 std::cout <<
"delta_u = " << delta_u
678 <<
"\ndelta_v = " << delta_v <<
"\n";
682 std::cout <<
"ITERS === " << iters << std::endl;
684 std::cout <<
"iters = " << iters <<
"\n";
721 for (
int i=0; i<4; ++i)
723 if (v[i].lon > 180.0) v[i].lon -= 360.0;
765 <<
"DEBUG ossimH5GridModel::extrapolate: entering... " << std::endl;
780 <<
"DEBUG ossimH5GridModel::extrapolate: returning..." << std::endl;
809 if (edgePt.
lon < 0.0 ) edgePt.
lon += 360.0;
810 if ( image_center.
lon < 0.0 ) image_center.
lon += 360.0;
819 const double DEG_PER_MTR = 8.983152841e-06;
821 ossimDpt deltaPt (edgePt-image_center);
824 ossimDpt edgePt_prime (edgePt - epsilonPt);
829 ossimGpt edgeGP (edgePt.lat, edgePt.lon, height);
830 ossimGpt edgeGP_prime (edgePt_prime.
lat, edgePt_prime.
lon, height);
845 double dsamp_drad = (edgePt.samp - edgePt_prime.
samp)/epsilon;
846 double dline_drad = (edgePt.line - edgePt_prime.
line)/epsilon;
854 ossimDpt extrapolated_ip (edgePt.samp + delta*dsamp_drad,
855 edgePt.line + delta*dline_drad);
860 <<
"DEBUG ossimH5GridModel::extrapolate: returning..." << std::endl;
864 return extrapolated_ip;
880 os << setprecision(10) <<
"MULTIPOLYGON(((";
900 os << lon <<
" " << lat <<
",";
902 if (
x != rect.
ur().
x )
904 x = ossim::min<ossim_int32>(
x+
STEP, rect.
ur().
x );
915 y = ossim::min<ossim_int32>(
y+
STEP, rect.
lr().
y );
927 os << lon <<
" " << lat <<
",";
929 if (
y != rect.
lr().
y )
931 y = ossim::min<ossim_int32>(
y+
STEP, rect.
lr().
y );
942 x = ossim::max<ossim_int32>( rect.
lr().
x-
STEP, 0 );
954 os << lon <<
" " << lat <<
",";
958 x = ossim::max<ossim_int32>(
x-
STEP, 0 );
969 y = ossim::max<ossim_int32>(
y-
STEP, 0 );
981 if ( (
x == 0 ) && (
y == 0 ) )
983 os << lon <<
" " << lat;
987 os << lon <<
" " << lat <<
",";
992 y = ossim::max<ossim_int32>(
y-
STEP, 0 );
1021 fslat<< setprecision(10) <<endl;
1022 fslon<< setprecision(10) <<endl;
1029 fslat << pt.
u <<
" " << pt.
v <<
" " << lat << endl;
1030 fslon << pt.
u <<
" " << pt.
v <<
" " << lon << endl;
virtual void worldToLineSample(const ossimGpt &world_point, ossimDpt &image_point) const
METHOD: extrapolate() Extrapolates solutions for points outside of the image.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saveState Saves state of object to a keyword list.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Represents serializable keyword/value map.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
virtual ~ossimH5GridModel()
virtual destructor
bool theExtrapolateGroundFlag
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
double nan()
Method to return ieee floating point double precision NAN.
const ossimIpt & size() const
ossim_uint32 height() const
static ossimString toString(bool aValue)
Numeric to string methods.
void setDomainType(DomainType dt)
ossimScalarType getScalarType(const H5::DataSet *dataset)
void setNullValue(double value)
const ossimIpt & ul() const
void initialize(const ossimIpt &size, const ossimDpt &origin, const ossimDpt &spacing, double null_value=OSSIM_DEFAULT_NULL_PIX_DOUBLE)
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
OSSIM_DLL ossimByteOrder byteOrder()
ossim_float64 hgt
Height in meters above the ellipsiod.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Fulfills ossimObject base-class pure virtuals.
bool clipLineSegment(ossimDpt &p1, ossimDpt &p2) const
METHOD: clipLineSegment(p1, p2) Implements Cyrus-Beck clipping algorithm as described in: http://www...
double distanceTo(const ossimGpt &arg_gpt) const
METHOD: distanceTo(ossimGpt) Computes straight-line distance in meters between this and arg gpt: ...
virtual ossimGpt extrapolate(const ossimDpt &imgPt, const double &height=ossim::nan()) const
Implements its own extrapolation since this can be handled by ossimDblGrid.
void enableExtrapolation(bool arg=true)
void limitLonTo180()
METHOD: limitLonTo180() Converts the lon data member to a value between -180 and +180: ...
bool setGridNodes(H5::DataSet *latDataSet, H5::DataSet *lonDataSet, const ossimIrect &validRect)
Initializes the latitude and longitude ossimDblGrids from file.
void initializeModelParams(ossimIrect imageBounds)
Initializes base class data members after grids have been assigned.
ossimDpt theSubImageOffset
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossimIpt midPoint() const
bool toBool() const
String to numeric methods.
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
unsigned int ossim_uint32
ossimPolygon theBoundGndPolygon
bool hasNans() const
will sequence through the polygon and check to see if any values are NAN
ossimH5GridModel()
default constructor.
double getNode(const ossimIpt &p) const
const ossimIpt & lr() const
ossim_uint32 width() const
bool pointWithin(const ossimDpt &point) const
METHOD: pointWithin(ossimDpt) Returns TRUE if point is inside polygon.
ossimByteOrder getByteOrder(const H5::AbstractDs *dataset)
const ossimIpt & ur() const
bool theHeightEnabledFlag
ossimRefPtr< ossimProjection > theSeedFunction
Used as an initial guess for iterative solutions and a guess for points outside the support bounds...
static ossimProjectionFactoryRegistry * instance()
ossim_uint32 getNumberOfVertices() const
ossimDrect theImageClipRect
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Fulfills ossimObject base-class pure virtuals.
ossimRefPtr< ossimProjection > getBilinearProjection(H5::DataSet &latDataSet, H5::DataSet &lonDataSet, const ossimIrect &validRect)
Gets bilinear projection from Latitude, Longitude layer.
ossimPolygon m_boundGndPolygon
virtual ossimDpt extrapolate(const ossimGpt &gp) const
extrapolate() Extrapolates solutions for points outside of the image.
bool getWktFootprint(std::string &s) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
std::basic_ofstream< char > ofstream
Class for char output file streams.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
loadState Loads state of object from a keyword list.
virtual void worldToLineSample(const ossimGpt &worldPoint, ossimDpt &lineSampPt) const =0
bool crossesDateline(H5::DataSet &dataset, const ossimIrect &validRect)
Checks for dateline cross.
void setNode(const ossimIpt &p, const double &value)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual void lineSampleHeightToWorld(const ossimDpt &image_point, const double &heightEllipsoid, ossimGpt &world_pt) const
This is the virtual that performs the actual work of projecting the image point to the earth at some ...
RTTI_DEF1(ossimH5GridModel, "ossimH5GridModel", ossimCoarseGridModel)
const std::string & string() const
const ossimDpt & spacing() const
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.