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

Image3Dlinear.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  */
00020 #include<ImLib3D/Image3D.hpp>
00021 
00022 #ifndef _Image3Dlinear_hpp
00023 #define _Image3Dlinear_hpp
00024 
00025 
00026 #include<ImLib3D/Complex.hpp>
00027 #include<ImLib3D/Zero.hpp>
00028 
00029 
00030 // **************** Image3Dlinear ***************************
00032 
00036 template<class Im3DValue>
00037 class Image3Dlinear : public Container3D<Im3DValue>
00038 {
00039     // ********* template typedefs
00040 private:
00041     typedef Container3D<Im3DValue> _Base;
00042     typedef Image3Dlinear<Im3DValue> _Self;
00043 public:
00044     typedef Im3DValue value_type;
00045 //  std_typedefs;
00046 protected:
00047     mutable Interpolator3D<Im3DValue> *interpolator;
00048     mutable bool destroyInterpolator;
00049     Im3DValue zero;
00050 
00051 public:
00052     virtual string GetTypeName() const {return TypeName<_Self>();}
00053 
00055 
00058     Im3DValue  Value( float x, float y, float z ) const;
00059     Im3DValue  Value( const Vect3Df &v ) const {return Value(v.x,v.y,v.z);}
00060     void SetInterpolator(Interpolator3D<Im3DValue> *_interpolator,bool autoDestroy=true,bool autoReset=true) const
00061     {
00062         // cleanup
00063         if(interpolator && autoDestroy){delete interpolator;}
00064         // new values
00065         interpolator=_interpolator;
00066         destroyInterpolator=autoDestroy;
00067         // do optional reset
00068         if(autoReset && interpolator){interpolator->Reset(this);}
00069     }
00070     Interpolator3D<Im3DValue>       *GetInterpolator()       {return interpolator;}
00071     const Interpolator3D<Im3DValue> *GetInterpolator() const {return interpolator;}
00072 
00074     Im3DValue Sum() const 
00075     {
00076         Im3DValue sum=Zero<Im3DValue>();
00077         for(typename _Self::const_iteratorFast p=this->begin(); p!=this->end(); p++ )
00078         {
00079             sum+=*p;
00080         }
00081         return sum;
00082     }
00083 
00084     // **************************************************
00085     // ****************** Accessors *********************
00086     // **************************************************
00088     Im3DValue      SafeValue(int pos)     const ;
00089     Im3DValue      SafeValue(int x,int y,int z) const   
00090     {return this->IsInside(x,y,z) ? (*this)(x,y,z) : zero ;}
00091     Im3DValue      SafeValue(const Vect3Di &v)  const   
00092     {return this->IsInside(v    ) ? (*this)(v    ) : zero ;}
00093 //      Im3DValue      SafeValue(int x,int y,int z) const   
00094 //      {return IsInside(x,y,z) ? (*this)(x,y,z) : (properties.background ? *properties.background : zero) ;}
00095 //      Im3DValue      SafeValue(const Vect3Di &v)  const   
00096 //      {return IsInside(v    ) ? (*this)(v    ) : (properties.background ? *properties.background : zero) ;}
00098 
00099     void ComplexImag(Image3Dlinear<float> &imag) const;
00100     void ComplexReal(Image3Dlinear<float> &imag) const;
00101     void ComplexNorm2(Image3Dlinear<float> &imag) const;
00102     void ComplexModule(Image3Dlinear<float> &imag) const;
00104 
00105     void GetComponent(int c,Image3Dlinear<float> &res) const;
00107     void SetComponent(int c,const Image3Dlinear<float> &src);
00109     double L2Norm() const;
00110 
00111     virtual void Write(ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL) const
00112     {
00113         node=this->CreateWriteNode(file,parentNode,node);
00114         if(!file->HasAttribute(node,"Type")){node->set_attribute("Type",GetTypeName());}
00115         _Base::Write(file,NULL,node);
00116     }
00117 
00118 
00119     // **************************************************
00120     // ****************** Operators *********************
00121     // **************************************************
00123     _Self& operator+=(const _Self &im);     
00124     _Self& operator+=(const Im3DValue &scalarValue);    
00125     _Self& operator-=(const _Self &im);     
00126     _Self& operator-=(const Im3DValue &scalarValue);    
00127     _Self& operator*=(const _Self &im); 
00128     _Self& operator*=(double scalarValue);  
00129     _Self& operator/=(const _Self &im); 
00130 
00131 
00132     template<class OtherIm3DValue >
00133     Image3Dlinear & operator=(const Image3Dlinear<OtherIm3DValue> & other)
00134     {
00135         Container3D<Im3DValue>::operator=(other);
00136         ComputeZero();
00137         SetInterpolator(NULL);//FIXME, should duplicate interpolator?
00138         return *this;
00139     }
00140     Image3Dlinear & operator=(const Image3Dlinear & other)
00141     {
00142         Container3D<Im3DValue>::operator=(*dynamic_cast<const Container3D<Im3DValue> *>(&other));
00143         zero=other.zero;
00144         SetInterpolator(NULL);//FIXME, should duplicate
00145         //FIXME copy zero,interpolator etc.?
00146         return *this;
00147     } 
00148 
00149     
00150     void ComputeZero()
00151     {
00152         SetZero<Im3DValue>::Set(zero);
00153     }
00155     void ReadWithImageTypeConversion(const string &fname0);
00156 
00158     virtual ~Image3Dlinear();
00159 
00160     Image3Dlinear(const Image3Dlinear & other) : 
00161         Container3D<Im3DValue>(other),
00162         interpolator(NULL),
00163         destroyInterpolator(false)
00164     {
00165         ComputeZero();
00166     }
00167 
00168     explicit Image3Dlinear(const Size3D &size) : 
00169         Container3D<Im3DValue>(size),
00170         interpolator(NULL),
00171         destroyInterpolator(false)
00172     {
00173         ComputeZero();
00174     }
00175 
00176     Image3Dlinear(int _width, int _height, int _depth) : 
00177         Container3D<Im3DValue>(_width,_height,_depth),
00178         interpolator(NULL),
00179         destroyInterpolator(false)
00180     {
00181         ComputeZero();
00182     }
00183 
00184 
00185     explicit Image3Dlinear(const string& fname):
00186         Container3D<Im3DValue>(),
00187         interpolator(NULL),
00188         destroyInterpolator(false)
00189     {
00190         Streamable::ReadFromFile(fname);ComputeZero();
00191     }
00192 
00193     explicit Image3Dlinear(const char   *fname):
00194         Container3D<Im3DValue>(),
00195         interpolator(NULL),
00196         destroyInterpolator(false)
00197     {
00198         Streamable::ReadFromFile(fname);ComputeZero();
00199     }
00200 
00201     explicit Image3Dlinear(      char   *fname):
00202         Container3D<Im3DValue>(),
00203         interpolator(NULL),
00204         destroyInterpolator(false)
00205     {
00206         Streamable::ReadFromFile(fname);ComputeZero();
00207     }
00208 
00209     Image3Dlinear() :
00210         Container3D<Im3DValue>(),
00211         interpolator(NULL),
00212         destroyInterpolator(false)
00213     {
00214         ComputeZero();
00215     }
00216 
00217     template<class OtherImageType >
00218     Image3Dlinear(const OtherImageType & other):
00219         Container3D<value_type>(other),
00220         interpolator(NULL),
00221         destroyInterpolator(false)
00222     {
00223         ComputeZero();
00224     }
00225 
00227 };
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 #include<ImLib3D/Vect3D.hpp>
00236 #include<ImLib3D/Complex.hpp>
00237 typedef Image3Dlinear<float>    Image3Df;
00238 typedef Image3Dlinear<double>   Image3Dd;
00239 typedef Image3Dlinear<Vect3Df>  Field3Df;
00240 typedef Image3Dlinear<complexd> Image3Dcomplex;
00241 typedef Image3Dlinear<complexd> Image3Dcomplexd;
00242 typedef Image3Dlinear<complexf> Image3Dcomplexf;
00243 typedef Image3Dlinear<int>      LabelImage3D;
00244 
00245 
00246 #include<ImLib3D/Mask3D.hpp>
00247 
00248 template<> inline string TypeName<Image3Df>(){return "Image3Df";}
00249 template<> inline string TypeName<Image3Dd>(){return "Image3Dlinear<double>";}
00250 template<> inline string TypeName<Image3Dlinear<int> >(){return "Image3Dlinear<int>";}
00251 template<> inline string TypeName<Image3Dlinear<short int> >(){return "Image3Dlinear<short int>";}
00252 template<> inline string TypeName<Image3Dlinear<Vect3Df> >(){return "Image3Dlinear<Vect3Df>";}
00253 template<> inline string TypeName<Image3Dcomplexf >(){return "Image3Dlinear<std::complex<float> >";}
00254 template<> inline string TypeName<Image3Dcomplexd >(){return "Image3Dlinear<std::complex<double> >";}
00255 
00256 #endif // _Image3Dlinear_hpp
00257 

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