//////////////////////////////////////////////////////////////////////
//
//                             Pixie
//
// Copyright © 1999 - 2003, Okan Arikan
//
// Contact: okan@cs.berkeley.edu
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//
//  File				:	volume.h
//  Classes				:	CVolume
//  Description			:	Models an explosion
//
////////////////////////////////////////////////////////////////////////
#ifndef VOLUME_H
#define VOLUME_H

#include "common/global.h"
#include "common/algebra.h"
#include "attributes.h"
#include "options.h"


///////////////////////////////////////////////////////////////////////
// Class				:	CVolume
// Description			:	Encapsulates a particle cloud
// Comments				:
// Date last edited		:	3/28/2003
class	CVolume : public CFileResource {

	///////////////////////////////////////////////////////////////////////
	// Class				:	CVoxel
	// Description			:	Encapsulates a voxel
	// Comments				:
	// Date last edited		:	3/28/2003
	class CVoxel {
	public:
		float			density;		// The density in the voxel
		vector			emit;			// The energy that we want to emit from this voxel
		vector			indirect;		// The indirect energy that we've received at this voxel
	};

	///////////////////////////////////////////////////////////////////////
	// Class				:	CIndirectNode
	// Description			:	Encapsulates an indirect illumination node
	// Comments				:
	// Date last edited		:	3/28/2003
	class CIndirectNode {
	public:
						~CIndirectNode();

		vector			emit;			// The amount of total power emitted from this node
		vector			middle;			// The coordinates of the middle
		float			side;			// The side length of the oc
		CIndirectNode	*children[8];	// The 8 children of this voxel
	};
public:
					CVolume(CAttributes *,matrix *,const char *);
					~CVolume();

	void			properties(float &,const float *);
	int				emit(int,float *,float *,float *);
	void			estimate(float *,const float *,const float *,float);

	int				numVoxels;					// The number of voxel cells
	float			side;						// The length of one side
	float			volume;						// Volume of a voxel grid
	float			stepSize;					// The volume step size
	vector			emittedEnergy;				// The total emitted energy
	CVoxel			***grids;					// The grids
	CIndirectNode	*root;						// The indirect illumination root node
	int				maxIndirectDepth;			// The indirect illumination maximum depth
	float			asMu,abMu;					// Scattering and absorbsion coefficients	
	vector			bmin,bmax;					// The volume bounding volume
private:
	void			insertIndirect(const float *,const float *);
	float			integrateIndirect(const float *,const float *,float);
};


#endif





