00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00022 #include<ImLib3D/Image3D.hpp>
00023 #include<ImLib3D/Properties.hpp>
00024
00025
00026 void
00027 Properties::AddMask(const Size3D &size)
00028 {
00029 if(!mask){mask=new Mask3D(size);mask->Fill(1);}
00030 }
00031 bool
00032 ImageProperty::IsXML()
00033 {
00034 return dynamic_cast<PropertyXML *>(this)!=NULL;
00035 }
00036
00037
00039 void
00040 Properties::ClearProperties()
00041 {
00042 if(mask) {delete mask;mask=NULL;}
00043 if(iCenter){delete iCenter;iCenter=NULL;}
00044 for(map<string,Prop *>::iterator p=properties.begin();p!=properties.end();++p)
00045 {
00046 delete (*p).second;
00047 }
00048 properties.clear();
00049 }
00050 void
00051 Properties::Remove(const string &name)
00052 {
00053 if(name=="Mask" && mask){delete mask;mask=NULL;}
00054 else
00055 if(name=="iCenter" && iCenter){delete iCenter;iCenter=NULL;}
00056 else
00057 {properties.erase(name);}
00058 }
00059
00060 void
00061 Properties::operator=(const Properties &other)
00062 {
00063 ClearProperties();
00064 if(other.mask ) {mask =new Mask3D(*other.mask);}
00065 if(other.iCenter) {iCenter=new Vect3Di(*other.iCenter);}
00066 for(map<string,Prop *>::const_iterator p=other.properties.begin();p!=other.properties.end();++p)
00067 {
00068 properties[((*p).second)->name]=((*p).second)->Duplicate();
00069 }
00070
00071 }
00072
00073 bool
00074 Properties::operator==(const Properties &other) const
00075 {
00076 if( ((mask ==NULL) !=(other.mask ==NULL)) || (mask && !(*mask == *other.mask ))){return false;}
00077 if( ((iCenter==NULL) !=(other.iCenter==NULL)) || (iCenter && !(*iCenter == *other.iCenter ))){return false;}
00078 if(properties.size()!=other.properties.size()){return false;}
00079 for(map<string,Prop *>::const_iterator p=other.properties.begin();p!=other.properties.end();++p)
00080 {
00081 Prop *oprop=(*p).second;
00082 if(properties.find(oprop->name)==properties.end()){return false;}
00083 if(!((*properties[oprop->name])==(*oprop))){return false;}
00084 }
00085 return true;
00086 }
00087
00088 void
00089 Properties::Read( ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node)
00090 {
00091 node=CreateReadNode("Properties",file,parentNode,node);
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 vector<xmlpp::Element *> propNodes=ChildElements(node);
00102 for(vector<xmlpp::Element *>::iterator p=propNodes.begin();p!=propNodes.end();++p)
00103 {
00104 xmlpp::Element::NodeList nodeList;
00105 xmlpp::Element *snode=*p;
00106 string name=(*p)->get_name();
00107 if(name=="Mask3D")
00108 {
00109 mask=new Mask3D();
00110 if((nodeList=snode->get_children("ImLib3DImage")).size()<1)
00111 {ThrowError("Properties::Read: no ImLib3DImage node in Mask3D node");}
00112 mask->Read(file,snode);
00113 }
00114 else
00115 if(name=="iCenter")
00116 {
00117 iCenter=new Vect3Di(
00118 LongInt(snode->get_attribute("x" )->get_value()) ,
00119 LongInt(snode->get_attribute("y" )->get_value()) ,
00120 LongInt(snode->get_attribute("z" )->get_value()) );
00121 }
00122 else
00123 {
00124
00125 PropXML *propxml=new PropXML(name);
00126 propxml->Read(file,NULL,snode);
00127 properties[name]=propxml;
00128 }
00129 }
00130
00131 vector<PropXML *> parseable;
00132 for(map<string,Prop *>::iterator p=properties.begin();p!=properties.end();++p)
00133 {
00134 if(!((*p).second)->IsXML()){continue;}
00135 PropXML *propxml=(PropXML *)((*p).second);
00136 if(propxml->RootElement()->get_attribute("PropertyType"))
00137 {
00138 if(propxml->RootElement()->get_attribute("PropertyType")->get_value()=="PropertyWrapPtr")
00139 {
00140 parseable.push_back(propxml);
00141 }
00142 }
00143 }
00144
00145 for(uint i=0;i<parseable.size();i++)
00146 {
00147 string name=parseable[i]->name;
00148 string type=parseable[i]->RootElement()->get_attribute("type")->get_value();
00149 if(type=="Vect3Df" ){DefaultParse<Vect3Df>(name);}
00150 if(type=="Vect3D<float, float>"){DefaultParse<Vect3Df>(name);}
00151 if(type=="Vect3Di" ){DefaultParse<Vect3Di>(name);}
00152 if(type=="Vect3D<int, float>" ){DefaultParse<Vect3Di>(name);}
00153 if(type=="RectZone3Di" ){DefaultParse<RectZone3Di>(name);}
00154 if(type=="RectZone3Df" ){DefaultParse<RectZone3Df>(name);}
00155 if(type=="int" ){DefaultParse<int >(name);}
00156 if(type=="float" ){DefaultParse<float >(name);}
00157 if(type=="double" ){DefaultParse<double >(name);}
00158 if(type=="byte" ){DefaultParse<byte >(name);}
00159 if(type=="string" ){DefaultParse<string >(name);}
00160 }
00161 }
00162
00163 void
00164 Properties::Write(ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node) const
00165 {
00166 node=CreateWriteNode("Properties",file,parentNode,node);
00167
00168 for(map<string,Prop *>::iterator p=properties.begin();p!=properties.end();++p)
00169 {
00170 Prop *prop=(*p).second;
00171 printf("Writing Property:\"%s\" (is xml:%d)\n",prop->name.c_str(),prop->IsXML());
00172 prop->Write(file,node);
00173 }
00174 if(mask )
00175 {
00176 xmlpp::Element *maskNode=node->add_child("Mask3D");
00177 mask->Write(file,maskNode);
00178 }
00179 if(iCenter)
00180 {
00181 xmlpp::Element *cnode=node->add_child("iCenter");
00182 cnode->set_attribute("x",SPrintf("%d",iCenter->x));
00183 cnode->set_attribute("y",SPrintf("%d",iCenter->y));
00184 cnode->set_attribute("z",SPrintf("%d",iCenter->z));
00185 }
00186
00187 }
00188
00189
00190