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

Transformation.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  */
00019 #ifndef _Transformation_hxx
00020 #define _Transformation_hxx
00021 #include<ImLib3D/Interpolator3D.hpp>
00022 #include<ImLib3D/SplineInterpolation.hpp>
00023 #include<ImLib3D/TestPatterns.hpp>
00024 #include<ImLib3D/Interpolator3D.hxx>
00025 
00026 
00027 
00028 namespace IP3D
00029 {
00030 template <>
00031 void
00032 TransformWithInverseField<Mask3D>(const Mask3D& imOrig, const Field3Df& field, Mask3D& _imRes);
00033 }
00035 
00040 template <class ImageType>
00041 void
00042 IP3D::TransformWithInverseField(const ImageType& src, const Field3Df& field, ImageType& _res)
00043 {
00044     typedef typename ImageType::value_type Im3DValue;
00045     // Image Args
00046     ImageProcessorArgs<ImageType> args(ImArgs(src),_res);
00047     args.SetDestSize(field.Size());
00048     ImageType &res=args.GetDest();
00049 
00050     if((void *)&_res==(void *)&field){ThrowError("IP3D::TransformWithInverseField can't transform field with itself");}
00051 
00052     if(src.HasMask())
00053     {
00054         res.AddMask();
00055         IP3D::TransformWithInverseField(src.Mask(),field,res.Mask());
00056     }
00057 
00058     // If no interpolator use default
00059     Interpolator3D<typename ImageType::value_type> *iSpline=NULL;
00060     if(!src.GetInterpolator())
00061     {       
00062         string interpolName=(src.Has("DefaultInterpolatorName") ? src.template Property < string >("DefaultInterpolatorName") : "Spline 5");
00063         
00064         iSpline=Interpolator3D<typename ImageType::value_type>::Create(interpolName);
00065 //  new SplineInterpolator3D<typename ImageType::value_type>(5);
00066         if(!iSpline){ThrowError("couldnt create spline interpol???????");}
00067         (*(ImageType *)&src).SetInterpolator(iSpline);
00068     }
00069 
00070     typename ImageType::iteratorXYZ p;
00071     ImageProgress tracker("CTransformWithInverseField",p);
00072     for(p=res.begin();p!=res.end();++p)
00073     {
00074         Vect3Df P=field(p.x,p.y,p.z)+Vect3Df(p.x,p.y,p.z);
00075         *p=src.Value(P.x,P.y,P.z);
00076     }
00077 
00078     // If we used default interpolator, free it
00079     if(iSpline)
00080     {
00081         (*(ImageType *)&src).SetInterpolator(NULL);
00082     }
00083 
00084 }
00085 
00086 
00087 
00089 template <class ImageType>
00090 void
00091 IP3D::TransformAffine(const ImageType& src, const Affine3DTransform& transfo, ImageType& _res,const Size3D *resSize)
00092 {
00093     TaskInProgress tracker("CTransformAffine");
00094     ImageProcessorArgs<ImageType> args(ImArgs(src),_res);
00095     if(resSize){args.SetDestSize(*resSize);}
00096     else{args.SameSize();}
00097     ImageType &res=args.GetDest();
00098 
00099     Field3Df field(res.Size());
00100     TransformAffineHelpers::CreateInverseField(field, transfo);
00101     IP3D::TransformWithInverseField(src, field, res);
00102 }
00103 
00104 
00105 #endif //_Transformation_hxx

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