// FilterBase.cpp: implementation of the CFilterBase class.
//
//////////////////////////////////////////////////////////////////////

/** \file FilterBase.cpp
	\brief implementace třídy CFilterBase
*/

#include "stdafx.h"
#include "FilterBase.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
#endif


IMPLEMENT_DYNAMIC(CFilterBase, CObject)

int CFilterBase::num_filters = 0;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//Defaultni konstruktor
CFilterBase::CFilterBase()
{
	TRACE("-- Entering CFilterBase default constructor --\n");
	
	m_len = 8;
	m_FilterName = new char[m_len + 1];
	strcpy(m_FilterName, "Untitled");

	m_supersample.X = 1;
	m_supersample.Y = 1;

//MR	m_CameraFocus = 0;
//MR	m_DistanceToCamera = 0;
	m_bSave = false;
	m_bDisplay = false;
	m_bUse = false;

	num_filters++;
	TRACE("%d: \"%s\" object created\n\n", num_filters, m_FilterName);
}

//Konstruktor s parametry
CFilterBase::CFilterBase(float CameraFocus, float DistanceToCamera, const char* name)
{
	TRACE("-- Entering CFilterBase parameter constructor --\n");

	m_len = strlen(name);
	if(m_len == 0)
	{
		m_len = 8;
		m_FilterName = new char[m_len + 1];
		strcpy(m_FilterName, "Untitled");
	}
	else
	{
		m_FilterName = new char[m_len + 1];
		strcpy(m_FilterName, name);
	}
	

//MR	m_CameraFocus = CameraFocus;
//MR	m_DistanceToCamera = DistanceToCamera;

	m_supersample.X = 1;
	m_supersample.Y = 1;

	m_bSave = false;
	m_bDisplay = false;
	m_bUse = false;

	num_filters++;
	TRACE("%d: \"%s\" object created\n\n", num_filters, m_FilterName);
}

//Destruktor
CFilterBase::~CFilterBase()
{
	//TRACE("-- Entering CFilterBase destructor --\n");
	TRACE("%d: \"%s\" object destructed\n", num_filters, m_FilterName);
	--num_filters;
	TRACE("%d left\n\n", num_filters);

	//Dump(afxDump);
	if (m_FilterName)
		delete[] m_FilterName;
}

//kopirovaci konstruktor
CFilterBase::CFilterBase(const CFilterBase & fb)
{
	TRACE("-- Entering CFilterBase copy constructor --\n" );

	m_len = fb.m_len;
	m_FilterName = new char[m_len +1];
	strcpy(m_FilterName, fb.m_FilterName);

//MR	m_CameraFocus = fb.m_CameraFocus;
//MR	m_DistanceToCamera = fb.m_DistanceToCamera;

	m_supersample.X = fb.m_supersample.X;
	m_supersample.Y = fb.m_supersample.Y;

	m_bSave = fb.m_bSave;
	m_bDisplay = fb.m_bDisplay;
	m_bUse = fb.m_bUse;

	num_filters++;
	TRACE("%d: \"%s\" object created\n\n", num_filters, m_FilterName);
}


//Operator prirazeni
CFilterBase & CFilterBase::operator=(const CFilterBase & fb)
{
	TRACE("-- Entering CFilterBase operator= --\n\n");

	if (this == &fb)
		return *this;
	delete [] m_FilterName;
	m_len = fb.m_len;
	m_FilterName = new char[m_len +1];
	strcpy(m_FilterName, fb.m_FilterName);

//MR	m_CameraFocus = fb.m_CameraFocus;
//MR	m_DistanceToCamera = fb.m_DistanceToCamera;

	m_supersample.X = fb.m_supersample.X;
	m_supersample.Y = fb.m_supersample.Y;

	m_bSave = fb.m_bSave;
	m_bDisplay = fb.m_bDisplay;
	m_bUse = fb.m_bUse; 
	
	return *this;
}

//prejmenovani filtru
void CFilterBase::Rename(const char* name)
{	
	TRACE("-- Entering CFilterBase::Rename --\n");
	TRACE("Puvodni nazev: \"%s\"\n", m_FilterName);

	delete [] m_FilterName;
	if(name != NULL)
	{
		m_len = strlen(name);
		m_FilterName = new char[m_len + 1];
		strcpy(m_FilterName, name);
	}
	

	TRACE("Novy nazev: \"%s\"\n\n", m_FilterName);
}

//nastavi rozemry filtru a stred
void CFilterBase::SetSize(CStructures::iPoint size)
{
	TRACE("-- Entering CFilterBase::SetSize ---\n");

	m_Width = size.X;
	m_Height = size.Y;

	m_Center.X = (float)m_Width / 2;	//stred filtru
	m_Center.Y = (float)m_Height / 2;	//stred filtru

	TRACE("------ Nastaveno rozliseni filtru <%d x %d>\n", m_Width, m_Height);
	TRACE("------ Stred: x = %f, y = %f\n",m_Center.X, m_Center.Y);
}

//vrati rozmery filtru
CStructures::iPoint CFilterBase::GetSize() const
{
	CStructures::iPoint size;

	size.X = m_Width;
	size.Y = m_Height;

	return size;
}

void CFilterBase::SetSupersample(CStructures::Supersample supersample)
{
	m_supersample.X = supersample.X;
	m_supersample.Y = supersample.Y;
}

float CFilterBase::GetDistanceToCenter(CStructures::iPoint point) const
{
	//TRACE("-- Entering CFilterBase::GetDistanceToCenter --\n");
	
	float distance =  sqrtf((((float)point.X*point.X) + ((float)point.Y*point.Y)));
	return distance;

	TRACE("Vzdalenost bodu [%d : %d] od stredu = %f\n", point.X, point.Y, distance);
}


void CFilterBase::Transform(CPixelArray* pSource, CPixelArray* pTarget)
{
	TRACE("Entering CFilterBase::Transform\n");
}

//zobrazi info o filtru
void CFilterBase::Show()
{
	cout << "Name: " << m_FilterName <<"\n" ;//MR<< Camera focus: " << m_CameraFocus << "\nDistanceToCamera: " << m_DistanceToCamera << "\n"; 
}

//dumping objektu
#ifdef _DEBUG
void CFilterBase::Dump(CDumpContext& dc) const
{
	CObject::Dump(dc);
	dc << "Filter name: " << m_FilterName << "\nCamera focus: " <<"\n" ;//MR << m_CameraFocus << "\nDistanceToCamera: " << m_DistanceToCamera << "\n"; 
}
#endif // _DEBUG
