#ifndef __MANDOWIZARD_HH
#define __MANDOWIZARD_HH

#include <boost/shared_ptr.hpp>
#include "image.h"
#include "image_dc1394input.h"
#include "image_v4linput.h"
#include "rgba.h"
#include <QtGui/QDialog>
#include "cameraProjectorCalibration.hh"
#include "pointerRecognition.hh"
#include "ui_mandoWizard.hh"

class CalibrateWidget;
class CrossWidget;
class SelectRectWidget;
class VideoWidget;

class MandoWizard: public QDialog
{
  Q_OBJECT
public:
  typedef mimas::image_input< mimas::rgba< unsigned char > > Video;
  typedef mimas::image_v4linput< mimas::rgba< unsigned char > > V4LInput;
  typedef mimas::image_dc1394input< mimas::rgba< unsigned char > > DC1394Input;
  typedef boost::shared_ptr< Video > VideoPtr;
  typedef boost::shared_ptr< V4LInput > V4LInputPtr;
  typedef boost::shared_ptr< DC1394Input > DC1394InputPtr;
  typedef boost::numeric::ublas::vector< double > Vector;
  MandoWizard( QWidget *parent = 0, Qt::WFlags = 0 );
  PointerRecognitionPtr pointerRecognition;
  VideoPtr input;
  V4LInputPtr v4lInput;
  DC1394InputPtr dc1394Input;
public slots:
  void updateEnabled(void);
protected slots:
  void calibrate();
  void previousPage();
  void nextPage();
  void loadSearchPattern();
  void loadProjectedPattern();
  void reconnectCamera();
  void displayCalibFrame(int);
  void displayDifference(bool);
  void grabReferenceImage();
  void setThreshold(int);
  void setSigma(double);
  void setRange(int);
  void startDrag();
  void stopDrag();
  void setCameraParameters(void);
protected:
  virtual void timerEvent( QTimerEvent *e );
  void showPage( int index );
  bool loadImage( const char *title,
                  mimas::image< mimas::rgba< unsigned char > > &img );
  void setupVideo(void);
  void displayCalibResult( int index, bool diff );
  VideoPtr camera(void) throw (mimas::mimasexception);
  mimas::image< mimas::rgba< unsigned char > > grabColourFrame( bool twice = true )
    throw (mimas ::mimasexception);
  mimas::image< unsigned char > grabFrame(void) throw (mimas::mimasexception);
  Ui::MandoWizard ui;
  mimas::image< mimas::rgba< unsigned char > > searchPattern;
  mimas::image< mimas::rgba< unsigned char > > projectedPattern;
  VideoWidget *videoWidget;
  VideoWidget *searchPatternWidget;
  VideoWidget *projectedPatternWidget;
  CrossWidget *calibFrameWidget;
  SelectRectWidget *referenceImageWidget;
  CrossWidget *segmentedWidget;
  int videoTimer;
  CalibrateWidget *calibrateWidget;
  int calibTimer;
  CameraProjectorCalibrationPtr cameraProjectorCalibration;
  enum { Init = 0, First, Second, Third, Fourth, Fifth, Closing, Finished }
    calibState;
  int segmentationTimer;
  int screenW;
  int screenH;
  int pointerTimer;
};

#endif