00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "Cloud3DTranslator.h"
00031 #include "AIDA/ICloud3D.h"
00032 #include "AIDA_Dev/IDevCloud3D.h"
00033 #include "AIDA_Dev/IDevHistogramFactory.h"
00034
00035 #include "DataXML/DataObject.h"
00036
00037 static const std::string emptyString = "";
00038
00040 Anaphe::AIDA_XMLStore::Cloud3DTranslator::Cloud3DTranslator(const AIDA::ICloud3D * cloud, const std::string & name, const std::string & path ) :
00041 m_cloud(cloud), m_name(name), m_path(path)
00042 {
00043 }
00045 Anaphe::AIDA_XMLStore::Cloud3DTranslator::Cloud3DTranslator(const DataXML::DataObject * xmlObject) :
00046 m_element(*xmlObject)
00047 {
00048 }
00049
00050
00051 Anaphe::AIDA_XMLStore::Cloud3DTranslator::~Cloud3DTranslator()
00052 {
00053 }
00054
00055 Anaphe::AIDA_XMLStore::Cloud3DTranslator::Cloud3DTranslator(const Anaphe::AIDA_XMLStore::Cloud3DTranslator &)
00056 {
00057 }
00058
00059 Anaphe::AIDA_XMLStore::Cloud3DTranslator & Anaphe::AIDA_XMLStore::Cloud3DTranslator::operator = (const Anaphe::AIDA_XMLStore::Cloud3DTranslator &rhs)
00060 {
00061 if (this == &rhs) return *this;
00062
00063 return *this;
00064 }
00065
00066 bool Anaphe::AIDA_XMLStore::Cloud3DTranslator::toXML()
00067 {
00068
00069 appendObjectHeader(m_element,"cloud3d",m_name,m_cloud->title(),m_path);
00070
00071
00072 AIDA::Dev::IDevCloud3D* dev_cloud =
00073 dynamic_cast< AIDA::Dev::IDevCloud3D* >( const_cast<AIDA::ICloud3D * > (m_cloud ));
00074
00075 if ( !dev_cloud ) return false;
00076 m_element.setAttribute("maxEntries", toString(static_cast<int>(dev_cloud->cacheSize() )));
00077
00078 m_element.setAttribute("lowerEdgeX", toString(m_cloud->lowerEdgeX()));
00079 m_element.setAttribute("upperEdgeX", toString(m_cloud->upperEdgeX()));
00080 m_element.setAttribute("lowerEdgeY", toString(m_cloud->lowerEdgeY()));
00081 m_element.setAttribute("upperEdgeY", toString(m_cloud->upperEdgeY()));
00082 m_element.setAttribute("lowerEdgeZ", toString(m_cloud->lowerEdgeZ()));
00083 m_element.setAttribute("upperEdgeZ", toString(m_cloud->upperEdgeZ()));
00084
00085
00086 appendAnnotation(m_element,m_cloud->annotation());
00087
00088 if (!setData () ) return false;
00089 return true;
00090
00091 }
00092
00093
00094 bool Anaphe::AIDA_XMLStore::Cloud3DTranslator::setData()
00095 {
00096
00097
00098 DataXML::DataObject dataElement;
00099 dataElement.setName("entries1d");
00100 const int dim = 1;
00101 const int n = m_cloud->entries();
00102 for (int i = 0; i < n; ++i)
00103 appendCloudEntry(dataElement, dim,
00104 m_cloud->valueX(i), m_cloud->valueY(i), m_cloud->valueZ(i) ,m_cloud->weight(i));
00105
00106 m_element.appendChild(dataElement);
00107 return true;
00108 }
00109
00111
00112 AIDA::Dev::IDevCloud3D * Anaphe::AIDA_XMLStore::Cloud3DTranslator::createFromXML(AIDA::Dev::IDevHistogramFactory& factory)
00113 {
00114
00115 std::string title,options = emptyString;
00116 getObjectHeader(m_element,m_name,title,m_path,options);
00117 int nMax = -1;
00118 toValue(m_element.getAttributeValue("maxEntries"), nMax);
00119
00120
00121 AnnotationData annoData;
00122 getAnnotation(m_element,annoData);
00123
00124
00125
00126 AIDA::Dev::IDevCloud3D * cloud =
00127 factory.createCloud3D( title, nMax,options );
00128
00129
00130
00131
00132 AIDA::IAnnotation & anno = cloud->annotation();
00133 setAnnotation(&anno,annoData);
00134
00135
00136
00137 const DataXML::DataObject * dataElement = m_element.getChild("entries3d");
00138 if (!dataElement) return cloud;
00139 for (std::vector<DataXML::DataObject>::const_iterator entryElement = dataElement->children().begin(); entryElement != dataElement->children().end(); ++entryElement) {
00140 if (entryElement->name() == "entry3d") {
00141 double xval,yval,zval = 0;
00142 double weight = 1;
00143 getCloudEntryData(*entryElement,1,xval,yval,zval,weight);
00144
00145 cloud->fill(xval,yval,zval,weight);
00146 }
00147 }
00148
00149 return cloud;
00150 }
00151