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

ConvenienceProcessors.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 
00022 #ifndef _ConvenienceProcessors_hpp
00023 #define _ConvenienceProcessors_hpp
00024 
00025 #include<ImLib3D/ImageProcessor.hpp>
00026 
00027 namespace IP3D
00028 {
00039     template <class ImageType1,class ImageType2>
00040     void ImageTypeConversion(const ImageType1& src,ImageType2& res){res=src;}
00041 };
00042 
00043 namespace IP3D
00044 {
00054     template <class ImageType>
00055     void Crop(const ImageType& src,const RectZone3Di &zone,ImageType& res0);
00056 };
00057 
00058 
00059 namespace IP3D
00060 {
00070     template <class ImageType>
00071     void FindFirstDifference(const ImageType& src1,const ImageType& src2,bool &found,Vect3Di &pos)
00072     {
00073         if(src1.Size()!=src2.Size()){ThrowError("CFindFirstDifference images size differ");}
00074         typename ImageType::const_iterator p=mismatch(src1.begin(),src1.end(),src2.begin()).first;
00075         if(p!=src1.end()){found=true;pos=p.ComputePosition();}
00076         else{found=false;}
00077     }
00078 };
00079 
00080 
00081 namespace IP3D
00082 {
00094     template <class ImageType>
00095     void FindMinMax(const ImageType& src,
00096                       typename ImageType::value_type& vmin,
00097                       typename ImageType::value_type& vmax,
00098                       Vect3Di *posMin=NULL,
00099                       Vect3Di *posMax=NULL)
00100     {
00101         typename ImageType::const_iterator p;
00102         typename ImageType::const_iterator pmin=src.begin();
00103         typename ImageType::const_iterator pmax=src.begin();
00104         vmin=src(0,0,0);
00105         vmax=src(0,0,0);
00106         for(p=src.begin();p!=src.end();++p)
00107         {
00108             if(*p<vmin){pmin=p;vmin=*p;}
00109             if(*p>vmax){pmax=p;vmax=*p;}
00110         }
00111         if(posMin){*posMin=pmin.ComputePosition();}
00112         if(posMax){*posMax=pmax.ComputePosition();}
00113     }
00114 };
00115 
00116 namespace IP3D
00117 {
00120     template <class ImageType>
00121     void L2Norm(const ImageType& src, double& energy)
00122     {
00123         energy = src.L2Norm();
00124     }
00125 };
00126 
00127 namespace IP3D
00128 {
00138     template <class ImageType>
00139     void SetAllVoxels(const ImageType& src, const typename ImageType::value_type& v,ImageType& res)
00140     {
00141         if(&res!=&src){res=src;}
00142         res.Fill(v);
00143     }
00144 };
00145 
00146 namespace IP3D
00147 {
00158     template <class ImageType>
00159     void AddMask(const ImageType& src,ImageType& res, const Mask3D *mask=NULL)
00160     {
00161         if(&res!=&src){res=src;}
00162         res.AddMask();
00163         if(mask)
00164         {
00165             if(mask->Size()!=res.Size()){ThrowError("CAddMask: mask size does not mathc with images size");}
00166             res.Mask()=*mask;
00167         }
00168     }
00169 };
00170 namespace IP3D
00171 {
00179     template <class ImageType>
00180     void GetMask(const ImageType& src,Mask3D& res)
00181     {
00182         if(!src.HasMask()){ThrowError("GetMask: no mask");}
00183         res=src.Mask();
00184     }
00185 };
00186 
00187 namespace IP3D
00188 {
00201     template<class ImageType>
00202     void ApplyMask(const ImageType& src, ImageType& res, byte maskvalue=0, const Mask3D* optmask=NULL);
00203 };
00204 
00205 namespace IP3D
00206 {
00215     template <class ImageType>
00216     void SetDefaultInterpolator(const ImageType& src,const string&name,ImageType &res)
00217     {
00218         res=src;
00219         res.SetProperty("DefaultInterpolatorName",name);
00220     }
00221 };
00222 
00223 namespace IP3D
00224 {
00233     template <class ComplexImageType>
00234     void ExtractFromComplexImage(const ComplexImageType& src,const string &type,Image3Df &res);
00235 };
00236 
00237 
00238 namespace IP3D
00239 {
00251     template <class ImageType>
00252     void SetProperty(const ImageType& src,const string &name,const string &typeName,string value,ImageType &res)
00253     {
00254         res=src;
00255         xmlpp::Document tmpDocument;
00256         xmlpp::Element *node=tmpDocument.create_root_node(name);
00257         node->set_attribute("value",value);
00258         node->set_attribute("PropertyType","PropertyWrapPtr");
00259         node->set_attribute("type",typeName);
00260         PropertyXML propertyXML(name,node);
00261         res.properties.AddUnparsed(name,propertyXML);
00262     }
00263 };
00264 
00265 namespace IP3D
00266 {
00275     template <class ImageType>
00276     void RemoveProperty(const ImageType& src,const string &name,ImageType &res)
00277     {
00278         res=src;
00279         res.properties.Remove(name);
00280     }
00281 };
00282 
00283 
00284 namespace IP3D
00285 {
00297     template <class ImageType>
00298     void Pad(const ImageType& src,Vect3Di paddingV,ImageType &res,bool padLinear=false)
00299     {
00300         Vect3Di newSize=src.SizeV()+2*paddingV;
00301         res.Resize(Size3D(newSize));
00302         IP3D::InsertImage(res,src,paddingV,res);
00303         for(int dir=0;dir<3;dir++)
00304         {
00305             if(!paddingV(dir)){continue;}
00306             for(int t=0;t<2;t++)
00307             {
00308                 Vect3Di p0(0,0,0),p1=newSize-Vect3Di(1,1,1);
00309                 if(t==1)
00310                 {
00311                     p0(dir)=newSize(dir)-paddingV(dir);
00312                 }
00313                 else
00314                 {
00315                     p1(dir)=paddingV(dir)-1;
00316                 }
00317                 RectZone3Di centralZone(paddingV,src.Size());
00318                 RectZone3Di zone(p0,p1);
00319                 typename ImageType::iteratorZone p(zone);
00320                 for(p=res.begin();p!=res.end();p++)
00321                 {
00322                     if(padLinear)
00323                     {
00324                         Vect3Di closest=centralZone.ClosestPoint(p.Pos());
00325                         Vect3Df dPos=closest-p.Pos();
00326                         dPos.x/=paddingV.x;
00327                         dPos.y/=paddingV.y;
00328                         dPos.z/=paddingV.z;
00329                         *p=(typename ImageType::value_type)((max(0.0f,1-dPos.Norm()))*res(closest));
00330                     }
00331                     else
00332                     {
00333                         *p=0;
00334                     }
00335                 }
00336             }  
00337         }
00338     }
00339 }
00340 
00341 #include<ImLib3D/ConvenienceProcessors.hxx>
00342 
00343 #endif// _ConvenienceProcessors_hpp

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