vnl_xio_quaternion.hxx
Go to the documentation of this file.
1 // This is core/vnl/xio/vnl_xio_quaternion.hxx
2 #ifndef vnl_xio_quaternion_hxx_
3 #define vnl_xio_quaternion_hxx_
4 
5 #include "vnl_xio_quaternion.h"
6 #include <vnl/vnl_quaternion.h>
7 #include <vsl/vsl_basic_xml_element.h>
8 
9 //=================================================================================
10 template<class T>
11 void x_write(std::ostream & os, vnl_quaternion<T> const& q, std::string name)
12 {
13  vsl_basic_xml_element element(name);
14  element.add_attribute("x", q.x());
15  element.add_attribute("y", q.y());
16  element.add_attribute("z", q.z());
17  element.add_attribute("r", q.r());
18  element.x_write(os);
19 }
20 
21 //=================================================================================
22 template<class T>
23 void x_write_tree(std::ostream & os, vnl_quaternion<T> const& q, std::string name)
24 {
25  vsl_basic_xml_element element(name);
26  element.append_cdata("<x>"); element.append_cdata(q.x()); element.append_cdata("</x>");
27  element.append_cdata("<y>"); element.append_cdata(q.y()); element.append_cdata("</y>");
28  element.append_cdata("<z>"); element.append_cdata(q.z()); element.append_cdata("</z>");
29  element.append_cdata("<r>"); element.append_cdata(q.r()); element.append_cdata("</r>");
30  element.x_write(os);
31 }
32 
33 #undef VNL_XIO_QUATERNION_INSTANTIATE
34 #define VNL_XIO_QUATERNION_INSTANTIATE(T) \
35 template VNL_EXPORT void x_write(std::ostream &, vnl_quaternion<T > const&, std::string); \
36 template VNL_EXPORT void x_write_tree(std::ostream &, vnl_quaternion<T > const&, std::string)
37 
38 #endif // vnl_xio_quaternion_hxx_
T & z()
Imaginary component, parallel to axis of rotation.
T & r()
Real component.
4-element vector that represents rotation in 3D.
Definition: vnl_fwd.h:29
void VNL_EXPORT x_write_tree(std::ostream &os, vnl_matrix< T > const &v, std::string name="vnl_matrix")
XML save vnl_matrix as a 3-level tree to stream.
T & y()
Imaginary component, parallel to axis of rotation.
T & x()
Imaginary component, parallel to axis of rotation.
XML write a vnl_quaternion Two functions which write a valid XML fragment to an ostream.
Unit quaternion represents rotation in 3D.
void VNL_EXPORT x_write(std::ostream &os, vnl_matrix< T > const &v, std::string name="vnl_matrix")
XML save vnl_matrix to stream.