/****************************************************************************************************

		FastFourrier.h
		Copyright: (c) 2002 Eovia Corp. All rights reserved.

		Author:	Arnaud
		Date:	10/26/2006

****************************************************************************************************/

#ifndef __FastFourrier__
#define __FastFourrier__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCBasicTypes.h"
#include "MCArray.h"
#include "MCClassArray.h"
#include "Complex.h"


/// \addtogroup Math
/// \{

/// FFT and IFFT implementation for 1D and 2D data
/// The transformations are done "in place"
///
class TFastFourrier : public TMCObject
{
public:
	TFastFourrier();

	void		Init(int32 power, boolean directFFT);

	void		Transform1D(TMCArray<TComplex>& f);
	void		Transform2D(TMCClassArray< TMCArray<TComplex> >& f);

	void		TransformRow(TMCClassArray< TMCArray<TComplex> >& f, int32 row);
	void		TransformCol(TMCClassArray< TMCArray<TComplex> >& f, int32 col);
	
protected:
	int32		ReverseBits			(int32 ii);
	void		FillReversedBits	();
	void		FillTwidles			(boolean directFFT);

	template <class T> void	TransformArray	(T& f);

	struct TColumnAlias : public TMCObject
	{
		TColumnAlias(TMCClassArray< TMCArray<TComplex> >& aliasedArray) : fAliasedArray(aliasedArray) 
		{
			fCurrentColumn= 0;
		}

		inline TComplex& operator[]		(uint32 i) 	{ return fAliasedArray[i][fCurrentColumn]; }

		TMCClassArray< TMCArray<TComplex> >& fAliasedArray;
		int32 fCurrentColumn;
	};

protected:
	int32		fPower;
	int32		fN;
	int32		fNDiv2;

	TMCArray<int32>		fReversedBits;
	TMCArray<TComplex>	fTwidles;
};

/// \}




#endif
