00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00020 #include<ImLib3D/Image3D.hpp>
00021
00022 float
00023 Image3D::FloatValue(int x,int y,int z) const
00024 {
00025 ThrowError("Image3D::FloatValue not implemented for this image type:\"%s\"",GetTypeName());
00026 return 0;
00027 }
00028
00029 string
00030 Image3D::GetTypeName() const
00031 {
00032 return TypeName<Image3D>();
00033 }
00034
00035 void
00036 Image3D::Write(ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node) const
00037 {
00038 node=CreateWriteNode(file,parentNode,node);
00039
00040
00041 if(!file->HasAttribute(node,"Type")){node->set_attribute("Type",GetTypeName());}
00042
00043 if(!file->HasChild(node,"Size"))
00044 {
00045 xmlpp::Element *sizeN=node->add_child("Size");
00046 sizeN->set_attribute("width" ,SPrintf("%d",width ));
00047 sizeN->set_attribute("height",SPrintf("%d",height));
00048 sizeN->set_attribute("depth" ,SPrintf("%d",depth ));
00049 }
00050
00051 if(!file->HasChild(node,"Properties"))
00052 {
00053 properties.Write(file,node);
00054 }
00055 }
00056
00057 void
00058 Image3D::Read(ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node)
00059 {
00060 node=CreateReadNode(file,parentNode,node);
00061
00062 if(file->debug){cout << "Image3D::Read: " << endl;file->ShowXML(node);}
00063
00064
00065
00066 xmlpp::Element *sizeN=file->GetChild(node,"Size");
00067 if(file->debug){cout << "reading width:" << sizeN->get_attribute("width" )->get_value() << endl;}
00068 int w =file->GetIntAttribute(sizeN,"width" );
00069 int h =file->GetIntAttribute(sizeN,"height" );
00070 int d =file->GetIntAttribute(sizeN,"depth" );
00071 Resize(Size3D(w,h,d));
00072
00073
00074 properties.Read(file,node);
00075 }
00076
00077
00078
00079 void
00080 Image3D::SetSize(const Size3D &newSize)
00081 {
00082 width =newSize.width;
00083 height=newSize.height;
00084 depth =newSize.depth;
00085 nvoxels=width*height*depth;
00086 if(nvoxels<0){ThrowError("Image3D::Resize size<0??");}
00087 }
00088
00089 void
00090 Image3D::Resize(const Size3D &newSize)
00091 {
00092 if(newSize==Size()){return;}
00093 SetSize(newSize);
00094 }
00095
00096
00097
00098
00099 Image3D&
00100 Image3D::operator=(const Image3D & other)
00101 {
00102
00103 if (this == &other){return *this;}
00104
00105 if(other.Size()!=Size()){Resize(other.Size());}
00106
00107
00108 properties=other.properties;
00109
00110 return *this;
00111 }
00112
00113
00114
00115
00116 bool
00117 Image3D::operator==(const Image3D & other) const
00118 {
00119 if(other.Size()!=Size()){return false;}
00120 if(!(properties==other.properties)){return false;}
00121 return true;
00122 }
00123
00124
00125
00126 Image3D::~Image3D()
00127 {
00128 ;
00129 }
00130
00131
00132
00133 Image3D::Image3D(int _width, int _height, int _depth) :
00134 properties(this)
00135 {
00136 SetSize(Size3D(_width,_height,_depth));
00137 }
00138
00139
00140 Image3D::Image3D():
00141 properties(this)
00142 {
00143 SetSize(Size3D(0,0,0));
00144 }
00145
00146
00147
00148
00149 Image3D::Image3D(const Size3D &size):
00150 properties(this)
00151 {
00152 SetSize(size);
00153 }
00154
00155
00156
00157 Image3D::Image3D(const Image3D & origCont) :
00158 properties(this)
00159 {
00160 SetSize(origCont.Size());
00161 (*this)=origCont;
00162 }
00163