00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef SPLINE_XMLIO_H
00010 #define SPLINE_XMLIO_H
00011
00012 #include <xml/XmlReader.hpp>
00013 #include <xml/XmlWriter.hpp>
00014 #include <spline/PeriodicBspline.hpp>
00015 #include <core/xmlio.hpp>
00016
00017 namespace imaging
00018 {
00046 template<>
00047 template <class DATA_t>
00048 class xml_handler< PeriodicBspline<DATA_t> >
00049 {
00050 public:
00052 static const std::string element_name;
00053
00054 void read_object(XmlReader & in, PeriodicBspline<DATA_t> & object) const
00055 {
00056 std::vector<float_t> knots;
00057 std::vector<DATA_t> coefficients;
00058 size_t spline_order;
00059
00060 in >> XmlReader::element("knot") >> knots;
00061 in >> XmlReader::element("coefficient") >> coefficients;
00062 in >> XmlReader::element("spline_order") >> spline_order >> XmlReader::end_element;
00063
00064 object.resize(spline_order, coefficients.size());
00065
00066 if(knots.size() == 0)
00067 for(size_t i = 0; i < object.n_knots(); ++i)
00068 object.set_knot(i, float_t(i));
00069
00070 if(knots.size() != 0 && knots.size() != object.n_knots())
00071 throw Exception("Wrong number of knots in xml_handler<PeriodicBspline>::read_object().");
00072
00073 for(size_t i = 0; i < coefficients.size(); ++i)
00074 object.set_coefficient(i, coefficients[i]);
00075
00076 for(size_t i = 0; i < knots.size(); ++i)
00077 object.set_knot(i, knots[i]);
00078 }
00079
00080 void write_object(const PeriodicBspline<DATA_t> & object, XmlWriter & out) const
00081 {
00082 out << XmlWriter::element("spline_order") << object.spline_order() << XmlWriter::end_element;
00083
00084 out << XmlWriter::element("spline_order") << object.spline_order() << XmlWriter::end_element;
00085
00086 for(size_t i = 0; i < object.n_coefficients(); ++i)
00087 out << XmlWriter::element("coefficient") << object.coefficient(i) << XmlWriter::end_element;
00088
00089 for(size_t i = 0; i < object.n_knots(); ++i)
00090 out << XmlWriter::element("knot") << object.knot(i) << XmlWriter::end_element;
00091 }
00093 };
00094
00096 template<>
00097 template <class DATA_t>
00098 const std::string xml_handler< PeriodicBspline<DATA_t> >::element_name = "periodic_spline_curve";
00131 template<>
00132 template <class DATA_t>
00133 class xml_handler< Bspline<DATA_t> >
00134 {
00135 public:
00137 static const std::string element_name;
00138
00139 void read_object(XmlReader & in, Bspline<DATA_t> & object) const
00140 {
00141 std::vector<float_t> knots;
00142 std::vector<DATA_t> coefficients;
00143 size_t spline_order;
00144
00145 in >> XmlReader::element("knot") >> knots;
00146 in >> XmlReader::element("coefficient") >> coefficients;
00147 in >> XmlReader::element("spline_order") >> spline_order >> XmlReader::end_element;
00148
00149 object.resize(spline_order, coefficients.size());
00150
00151 if(knots.size() == 0)
00152 for(size_t i = 0; i < object.n_knots(); ++i)
00153 object.set_knot(i, float_t(i));
00154
00155 if(knots.size() != 0 && knots.size() != object.n_knots())
00156 throw Exception("Wrong number of knots in xml_handler<Bspline>::read_object().");
00157
00158 for(size_t i = 0; i < coefficients.size(); ++i)
00159 object.set_coefficient(i, coefficients[i]);
00160
00161 for(size_t i = 0; i < knots.size(); ++i)
00162 object.set_knot(i, knots[i]);
00163 }
00164
00165 void write_object(const Bspline<DATA_t> & object, XmlWriter & out) const
00166 {
00167 out << XmlWriter::element("spline_order") << object.spline_order() << XmlWriter::end_element;
00168
00169 out << XmlWriter::element("spline_order") << object.spline_order() << XmlWriter::end_element;
00170
00171 for(size_t i = 0; i < object.n_coefficients(); ++i)
00172 out << XmlWriter::element("coefficient") << object.coefficient(i) << XmlWriter::end_element;
00173
00174 for(size_t i = 0; i < object.n_knots(); ++i)
00175 out << XmlWriter::element("knot") << object.knot(i) << XmlWriter::end_element;
00176 }
00178 };
00179
00181 template<>
00182 template <class DATA_t>
00183 const std::string xml_handler< Bspline<DATA_t> >::element_name = "spline_curve";
00185 }
00186
00187
00188 #endif