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

Transformation.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 #ifndef _Transformation_hpp
00019 #define _Transformation_hpp
00020 
00030 #include<ImLib3D/Affine3DTransform.hpp>
00031 #include<ImLib3D/Display.hpp>
00032 #include<ImLib3D/ImageProgress.hpp>
00033 
00034 
00035 
00036 namespace IP3D
00037 {
00056     template <class ImageType>
00057     void TransformWithInverseField(const ImageType& imOrig, const Field3Df& field, ImageType& imRes);
00059 //      template <class ImageType>
00060 //      static void ApplyInt(const ImageType& imOrig, const Field3Df& field, ImageType& _imRes);
00061 };
00062 
00063 namespace IP3D
00064 {
00079     template <class ImageType>
00080     void TransformAffine(const ImageType& imOrig, const Affine3DTransform& transfo, ImageType& imDest,const Size3D *resSize=NULL);
00081     namespace TransformAffineHelpers
00082     {
00083         void CreateInverseField(Field3Df &field, const Affine3DTransform& transfo);
00084     }
00085 };
00086 
00087 namespace IP3D
00088 {
00099     template <class ImageType>
00100     void Scale(const ImageType& src, const Size3D& newSize, ImageType& res)
00101     {
00102         Affine3DTransform trf;
00103         trf.SetScale(newSize.width /(float)src.Width(),
00104                      newSize.height/(float)src.Height(),
00105                      newSize.depth /(float)src.Depth());
00106 
00107         IP3D::TransformAffine(src,trf,res,&newSize);
00108     }
00109 };
00110 namespace IP3D
00111 {
00120     template <class ImageType>
00121     void WrapTranslate(const ImageType& src, const Vect3Di& t0, ImageType& res0)
00122     {
00123         ImageProcessorArgs<ImageType> args(ImArgs(src),res0);
00124         args.SameSize();
00125         ImageType &res=args.GetDest();
00126 
00127         // Translate mask:
00128         if (src.HasMask())
00129         {
00130             res.AddMask();
00131             WrapTranslate(src.Mask(), t0, res.Mask());
00132         }
00133 
00134         // make sure translation is >0
00135         Vect3Di t=t0;
00136         for(uint i=0;i<3;i++)
00137         {
00138             if(t(i)<0){t(i)+=src.SizeV()(i)*(1+abs(t(i)/src.SizeV()(i)));}
00139         }
00140         // do translation
00141         for(typename ImageType::const_iteratorXYZ p=src.begin();p!=src.end();++p)
00142         {
00143             res((p.x+t.x)%src.Width(),
00144                 (p.y+t.y)%src.Height(),
00145                 (p.z+t.z)%src.Depth())  =*p;
00146         }
00147     }
00148 };
00149 
00150 namespace IP3D
00151 {
00161     template <class ImageType>
00162     void Flip(const ImageType& src, const string &axes, ImageType& res0)
00163     {
00164         ImageProcessorArgs<ImageType> args(ImArgs(src),res0);
00165         args.SameSize();
00166         ImageType &res=args.GetDest();
00167 
00168         res=src;
00169         for(uint i=0;i<axes.size();i++)
00170         {
00171             int d=axes[i]-'X';
00172             if(d<0 || d>2){ThrowError("CFlip:: bad axis:\"%c\"\n",axes[i]);}
00173             ImageType tmp=res;
00174             
00175             for(typename ImageType::iteratorXYZ p=res.begin();p!=res.end();++p)
00176             {
00177                 Vect3Di pos=p.Pos();
00178                 pos(d)=res.SizeV()(d)-pos(d)-1;
00179                 tmp(pos)=*p;
00180             }
00181             res=tmp;
00182         }
00183         if (src.HasMask())
00184         {
00185             res.AddMask();
00186             Flip(src.Mask(),axes,res.Mask());
00187         }
00188     }
00189 };
00190 
00191 
00192 namespace IP3D
00193 {
00203     template <class ImageType>
00204     void SwapAxes(const ImageType& src, const string &axes, ImageType& res0)
00205     {
00206         if(axes.size()!=2){ThrowError("CSwapAxes:: axes should contain 2 axes");}
00207         int a=axes[0]-'X';
00208         if(a<0 || a>2){ThrowError("CSwapAxes:: bad axis:\"%c\"\n",axes[a]);}
00209         int b=axes[1]-'X';
00210         if(b<0 || b>2){ThrowError("CSwapAxes:: bad axis:\"%c\"\n",axes[b]);}
00211         Vect3Di newSize=src.SizeV();
00212         newSize(a)=src.SizeV()(b);
00213         newSize(b)=src.SizeV()(a);
00214         
00215         ImageProcessorArgs<ImageType> args(ImArgs(src),res0);
00216         args.SetDestSize(Size3D(newSize));
00217         ImageType &res=args.GetDest();
00218             
00219         for(typename ImageType::const_iteratorXYZ p=src.begin();p!=src.end();++p)
00220         {
00221             Vect3Di pos=p.Pos();
00222             pos(a)=p.Pos()(b);
00223             pos(b)=p.Pos()(a);
00224             res(pos)=*p;
00225         }
00226     }
00227 };
00228 
00229 
00230 #include<ImLib3D/Transformation.hxx>
00231 
00232 #endif //_Transformation_hpp

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