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

Arithmetic.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  */
00028 #ifndef _Arithmetic_hxx
00029 #define _Arithmetic_hxx
00030 
00031 
00033 
00037 template <class ImageType>
00038 void
00039 IP3D::Addition(const ImageType& im1, const ImageType& im2, ImageType& _imDest)
00040 {
00041     ImageProcessorArgs<ImageType> args(ImArgs(im1,im2),_imDest);
00042     args.SameSize();
00043     args.InPlace();
00044     ImageType &imDest=args.GetDest();
00045 
00046     typename ImageType::const_iteratorFast p1;
00047     typename ImageType::const_iteratorFast p2;
00048     typename ImageType::iteratorFast pDest;
00049     
00050     for (p1 = im1.begin(), p2 = im2.begin(), pDest = imDest.begin(); pDest != imDest.end(); p1++, p2++, pDest++)
00051     {
00052         (*pDest) = (*p1) + (*p2);
00053     }
00054 
00055 }
00056 
00058 
00065 template <class ImageType>
00066 void
00067 IP3D::AdditionWithConstant(const ImageType& src, const typename ImageType::value_type& scalarValue, ImageType& res)
00068 {
00069     res=src;
00070 
00071     for(typename ImageType::iteratorFast p=res.begin();p!=res.end();++p)
00072     {
00073         (*p)+=scalarValue;
00074     }
00075 }
00076 
00078 
00082 template <class ImageType>
00083 void
00084 IP3D::Difference(const ImageType& im1, const ImageType& im2, ImageType& _imDest)
00085 {
00086     ImageProcessorArgs<ImageType> args(ImArgs(im1,im2),_imDest);
00087     args.SameSize();
00088     args.InPlace();
00089     ImageType &imDest=args.GetDest();
00090 
00091     typename ImageType::const_iteratorFast p1;
00092     typename ImageType::const_iteratorFast p2;
00093     typename ImageType::iteratorFast pDest;
00094     
00095     for (p1 = im1.begin(), p2 = im2.begin(), pDest = imDest.begin(); pDest != imDest.end(); p1++, p2++, pDest++)
00096     {
00097         (*pDest) = (*p1) - (*p2);
00098     }
00099 }
00100 
00102 
00109 template <class ImageType>
00110 void
00111 IP3D::DifferenceWithConstant(const ImageType& src, const typename ImageType::value_type& scalarValue, ImageType& res)
00112 {
00113     res=src;
00114 
00115     for(typename ImageType::iteratorFast p=res.begin();p!=res.end();++p)
00116     {
00117         (*p)-=scalarValue;
00118     }
00119 }
00120 
00122 
00125 template <class ImageType>
00126 void
00127 IP3D::Multiplication(const ImageType& im1, const ImageType& im2, ImageType& _imDest)
00128 {
00129     ImageProcessorArgs<ImageType> args(ImArgs(im1,im2),_imDest);
00130     args.SameSize();
00131     args.InPlace();
00132     ImageType &imDest=args.GetDest();
00133 
00134     typename ImageType::const_iteratorFast p1;
00135     typename ImageType::const_iteratorFast p2;
00136     typename ImageType::iteratorFast pDest;
00137     
00138     for (p1 = im1.begin(), p2 = im2.begin(), pDest = imDest.begin(); pDest != imDest.end(); p1++, p2++, pDest++)
00139     {
00140         (*pDest) = (*p1) * (*p2);
00141     }
00142 }
00143 
00145 
00148 template <class ImageType>
00149 void
00150 IP3D::Division(const ImageType& im1, const ImageType& im2, ImageType& _imDest)
00151 {
00152     ImageProcessorArgs<ImageType> args(ImArgs(im1,im2),_imDest);
00153     args.SameSize();
00154     args.InPlace();
00155     ImageType &imDest=args.GetDest();
00156 
00157     typename ImageType::const_iteratorFast p1;
00158     typename ImageType::const_iteratorFast p2;
00159     typename ImageType::iteratorFast pDest;
00160     
00161     for (p1 = im1.begin(), p2 = im2.begin(), pDest = imDest.begin(); pDest != imDest.end(); p1++, p2++, pDest++)
00162     {
00163         (*pDest) = (*p1) / (*p2);
00164     }
00165 }
00166 
00168 
00175 template <class ImageType>
00176 void
00177 IP3D::MultiplicationWithConstant(const ImageType& src, double v, ImageType& res)
00178 {
00179     res=src;
00180 
00181     for(typename ImageType::iteratorFast p=res.begin();p!=res.end();++p)
00182     {
00183         (*p)=(typename ImageType::value_type)(v*(*p));
00184     }
00185 }
00186 
00187 template <class ImageType>
00188 void
00189 IP3D::MaxImage(const ImageType& im1, const ImageType& im2, ImageType& _imDest)
00190 {
00191     ImageProcessorArgs<ImageType> args(ImArgs(im1,im2),_imDest);
00192     args.SameSize();
00193     args.InPlace();
00194     ImageType &imDest=args.GetDest();
00195 
00196     typename ImageType::const_iteratorFast p1;
00197     typename ImageType::const_iteratorFast p2;
00198     typename ImageType::iteratorFast pDest;
00199     
00200     for (p1 = im1.begin(), p2 = im2.begin(), pDest = imDest.begin(); pDest != imDest.end(); p1++, p2++, pDest++)
00201     {
00202         (*pDest) = max((*p1) , (*p2));
00203     }
00204 
00205 }
00206 template <class ImageType>
00207 void
00208 IP3D::Abs(const ImageType& im1, ImageType& _imDest)
00209 {
00210     ImageProcessorArgs<ImageType> args(ImArgs(im1),_imDest);
00211     args.SameSize();
00212     args.InPlace();
00213     ImageType &imDest=args.GetDest();
00214 
00215     typename ImageType::const_iteratorFast p1;
00216     typename ImageType::iteratorFast pDest;
00217     
00218     for (p1 = im1.begin(), pDest = imDest.begin(); pDest != imDest.end(); p1++, pDest++)
00219     {
00220         (*pDest) = AbsoluteValue(*p1);
00221     }
00222 
00223 }
00224 
00225 
00226 // **************************** Image3Dlinear : Operators********************
00227 template<class Im3DValue>
00228 Image3Dlinear<Im3DValue> &Image3Dlinear<Im3DValue>::operator+=(const Image3Dlinear<Im3DValue> &other)
00229 {
00230     IP3D::Addition(*this, other, *this);
00231     return *this;
00232 }
00233 
00234 template<class Im3DValue>
00235 Image3Dlinear<Im3DValue> &Image3Dlinear<Im3DValue>::operator+=(const Im3DValue& scalarValue)
00236 {
00237     IP3D::AdditionWithConstant(*this, scalarValue, *this);
00238     return *this;
00239 }
00240 
00241 template<class Im3DValue>
00242 Image3Dlinear<Im3DValue> &Image3Dlinear<Im3DValue>::operator-=(const Image3Dlinear<Im3DValue> &other)
00243 {
00244     IP3D::Difference(*this, other, *this);
00245     return *this;
00246 }
00247 
00248 template<class Im3DValue>
00249 Image3Dlinear<Im3DValue> &Image3Dlinear<Im3DValue>::operator-=(const Im3DValue& scalarValue)
00250 {
00251     IP3D::DifferenceWithConstant(*this, scalarValue, *this);
00252     return *this;
00253 }
00254 
00255 template<class Im3DValue>
00256 Image3Dlinear<Im3DValue> &Image3Dlinear<Im3DValue>::operator*=(const Image3Dlinear<Im3DValue> &other)
00257 {
00258     IP3D::Multiplication(*this, other, *this);
00259     return *this;
00260 }
00261 
00262 template<class Im3DValue>
00263 Image3Dlinear<Im3DValue> &Image3Dlinear<Im3DValue>::operator*=(double scalarValue)
00264 {
00265     IP3D::MultiplicationWithConstant(*this, scalarValue, *this);
00266     return *this;
00267 }
00268 
00269 template<class Im3DValue>
00270 Image3Dlinear<Im3DValue> &Image3Dlinear<Im3DValue>::operator/=(const Image3Dlinear<Im3DValue> &other)
00271 {
00272     IP3D::Division(*this, other, *this);
00273     return *this;
00274 }
00275 
00276 
00277 #endif // _Arithmetic_hxx

Generated on Fri Jun 17 13:35:14 2005 for ImLib3D by  doxygen 1.4.2