41void LUDecomp(
Matrix,
int const,
int const,
int[],
int*,
int*);
42void LULinearSolve(
Matrix const,
int const,
int const[],
double[]);
58 for (
int i = 2; i <= nHalfWindow + 1; i++)
87 int const nSize = pLineIn->
nGetSize();
92 for (
int i = 0; i < nSize; i++)
96 int nXThis = PtiThis.
nGetX();
97 int nYThis = PtiThis.
nGetY();
114 double dWindowTotX = 0, dWindowTotY = 0;
120 if ((k > 0) && (k < nSize))
122 dWindowTotX += pLineIn->
dGetXAt(k);
123 dWindowTotY += pLineIn->
dGetYAt(k);
148 else if (i >= (nSize - nHalfWindow))
152 double dWindowTotX = 0, dWindowTotY = 0;
158 if ((k > 0) && (k < nSize))
160 dWindowTotX += pLineIn->
dGetXAt(k);
161 dWindowTotY += pLineIn->
dGetYAt(k);
193 if ((k >= 0) && (k < nSize))
220 double const dHalfWindow = nHalfWindow;
223 int const nSize = pLineIn->
nGetSize();
228 for (
int i = 0; i < nSize; i++)
237 nXThis =
tMax(nXThis, 0);
238 nYThis =
tMax(nYThis, 0);
248 double nTmpWindow = 0;
249 double dWindowTotX = 0, dWindowTotY = 0;
253 for (
int j = 0; j <= i; j++)
256 double const weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
257 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
258 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
259 nTmpWindow += weight;
263 else if (i >= nSize - nHalfWindow)
265 for (
int j = nSize - 1; j >= i; j--)
267 double const weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
268 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
269 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
270 nTmpWindow += weight;
276 for (
int j = i - nHalfWindow; j < i + nHalfWindow; j++)
278 double const weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
279 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
280 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
281 nTmpWindow += weight;
336 LTemp[i] =
CGeom2DPoint(dWindowTotX / nTmpWindow, dWindowTotY / nTmpWindow);
352 int const nSize =
static_cast<int>(pdVSlope->size());
353 vector<double> dVSmoothed = *pdVSlope;
359 for (
int i = 0; i < nSize; i++)
362 double dWindowTot = 0;
369 if ((k < 0) || (k >= nSize))
372 dWindowTot += pdVSlope->at(k);
376 dVSmoothed[i] = dWindowTot /
static_cast<double>(nTmpWindow);
379 if (dVSmoothed[i] >= 0)
393void CSimulation::CalcSavitzkyGolay(
double dFilterCoeffsArray[],
int const nWindowSize,
int const nLeft,
int const nRight,
int const nDerivOrder,
int const nSmoothPolyOrder)
396 if ((nWindowSize < nLeft + nRight + 1) || (nLeft < 0) || (nRight < 0) || (nDerivOrder > nSmoothPolyOrder) || (nSmoothPolyOrder >
static_cast<int>(
SAVGOL_POLYNOMIAL_MAX_ORDER)) || (nLeft + nRight < nSmoothPolyOrder))
398 cerr <<
ERR <<
"Error in arguments to CalcSavitzkyGolay" << endl;
412 dSolutionArray[i] = 0;
416 for (
int ipj = 0; ipj <= 2 * nSmoothPolyOrder; ipj++)
424 for (
int k = 1; k <= nRight; k++)
427 for (
int k = 1; k <= nLeft; k++)
428 dSum += pow(-k, ipj);
430 int const mm =
tMin(ipj, 2 * nSmoothPolyOrder - ipj);
435 dMatrix[1 + (ipj + imj) / 2][1 + (ipj - imj) / 2] = dSum;
441 int nDCode = 0, nICode = 0;
445 dSolutionArray[nDerivOrder + 1] = 1;
448 LULinearSolve(dMatrix, nSmoothPolyOrder + 1, nIndexArray, dSolutionArray);
455 for (
int n = -nLeft; n <= nRight; n++)
458 double dSum = dSolutionArray[1];
461 for (
int m = 1; m <= nSmoothPolyOrder; m++)
464 dSum += dSolutionArray[m + 1] * dFac;
468 int const nInd = ((nWindowSize - n) % nWindowSize) + 1;
469 dFilterCoeffsArray[nInd] = dSum;
478void LUDecomp(
Matrix A,
int const N,
int const np,
int nIndexArray[],
int* nDCode,
int* nICode)
486 double const TINY = 1e-12;
487 double AMAX, DUM, SUM;
488 double* VV =
new double[np];
489 int I, IMAX = 0, J, K;
494 for (I = 1; I <= N; I++)
498 for (J = 1; J <= N; J++)
499 if (
tAbs(A[I][J]) > AMAX)
500 AMAX =
tAbs(A[I][J]);
512 for (J = 1; J <= N; J++)
514 for (I = 1; I < J; I++)
518 for (K = 1; K < I; K++)
519 SUM -= A[I][K] * A[K][J];
526 for (I = J; I <= N; I++)
530 for (K = 1; K < J; K++)
531 SUM -= A[I][K] * A[K][J];
534 DUM = VV[I] *
tAbs(SUM);
545 for (K = 1; K <= N; K++)
548 A[IMAX][K] = A[J][K];
552 *nDCode = -(*nDCode);
556 nIndexArray[J] = IMAX;
558 if (
tAbs(A[J][J]) < TINY)
565 for (I = J + 1; I <= N; I++)
579void LULinearSolve(
Matrix const A,
int const N,
int const nIndexArray[],
double B[])
584 for (
int I = 1; I <= N; I++)
586 int const LL = nIndexArray[I];
591 for (
int J = II; J < I; J++)
592 SUM -= A[I][J] * B[J];
600 for (
int I = N; I > 0; I--)
605 for (
int J = I + 1; J <= N; J++)
606 SUM -= A[I][J] * B[J];
608 B[I] = SUM / A[I][I];
Contains CGeom2DPoint definitions.
Contains CGeom2DIPoint definitions.
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.
int m_nCoastSmoothingWindowSize
The size of the window used for coast smoothing. Must be an odd number.
int m_nSavGolCoastPoly
The order of the coastline profile smoothing polynomial if Savitzky-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 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
The size of the window used for running-mean coast-normal profile smoothing (must be odd)
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 CGeomLine definitions.
Contains CSimulation definitions.
double Matrix[SAVGOL_POLYNOMIAL_MAX_ORDER+2][SAVGOL_POLYNOMIAL_MAX_ORDER+2]