#include "CUDABilateralFilterWidget.h"
#include <iostream>

CUDABilateralFilterWidget::CUDABilateralFilterWidget(QWidget *parent) :
	QWidget(parent)
{
	setupUi(this);

	connect(this->m_RangeSigmaSpatialSlider, SIGNAL(sliderMoved(int)), this, SLOT(RangeSigmaSpatialSliderChanged(int)));
	connect(this->m_RangeSigmaRangeSlider, SIGNAL(sliderMoved(int)), this, SLOT(RangeSigmaRangeSliderChanged(int))); 

	connect(this->m_RGBSigmaSpatialSlider, SIGNAL(sliderMoved(int)), this, SLOT(RGBSigmaSpatialSliderChanged(int)));
	connect(this->m_RGBSigmaRangeSlider, SIGNAL(sliderMoved(int)), this, SLOT(RGBSigmaRangeSliderChanged(int))); 
	connect(this->m_RangeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(RangeDataCheckBoxChanged(bool)));
	connect(this->m_RGBCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(RGBDataCheckBoxChanged(bool)));

	connect(this->m_RangeKernelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(RangeKernelSizeComboboxChanged(int)));
	connect(this->m_RGBKernelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(RGBKernelSizeComboboxChanged(int)));

	// Enabled by default
	this->m_RangeCheckBox->setChecked(true);
	this->m_RGBCheckBox->setChecked(false);
}


CUDABilateralFilterWidget::~CUDABilateralFilterWidget()
{
}


//----------------------------------------------------------------------------
void
CUDABilateralFilterWidget::Preset()
{	
	m_RangeSigmaSpatialSlider->setMinimum(1);
	m_RangeSigmaSpatialSlider->setMaximum(100);
	m_RangeSigmaSpatialSlider->setValue(60);
	RangeSigmaSpatialSliderChanged(60);

	m_RangeSigmaRangeSlider->setMinimum(1);
	m_RangeSigmaRangeSlider->setMaximum(100);
	m_RangeSigmaRangeSlider->setSingleStep(1);
	m_RangeSigmaRangeSlider->setValue(40);
	RangeSigmaRangeSliderChanged(40);

	m_RGBSigmaSpatialSlider->setMinimum(1);
	m_RGBSigmaSpatialSlider->setMaximum(100);
	m_RGBSigmaSpatialSlider->setValue(20);
	RGBSigmaSpatialSliderChanged(20);

	m_RGBSigmaRangeSlider->setMinimum(1);
	m_RGBSigmaRangeSlider->setMaximum(1000000);
	m_RGBSigmaRangeSlider->setSingleStep(1);
	m_RGBSigmaRangeSlider->setValue(500000);
	RGBSigmaRangeSliderChanged(500000);
}


//----------------------------------------------------------------------------
void
CUDABilateralFilterWidget::RangeSigmaSpatialSliderChanged(int value)
{
	float scaled = value/10.f;
	m_RangeSigmaSpatialLabel->setText(QString::number(scaled));
	emit RangeSigmaSpatialChanged(scaled);
}


//----------------------------------------------------------------------------
void
CUDABilateralFilterWidget::RangeSigmaRangeSliderChanged(int value)
{
	float scaled = value;
	m_RangeSigmaRangeLabel->setText(QString::number(scaled));
	emit RangeSigmaRangeChanged(scaled);
}


//----------------------------------------------------------------------------
void
CUDABilateralFilterWidget::RangeKernelSizeComboboxChanged(int index)
{
	emit RangeKernelSizeChanged(index+1);
}


//----------------------------------------------------------------------------
void
CUDABilateralFilterWidget::RGBSigmaSpatialSliderChanged(int value)
{
	//float scaled = value;
	float scaled = value/10.f;
	m_RGBSigmaSpatialLabel->setText(QString::number(scaled));
	emit RGBSigmaSpatialChanged(scaled);
}


//----------------------------------------------------------------------------
void
CUDABilateralFilterWidget::RGBSigmaRangeSliderChanged(int value)
{
	//float scaled = value;
	float scaled = value/1000.f;
	m_RGBSigmaRangeLabel->setText(QString::number(scaled));
	emit RGBSigmaRangeChanged(scaled);
}


//----------------------------------------------------------------------------
void
CUDABilateralFilterWidget::RGBKernelSizeComboboxChanged(int index)
{
	emit RGBKernelSizeChanged(index+1);
}



