#include "ClampRangeImageFilterPlugin.h"

ClampRangeImageFilterPlugin::ClampRangeImageFilterPlugin()
{
	// Initialize filter
	m_Filter = CRType::New();
	m_LowerBound = 0;
	m_UpperBound = 7000;
	m_Filter->SetLowerBound(m_LowerBound);
	m_Filter->SetUpperBound(m_UpperBound);

	// Create GUI widget and connect signals and slots
	m_Widget = new CRWidget();
	connect(m_Widget, SIGNAL(LowerBoundChanged(float)), this, SLOT(SetLowerBound(float)));
	connect(m_Widget, SIGNAL(UpperBoundChanged(float)), this, SLOT(SetUpperBound(float)));

	connect(m_Widget, SIGNAL(RangeDataCheckBoxChanged(bool)), this, SLOT(SetRangeFilterMode(bool)));
}

ClampRangeImageFilterPlugin::~ClampRangeImageFilterPlugin()
{
	delete m_Widget;
}


//----------------------------------------------------------------------------
QWidget*
ClampRangeImageFilterPlugin::GetPluginGUI()
{
	return m_Widget;
}


//----------------------------------------------------------------------------
ClampRangeImageFilterPlugin::FilterPlugin::FilterPointer 
ClampRangeImageFilterPlugin::GetFilter()
{
	return (FilterPlugin::FilterType*)m_Filter;
}


//----------------------------------------------------------------------------
void
ClampRangeImageFilterPlugin::SetLowerBound(float value)
{
	if ( m_LowerBound == value )
		return;

	LockPlugin();

	m_LowerBound = value;

	LockPipeline();
	m_Filter->SetLowerBound(m_LowerBound);
	UnlockPipeline();


	UnlockPlugin();
}


//----------------------------------------------------------------------------
void
ClampRangeImageFilterPlugin::SetUpperBound(float value)
{
	if ( m_UpperBound == value )
		return;

	LockPlugin();

	m_UpperBound = value;

	LockPipeline();
	m_Filter->SetUpperBound(m_UpperBound);
	UnlockPipeline();


	UnlockPlugin();
}