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

Image3D.cpp

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 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     // **** Optionally add unset image properties ***
00040     // set image type (Image3Df, Field3D etc....) 
00041     if(!file->HasAttribute(node,"Type")){node->set_attribute("Type",GetTypeName());}
00042     // store Size information
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     // store the image Properties
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     //image size
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     //image properties
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     // don't copy if its the same object
00103     if (this == &other){return *this;}
00104     // resize (Resize method is virtual)
00105     if(other.Size()!=Size()){Resize(other.Size());}
00106 
00107     // now copy properties
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 

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