00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00099 for(i=0;i<srcArgs.size();i++)
00100 {
00101 bounds=bounds.LargerBound(srcArgs[i].image->Size());
00102 }
00103
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
00120 ImageType *dup=new ImageType();
00121 srcArgs[argn].duplicate=dup;
00122 IP3D::ResizeImageSupport(*srcArgs[argn].image,bounds,*dup);
00123
00124
00125
00126 return *dup;
00127 }
00128 }
00129 template <class ImageType>
00130 ImageType &ImageProcessorArgs<ImageType>::GetDest(int argn)
00131 {
00132
00133 for(uint i=0;i<srcArgs.size();i++)
00134 {
00135
00136
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