
#include <cv.h>
#include <highgui.h>


#ifndef EIGHT_POINT_H
#define EIGHT_POINT_H

class EightPoint {
 public:
  EightPoint();
  ~EightPoint();

  void initialize(char *);


  static int numOfRuns;
  static char leftWindowName[20];
  static char rightWindowName[20];

  IplImage *leftImage;
  IplImage *rightImage;
  CvSize imageSize;
  int totalNumPoints;
  int numPoints;
  int *pointIndices;

  CvPoint2D64d *leftPoints;
  CvPoint2D64d *rightPoints;
  
  CvPoint3D64d leftEpipole;
  CvPoint3D64d rightEpipole;
  CvMat fMat;
  
  CvMat unnormFMat;
  CvMat normFMat;
  double unnormConditionNum;
  double normConditionNum;
  double unnormActiveError;
  double normActiveError;
  void epipolarG(int step);
  void drawEpipolarLines(int numLines);

  ofstream unnormConditionNumFS;
  ofstream normConditionNumFS;
  ofstream unnormActiveErrorFS;
  ofstream normActiveErrorFS;
  

 private:
  char leftImageFN[20], rightImageFN[20];
  void choosePoints(int);
  bool inPointIndices(int, int);
  void findUnnormFMat(void);
  void findNormFMat(void);
  void constructAMat(void);
  void allocateMats(int);
  void freeMats(void);
  void constructNormTs(void);
  void printMat(CvMat *m, int nRow, int nCol);
  void create3x3MatFromCol(CvMat *dstM, CvMat *srcM, int colN);
  void epipolarLine(CvMat *, CvPoint2D64d *, IplImage *);


  bool isNormalized;
  CvMat AMat, UMat, VMat, WMat;
  CvMat leftNormT, rightNormT;
 
  //temp use
  CvMat tU, tV, tD, ttM;
  CvMat m1, m2, m1x3, m1x1, m3x3;
};



#endif

