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

		DirectionSampler.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Charles
		Date:	10/2/2003

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

#ifndef __DirectionSampler__
#define __DirectionSampler__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCBasicTypes.h"
#include "MCColorRGB.h"
#include "RenderTypes.h"
#include "MCClassArray.h"

class TMCPoint;


class TDirectionSampler
{
public:
	struct GridSample
	{
		TMCColorRGBA	fColor;
	};

public:
	TDirectionSampler(const int32 quality);
	~TDirectionSampler();

	int32 GetQuality() const { return fQuality; }

	void	ReInit();
protected:
	// sample recursively a square on the grid
	virtual void SampleArea(const TMCPoint&	position,		// position in the grid
							int32			level,			// inverse depth
							const real		threshold
							);


	// sample the grid
	virtual void SampleGrid();

		
	// average the lighting over the sampling grid
	TMCColorRGBA AverageLighting();

	// Samples a direction defined by a position in the grid
	virtual void SampleDirection(const TMCPoint& position) = 0;

	// Returns a reference to a sample of the grid
	inline GridSample& GetSample(const TMCPoint& position) { return fGrid[position.x + position.y * fSamplePerLine]; }

	inline int32 GetSampleOffset(const TMCPoint& position) { return position.x + position.y * fSamplePerLine; }

	// Interpolate or sample the center of two points
	void  InterpolateOrSample(const TMCPoint&	position,
							  const int32		leftSampleOffset,
							  const int32		rightSampleOffset,
							  const real		threshold);

	// Interpolate the color over a square area
	virtual void InterpolateColor(const TMCPoint& position,int32 size);
	virtual void AverageColor(const int32 sampleOffset, const int32 leftSampleOffest, const int32 rightSampleOffest);

protected:
	int32						fMaxDepth;		// maximum sampling depth

	TMCClassArray< GridSample >			fGrid;				// sampling grid
	TMCArray<boolean>					fHasBeenSampled;	// for each sample in the grid

	int32						fSamplePerLine;	// offset to the next line of the grid
	real						fDeltaX;
	real						fDeltaY;
	
	int32						fQuality;		// rendering quality
};





#endif
