/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016 Raytrix GmbH. All rights reserved.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once

#include "DLLInterface.h"
#include "Pimpl.h"

#include "Calibration.h"
#include "RayImage.h"

#include "Rx.Core/RxString.h"
#include "Rx.Core.Ex/RxImage.h"
#include "Rx.Core.Ex/RxMetaData.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// namespace: Rx.LFR
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Rx
{
	namespace LFR
	{
		class CRayFileWriter_Impl;

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>
		/// 	Provides methods for writing a ray image to a ray file.
		/// </summary>
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		class RX_API CRayFileWriter : public CPimpl<CRayFileWriter_Impl, Interfaces::ERayFileWriter::ID>
		{
		public:

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Writes the given ray image to the given file.
			///
			/// 	Requires an authenticated dongle (Rx::LFR::CLightFieldRuntime::Authenticate) with the Rx::Dongle::ERuntimeFeature::Save
			/// 	feature.
			/// </summary>
			///
			/// <param name="sxFile"> The file. </param>
			/// <param name="xImg">   [in,out] The ray image. The meta data gets updated while writing. </param>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			static void Write(const CRxString& sxFile, CRayImage& xImg);

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Writes the given ray image to the given file but overwrites the meta data by the given one.
			///
			/// 	Requires an authenticated dongle (Rx::LFR::CLightFieldRuntime::Authenticate) with the Rx::Dongle::ERuntimeFeature::Save
			/// 	feature.
			/// </summary>
			///
			/// <param name="sxFile"> The file. </param>
			/// <param name="xImg">   The ray image. </param>
			/// <param name="xMeta">  [in,out] The meta data. This gets updated while writing. </param>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			static void Write(const CRxString& sxFile, const CRayImage& xImg, CRxMetaData& xMeta);

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Writes the given ray image to the given file.
			///
			/// 	Requires an authenticated dongle (Rx::LFR::CLightFieldRuntime::Authenticate) with the Rx::Dongle::ERuntimeFeature::Save
			/// 	feature.
			/// </summary>
			///
			/// <param name="sxFile"> The file. </param>
			/// <param name="xImg">   The ray image. </param>
			/// <param name="xCalib"> The calibration of the ray image. </param>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			static void Write(const CRxString& sxFile, const CRxImage& xImg, const CCalibration& xCalib);

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Writes the given ray image to the given file.
			///
			/// 	Requires an authenticated dongle (Rx::LFR::CLightFieldRuntime::Authenticate) with the Rx::Dongle::ERuntimeFeature::Save
			/// 	feature.
			/// </summary>
			///
			/// <param name="sxFile"> The file. </param>
			/// <param name="xImg">   The ray image. </param>
			/// <param name="xCalib"> The calibration of the ray image. </param>
			/// <param name="xMeta">  [in,out] The meta data. This gets updated while writing. </param>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			static void Write(const CRxString& sxFile, const CRxImage& xImg, const CCalibration& xCalib, CRxMetaData& xMeta);

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Writes the given gray image to the given file.
			///
			/// 	Requires an authenticated dongle (Rx::LFR::CLightFieldRuntime::Authenticate).
			/// </summary>
			///
			/// <param name="sxFile"> The file. </param>
			/// <param name="xImg">   The gray image. </param>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			static void WriteGrayImage(const CRxString& sxFile, const CRxImage& xImg);

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			/// <summary>
			/// 	Gets the interface defined by ERayFileWriterInterface.
			/// </summary>
			///
			/// <param name="eData"> The interface type. </param>
			///
			/// <returns> Null if it fails, else the interface. </returns>
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			static void* GetInterface(Interfaces::ERayFileWriter::ID eData);

		private:

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			CRayFileWriter();
			~CRayFileWriter();
			CRayFileWriter(const CRayFileWriter&);
			CRayFileWriter& operator=(const CRayFileWriter&);
		};
	}
}
