/**
 * \file rectification.h
 * \brief the header file for rectification.c
 *
 *  \date Jun 9, 2009
 *  \author Alexander Pimenov
 */

#ifndef RECTIFICATION_H_
#define RECTIFICATION_H_
#ifdef __cplusplus
	extern "C" {
#endif

#include "geometry.h"
#include "matrix.h"
#include "projective.h"

/**
 * \brief This structure describes the correspondence of the points between the "left" and the "right" image
 */
typedef struct Correspondance_TAG {
	vector2Dd start; /**< \brief The point in the "left" image */
	vector2Dd end;   /**< \brief The point in the "right" image */
	uint16_t value;  /**< \brief The weight of the correspondence */
	uint16_t flags;  /**< \brief Some flags */
} Correspondance;

typedef struct CorrespondanceList_TAG {
	int corrNumber;
	Correspondance *corr;
};

Matrix* rectifyRANSAC (Correspondance *points, int pointNumber, int trySize, int maxIterations, double treshold);

void findEpipoleFromMatrix(Matrix *F, vector3Dd *e1, vector3Dd* e2);
void findEpipole(projectiveTransform2D *F, vector3Dd *e1, vector3Dd* e2);

void getRectificationTransformationSimple1(projectiveTransform2D *F, Correspondance *points, int pointNumber, projectiveTransform2D *leftTranstorm, projectiveTransform2D *rightTranstorm, vector3Dd z);
void getRectificationTransformationOptimal(projectiveTransform2D *F, Correspondance *points, int pointNumber, projectiveTransform2D *leftTranstorm, projectiveTransform2D *rightTranstorm, vector3Dd z);
double doLateralCorrection(Correspondance *points, int pointNumber, projectiveTransform2D *leftTranstorm, projectiveTransform2D *rightTranstorm);

void getLateralCorrection(
		Correspondance *points,
		int pointNumber,
		projectiveTransform2D *leftTranstorm,
		projectiveTransform2D *rightTranstorm,
		double *minimum,
		double *maximum);



double getNormalisingTransformation(Correspondance *points, int pointNumber, projectiveTransform2D *left, projectiveTransform2D *right );
void transformCorrespondence(Correspondance *points, int pointNumber, projectiveTransform2D *left, projectiveTransform2D *right);

#ifdef __cplusplus
	} // 	extern "C"
#endif
#endif /* RECTIFICATION_H_ */
