00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00020 #ifndef _BitImage3D_hxx
00021 #define _BitImage3D_hxx
00022
00023 #include<ImLib3D/Arithmetic.hpp>
00024
00025
00026
00027
00028
00029
00030 template<class FieldType,int bitsPerValue,class ValueType>
00031 string
00032 BitImage3D<FieldType,bitsPerValue,ValueType>::GetTypeName() const
00033 {
00034 return SPrintf("BitImage3D<%s,%d,%s>",TypeName<FieldType>(),bitsPerValue,TypeName<ValueType>());
00035 }
00036
00037
00038 template<class FieldType,int bitsPerValue,class ValueType>
00039 void
00040 BitImage3D<FieldType,bitsPerValue,ValueType>::Write(ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node) const
00041 {
00042 node=CreateWriteNode(file,parentNode,node);
00043
00044
00045 if(!file->HasAttribute(node,"Type")){node->set_attribute("Type",GetTypeName());}
00046
00047 imageData.Write(file,node);
00048
00049 Image3D::Write(file,NULL,node);
00050 }
00051 template<class FieldType,int bitsPerValue,class ValueType>
00052 void
00053 BitImage3D<FieldType,bitsPerValue,ValueType>::Read(ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node)
00054 {
00055 node=CreateReadNode(file,parentNode,node);
00056 Image3D::Read(file,NULL,node);
00057
00058 string type=file->GetAttribute(node,"Type");
00059 if(type!=GetTypeName()){ThrowError("BitImage3D::Read: Expected type:\"%s\" found type:\"%s\"",GetTypeName(),type);}
00060
00061 imageData.Read(file,node);
00062 }
00063
00064
00065 template<class FieldType,int bitsPerValue,class ValueType>
00066 void
00067 BitImage3D<FieldType,bitsPerValue,ValueType>::Resize(const Size3D &newSize)
00068 {
00069
00070 Image3D::Resize(newSize);
00071 imageData.Resize(Size3D((newSize.width*bitsPerValue+bitsPerField-1)/bitsPerField,newSize.height,newSize.depth));
00072 widthXheight=width*height;
00073 imageDataEnd=iteratorFast(this,GetNVoxels());
00074 const_imageDataEnd=const_iteratorFast(this,GetNVoxels());
00075 }
00076
00077
00078
00079 template<class FieldType,int bitsPerValue,class ValueType>
00080 BitImage3D<FieldType,bitsPerValue,ValueType>&
00081 BitImage3D<FieldType,bitsPerValue,ValueType>::operator=(const BitImage3D<FieldType,bitsPerValue,ValueType> & other)
00082 {
00083 if(other.Size()!=Size()){Resize(other.Size());}
00084 if (this == &other){return *this;}
00085
00086 *((Image3D*)this)=other;
00087
00088 imageData=other.imageData;
00089 return *this;
00090 }
00091
00092
00093
00094 template<class FieldType,int bitsPerValue,class ValueType>
00095 bool
00096 BitImage3D<FieldType,bitsPerValue,ValueType>::operator==(const BitImage3D<FieldType,bitsPerValue,ValueType> & other) const
00097 {
00098 if(other.Size()!=Size()){return false;}
00099
00100 const_iteratorFast pOrig;
00101 const_iteratorXYZ p;
00102 for (p = begin(),pOrig=other.begin(); p != end(); p++,pOrig++)
00103 {
00104 if(!((*p) == (*pOrig))){return false;}
00105 }
00106
00107 if(!(properties==other.properties)){return false;}
00108
00109 return true;
00110 }
00111
00112
00113
00114
00115 template<class FieldType,int bitsPerValue,class ValueType>
00116 BitImage3D<FieldType,bitsPerValue,ValueType>::~BitImage3D()
00117 {
00118 }
00119
00120
00121 template<class FieldType,int bitsPerValue,class ValueType>
00122 BitImage3D<FieldType,bitsPerValue,ValueType>::BitImage3D(int _width, int _height, int _depth) :
00123 Image3D(_width,_height,_depth)
00124 {
00125 Resize(Size3D(_width,_height,_depth));
00126 }
00127
00128 template<class FieldType,int bitsPerValue,class ValueType>
00129 BitImage3D<FieldType,bitsPerValue,ValueType>::BitImage3D():
00130 Image3D()
00131 {
00132 Resize(Size3D(0,0,0));
00133 }
00134
00135
00136
00137 template<class FieldType,int bitsPerValue,class ValueType>
00138 BitImage3D<FieldType,bitsPerValue,ValueType>::BitImage3D(const Size3D &size):
00139 Image3D(size)
00140 {
00141 Resize(size);
00142 }
00143
00144
00145 template<class FieldType,int bitsPerValue,class ValueType>
00146 BitImage3D<FieldType,bitsPerValue,ValueType>::BitImage3D(const BitImage3D & origCont) :
00147 Image3D(origCont)
00148 {
00149 Resize(origCont.Size());
00150 (*this)=origCont;
00151 }
00152
00153
00154
00155
00156 template<class FieldType,int bitsPerValue,class ValueType>
00157 BitImage3D<FieldType,bitsPerValue,ValueType> &BitImage3D<FieldType,bitsPerValue,ValueType>::operator+=(const BitImage3D<FieldType,bitsPerValue,ValueType> &other)
00158 {
00159 IP3D::Addition(*this, other, *this);
00160 return *this;
00161 }
00162
00163 template<class FieldType,int bitsPerValue,class ValueType>
00164 BitImage3D<FieldType,bitsPerValue,ValueType> &BitImage3D<FieldType,bitsPerValue,ValueType>::operator+=(const FieldType& scalarValue)
00165 {
00166 IP3D::AdditionWithConstant(*this, scalarValue, *this);
00167 return *this;
00168 }
00169
00170 template<class FieldType,int bitsPerValue,class ValueType>
00171 BitImage3D<FieldType,bitsPerValue,ValueType> &BitImage3D<FieldType,bitsPerValue,ValueType>::operator-=(const BitImage3D<FieldType,bitsPerValue,ValueType> &other)
00172 {
00173 IP3D::Difference(*this, other, *this);
00174 return *this;
00175 }
00176
00177 template<class FieldType,int bitsPerValue,class ValueType>
00178 BitImage3D<FieldType,bitsPerValue,ValueType> &BitImage3D<FieldType,bitsPerValue,ValueType>::operator-=(const FieldType& scalarValue)
00179 {
00180 IP3D::DifferenceWithConstant(*this, scalarValue, *this);
00181 return *this;
00182 }
00183
00184 template<class FieldType,int bitsPerValue,class ValueType>
00185 BitImage3D<FieldType,bitsPerValue,ValueType> &BitImage3D<FieldType,bitsPerValue,ValueType>::operator*=(const BitImage3D<FieldType,bitsPerValue,ValueType> &other)
00186 {
00187 IP3D::Multiplication(*this, other, *this);
00188 return *this;
00189 }
00190
00191 template<class FieldType,int bitsPerValue,class ValueType>
00192 BitImage3D<FieldType,bitsPerValue,ValueType> &BitImage3D<FieldType,bitsPerValue,ValueType>::operator*=(double scalarValue)
00193 {
00194 IP3D::MultiplicationWithConstant(*this, scalarValue, *this);
00195 return *this;
00196 }
00197
00198 template<class FieldType,int bitsPerValue,class ValueType>
00199 BitImage3D<FieldType,bitsPerValue,ValueType> &BitImage3D<FieldType,bitsPerValue,ValueType>::operator/=(const BitImage3D<FieldType,bitsPerValue,ValueType> &other)
00200 {
00201 IP3D::Division(*this, other, *this);
00202 return *this;
00203 }
00204
00205
00206 #endif // _BitImage3D_hxx