00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00021 #ifndef _Image3D_hpp
00022 #define _Image3D_hpp
00023
00024 #include<imlib3dconfig.h>
00025
00026 #include<ImLib3D/CppTools.hpp>
00027 #include<ImLib3D/RectZone3D.hpp>
00028 #include<ImLib3D/Vect3D.hpp>
00029 #include<ImLib3D/ImLib3DFile.hpp>
00030 #include<ImLib3D/Size3D.hpp>
00031 #include<ImLib3D/Properties.hpp>
00032
00033 class Mask3D;
00034
00035
00037
00040 class Image3D : public Streamable
00041 {
00042 protected:
00044 int width;
00046 int height;
00048 int depth;
00050 int nvoxels;
00051
00052 public:
00054
00056 virtual string GetTypeName() const;
00057 public:
00058 Properties properties;
00059
00060
00061
00062
00064 inline const Mask3D &Mask() const {return *properties.mask;}
00065 inline Mask3D &Mask() {return *properties.mask;}
00066 inline bool HasMask() const {return properties.mask!=NULL;}
00067 Mask3D &AddMask(){properties.AddMask(Size());return Mask();}
00068 inline byte Mask(const Vect3Di &P) const ;
00069 inline byte &Mask(const Vect3Di &P) ;
00070 inline byte Mask(int x,int y,int z) const ;
00071 inline byte &Mask(int x,int y,int z) ;
00072 void RemoveMask();
00073
00074 bool Has(const string &propname) const {return properties.Has(propname);}
00075
00076 template<class PType> PType &Property(const string &name)
00077 {return properties.template GetTemplatedProperty<PType>(name);}
00078 template<class PType> const PType &Property(const string &name) const
00079 {return properties.template GetTemplatedProperty<PType>(name);}
00080
00081 template<class PType> void AddProperty(const string &name,PType v) {properties.Add(name,v);}
00082 template<class PType> void SetProperty(const string &name,PType v) {properties.Add(name,v);}
00083
00085
00086 inline int Width() const {return width;}
00087 inline int Height() const {return height;}
00088 inline int Depth() const {return depth;}
00089 inline Size3D Size() const {return Size3D (width,height,depth);}
00090 inline Vect3Di SizeV() const {return Vect3Di(width,height,depth);}
00091 RectZone3Di GetZone() const {return RectZone3Di(0,0,0,width-1,height-1,depth-1);}
00092 inline int GetNVoxels() const {return nvoxels;}
00094
00096 inline bool IsInside(float x,float y,float z) const {return x>=0 && y>=0 && z>=0 && x<Width() && y<Height() && z<Depth() ;}
00097 inline bool IsInside(int x,int y,int z) const {return x>=0 && y>=0 && z>=0 && x<Width() && y<Height() && z<Depth() ;}
00098 inline bool IsInside(const Vect3Di &P) const {return IsInside(P.x,P.y,P.z);}
00099 inline void AssertBounds(int x,int y,int z) const
00100 {
00101 if(nvoxels!=width*height*depth)
00102 {ThrowError("Image3D::AssertBounds: incoherence in sizes");}
00103 if(!IsInside(x,y,z)){ThrowError("Image3D::AssertBounds: pos:%d %d %d image size:%d %d %d\n",x,y,z,
00104 width,height,depth);}
00105 }
00106 inline void AssertBounds(int pos) const
00107 {
00108 if(nvoxels!=width*height*depth)
00109 {ThrowError("Image3D::AssertBounds: incoherence in sizes");}
00110 if(pos<0 || pos>=nvoxels){ThrowError("Image3D::AssertBounds: pos:%d image size:%d %d %d: \n",pos,
00111 width,height,depth);}
00112 }
00114
00120 virtual float FloatValue(int x,int y,int z) const;
00121 float FloatValue(const Vect3Di &pos) const {return FloatValue(pos.x,pos.y,pos.z);}
00123
00124
00125
00126
00127
00129 protected:
00131 xmlpp::Element *CreateWriteNode(ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL) const
00132 {
00133 return Streamable::CreateWriteNode("ImLib3DImage",file,parentNode,node);
00134 }
00136 xmlpp::Element *CreateReadNode(ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL)
00137 {
00138 return Streamable::CreateReadNode("ImLib3DImage",file,parentNode,node);
00139 }
00140 public:
00141
00143
00148 virtual void Read( ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL) ;
00149 virtual void Write(ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL) const;
00150 public:
00152 virtual void WriteToFile (const string &fname) const {Streamable::WriteToFile(fname);}
00154
00155 private:
00156 void SetSize(const Size3D &newSize);
00157 public:
00158 virtual void Resize(const Size3D &newSize);
00159
00161 Image3D& operator=(const Image3D & other);
00162 bool operator==(const Image3D & other) const;
00163 bool operator!=(const Image3D & other) const {return !(this->operator==(other));}
00165
00166
00167
00168
00170
00171 public:
00173 virtual ~Image3D();
00174 Image3D();
00175 Image3D(int _width, int _height, int _depth);
00176
00178 Image3D(const Size3D &size);
00179 Image3D(const Image3D & other);
00181
00182 };
00183
00184 template<> inline string TypeName<Image3D>(){return "Image3D";}
00185
00186 #include<ImLib3D/Container3D.hpp>
00187
00188 #endif // _Image3D_hpp