/*======================================================================================

	Program:		Range Imaging Toolkit (RITK)
	Module:			ritkRImageIOBase.h
	Version:		$Revision: 1761 $
	Date:			$Date: 2011-09-23 17:25:41 +0200 (Fri, 23 Sep 2011) $

	Copyright (c) 2010-2011
	Pattern Recognition Lab, 
    University Erlangen-Nuremberg, Germany
    All rights reserved.

	This program 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 RITKCopyright.txt for more information.

	http://www5.informatik.uni-erlangen.de/research/software/ritk

========================================================================================*/

#ifndef RIMAGEIOBBASE_H__
#define RIMAGEIOBBASE_H__

#include <itkLightProcessObject.h>
#include "ritkRImage.h"

namespace ritk
{

/**	@ingroup	Common
 *	@class		RImageIOBase
 *	@author		Jakob Wasza
 *	@brief		File IO functionality for range images
 *
 *	@details
 *	This class provides the basic interface for file IO functionality for range images. In particular,
 *	this includes setting the filename and reading/writing single range image frames. RImageIOBase and subclasses
 *	are NOT meant to be a direct part of an image processing pipeline but are designed to provide IO functionality
 *	only. 
 *	@sa	RImageIOManager
 *	@sa RImageFileSource
 */
template<class TRImageBase>
class RImageIOBase : public itk::LightProcessObject
{
public:
	/** @name Standard typedefs */
	//@{
	typedef RImageIOBase				Self;
	typedef itk::LightProcessObject		Superclass;
	typedef itk::SmartPointer<Self>		Pointer;
	//@}

	/**	@name RImage typedefs */
	//@{
	typedef TRImageBase								RImageBaseType;
	typedef typename RImageBaseType::Pointer			RImageBasePointer;
	typedef typename RImageBaseType::ConstPointer		RImageBaseConstPointer;
	//@}

	/// RTTI
	itkTypeMacro(RImageIOBase, itk::LightProcessObject);

	/** @name Set/Get the name of the file to be read/written. Will just access the member*/
	//@{
	virtual void SetFileName(std::string FileName);
	virtual std::string GetFileName();
	//@}

	/// Return the class name of the range image that this IO object can process
	virtual const char* GetRImageClassName()=0;

	/// Return the number of frames that are available
	virtual unsigned int GetNumberOfFrames()=0;

	/// The resolution of the frames
	virtual void GetResolution(unsigned int *SX, unsigned int *SY)=0;

	/// Get the timestamps for ALL frames. This base class' implementation will just return the member.
	virtual const std::vector<typename RImageBaseType::TimeStampType>& GetTimeStamps() const;

	/// Write a frame
	virtual void WriteFrame(RImageBaseConstPointer Frame)=0;

	/// Read a frame
	virtual RImageBasePointer ReadFrame(unsigned int ID)=0;

	/// Close the input/output stream
	virtual void Close();

protected:
	/// Constructor
	RImageIOBase();
	/// Destructor
	virtual ~RImageIOBase();

protected:
	/// The filename
	std::string m_FileName;
	/// Vector holding the individual timestamps. Subclasses should store the timestamps in this member
	std::vector<typename RImageBaseType::TimeStampType> m_TimeStamps;

private:
	/// purposely not implemented
	RImageIOBase(Self&); 
	/// purposely not implemented
	void operator=(const Self&); 
};

/// Explicit template instantiation
typedef RImageIOBase<RImageF2> RImageIOBaseF2;


} // end namespace ritk

#endif // RIMAGEIOBBASE_H__