#if !defined(PM_FOOTPRINT_H)
#define PM_FOOTPRINT_H
//
// Describe a segment of an image
//
typedef struct {
    int y;                              //!< Row that span's in
    int x0;                             //!< Starting column (inclusive)
    int x1;                             //!< Ending column (inclusive)
} pmSpan;

pmSpan *pmSpanAlloc(int y, int x1, int x2);
bool pmSpanTest(const psPtr ptr);
int pmSpanSortByYX (const void **a, const void **b);

typedef struct {
    const int id;                       //!< unique ID
    int npix;                           //!< number of pixels in this pmFootprint
    psArray *spans;                     //!< the pmSpans
    psRegion bbox;                      //!< the pmFootprint's bounding box
    psArray *peaks;                     //!< the peaks lying in this footprint
    psRegion region;   //!< A region describing the psImage the footprints live in
    bool normalized;                    //!< Are the spans sorted? 
} pmFootprint;

pmFootprint *pmFootprintAlloc(int nspan, const psImage *img);
bool pmFootprintTest(const psPtr ptr);

pmFootprint *pmFootprintNormalize(pmFootprint *fp);
int pmFootprintSetNpix(pmFootprint *fp);
void pmFootprintSetBBox(pmFootprint *fp);
psArray *pmFindFootprints(const psImage *img, const float threshold, const int npixMin);
pmFootprint *pmFindFootprintAtPoint(const psImage *img,
                                    const float threshold,
                                    const psArray *peaks,
                                    int row, int col);

psArray *pmGrowFootprintArray(const psArray *footprints, int r);
psArray *pmMergeFootprintArrays(const psArray *footprints1, const psArray *footprints2,
                                const int includePeaks);

psImage *pmSetFootprintArrayIDs(const psArray *footprints, const bool relativeIDs);
psImage *pmSetFootprintID(const pmFootprint *fp, const int id);

psErrorCode pmPeaksAssignToFootprints(psArray *footprints, const psArray *peaks);

psErrorCode pmFootprintArrayCullPeaks(const psImage *img, const psImage *weight, psArray *footprints,
                                 const float nsigma, const float threshold_min);
psErrorCode pmFootprintCullPeaks(const psImage *img, const psImage *weight, pmFootprint *fp,
                                 const float nsigma, const float threshold_min);

psArray *pmFootprintArrayToPeaks(const psArray *footprints);

#endif
