00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _frePointSetToXMLStreamObject_txx
00024 #define _frePointSetToXMLStreamObject_txx
00025
00026 #include "frePointSetToXMLStreamObject.h"
00027 #include "freXMLValueSet.h"
00028
00029 namespace FREE
00030 {
00031
00032 template <class TPointSet>
00033 PointSetToXMLStreamObject<TPointSet>
00034 ::PointSetToXMLStreamObject() : XMLStreamObject(XMLTags::PointSet)
00035 {
00036 m_PointSet = PointSetType::New();
00037 m_PointSet->SetPointData(PointSetType::PointDataContainer::New());
00038 }
00039
00040
00041 template <class TPointSet>
00042 void
00043 PointSetToXMLStreamObject<TPointSet>::
00044 SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData)
00045 {
00046 if (rsXMLSubTag == XMLTags::Point)
00047 {
00048 XMLValueSet values;
00049 values.SetXMLTag(XMLTags::Point);
00050 values.LoadFromString(rsXMLSubElement);
00051 PointType point;
00052
00053 typename PointType::CoordRepType value;
00054 for (unsigned long i=0; i<point.Size(); i++)
00055 {
00056 values.GetValue(value,i);
00057 point[i]=value;
00058 }
00059
00060 m_PointSet->GetPoints()->InsertElement(m_PointSet->GetPoints()->Size(),point);
00061 }
00062 };
00063
00064 template <class TPointSet>
00065 std::string
00066 PointSetToXMLStreamObject<TPointSet>::
00067 SaveData(const unsigned int& iDepth, bool& bHasSubElements) const
00068 {
00069 std::string sResult;
00070
00071 for (unsigned long i=0; i<m_PointSet->GetPoints()->Size(); i++)
00072 {
00073 PointType point = m_PointSet->GetPoints()->ElementAt(i);
00074
00075 std::string sData;
00076 for(typename PointType::ConstIterator pos = point.Begin(); pos != point.End(); pos++)
00077 {
00078 AddSubElement(sData,cXML_ParameterValue,Convert::ToStr(*pos),iDepth+1);
00079 }
00080
00081 AddSubElement(sResult,XMLTags::Point,sData,iDepth);
00082 }
00083
00084 bHasSubElements = true;
00085 return sResult;
00086 };
00087
00088 template <class TPointSet>
00089 void
00090 PointSetToXMLStreamObject<TPointSet>::
00091 AttributesLoadProcessing(const AttributesType& rAttributes)
00092 {
00093 for (AttributesType::const_iterator pos = rAttributes.begin(); pos!= rAttributes.end(); pos++)
00094 {
00095 if (pos->first==XMLTags::PointSetDim)
00096 {
00097 if (Convert::ToUInt(pos->second) != PointSetType::PointDimension) throwExceptionMacro("Error, point set strored in xml file has wrong dimension. Needed: "<<PointSetType::PointDimension<<"; xml: "<<pos->second);
00098 }
00099 };
00100
00101 Superclass::AttributesLoadProcessing(rAttributes);
00102 };
00103
00104 template <class TPointSet>
00105 void
00106 PointSetToXMLStreamObject<TPointSet>::
00107 SaveAttributes(AttributesSaveListType& rAttributes) const
00108 {
00109 rAttributes.push_back(AttributesType::value_type(XMLTags::PointSetDim,Convert::ToStr(PointSetType::PointDimension)));
00110
00111 Superclass::SaveAttributes(rAttributes);
00112 };
00113
00114 template <class TPointSet>
00115 typename PointSetToXMLStreamObject<TPointSet>::PointSetType*
00116 PointSetToXMLStreamObject<TPointSet>::
00117 GetPointSet()
00118 {
00119 return m_PointSet;
00120 };
00121
00122 template <class TPointSet>
00123 void
00124 PointSetToXMLStreamObject<TPointSet>::
00125 SetPointSet(PointSetType* pSet)
00126 {
00127 m_PointSet = pSet;
00128 };
00129
00130
00131 }
00132
00133 #endif