54 for (
int i = 2; i <= nHalfWindow + 1; i++)
87 for (
int i = 0; i < nSize; i++)
92 int nXThis = PtiThis.
nGetX();
93 int nYThis = PtiThis.
nGetY();
112 double dWindowTotX = 0, dWindowTotY = 0;
117 if ((k > 0) && (k < nSize))
119 dWindowTotX += pLineIn->
dGetXAt(k);
120 dWindowTotY += pLineIn->
dGetYAt(k);
144 else if (i >= (nSize - nHalfWindow))
148 double dWindowTotX = 0, dWindowTotY = 0;
153 if ((k > 0) && (k < nSize))
155 dWindowTotX += pLineIn->
dGetXAt(k);
156 dWindowTotY += pLineIn->
dGetYAt(k);
186 if ((k >= 0) && (k < nSize))
213 double dHalfWindow = nHalfWindow;
221 for (
int i = 0; i < nSize; i++)
230 nXThis =
tMax(nXThis, 0);
231 nYThis =
tMax(nYThis, 0);
241 double nTmpWindow = 0;
242 double dWindowTotX = 0, dWindowTotY = 0;
245 for (
int j = 0; j <= i; j++)
248 double weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
249 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
250 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
251 nTmpWindow += weight;
254 else if (i >= nSize - nHalfWindow)
256 for (
int j = nSize - 1; j >= i; j--)
258 double weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
259 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
260 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
261 nTmpWindow += weight;
266 for (
int j = i - nHalfWindow; j < i + nHalfWindow; j++)
268 double weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
269 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
270 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
271 nTmpWindow += weight;
326 LTemp[i] =
CGeom2DPoint(dWindowTotX / nTmpWindow, dWindowTotY / nTmpWindow);
342 int const nSize =
static_cast<int>(pdVSlope->size());
343 vector<double> dVSmoothed = *pdVSlope;
349 for (
int i = 0; i < nSize; i++)
352 double dWindowTot = 0;
358 if ((k < 0) || (k >= nSize))
361 dWindowTot += pdVSlope->at(k);
365 dVSmoothed[i] = dWindowTot /
static_cast<double>(nTmpWindow);
368 if (dVSmoothed[i] >= 0)
381void CSimulation::CalcSavitzkyGolay(
double dFilterCoeffsArray[],
int const nWindowSize,
int const nLeft,
int const nRight,
int const nDerivOrder,
int const nSmoothPolyOrder)
384 if ((nWindowSize < nLeft + nRight + 1) || (nLeft < 0) || (nRight < 0) || (nDerivOrder > nSmoothPolyOrder) || (nSmoothPolyOrder >
static_cast<int>(
SAVGOL_POLYNOMIAL_MAX_ORDER)) || (nLeft + nRight < nSmoothPolyOrder))
386 cerr <<
ERR <<
"Error in arguments to CalcSavitzkyGolay" << endl;
398 dSolutionArray[i] = 0;
402 for (
int ipj = 0; ipj <= 2 * nSmoothPolyOrder; ipj++)
408 for (
int k = 1; k <= nRight; k++)
410 for (
int k = 1; k <= nLeft; k++)
411 dSum += pow(-k, ipj);
412 int mm =
tMin(ipj, 2 * nSmoothPolyOrder - ipj);
416 dMatrix[1 + (ipj + imj) / 2][1 + (ipj - imj) / 2] = dSum;
422 int nDCode = 0, nICode = 0;
426 dSolutionArray[nDerivOrder + 1] = 1;
429 LULinearSolve(dMatrix, nSmoothPolyOrder + 1, nIndexArray, dSolutionArray);
436 for (
int n = -nLeft; n <= nRight; n++)
439 double dSum = dSolutionArray[1];
441 for (
int m = 1; m <= nSmoothPolyOrder; m++)
444 dSum += dSolutionArray[m + 1] * dFac;
448 int nInd = ((nWindowSize - n) % nWindowSize) + 1;
449 dFilterCoeffsArray[nInd] = dSum;
456void LUDecomp(
Matrix A,
int const N,
int const np,
int nIndexArray[],
int *nDCode,
int *nICode)
465 double AMAX, DUM, SUM;
466 double *VV =
new double[np];
467 int I, IMAX = 0, J, K;
472 for (I = 1; I <= N; I++)
475 for (J = 1; J <= N; J++)
476 if (
tAbs(A[I][J]) > AMAX)
477 AMAX =
tAbs(A[I][J]);
489 for (J = 1; J <= N; J++)
491 for (I = 1; I < J; I++)
494 for (K = 1; K < I; K++)
495 SUM -= A[I][K] * A[K][J];
500 for (I = J; I <= N; I++)
503 for (K = 1; K < J; K++)
504 SUM -= A[I][K] * A[K][J];
507 DUM = VV[I] *
tAbs(SUM);
517 for (K = 1; K <= N; K++)
520 A[IMAX][K] = A[J][K];
524 *nDCode = -(*nDCode);
528 nIndexArray[J] = IMAX;
529 if (
tAbs(A[J][J]) < TINY)
535 for (I = J + 1; I <= N; I++)
551 for (
int I = 1; I <= N; I++)
553 int LL = nIndexArray[I];
557 for (
int J = II; J < I; J++)
558 SUM -= A[I][J] * B[J];
564 for (
int I = N; I > 0; I--)
568 for (
int J = I + 1; J <= N; J++)
569 SUM -= A[I][J] * B[J];
570 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.
int m_nSavGolCoastPoly
The order of the coastline profile smoothing polynomial if Savitsky-Golay smoothing is used (usually ...
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 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 costline-normal profiles.
int m_nProfileSmoothWindow
The size of the window used for running-mean coast-normal profile smoothing (must be odd)
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]