57 for (
int i = 2; i <= nHalfWindow + 1; i++)
91 for (
int i = 0; i < nSize; i++)
95 int nXThis = PtiThis.
nGetX();
96 int nYThis = PtiThis.
nGetY();
113 double dWindowTotX = 0, dWindowTotY = 0;
119 if ((k > 0) && (k < nSize))
121 dWindowTotX += pLineIn->
dGetXAt(k);
122 dWindowTotY += pLineIn->
dGetYAt(k);
147 else if (i >= (nSize - nHalfWindow))
151 double dWindowTotX = 0, dWindowTotY = 0;
157 if ((k > 0) && (k < nSize))
159 dWindowTotX += pLineIn->
dGetXAt(k);
160 dWindowTotY += pLineIn->
dGetYAt(k);
192 if ((k >= 0) && (k < nSize))
219 double dHalfWindow = nHalfWindow;
227 for (
int i = 0; i < nSize; i++)
236 nXThis =
tMax(nXThis, 0);
237 nYThis =
tMax(nYThis, 0);
247 double nTmpWindow = 0;
248 double dWindowTotX = 0, dWindowTotY = 0;
252 for (
int j = 0; j <= i; j++)
255 double weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
256 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
257 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
258 nTmpWindow += weight;
262 else if (i >= nSize - nHalfWindow)
264 for (
int j = nSize - 1; j >= i; j--)
266 double weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
267 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
268 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
269 nTmpWindow += weight;
275 for (
int j = i - nHalfWindow; j < i + nHalfWindow; j++)
277 double weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
278 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
279 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
280 nTmpWindow += weight;
335 LTemp[i] =
CGeom2DPoint(dWindowTotX / nTmpWindow, dWindowTotY / nTmpWindow);
351 int const nSize =
static_cast<int>(pdVSlope->size());
352 vector<double> dVSmoothed = * pdVSlope;
358 for (
int i = 0; i < nSize; i++)
361 double dWindowTot = 0;
368 if ((k < 0) || (k >= nSize))
371 dWindowTot += pdVSlope->at(k);
375 dVSmoothed[i] = dWindowTot /
static_cast<double>(nTmpWindow);
378 if (dVSmoothed[i] >= 0)
392void CSimulation::CalcSavitzkyGolay(
double dFilterCoeffsArray[],
int const nWindowSize,
int const nLeft,
int const nRight,
int const nDerivOrder,
int const nSmoothPolyOrder)
395 if ((nWindowSize < nLeft + nRight + 1) || (nLeft < 0) || (nRight < 0) || (nDerivOrder > nSmoothPolyOrder) || (nSmoothPolyOrder >
static_cast<int>(
SAVGOL_POLYNOMIAL_MAX_ORDER)) || (nLeft + nRight < nSmoothPolyOrder))
397 cerr <<
ERR <<
"Error in arguments to CalcSavitzkyGolay" << endl;
411 dSolutionArray[i] = 0;
415 for (
int ipj = 0; ipj <= 2 * nSmoothPolyOrder; ipj++)
423 for (
int k = 1; k <= nRight; k++)
426 for (
int k = 1; k <= nLeft; k++)
427 dSum += pow(-k, ipj);
429 int mm =
tMin(ipj, 2 * nSmoothPolyOrder - ipj);
434 dMatrix[1 + (ipj + imj) / 2][1 + (ipj - imj) / 2] = dSum;
440 int nDCode = 0, nICode = 0;
444 dSolutionArray[nDerivOrder + 1] = 1;
447 LULinearSolve(dMatrix, nSmoothPolyOrder + 1, nIndexArray, dSolutionArray);
454 for (
int n = -nLeft; n <= nRight; n++)
457 double dSum = dSolutionArray[1];
460 for (
int m = 1; m <= nSmoothPolyOrder; m++)
463 dSum += dSolutionArray[m + 1] * dFac;
467 int nInd = ((nWindowSize - n) % nWindowSize) + 1;
468 dFilterCoeffsArray[nInd] = dSum;
475void LUDecomp(
Matrix A,
int const N,
int const np,
int nIndexArray[],
int* nDCode,
int* nICode)
484 double AMAX, DUM, SUM;
485 double* VV =
new double[np];
486 int I, IMAX = 0, J, K;
491 for (I = 1; I <= N; I++)
495 for (J = 1; J <= N; J++)
496 if (
tAbs(A[I][J]) > AMAX)
497 AMAX =
tAbs(A[I][J]);
509 for (J = 1; J <= N; J++)
511 for (I = 1; I < J; I++)
515 for (K = 1; K < I; K++)
516 SUM -= A[I][K] * A[K][J];
523 for (I = J; I <= N; I++)
527 for (K = 1; K < J; K++)
528 SUM -= A[I][K] * A[K][J];
531 DUM = VV[I] *
tAbs(SUM);
542 for (K = 1; K <= N; K++)
545 A[IMAX][K] = A[J][K];
549 * nDCode = -( * nDCode);
553 nIndexArray[J] = IMAX;
555 if (
tAbs(A[J][J]) < TINY)
562 for (I = J + 1; I <= N; I++)
578 for (
int I = 1; I <= N; I++)
580 int LL = nIndexArray[I];
585 for (
int J = II; J < I; J++)
586 SUM -= A[I][J] * B[J];
594 for (
int I = N; I > 0; I--)
599 for (
int J = I + 1; J <= N; J++)
600 SUM -= A[I][J] * B[J];
602 B[I] = SUM / A[I][I];
void Resize(int const)
Resizes the vector which represents this 2D shape.
Geometry class used to represent 2D point objects with integer coordinates.
int nGetY(void) const
Returns the CGeom2DIPoint object's integer Y coordinate.
int nGetX(void) const
Returns the CGeom2DIPoint object's integer X coordinate.
Geometry class used to represent 2D point objects with floating-point coordinates.
Geometry class used to represent 2D vector line objects.
CGeom2DPoint * pPtGetAt(int const)
Returns the point at a given place in the line.
double dGetYAt(int const)
Returns the Y value at a given place in the line.
double dGetXAt(int const)
Returns the X value at a given place in the line.
void CalcSavitzkyGolayCoeffs(void)
Calculates the Savitzky-Golay smoothing coefficients for a given size of smoothing window....
static void CalcSavitzkyGolay(double[], int const, int const, int const, int const, int const)
CalcSavitzkyGolay uses LULinearSolve and LUDecomp. It returns dFilterCoeffsArray[nWindowSize],...
CGeomLine LSmoothCoastRunningMean(CGeomLine *) const
Does running-mean smoothing of a CGeomLine coastline vector (is in external CRS coordinates)
int m_nXGridSize
The size of the grid in the x direction.
CGeom2DIPoint PtiExtCRSToGridRound(CGeom2DPoint const *) const
Transforms a pointer to a CGeom2DPoint in the external CRS to the equivalent CGeom2DIPoint in the ras...
int m_nYGridSize
The size of the grid in the y direction.
void KeepWithinValidGrid(int &, int &) const
Constrains the supplied point (in the grid CRS) to be a valid cell within the raster grid.
vector< double > dVSmoothProfileSlope(vector< double > *) const
Does running-mean smoothing of the slope of a coastline-normal profile.
vector< double > m_VdSavGolFCRWCoast
Savitzky-Golay filter coefficients for the coastline vector(s)
CGeomLine LSmoothCoastSavitzkyGolay(CGeomLine *, int const, int const) const
Does smoothing of a CGeomLine coastline vector (is in external CRS coordinates) using a Savitzky-Gola...
bool bIsWithinValidGrid(int const, int const) const
Checks whether the supplied point (an x-y pair, in the grid CRS) is within the raster grid,...
bool bIsInterventionCell(int const, int const) const
Returns true if the cell is an intervention.
vector< int > m_VnSavGolIndexCoast
Savitzky-Golay shift index for the coastline vector(s)
double m_dProfileMaxSlope
Maximum slope on coastline-normal profiles.
int m_nProfileSmoothWindow
int m_nCoastSmoothWindow
The size of the window used for coast smoothing. Must be an odd number.
This file contains global definitions for CoastalME.
int const SAVGOL_POLYNOMIAL_MAX_ORDER
bool bFPIsEqual(const T d1, const T d2, const T dEpsilon)
Contains CSimulation definitions.
void LULinearSolve(Matrix const, int const, int const[], double[])
Solves the set of N linear equations A . X = B. Here A is input, not as the matrix A but rather as it...
void LUDecomp(Matrix, int const, int const, int[], int *, int *)
Given an N x N matrix A, this routine replaces it by the LU decomposition of a rowwise permutation of...
double Matrix[SAVGOL_POLYNOMIAL_MAX_ORDER+2][SAVGOL_POLYNOMIAL_MAX_ORDER+2]