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

Container3D.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  */
00021 #ifndef _Container3D_hpp
00022 #define _Container3D_hpp
00023 
00024 #include<imlib3dconfig.h>
00025 
00026 #include<ImLib3D/CppTools.hpp>
00027 #include<ImLib3D/RectZone3D.hpp>
00028 #include<ImLib3D/Vect3D.hpp>
00029 #include <assert.h>
00030 #include <fstream>
00031 #include<ImLib3D/ImLib3DFile.hpp>
00032 #include<ImLib3D/Size3D.hpp>
00033 #include<ImLib3D/Properties.hpp>
00034 #include<ImLib3D/Image3D.hpp>
00035 #include<ImLib3D/FloatCast.hpp>
00036 
00037 template<class Im3DValue> 
00038 class Interpolator3D;
00039 
00040 #define _Container3D_internal
00041 #include<ImLib3D/Container3DIterators.hpp>
00042 #undef  _Container3D_internal
00043 
00044 
00045 template<class T>
00046 struct HasPointerIterators
00047 {
00048     typedef __true_type value;
00049 };
00050 
00051 // ********************** Container3D ********************
00053 
00056 template<class Im3DValue>
00057 class Container3D : public Image3D
00058 {
00059 private:
00061     Im3DValue *imageData;
00063     Im3DValue *imageDataEnd;
00065     int widthXheight;
00066 
00068     typedef Container3D<Im3DValue> _Self;
00069 public:
00071     typedef Im3DValue value_type;
00072 public:
00074 
00075     typedef CTR3D_iteratorFast<      Container3D,Im3DValue &,Im3DValue *>    iterator;
00076     typedef CTR3D_iteratorFast<      Container3D,Im3DValue &,Im3DValue *>    iteratorFast;
00077     typedef CTR3D_iteratorXYZ<       Container3D,Im3DValue &,Im3DValue *>    iteratorXYZ;
00078     typedef CTR3D_iteratorZone<      Container3D,Im3DValue &,Im3DValue *>    iteratorZone;
00079     typedef CTR3D_iteratorFastMasked<Container3D,Im3DValue &,Im3DValue *>    iteratorFastMasked;
00080     typedef CTR3D_iteratorXYZMasked<Container3D,Im3DValue &,Im3DValue *>     iteratorXYZMasked;
00081     typedef CTR3D_iteratorBoxConcentric<Container3D,Im3DValue &,Im3DValue *> iteratorBoxConcentric;
00082 
00083     typedef CTR3D_iteratorFast<      const Container3D,const Im3DValue &,const Im3DValue *>    const_iterator;
00084     typedef CTR3D_iteratorFast<      const Container3D,const Im3DValue &,const Im3DValue *>    const_iteratorFast;
00085     typedef CTR3D_iteratorXYZ<       const Container3D,const Im3DValue &,const Im3DValue *>    const_iteratorXYZ;
00086     typedef CTR3D_iteratorZone<      const Container3D,const Im3DValue &,const Im3DValue *>    const_iteratorZone;
00087     typedef CTR3D_iteratorFastMasked<const Container3D,const Im3DValue &,const Im3DValue *>    const_iteratorFastMasked;
00088     typedef CTR3D_iteratorXYZMasked< const Container3D,const Im3DValue &,const Im3DValue *>    const_iteratorXYZMasked;
00089     typedef CTR3D_iteratorBoxConcentric<const Container3D,const Im3DValue &,const Im3DValue *> const_iteratorBoxConcentric;
00090 
00091     typedef reverse_iterator<const_iterator> const_reverse_iterator;
00092     typedef reverse_iterator<      iterator>       reverse_iterator;
00094 
00095 public:
00097     virtual string GetTypeName() const {return TypeName<_Self>();}
00098 public:
00100 
00101     iteratorFast         begin()       {return iteratorFast(this,imageData);}
00102     const_iteratorFast   begin() const {return const_iteratorFast(this,imageData);}
00104     inline iteratorFast         end()         {return iteratorFast(this,imageDataEnd);}
00105     inline const_iteratorFast   end()   const {return const_iteratorFast(this,imageDataEnd);}
00106 
00107     inline       reverse_iterator rbegin()         { return       reverse_iterator(end()); }
00108     inline const_reverse_iterator rbegin() const   { return const_reverse_iterator(end()); }
00109     inline       reverse_iterator rend()           { return       reverse_iterator(begin()); }
00110     inline const_reverse_iterator rend() const     { return const_reverse_iterator(begin()); }
00111 
00113     // **************************************************
00114     // ****************** accessors *********************
00115     // **************************************************
00117     bool HasSupport() const {return Has("Support");}
00118     RectZone3Df    &AddSupport(const Vect3Df &p0,const Vect3Df &p1)
00119     {properties.Add("Support",RectZone3Df(p0,p1));return Support();}
00120     RectZone3Df    &AddSupport(const RectZone3Df& otherSupport)
00121     {properties.Add("Support",otherSupport);return Support();}
00122     RectZone3Df       &Support()       {return Property<RectZone3Df>("Support");}
00123     RectZone3Df const &Support() const {return Property<RectZone3Df>("Support");}   
00125 
00126 
00127     inline       Im3DValue *GetData()          {return imageData;}
00128     inline const Im3DValue *GetData() const    {return imageData;}
00129     inline       Im3DValue *GetDataEnd()       {return imageDataEnd;}
00130     inline const Im3DValue *GetDataEnd() const {return imageDataEnd;}
00132     
00134 #ifdef SAFE_DEBUG
00135     inline       Im3DValue &operator()(int pos)                 {AssertBounds(pos);return imageData[pos];}
00136     inline const Im3DValue &operator()(int pos)           const {AssertBounds(pos);return imageData[pos];}
00137     inline       Im3DValue &operator()(int x,int y,int z)       {AssertBounds(x,y,z);return imageData[x+y*width+z*widthXheight];}
00138     inline const Im3DValue &operator()(int x,int y,int z) const {AssertBounds(x,y,z);return imageData[x+y*width+z*widthXheight];}
00139     inline       Im3DValue &operator()(const Vect3Di &v)        {AssertBounds(v.x,v.y,v.z);return imageData[v.x+v.y*width+v.z*widthXheight];}
00140     inline const Im3DValue &operator()(const Vect3Di &v)  const {AssertBounds(v.x,v.y,v.z);return imageData[v.x+v.y*width+v.z*widthXheight];}
00141 #else //SAFE_DEBUG
00142     inline       Im3DValue &operator()(int pos)                 {return imageData[pos];}
00143     inline const Im3DValue &operator()(int pos)           const {return imageData[pos];}
00144     inline       Im3DValue &operator()(int x,int y,int z)       {return imageData[x+y*width+z*widthXheight];}
00145     inline const Im3DValue &operator()(int x,int y,int z) const {return imageData[x+y*width+z*widthXheight];}
00146     inline       Im3DValue &operator()(const Vect3Di &v)        {return imageData[v.x+v.y*width+v.z*widthXheight];}
00147     inline const Im3DValue &operator()(const Vect3Di &v)  const {return imageData[v.x+v.y*width+v.z*widthXheight];}
00148 #endif //SAFE_DEBUG
00149     virtual float FloatValue(int x,int y,int z) const {return FloatCast<Im3DValue>::Cast((*this)(x,y,z));}
00151 
00152 
00153     // **************************************************
00154     // ****************** methods   *********************
00155     // **************************************************
00156 
00158     void  deprecated SetAll(const Im3DValue & value) {Fill(value);}
00160     void  Fill(const Im3DValue & value){fill(begin(),end(),value);}
00161 protected:
00162     bool WarnOnUnkownType() const;
00163 
00165 public:
00167 
00172     virtual void Read( ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL)      ;
00173     virtual void Write(ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL) const;
00174 private:
00176     virtual void WriteBinary(ImLib3DFile *file) const;
00178     virtual void ReadBinary(ImLib3DFile *file);
00180     virtual int  GetBinarySize() const {WarnOnUnkownType();return sizeof(Im3DValue)*GetNVoxels();}
00181 public:
00183     virtual void WriteToFile (const string &fname) const {Streamable::WriteToFile(fname);}
00185 
00186 public:
00187     void Resize(const Size3D &newSize);
00188 
00190     template<class OtherImageType >
00191     _Self& operator= (const OtherImageType & other);
00192     _Self& operator= (const _Self & other);
00193     bool   operator==(const _Self & other) const;
00194     bool   operator!=(const _Self & other) const {return !(this->operator==(other));}
00196 
00197     // **************************************************
00198     // ****************** constructors/destructors*******
00199     // **************************************************
00201 
00202 protected:
00203     void Allocate();
00204     void DeAllocate();
00205 public:
00206 
00208     virtual ~Container3D();
00209 protected:
00210 public:
00211     Container3D();
00212     Container3D(int _width, int _height, int _depth);
00213     explicit Container3D(const string& fname){ReadFromFile(fname);}
00214     explicit Container3D(const char   *fname){ReadFromFile(fname);}
00215     explicit Container3D(      char   *fname){ReadFromFile(fname);}
00217     explicit Container3D(const Size3D &size);
00218     Container3D(const Container3D & other);
00219     template<class OtherImageType >
00220     Container3D(const OtherImageType & other):
00221         Image3D(other),
00222         imageData(NULL),imageDataEnd(NULL)
00223     {
00224         Resize(other.Size());
00225         operator=(other);
00226     }
00227 
00228 
00230 
00231 };
00232 
00233 extern string Container3D_ReadImageType(const string &fname);
00234 
00235 
00236 
00241 #define std_typedefs typedef Im3DValue value_type;      \
00242     typedef typename _Base::iteratorZone iteratorZone;  \
00243     typedef typename _Base::iteratorFast iteratorFast;  \
00244     typedef typename _Base::iteratorXYZ  iteratorXYZ;   \
00245     typedef typename _Base::const_iteratorZone const_iteratorZone;  \
00246     typedef typename _Base::const_iteratorFast const_iteratorFast;  \
00247     typedef typename _Base::const_iteratorXYZ  const_iteratorXYZ;    
00248 
00249 
00250 #include<ImLib3D/Image3Dlinear.hpp>
00251 
00252 #include<ImLib3D/Container3D.hxx>
00253 #include<ImLib3D/Image3Dlinear.hxx>
00254 #include<ImLib3D/Properties.hxx>
00255 
00256 
00257 #endif  // _Container3D_hpp

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