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

	Program:		RITK Plugins
	Module:			CUDANormalizedConvolutionRImageFilterPlugin.cxx
	Version:		$Revision: 898 $
	Date:			$Date: 2011-04-29 18:51:40 +0200 (Fri, 29 Apr 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

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

#include "CUDANormalizedConvolutionRImageFilterPlugin.h"
#include "ritkManager.h"


//----------------------------------------------------------------------------
CUDANormalizedConvolutionRImageFilterPlugin::CUDANormalizedConvolutionRImageFilterPlugin()
{
		
    // We need to initialize the CUDA context
    ritk::CudaContext::GetInstance(); 

	// Initialize filter
	m_Filter = FilterType::New();

	// Create GUI widget
	m_Widget = new CUDANormalizedConvolutionRImageFilterWidget();

	// Connect signals and slots
	connect(m_Widget, SIGNAL(RangeDataCheckBoxChanged(bool)),	this,	SLOT(SetRangeFilterMode(bool))	);
	connect(m_Widget, SIGNAL(RangeSigmaChanged(float)),			this,	SLOT(SetSigma(float))			);
	connect(m_Widget, SIGNAL(RangeKernelSizeChanged(int)),		this,	SLOT(SetKernelSize(int))		);

	// Range filtering by default
	emit SetRangeFilterMode(true);
}


//----------------------------------------------------------------------------
CUDANormalizedConvolutionRImageFilterPlugin::~CUDANormalizedConvolutionRImageFilterPlugin()
{
	delete m_Widget;
}


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


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

//----------------------------------------------------------------------------
void
CUDANormalizedConvolutionRImageFilterPlugin::SetSigma(float Sigma)
{
	this->LockPlugin();
	this->LockPipeline();
	m_Filter->SetRangeSigma(Sigma);
	this->UnlockPipeline();
	this->UnlockPlugin();
}


//----------------------------------------------------------------------------
void
CUDANormalizedConvolutionRImageFilterPlugin::SetKernelSize(int size)
{
	this->LockPlugin();
	this->LockPipeline();
	m_Filter->SetRangeKernelSize(size);
	this->UnlockPipeline();
	this->UnlockPlugin();
}



//----------------------------------------------------------------------------
void
CUDANormalizedConvolutionRImageFilterPlugin::SetParameter(QString Name, QString Value)
{	
	if ( strcmp(Name.toStdString().c_str(), "Sigma") == 0 )
	{
		int sigma = atoi(Value.toStdString().c_str());
		m_Widget->UpdateRangeSigma(sigma);
	}
	else if ( strcmp(Name.toStdString().c_str(), "Radius") == 0 )
	{
		int radius = atoi(Value.toStdString().c_str());
		m_Widget->UpdateRangeKernelSize(radius);
	}
}
