// Dilation.cpp
// Chris Pocock 2014

#include "Dilation.h"

Dilation::Dilation() {

	// Default class variables
	dilation_type = MORPH_ELLIPSE;
	dilation_elem = 2;
	dilation_size = 1;
	kernel_dil = getStructuringElement( dilation_type,Size( 1 + dilation_size, 1 + dilation_size ));

	// Trackbar  upper limits
	max_elem = 2;
	max_kernel_size = 21;
}

Dilation::~Dilation() {
}

// Dilate input image, return result
Mat Dilation::dilate(Mat &input){

	Mat output;
	cv::dilate(input, output, kernel_dil);
	return output;
}

// Update dilation element type and kernel size
void Dilation::update(){

		if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }
		else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }
		else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }

		kernel_dil = getStructuringElement( dilation_type,
				Size( 1 + dilation_size, 1 + dilation_size ));
}

// Create windows and trackbars for observation & live parameter tweaking
void Dilation::setupUi(){

	namedWindow( "Dilation", CV_WINDOW_AUTOSIZE );
	moveWindow("Dilation", 0, 100);

	createTrackbar( "Dilation Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Dilation",
			&dilation_elem, max_elem);

	createTrackbar( "Dilation Kernel size: \n 1+x", "Dilation",
			&dilation_size, max_kernel_size);
}
