00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
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
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
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