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

	Program:		Range Imaging Toolkit (RITK)
	Module:			ritkOpenGLPointPickerLinearControlUnit.cxx
	Version:		$Revision: 2786 $
	Date:			$Date: 2012-03-13 17:51:50 +0100 (Di, 13 Mrz 2012) $

	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

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

#include "ritkOpenGLPointPickerLinearControlUnit.h"

namespace ritk
{


//----------------------------------------------------------------------------
OpenGLPointPickerLinearControlUnit::OpenGLPointPickerLinearControlUnit( QWidget * parent, Qt::WindowFlags flags )
{
	// Std Qt
	setupUi(this);

	connect(this->m_SizeSlider, SIGNAL(sliderMoved(int)), this, SLOT(SizeSliderChanged(int)));
}


//----------------------------------------------------------------------------
OpenGLPointPickerLinearControlUnit::~OpenGLPointPickerLinearControlUnit()
{
}



//----------------------------------------------------------------------------
void
OpenGLPointPickerLinearControlUnit::UpdateDistance(float d)
{
	m_Mutex.lock();
	if(d != 0){
		QString res;
		res.setNum (d / 10.0f, 'f', 2);
		res += " cm";
		m_DistanceLabel->setText(res);
	} else {
		m_DistanceLabel->setText("-");
	}
	m_Mutex.unlock();
}


//----------------------------------------------------------------------------
void
OpenGLPointPickerLinearControlUnit::UpdatePoint1(const QVector3D p)
{
	m_Mutex.lock();
	if(p != QVector3D(0,0,0)){
		QString res;
		QString x;
		x.setNum(p.x(), 'f', 2);
		QString y;
		y.setNum(p.y(), 'f', 2);
		QString z;
		z.setNum(p.z(), 'f', 2);
		res = x +  ", " + y + ", " + z;
		m_Point1Label->setText(res);
	} else {
		m_Point1Label->setText("-");
	}
	m_Mutex.unlock();
}


//----------------------------------------------------------------------------
void
OpenGLPointPickerLinearControlUnit::UpdatePoint2(const QVector3D p)
{
	m_Mutex.lock();
	if(p != QVector3D(0,0,0)){
		QString res;
		QString x;
		x.setNum(p.x(), 'f', 2);
		QString y;
		y.setNum(p.y(), 'f', 2);
		QString z;
		z.setNum(p.z(), 'f', 2);
		res = x +  ", " + y + ", " + z;
		m_Point2Label->setText(res);
	} else {
		m_Point2Label->setText("-");
	}
	m_Mutex.unlock();
}



//----------------------------------------------------------------------------
void
OpenGLPointPickerLinearControlUnit::SizeSliderChanged(int value)
{
	float scaled = value;
	//m_SizeLabel->setText(QString::number(scaled));
	emit SizeChanged(scaled);
}


} // end namespace ritk
