#include "RuinsReconstructorPropertiesWidget.h"
#include "RuinsReconstructorProcessor.h"
#include "CanvasPointGrabber.h"

RuinsReconstructorPropertiesWidget::RuinsReconstructorPropertiesWidget( RuinsReconstructorProcessor *processor, QWidget *parent, Qt::WFlags f )
:  QWidget( parent, f ),  _processor( processor )
{	
	ui.setupUi( this );
	refresh();
	CornerDetector *cd = _processor->getCornerDetector();
	
	if( cd->getType() == 0 ) // type = FAST detector
	{
		_currentFASTInstance = dynamic_cast<FASTCornerDetector*>(cd);
		_currentKLTInstance = new KLTCornerDetector( CanvasPointGrabber::MAX_POINTS );
		ui.radioFAST->setChecked( true );
	}
	else
	{
		_currentKLTInstance = dynamic_cast<KLTCornerDetector*>(cd);
		_currentFASTInstance= new FASTCornerDetector( CanvasPointGrabber::MAX_POINTS );
		ui.radioFAST->setChecked( false );
	}

	if( _processor->usingKalmanFilter() )
	{
		ui.checkUseCalman->setChecked(true);
	}
	else
	{
		ui.checkUseCalman->setChecked(false);
	}
}
RuinsReconstructorPropertiesWidget::~RuinsReconstructorPropertiesWidget()
{
	// empty
}

void RuinsReconstructorPropertiesWidget::refresh()
{
	ui.threshold->setValue( _processor->getCornerDetector()->getThreshold() );
}

void RuinsReconstructorPropertiesWidget::on_threshold_valueChanged( int value )
{
	_processor->getCornerDetector()->setThreshold( value );
}

void RuinsReconstructorPropertiesWidget::on_radioFAST_toggled( bool on )
{
	if( on == true )
	{
		_processor->setCornerDetector( _currentFASTInstance );
	}
}
void RuinsReconstructorPropertiesWidget::on_radioKLT_toggled( bool on )
{
	if( on == true )
	{
		_processor->setCornerDetector( _currentKLTInstance );
	}
}

void RuinsReconstructorPropertiesWidget::on_btnRefresh_pressed()
{
	_processor->getCornerDetector()->refreshDetection();
}

void RuinsReconstructorPropertiesWidget::on_checkUseCalman_clicked( bool on )
{
	if( on )
	{
		_processor->setUseCalmanFilter( true );
	}
	else 
		_processor->setUseCalmanFilter( false );

}