/* ImLib3D
 * Copyright (c) 2001, ULP-IPB Strasbourg.
 *
 * This program 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 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 the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*!  \file InsertImage.hpp */
// this one is in its own file because it is needed by the ImageProcessor file
#ifndef _InsertImage_hpp
#define _InsertImage_hpp

#include<ImLib3D/ImageProcessor.hpp>

namespace IP3D
{
/*! #&InsertImage&#     Draws an image into another image.
        (x,y,z) Position where to insert image.
     <UL>Args:
      <LI>Source image     type:ImageType
      <LI>Image to insert  type:ImageType
      <LI>position         type:Vect3Di
      <LI>Result image     type:ImageType
     </UL>
~*/
	template <class ImageType>
	void InsertImage(const ImageType& src,const ImageType& insert,const Vect3Di &pos,ImageType& res);
};


namespace IP3D
{
template <class ImageType>
void
InsertImage(const ImageType& src,const ImageType& insert,const Vect3Di &pos,ImageType& res)
{
	if(&res!=&src){res=src;}

	RectZone3Di zone(pos,pos+insert.SizeV()-Vect3Di(1,1,1));
	typename ImageType::iteratorZone rp(zone);
	typename ImageType::const_iteratorFast op;
	for( op=insert.begin(),rp=res.begin(); rp!=res.end(); ++op,++rp )
	{
		*rp=*op;
	}
}
}//IP3DCLOSE

#ifdef  USE_EXPLICIT_INSTANTIATION
namespace IP3D
{
// explicit instantiation of common templates, only for faster compilation
extern template void InsertImage<Mask3D>(Mask3D const &, Mask3D const &, Vect3D<int, float> const &, Mask3D &);
extern template void InsertImage<Image3Df>(Image3Df const &, Image3Df const &, Vect3D<int, float> const &, Image3Df &);
}
#endif // USE_EXPLICIT_INSTANTIATION

#endif// _InsertImage_hpp
