#ifndef EDITSCENEDIALOG_H__
#define EDITSCENEDIALOG_H__

// Forward declaration
class LoadVTKDataJob;

#include <QDialog>
#include <QMessageBox>
#include "ui_EditSceneDialog.h"

#include "ritkThreadedJob.h"

#include <itkArray.h>
#include <itkArray2D.h>
#include "StatisticalModel.h"


/**	@class	EditSceneDialog
 *	@author	Jakob Wasza
 *	@brief	Edit a 3D scene to be used for simulation range images
 *
 *	@details
 *
 */
class EditSceneDialog : public QDialog, public Ui_EditSceneDialog
{
	Q_OBJECT

public:
	/// Constructor
	EditSceneDialog(QWidget* parent = 0);
	/// Destructor
	virtual ~EditSceneDialog();	

public slots:
	/**@name Add/remove an actor */
	//@{
	void AddActor();
	void AddActor(QString FileName);
	void RemoveActor();
	//@}


	/**	Load model and set the modes of variation */
	//@{
	void LoadModel();
	void SetMOV1Weight(int);
	void SetMOV2Weight(int);
	void SetMOV3Weight(int);
	void SetMOV4Weight(int);
	void SetMOV5Weight(int);
	//@}
	
protected:
	/// Render the model
	void RenderModel();

protected slots:
	/// Camera 
	void SetViewMode();
	/// Actor manipulation
	void SetManipulationMode();
	
	void MoveCam();
	
	/// Load VTK data
	void LoadDataResult(bool success, vtkSmartPointer<vtkPolyData> Data, QString message);

protected:
	/// Multi pupose message box
	QMessageBox *m_MessageBox;
	/// The file name
	QString m_FileName;
	/// Holding all loaded actors
	std::vector<vtkSmartPointer<ritk::ActorPipeline> > m_ActorList;

	/**	@name	Model related members */
	//@{
	/// The model type used here
	typedef StatisticalModel<itk::Array<double> ,itk::Array2D<double> > SMType;
	/// The model instance
	SMType::Pointer m_StatisticalModel;
	/// The associated VTK data
	vtkSmartPointer<vtkPolyData> m_ModelVTK;
	/// Holds the weights for the modes of variations
	itk::Array<double> m_MOVWeights;
	/// The model actor
	std::pair<vtkSmartPointer<vtkActor>, vtkSmartPointer<vtkPolyDataMapper> >  m_ModelActor;
	//@}




	/// Due to Qt limitations
	friend class LoadVTKDataJob;
};


/** @class	LoadVTKDataJob
 *	@author	Jakob Wasza
 *	@brief	Class that is used to load VTK data
 *
 *	@details
 *	Class that loads VTK data to a camera. Loading
 *	a big data file might block the main thread. Thus, a 
 *	threaded loading routine is provided by this class
 */
class LoadVTKDataJob : public ritk::ThreadedJob
{
	Q_OBJECT

public:
	/// Constructor
	LoadVTKDataJob(QString FileName);
	/// Destructor
	~LoadVTKDataJob();

	/// Work is done here
	void Execute();

signals:
	/// Signal that is emitted when the process finished
	void Finished(bool Success, vtkSmartPointer<vtkPolyData> Data=NULL, QString message=tr(""));

protected:
	/// The file name
	QString m_FileName;

private:
	/// Purposely not implemented
	LoadVTKDataJob();
};


#endif // EDITSCENEDIALOG_H__
