// FilterCamera.cpp: implementation of the CFilterCamera class.
//
//////////////////////////////////////////////////////////////////////

/** \file FilterCamera.cpp
	\brief implementace třídy CFilterCamera
*/

#include "stdafx.h"
#include "FilterCamera.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNAMIC(CFilterCamera, CFilterBase)

CFilterCamera::CFilterCamera(float CameraFocus, float DistanceToCamera, const char* name)
	: CFilterBase(CameraFocus, DistanceToCamera, name)
{
	TRACE("-- Entering CFilterCamera constructor --\n");
	m_type = 0;
}

CFilterCamera::~CFilterCamera()
{
	TRACE("-- Entering CFilterCamera destructor --\n");
	
	#ifdef _DEBUG
		Dump(afxDump);
	#endif // _DEBUG
}


CStructures::iPoint CFilterCamera::GetNextSize() const
{
	TRACE("-- Entering CFilterCamera::GetNextSize --\n");
	
	CStructures::iPoint nextSize;

	nextSize = CFilterBase::GetSize();
	//nextSize.X = m_Width;
	//nextSize.Y = m_Height;

	TRACE("Rozliseni nasledujiciho filtru: <%d x %d>\n", nextSize.X, nextSize.Y);

	return nextSize;
}

/*//MRCCC
void CFilterCamera::Transform(CPixelArray* pSource, CPixelArray* pTarget)
{
	TRACE("Entering CFilterCamera::Transform\n");

	int x,y, count=0;
	int xMax, yMax;
	CStructures::Point point, size;
	CStructures::ARGBPixel pixelValue;

	//float hodnota;

	size = CFilterBase::GetSize();


	xMax = (size.X/2)-1;
	yMax = (size.Y/2)-1;

	//----- TESTOVANI SUPERSAMPLINGU ------//
	//			Supersampling();
	//------------------------------------//

	
	long total = (size.X * size.Y)/100;
	long currPix = 0;

	TRACE("Processing CFilterCamera... <%d x %d>\r\n",size.X, size.Y);	
	printf(" <%d x %d>\n",size.X, size.Y);	

	for(x = -xMax; x < xMax; x++)
		for(y = -yMax; y < yMax; y++)
		{
			point.X = x;
			point.Y = y;

			//hodnota = pSource->GetGrayPixel(point);
			pixelValue = pSource->GetRGBPixel(point);

			//pTarget->SetGrayPixel(point, hodnota);
			pTarget->SetRGBPixel(point, pixelValue);

			count++;

			currPix++;
			if((currPix % total) == 0) printf("\r%d%% done", currPix/total);
		}

		printf("\n");

//#ifdef _OPENCV
//	pTarget->Display("Camera");
//#endif //_OPENCV

	
	//printf("\n\n");
	//TRACE("count = %d\n", count);		
}
*/

void CFilterCamera::Supersampling()
{
	int x,y; //zacatek subpixelu
	int xMax, yMax;
	int xOut, yOut;
	CStructures::Supersample supersample;
	

	CStructures::iPoint size, overSize;
//MR nepoužívá se	CStructures::Point subPixIndex;

	supersample = CFilterBase::GetSupersample();
	
	//rozliseni hrube mrizky
	size = CFilterBase::GetSize();

	xOut = - size.X/2 - 1;
	yOut = - size.Y/2 - 1;

	//rozliseni jemne mrizky
	overSize.X = size.X * supersample.X;
	overSize.Y = size.Y * supersample.Y;

	//jemna mrizka
	xMax = (overSize.X/2);
	yMax = (overSize.Y/2);

	
	//pres celou jemnou mrizku
	for(x = -xMax; x <= xMax; x += supersample.X)
	{
		xOut++;

		for(y = - yMax; y <= yMax; y+= supersample.Y)
		{
			yOut++;

			TRACE("Subpixel start at: <%d,%d>\n", x,y);
			int subX, subY; //souradnice subpixelu v hrubem pixelu
			int stepX, stepY; //krok po subpixelech

			for(stepX = 0; stepX < supersample.X; stepX++)
				for(stepY = 0; stepY < supersample.Y; stepY++)
				{
					subX = x + stepX;
					subY = y + stepY;
					TRACE("\tsubpixels <%d,%d>\n", subX, subY);
				}

			TRACE("Saving at <%d,%d>\n", xOut, yOut);
		}

		yOut = - size.Y/2 - 1;
	}
		
} 



#ifdef _DEBUG
void CFilterCamera::Dump(CDumpContext& dc) const
{
	CFilterBase::Dump(dc);

}
#endif // _DEBUG