47void LUDecomp(
Matrix,
int const,
int const,
int[],
int*,
int*);
48void LULinearSolve(
Matrix const,
int const,
int const[],
double[]);
64 for (
int i = 2; i <= nHalfWindow + 1; i++)
93 int const nSize = pLineIn->
nGetSize();
98 for (
int i = 0; i < nSize; i++)
102 int nXThis = PtiThis.
nGetX();
103 int nYThis = PtiThis.
nGetY();
120 double dWindowTotX = 0, dWindowTotY = 0;
126 if ((k > 0) && (k < nSize))
128 dWindowTotX += pLineIn->
dGetXAt(k);
129 dWindowTotY += pLineIn->
dGetYAt(k);
154 else if (i >= (nSize - nHalfWindow))
158 double dWindowTotX = 0, dWindowTotY = 0;
164 if ((k > 0) && (k < nSize))
166 dWindowTotX += pLineIn->
dGetXAt(k);
167 dWindowTotY += pLineIn->
dGetYAt(k);
199 if ((k >= 0) && (k < nSize))
226 double const dHalfWindow = nHalfWindow;
229 int const nSize = pLineIn->
nGetSize();
234 for (
int i = 0; i < nSize; i++)
243 nXThis =
tMax(nXThis, 0);
244 nYThis =
tMax(nYThis, 0);
254 double nTmpWindow = 0;
255 double dWindowTotX = 0, dWindowTotY = 0;
259 for (
int j = 0; j <= i; j++)
262 double const weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
263 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
264 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
265 nTmpWindow += weight;
269 else if (i >= nSize - nHalfWindow)
271 for (
int j = nSize - 1; j >= i; j--)
273 double const weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
274 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
275 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
276 nTmpWindow += weight;
282 for (
int j = i - nHalfWindow; j < i + nHalfWindow; j++)
284 double const weight = (dHalfWindow -
tAbs(i - j)) / dHalfWindow;
285 dWindowTotX += pLineIn->
dGetXAt(j) * weight;
286 dWindowTotY += pLineIn->
dGetYAt(j) * weight;
287 nTmpWindow += weight;
342 LTemp[i] =
CGeom2DPoint(dWindowTotX / nTmpWindow, dWindowTotY / nTmpWindow);
358 int const nSize =
static_cast<int>(pdVSlope->size());
359 vector<double> dVSmoothed = *pdVSlope;
365 for (
int i = 0; i < nSize; i++)
368 double dWindowTot = 0;
375 if ((k < 0) || (k >= nSize))
378 dWindowTot += pdVSlope->at(k);
382 dVSmoothed[i] = dWindowTot /
static_cast<double>(nTmpWindow);
385 if (dVSmoothed[i] >= 0)
399void CSimulation::CalcSavitzkyGolay(
double dFilterCoeffsArray[],
int const nWindowSize,
int const nLeft,
int const nRight,
int const nDerivOrder,
int const nSmoothPolyOrder)
402 if ((nWindowSize < nLeft + nRight + 1) || (nLeft < 0) || (nRight < 0) || (nDerivOrder > nSmoothPolyOrder) || (nSmoothPolyOrder >
static_cast<int>(
SAVGOL_POLYNOMIAL_MAX_ORDER)) || (nLeft + nRight < nSmoothPolyOrder))
404 cerr <<
ERR <<
"Error in arguments to CalcSavitzkyGolay" << endl;
418 dSolutionArray[i] = 0;
422 for (
int ipj = 0; ipj <= 2 * nSmoothPolyOrder; ipj++)
430 for (
int k = 1; k <= nRight; k++)
433 for (
int k = 1; k <= nLeft; k++)
434 dSum += pow(-k, ipj);
436 int const mm =
tMin(ipj, 2 * nSmoothPolyOrder - ipj);
441 dMatrix[1 + (ipj + imj) / 2][1 + (ipj - imj) / 2] = dSum;
447 int nDCode = 0, nICode = 0;
451 dSolutionArray[nDerivOrder + 1] = 1;
454 LULinearSolve(dMatrix, nSmoothPolyOrder + 1, nIndexArray, dSolutionArray);
461 for (
int n = -nLeft; n <= nRight; n++)
464 double dSum = dSolutionArray[1];
467 for (
int m = 1; m <= nSmoothPolyOrder; m++)
470 dSum += dSolutionArray[m + 1] * dFac;
474 int const nInd = ((nWindowSize - n) % nWindowSize) + 1;
475 dFilterCoeffsArray[nInd] = dSum;
484void LUDecomp(
Matrix A,
int const N,
int const np,
int nIndexArray[],
int* nDCode,
int* nICode)
492 double const TINY = 1e-12;
493 double AMAX, DUM, SUM;
494 double* VV =
new double[np];
495 int I, IMAX = 0, J, K;
500 for (I = 1; I <= N; I++)
504 for (J = 1; J <= N; J++)
505 if (
tAbs(A[I][J]) > AMAX)
506 AMAX =
tAbs(A[I][J]);
518 for (J = 1; J <= N; J++)
520 for (I = 1; I < J; I++)
524 for (K = 1; K < I; K++)
525 SUM -= A[I][K] * A[K][J];
532 for (I = J; I <= N; I++)
536 for (K = 1; K < J; K++)
537 SUM -= A[I][K] * A[K][J];
540 DUM = VV[I] *
tAbs(SUM);
551 for (K = 1; K <= N; K++)
554 A[IMAX][K] = A[J][K];
558 *nDCode = -(*nDCode);
562 nIndexArray[J] = IMAX;
564 if (
tAbs(A[J][J]) < TINY)
571 for (I = J + 1; I <= N; I++)
585void LULinearSolve(
Matrix const A,
int const N,
int const nIndexArray[],
double B[])
590 for (
int I = 1; I <= N; I++)
592 int const LL = nIndexArray[I];
597 for (
int J = II; J < I; J++)
598 SUM -= A[I][J] * B[J];
606 for (
int I = N; I > 0; I--)
611 for (
int J = I + 1; J <= N; J++)
612 SUM -= A[I][J] * B[J];
614 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
int m_nYGridSize
The size of the grid in the y direction.
void KeepWithinValidGrid(int &, int &) const
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
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]