/* @file  pmTrend2D.h
 *
 * functions to represent ways of modeling a 2D trend
 *
 * @author EAM, IfA
 *
 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
 * @date $Date: 2007-12-15 01:23:18 $
 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 */

# ifndef PM_TREND_2D_H
# define PM_TREND_2D_H

#include <pslib.h>

/// @addtogroup Objects Object Detection / Analysis Functions
/// @{

typedef enum {
    PM_TREND_NONE,
    PM_TREND_POLY_ORD,
    PM_TREND_POLY_CHEB,
    PM_TREND_MAP,
} pmTrend2DMode;

typedef struct {
    psPolynomial2D *poly;
    psImageMap *map;
    psStats *stats;                     // Statistics for clipped fitting
    psStatsOptions singleMean, singleStdev; // Staistics for mean and stdev when there's a single pixel
    pmTrend2DMode mode; // POLY_ORD, POLY_CHEB, MAP
} pmTrend2D;

// allocate a pmTrend2D structure tied to an image dimensions.  nXtrend,nYtrend is the order for the polynomials, max number of grid cells for
// psImageMap
pmTrend2D *pmTrend2DAlloc (pmTrend2DMode mode, psImage *image, int nXtrend, int nYtrend, psStats *stats);

bool psMemCheckTrend2D(psPtr ptr);

pmTrend2D *pmTrend2DNoImageAlloc (pmTrend2DMode mode, psImageBinning *binning, psStats *stats);

// allocate a pmTrend2D tied to an abstract field with size nXfield,nYfield
pmTrend2D *pmTrend2DFieldAlloc (pmTrend2DMode mode, int nXfield, int nYfield, int nXtrend, int nYtrend, psStats *stats);

bool pmTrend2DFit (pmTrend2D *trend, psVector *mask, psMaskType maskVal, psVector *x, psVector *y, psVector *f, psVector *df);

double pmTrend2DEval (pmTrend2D *trend, float x, float y);
psVector *pmTrend2DEvalVector (pmTrend2D *trend, psVector *x, psVector *y);

psString pmTrend2DModeToString (pmTrend2DMode mode);
pmTrend2DMode pmTrend2DModeFromString (psString name);

/// @}
# endif
