#pragma once

#include <windows.h>
#include "array.h"



class Point2D
{
public:
	int x;
	int y;
	float fx;
	float fy;
	int data;
	~Point2D(void);
	Point2D(void);
};

class ConexComp{
   
	public:
	ConexComp();
	~ConexComp();
   Point2D* Pontos;
   int num_pontos;
   Point2D*  Fecho;
   int num_pontos_f;
   Point2D* Extremos;
   int num_extremos;
   int label;
   Point2D pmin_x;
   Point2D center;

};

class SetConexComp{
public:
	SetConexComp();
	~SetConexComp();
ConexComp * Components;
int num_component;

};





class VImage
{
public:
	
	/*Imagen vindas da camera*/
	BYTE *	pImage;              //Imagen Original da câmera
	BYTE *  Proc_Image;				//Imagen processada
	BYTE *  Bin_Image;
	/*variaveis pro filtro do soubel*/
	int * ImageEo;
	int * ImageEs;
	/*Variaveis pro filtro do Canny*/
	float *Cn_Es;
	float *Cn_Eo;
	float *Cn_In;
	/*variaveis pra deteçao de cantos (corners)*/
	int * ImageGrax;
	int * ImageGray;
	Point2D * Corn_List;
	int n_Corners;
	
	/*componentes conexas*/
	int * Labels;
	int * labels_cont;
	int * labels_ref;
	Point2D init;
	int *fechados;
    int *valid_labels;
	Point2D *valid_labels_acc;
	int num_valid_labels;
	SetConexComp  *Componentes;
	bool recognition;
	bool fpoint;
    /*variaveis para a  calibracao da camera */
		Point2D * C_pontos;
		int num_calpontos;
	/*variaveis para a camera opengl*/
	double modelview[16];
	double projection[16];
	float dfocal;
	/*finding dos pontos de referncia*/
	Point2D *ref_points;

	/*variaveis para a transformada do Hough */
	 int   * houghMap;
	 int HMap_Height;
	 int HMap_Width;
	 float * Distances;
	 int step_Distance;
	 int  MaxDistance;
	 int  MaxAngle;
	 Point2D * Lines_List;
	
	/* variaveis gerais */
	long	xDPI;				//horizontal resolution
	long	yDPI;				//vertical resolution
	int     Height;
	int     Width;
	float * fcos;
	float * fsin;
	
	/*variaveis pra correcao radial e da luminosidade*/
	int *mapa , * mapaH,  *mapaV;
    float *radioFactor, *iFactor, *iFactorH ,*iFactorV;

	VImage(void);
	VImage(BYTE * pInfo,long XDpi,long YDpi,int width,int Height);
    ~VImage(void);
	void Filter_Gaussian();
	void GrayScale();
	void Filter_Soubel(int threshold);
	void Filter_Canny(int Up_Thr, int Down_Thr);
	void Corners(int threshold, int janela);
	void quicksort(Point2D * input_array, int top, int bottom);
	int partition(Point2D * input_array, int top, int bottom);
	void exchange(Point2D* input_array,int i, int j);
	void Extract_Corners(int janela);
	void find_conexcomponents();
	void find_conexcomponents2();
	void find_conexcomponents3();
	void find_interesting_points();
	void find_interesting_points2();
	void Desenha_Componentes();
	void find_convexHull();
	bool find_point_fecho(Point2D point, int component);
	void interesting_points();
	void recogquad_points(); 
    Point2D	inter_line(Point2D A, Point2D B, Point2D C,Point2D D);
	void Identifing_pattern1();
	void Camera_Calibration(/*Point2D *pImagem , int num_pontos, Point2D *pWorld*/);
	void Camera_Calibration1(/*Point2D *pImagem , int num_pontos, Point2D *pWorld*/);
	void init_Kalman();
	int chainHull_2D( Point2D* P, int n, Point2D* H );
	inline float isLeft( Point2D P0, Point2D P1, Point2D P2 );
	void conex(int i, int j, int label);
	void conex2(int i, int j, int label,int level);
	void Transform_Hough (int HMap_Height ,int threshold);
	void DrawLine(float m,int  n);
	void CameraParametersInit();
	void IRRCorrection ();
	int find_label(int label);
	
	float norma(Point2D vetor);
	Point2D Sub(Point2D a,Point2D b );  //a-b
	Point2D Unit(Point2D vetor);
	float ccw(Point2D a,Point2D b);//(a)X(b)
	float dot(Point2D a,Point2D b);//a.b
	

};
