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

ImageProcessor.hxx

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  */
00030 #ifndef _ImageProcessor_hxx
00031 #define _ImageProcessor_hxx
00032 
00033 #include<ImLib3D/ImageProcessor.hpp>
00034 #include<ImLib3D/InsertImage.hpp>
00035 
00036 template <class ImageType>
00037 void ImageProcessorArgs<ImageType>::AllSameSizeAssert()
00038 {
00039     if(srcArgs.size()==0){ThrowError("ImageProcessorArgs::AllSameSizeAssert: no src args");}
00040     Size3D size=srcArgs[0].image->Size();
00041     uint i;
00042     for(i=1;i<srcArgs.size();i++)
00043     {
00044         if(size!=srcArgs[i].image->Size()){ThrowError("ImageProcessorArgs::AllSameSizeAssert: sizes differ");}
00045     }
00046     for(i=0;i<destArgs.size();i++)
00047     {
00048         if(size!=destArgs[i].image->Size()){ThrowError("ImageProcessorArgs::AllSameSizeAssert: sizes differ");}
00049     }
00050 }
00051 
00052 template <class ImageType>
00053 void ImageProcessorArgs<ImageType>::InPlace()
00054 {
00055     uint i;
00056     for(i=0;i<srcArgs.size();i++)
00057     {
00058         srcArgs[i].SetConst(false);
00059     }   
00060 }
00061 
00062 template <class ImageType>
00063 void ImageProcessorArgs<ImageType>::SameSize()
00064 {
00065     if(srcArgs.size()==0){ThrowError("ImageProcessorArgs::AllSameSizeAssert: no src args");}
00066     Size3D size=srcArgs[0].image->Size();
00067     uint i;
00068     for(i=1;i<srcArgs.size();i++)
00069     {
00070         if(size!=srcArgs[i].image->Size())
00071         {
00072             cout << "previous image size" << size << endl;
00073             cout << "image          size" << srcArgs[i].image->Size() << endl;
00074             ThrowError("ImageProcessorArgs::SameSize: src sizes differ");
00075         }
00076     }
00077     for(i=0;i<destArgs.size();i++)
00078     {
00079         destArgs[i].image->Resize(size);
00080     }
00081 }
00082 
00083 template <class ImageType>
00084 void ImageProcessorArgs<ImageType>::SetDestSize(Size3D size)
00085 {
00086     uint i;
00087     for(i=0;i<destArgs.size();i++)
00088     {
00089         destArgs[i].newSize=size;
00090     }
00091 }
00092 
00093 template <class ImageType>
00094 void ImageProcessorArgs<ImageType>::UseLargerSrcBounds()
00095 {
00096     uint i;
00097     useLargerSrcBounds=true;
00098     // find larger bounds
00099     for(i=0;i<srcArgs.size();i++)
00100     {
00101         bounds=bounds.LargerBound(srcArgs[i].image->Size());
00102     }
00103     // resize dest images
00104     for(i=0;i<destArgs.size();i++)
00105     {
00106         destArgs[i].newSize=bounds;
00107     }
00108 
00109 }
00110 template <class ImageType>
00111 const ImageType &ImageProcessorArgs<ImageType>::GetSrc(int argn)
00112 {
00113     if(!useLargerSrcBounds || srcArgs[argn].image->Size()==bounds)
00114     {
00115         return *srcArgs[argn].image;
00116     }
00117     else
00118     {
00119         // return resized duplicate of src
00120         ImageType *dup=new ImageType();
00121         srcArgs[argn].duplicate=dup;
00122         IP3D::ResizeImageSupport(*srcArgs[argn].image,bounds,*dup);
00123         //      dup->Fill(dup->GetZero());
00124         //      IP3D::InsertImage(*dup,*srcArgs[argn].image,Vect3Di(0,0,0),*dup);
00125 //      dup->InsertImage(*srcArgs[argn].image,Vect3Di(0,0,0));
00126         return *dup;
00127     }
00128 }
00129 template <class ImageType>
00130 ImageType &ImageProcessorArgs<ImageType>::GetDest(int argn)
00131 {
00132     // check if dest image needs to be duplicated
00133     for(uint i=0;i<srcArgs.size();i++)
00134     {
00135         // duplicate if src=dest and const
00136         // or if useLargerSrcBounds 
00137         if( (destArgs[argn].image==srcArgs[i].image && srcArgs[i].srcIsConst) ||
00138             (useLargerSrcBounds && destArgs[i].image->Size()!=bounds) 
00139             )
00140         {
00141             destArgs[argn].duplicate=new ImageType(*(srcArgs[i].image));
00142             if(destArgs[argn].newSize!=Size3D(0,0,0)){destArgs[argn].duplicate->Resize(destArgs[argn].newSize);}
00143             return *(destArgs[i].duplicate);
00144         }
00145     }
00146     if(destArgs[argn].newSize!=Size3D(0,0,0)){destArgs[argn].image->Resize(destArgs[argn].newSize);}
00147     return *(destArgs[argn].image);
00148 }
00149 
00150 template <class ImageType>
00151 void  ImageProcessorArgs<ImageType>::Finished()
00152 {
00153     uint i;
00154     for(i=0;i<destArgs.size();i++)
00155     {
00156         if(destArgs[i].duplicate)
00157         {
00158             (*destArgs[i].image)=(*destArgs[i].duplicate);
00159             delete destArgs[i].duplicate;
00160             destArgs[i].duplicate=NULL;
00161         }           
00162     }       
00163 
00164     for(i=0;i<srcArgs.size();i++)
00165     {
00166         if(srcArgs[i].duplicate)
00167         {
00168             delete srcArgs[i].duplicate;
00169         }           
00170     }       
00171 }
00172 
00173 #endif // _ImageProcessor_hxx

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