/*======================================================================================

	Program:		Range Imaging Toolkit (RITK)
	Module:			ritkOpenGLRImageControlUnit.h
	Version:		$Revision: 1748 $
	Date:			$Date: 2011-09-23 15:47:56 +0200 (Fr, 23 Sep 2011) $

	Copyright (c) 2010-2011
	Pattern Recognition Lab, 
    University Erlangen-Nuremberg, Germany
    All rights reserved.

	This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
	See RITKCopyright.txt for more information.

	http://www5.informatik.uni-erlangen.de/research/software/ritk

========================================================================================*/

#ifndef OPENGLRIMAGECONTROLUNIT_H__
#define OPENGLRIMAGECONTROLUNIT_H__

#include "ritkVisualization.h"

#include <QMutex>

#include "ui_ritkOpenGLRImageControlUnit.h"

#include "ritkRImage.h"
#include "ritkImagePayloadVisualizationConfig.h"

namespace ritk
{

/**	@ingroup	Visualization
 *	@class		OpenGLRImageControlUnit
 *	@author		Sven Haase
 *	@brief		A controler for an RImageEntity
 *
 *	@details
 */
class VISUALIZATION_EXPORT OpenGLRImageControlUnit : public QDockWidget, public Ui_OpenGLRImageControlUnit
{
	Q_OBJECT

public:
	/// Constructor
	OpenGLRImageControlUnit( QWidget * parent = 0, Qt::WindowFlags flags = 0 );
	/// Destructor
	~OpenGLRImageControlUnit();

	/// Range image typedefs */
	//{
	typedef RImageF2				RangeImageType;
	typedef RImageF2::Pointer		RangeImagePointer;
	typedef RImageF2::ConstPointer	RangeImageConstPointer;
	//@}

public slots:
	/**	@brief	Update the GUI based on image payload configs
	 *	@param	Data	a vector containing image payload configs
	 *
	 *	@details
	 *	A call to this method will update the control unit's GUI to fit the visualization configurations.
	 *	In particular, this includes resetting and refilling the payload combo boxes with the given data. 
	 *	Internally, an index table mapping combo box ids to the correct payload id will be created. The latter is eventually
	 *	emitted when a combo box' current id changes. @sa PrimaryPayloadComboBoxIdChanged() @sa SecondaryPayloadComboBoxIdChanged \n
	 *	Note that both combo boxes will always contain the same entries, however, operating on their own table!
	 */
	virtual void ResetGUI(std::vector<ImagePayloadVisualizationConfig> Table);

signals:
	/// Signal that is emitted if the primary payload visualization configuration changed
	void PrimaryPayloadVisualizationConfigChanged(ImagePayloadVisualizationConfig Config);
	/// Signal that is emitted if the secondary payload visualization configuration changed
	void SecondaryPayloadVisualizationConfigChanged(ImagePayloadVisualizationConfig Config);

protected:
	/// Mutex used to synchronize rendering and data update
	QMutex m_Mutex;

	/// Table that holds the visualization configs where the i-th table entry corresponds to the i-th primary payload combo box entry and associated clamping
	std::vector<ImagePayloadVisualizationConfig> m_PrimaryImagePayloadConfigTable;

	/// Table that holds the visualization configs where the i-th table entry corresponds to the i-th secondary payload combo box entry and associated clamping
	std::vector<ImagePayloadVisualizationConfig> m_SecondaryImagePayloadConfigTable;

protected slots:
	/// Connected to the primary payload combo box' currentIndexChanged(int). This will resolve the combo box id to the correct payload id and emit PrimaryPayloadIdChanged().
	void PrimaryPayloadComboBoxIdChanged(int id);
	/// Connected to the primary payloads upper bound clamp spin box
	void PrimaryPayloadClampUpperBoundChanged(double value);
	/// Connected to the primary payloads lower bound clamp spin box
	void PrimaryPayloadClampLowerBoundChanged(double value);
	/// Connected to the primary payloads enable LUT check box
	void PrimaryPayloadEnableLUTCheckBoxChanged(bool enabled);
	/// Connected to the primary payloads LUT combo box
	void PrimaryPayloadLUTComboBoxIdChanged(int id);

	/// Connected to the secondary payload combo box' currentIndexChanged(int). This will resolve the combo box id to the correct payload id and emit SecondaryPayloadIdChanged().
	void SecondaryPayloadComboBoxIdChanged(int);
	/// Connected to the Secondary payloads upper bound clamp spin box
	void SecondaryPayloadClampUpperBoundChanged(double value);
	/// Connected to the Secondary payloads lower bound clamp spin box
	void SecondaryPayloadClampLowerBoundChanged(double value);
	/// Connected to the secondary payloads enable LUT check box
	void SecondaryPayloadEnableLUTCheckBoxChanged(bool enabled);
	/// Connected to the secondary payloads LUT combo box
	void SecondaryPayloadLUTComboBoxIdChanged(int id);
};




} // end namespace ritk

#endif // OPENGLRIMAGECONTROLUNIT_H__