Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

InsertImage.hpp

Go to the documentation of this file.
00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00020 // this one is in its own file because it is needed by the ImageProcessor file
00021 #ifndef _InsertImage_hpp
00022 #define _InsertImage_hpp
00023 
00024 #include<ImLib3D/ImageProcessor.hpp>
00025 
00026 namespace IP3D
00027 {
00037     template <class ImageType>
00038     void InsertImage(const ImageType& src,const ImageType& insert,const Vect3Di &pos,ImageType& res);
00039 };
00040 
00041 
00042 namespace IP3D
00043 {
00044 template <class ImageType>
00045 void
00046 InsertImage(const ImageType& src,const ImageType& insert,const Vect3Di &pos,ImageType& res)
00047 {
00048     if(&res!=&src){res=src;}
00049 
00050     RectZone3Di zone(pos,pos+insert.SizeV()-Vect3Di(1,1,1));
00051     typename ImageType::iteratorZone rp(zone);
00052     typename ImageType::const_iteratorFast op;
00053     for( op=insert.begin(),rp=res.begin(); rp!=res.end(); ++op,++rp )
00054     {
00055         *rp=*op;
00056     }
00057 }
00058 
00059 template <class ImageType>
00060 void
00061 ResizeImageSupport(const ImageType &src,const Size3D &newSize,ImageType &res0,const typename ImageType::value_type *fillValue=NULL)
00062 {
00063     ImageProcessorArgs<ImageType> args(ImArgs(src),res0);
00064     args.SetDestSize(newSize);
00065     ImageType &res=args.GetDest();
00066     // mask management
00067     bool hasMask=src.HasMask();
00068     if(hasMask && !res.HasMask()){res.AddMask();}
00069 
00070     // determine background value
00071     typename ImageType::value_type background;
00072     if(fillValue){background=*fillValue;}
00073     else
00074     {
00075         SetZero<typename ImageType::value_type>::Set(background,false);
00076     }
00077     // now actually copy data
00078     for(typename ImageType::iteratorXYZ p=res.begin();p!=res.end();p++)
00079     {
00080         if(src.IsInside(p.Pos()))
00081         {
00082             *p=src(p.Pos());
00083             if(hasMask){res.Mask(p.Pos())=src.Mask(p.Pos());}
00084         }
00085         else
00086         {
00087             *p=background;
00088             if(hasMask){res.Mask(p.Pos())=0;}
00089         }
00090     }
00091 }
00092 
00093 }//IP3DCLOSE
00094 
00095 
00096 #endif// _InsertImage_hpp

Generated on Fri Jun 17 13:36:05 2005 for ImLib3D by  doxygen 1.4.2