#ifndef  DETECT___LINES_H__
#define  DETECT___LINES_H__
#include "Steger.hpp"
typedef struct {
	long  cont1; /* Index of line that is already processed */
	long  cont2; /* Index of line tnat runs into cont1 */
	long  pos;   /* Index of the junction point in cont1 */
	float x;     /* x-(row-)coordinate of the junction point */
	float y;     /* y-(col-)coordinate of the junction point */
} junction;

typedef struct {
	short  x;
	short  y;
	double value;
	bool   done;
} crossref;

typedef struct {
	long x;
	long y;
} offset;

typedef struct {
	short r;   /* row coordinate of the chord */
	short cb;  /* column coordinate of the start of the chord */
	short ce;  /* column coordinate of the end of the chord */
} chord;

/* Run-length encoded region of an image.  This type is returned by the
threshold() function.  It provides the means to efficiently link line points
into lines. */
typedef struct {
	long  num;      /* number of chords */
	chord *rl;      /* array of chords */
} region;

#define INITIAL_SIZE   100  /* Initial size of dynamically realloc'ed arrays */
#define REALLOC_FACTOR 2   
#define FALSE false
#define TRUE	true

#define PI 3.14159265

#define MAX_ANGLE_DIFFERENCE (PI/6.0)

/* Maximum length by which a line is possibly extended in order to find a
junction with another line. */
#define MAX_LINE_EXTENSION (2.5*sigma)

void *xmalloc(size_t size);

void *xrealloc(
	void   *old_ptr,
	size_t size);

void threshold(
	unsigned char   *image,
	long   min,
	long   width,
	long   height,
	region *out);
void compute_contours(
	unsigned char    *ismax,
	float   *eigval,
	float   *normx,
	float   *normy,
	float   *posx,
	float   *posy,
	float   *gradx,
	float   *grady,
	contour ***result,
	long    *num_result,
	double  sigma,
	bool    extend_lines,
	int     mode,
	double  low,
	double  high,
	long    width,
	long    height);

#endif