31 static ossimTrace traceExec (
"ossimDblGrid:exec");
32 static ossimTrace traceDebug (
"ossimDblGrid:debug");
34 static const ossimString MAGIC_NUMBER (
"OSSIM_DBL_GRID");
45 theSpacing (0.0, 0.0),
51 theMeanIsComputed (false),
52 theExtrapIsEnabled (
true),
53 theDomainType (CONTINUOUS)
66 theExtrapIsEnabled (
true),
67 theDomainType (CONTINUOUS)
69 static const char MODULE[] =
"ossimDblGrid Constructor";
97 theExtrapIsEnabled (
true),
98 theDomainType (CONTINUOUS)
100 static const char MODULE[] =
"ossimDblGrid Constructor";
119 theExtrapIsEnabled (
true),
120 theDomainType (CONTINUOUS)
122 static const char MODULE[] =
"ossimDblGrid Constructor";
157 static const char MODULE[] =
"ossimDblGrid::initialize()";
206 static const char MODULE[] =
"ossimDblGrid::initialize()";
240 double value = input;
275 double value = input;
330 if ((xi >= 0.0) && (xi <= (double)
theSize.
x-1) && (yi >= 0.0) && (yi <= (double)
theSize.
y-1))
352 double wx1 = xi - x0;
353 double wy1 = yi - y0;
354 double wx0 = 1.0 - wx1;
355 double wy0 = 1.0 - wy1;
356 double w00 = wx0 * wy0;
357 double w01 = wx0 * wy1;
358 double w10 = wx1 * wy0;
359 double w11 = wx1 * wy1;
363 int index10 = index00;
364 int index11 = index00;
365 int index01 = index00;
367 if (x0 < (
theSize.
x-1)) index10 = index00 + 1;
370 if (x0 < (
theSize.
x-1)) index11 = index01 + 1;
374 if ((index00 > max_idx) || (index10 > max_idx) || (index11 > max_idx) || (index01 > max_idx))
386 double dp01_00 = p01 - p00;
387 double dp10_00 = p10 - p00;
388 double dp11_00 = p11 - p00;
392 else if (dp01_00 < -180.0)
397 else if (dp10_00 < -180.0)
402 else if (dp11_00 < -180.0)
407 double value = (p00*w00 + p01*w01 + p10*w10 + p11*w11) / (w00 + w01 + w10 + w11);
426 double dx=0, dy=0, dR_dx=0, dR_dy=0, R0;
509 if (dR_dx > 180.0) dR_dx -= 360.0;
510 else if (dR_dx < -180.0) dR_dx += 360.0;
512 if (dR_dy > 180.0) dR_dy -= 360.0;
513 else if (dR_dy < -180.0) dR_dy += 360.0;
516 double R = R0 + dR_dx*dx + dR_dy*dy;
527 if(&source ==
this)
return *
this;
558 for (
int i=0; i<buflen; i++)
574 static const char MODULE[] =
"ossimDblGrid::meanValue()";
592 static const char MODULE[] =
"ossimDblGrid::meanStdDev()";
608 static const char MODULE[] =
"ossimDblGrid::meanStdDev()";
615 double num_samples = 0.0;
659 return ((xi >= 0.0) && (xi <= ((double)
theSize.
x - 1.0)) &&
660 (yi >= 0.0) && (yi <= ((double)
theSize.
y - 1.0)));
675 static const char MODULE[] =
"ossimDblGrid::save()";
681 ios::fmtflags new_options = ios::scientific|ios::dec;
683 int new_precision = 12;
685 ios::fmtflags old_options = os.flags(new_options);
686 int old_precision = os.precision(new_precision);
692 std::strncpy(descr_buf, descr, 80);
693 descr_buf[80] =
'\0';
698 os << MAGIC_NUMBER <<
" " << descr_buf <<
"\n" 714 for (
int i=0; i<max_index; i++)
722 os.flags(old_options);
723 os.precision(old_precision);
738 static const char MODULE[] =
"ossimDblGrid::load()";
769 vector<ossimString> items = strbuf.
split(
" ",
true);
770 if (items.size() < 7)
776 size.
x = items[0].toInt();
777 size.
y = items[1].toInt();
778 origin.
u = items[2].toDouble();
779 origin.
v = items[3].toDouble();
782 null_value = items[6].toDouble();
785 if ((items.size() > 7))
794 for (
int i=0; i<max_index; i++)
827 if (
x > 0)
return blocked[4];
839 if (r > 5.02734) i = 12 + c;
840 else if (r > 1.49660) i = 13 + c;
841 else if (r > 0.66818) i = 14 + c;
842 else if (r > 0.19891) i = 15 + c;
843 else if (r > -0.19891) i = 0 + c;
844 else if (r > -0.66818) i = 1 + c;
845 else if (r > -1.49660) i = 2 + c;
846 else if (r > -5.02734) i = 3 + c;
869 if (
x > 0) blocked[4] =
true;
870 else blocked[12] =
true;
882 if (r > 5.02734) i = 12 + c;
883 else if (r > 1.49660) i = 13 + c;
884 else if (r > 0.66818) i = 14 + c;
885 else if (r > 0.19891) i = 15 + c;
886 else if (r > -0.19891) i = 0 + c;
887 else if (r > -0.66818) i = 1 + c;
888 else if (r > -1.49660) i = 2 + c;
889 else if (r > -5.02734) i = 3 + c;
914 static const char MODULE[] =
"ossimDblGrid::interpolateNullValuedNodes()";
928 std::vector<double> resampled_grid( buf_size, 0.0 );
930 double min_weight_needed = 4.0/decay_rate;
932 int start_x, start_y, end_x, end_y;
962 resampled_grid[node_idx] = node_value;
978 for (
int i=0; i<16; i++)
986 while ((sum_weights < min_weight_needed) && sample_found)
991 weight *= decay_rate;
992 sample_found =
false;
997 end_y = start_y + diameter;
998 end_x = start_x + diameter;
1000 for (
int yn=start_y; yn<=end_y; ++yn)
1002 if ((yn == start_y) || (yn == end_y))
1008 for (
int xn=start_x; xn<=end_x; ++xn)
1010 sample_found = sample_found ||
isInside(xn, yn);
1014 dx =
x - xn; dy =
y - yn;
1017 adj_delta = weight*sqrt((
double)(dx*dx + dy*dy));
1018 accumulator += sample/adj_delta;
1019 sum_weights += 1.0/adj_delta;
1031 sample_found = sample_found ||
isInside(start_x, yn);
1032 sample =
getNode(start_x, yn);
1035 dx =
x - start_x; dy =
y - yn;
1038 adj_delta = weight*sqrt((
double)(dx*dx + dy*dy));
1039 accumulator += sample/adj_delta;
1040 sum_weights += 1.0/adj_delta;
1045 sample_found = sample_found ||
isInside(end_x, yn);
1049 dx =
x - end_x; dy =
y - yn;
1052 adj_delta = weight*sqrt((
double)(dx*dx + dy*dy));
1053 accumulator += sample/adj_delta;
1054 sum_weights += 1.0/adj_delta;
1066 if (sum_weights != 0)
1067 resampled_grid[node_idx] = accumulator/sum_weights;
1078 for (node_idx=0; node_idx<buf_size; node_idx++)
1095 static const char MODULE[] =
"ossimDblGrid::filter()";
1099 int rx = (size_x - 1)/2;
1100 int ry = (size_y - 1)/2;
1105 int knl_ctr = ry*size_x + rx;
1106 double node_value, kernel_value;
1107 int resample_node_idx;
1111 ossimIpt resample_grid_size(end_x-start_x, end_y-start_y);
1112 ossimDpt resample_grid_origin(start_x, start_y);
1113 ossimDpt resample_grid_spacing(1,1);
1114 ossimDblGrid resample_grid(resample_grid_size, resample_grid_origin, resample_grid_spacing);
1116 resample_grid.
fill(0.0);
1119 for (
int y=start_y;
y<end_y;
y++)
1121 for (
int x=start_x;
x<end_x;
x++)
1123 resample_node_idx = resample_grid.
index(
x-start_x,
y-start_y);
1127 for (
int ky=-ry; ky<=ry; ky++)
1129 for (
int kx=-rx; kx<=rx; kx++)
1132 kernel_value = kernel[knl_ctr + ky*size_x + kx];
1133 resample_grid.
theGridData[resample_node_idx] += kernel_value*node_value;
1169 for (
int i=0; i<
size; i++)
1186 if (
value <= -180.0)
1188 else if (
value > 180.0)
1195 else if (
value >= 360.0)
1214 os <<
"\nDump of ossimDblGrid at " << (
void*) &grid
1215 <<
"\n theSize: " << grid.
theSize 1233 os <<
"\n node(" <<
x <<
", " <<
y <<
"): " << grid.
getNode(
x,
y);
bool isBlocked(bool *blocked, int x, int y)
ossim_float64 width() const
#define OSSIM_DEFAULT_MAX_PIX_DOUBLE
bool isInside(const ossimDpt &p) const
double nan()
Method to return ieee floating point double precision NAN.
const ossimDpt & ul() const
const ossimIpt & size() const
bool contains(char aChar) const
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
void initialize(const ossimIpt &size, const ossimDpt &origin, const ossimDpt &spacing, double null_value=OSSIM_DEFAULT_NULL_PIX_DOUBLE)
std::istream & getline(std::istream &is, ossimString &str, char delim)
double operator()(const ossimDpt &uv_point) const
void blockDirection(bool *blocked, int x, int y)
void enableExtrapolation(bool arg=true)
double extrapolate(double x, double y) const
bool load(std::istream &is)
#define OSSIM_DEFAULT_NULL_PIX_DOUBLE
#define OSSIM_DEFAULT_MIN_PIX_DOUBLE
double interpolate(double x, double y) const
Interpolates given non-integral point x, y.
unsigned int ossim_uint32
void setNearestNode(const ossimDpt &uv_point, const double &value)
double getNode(const ossimIpt &p) const
ossim_float64 height() const
void constrain(double &value) const
Constrains the value to the numerical domain specified in theDomainType.
void filter(int size_x, int size_y, double *kernel)
bool save(std::ostream &os, const char *descr) const
std::basic_istream< char > istream
Base class for char input streams.
ossim_uint32 index(int x, int y) const
const ossimDblGrid & operator=(const ossimDblGrid &grid)
const ossimDpt & origin() const
ostream & operator<<(ostream &os, const ossimDblGrid &grid)
void interpolateNullValuedNodes(const double &decay_rate=10.0)
double value(const ossimDpt &uv_point) const
void fill(double fill_value)
void setNode(const ossimIpt &p, const double &value)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
const ossimDpt & spacing() const