vgl_io_cylinder.hxx
Go to the documentation of this file.
1 #ifndef vgl_io_cylinder_hxx_
2 #define vgl_io_cylinder_hxx_
3 //:
4 // \file
5 #include <iostream>
6 #include "vgl_io_cylinder.h"
9 #include <vgl/vgl_cylinder.h>
10 #include <vsl/vsl_binary_io.h>
11 
12 
13 //: Binary save self to stream.
14 template<class T>
15 void vsl_b_write(vsl_b_ostream &os, const vgl_cylinder<T> & cyl)
16 {
17  constexpr short io_version_no = 1;
18  vsl_b_write(os, io_version_no);
19  vsl_b_write(os, cyl.center());
20  vsl_b_write(os, cyl.radius());
21  vsl_b_write(os, cyl.length());
22  vsl_b_write(os, cyl.orientation());
23 }
24 
25 //: Binary load self from stream
26 template<class T>
27 void vsl_b_read(vsl_b_istream &is, vgl_cylinder<T> & cyl)
28 {
29  vgl_point_3d<double> center;
30  vgl_vector_3d<double> orient;
31  double radius, length;
32 
33  if (!is)
34  return;
35  short ver;
36  vsl_b_read(is, ver);
37  switch (ver)
38  {
39  case 1:
40  // read center
41  vsl_b_read(is, center);
42  cyl.set_center(center);
43 
44  // read radius
45  vsl_b_read(is, radius);
46  cyl.set_radius(radius);
47 
48  // read length
49  vsl_b_read(is, length);
50  cyl.set_length(length);
51 
52  // read orientation
53  vsl_b_read(is, orient);
54  cyl.set_orientation(orient);
55  break;
56  default:
57  std::cerr << "vsol_cylinder: unknown I/O version " << ver << '\n';
58  }
59 }
60 
61 //: Print an ascii summary to the stream
62 template<class T>
63 void vsl_print_summary(std::ostream& os, const vgl_cylinder<T> & cyl)
64 {
65  //os << *this;
66  os << "Cylinder with center=" << cyl.center() << " radius=" << cyl.radius() << " length=" << cyl.length() << std::endl;
67 }
68 
69 #undef VGL_IO_CYLINDER_INSTANTIATE
70 #define VGL_IO_CYLINDER_INSTANTIATE(T) \
71 template void vsl_print_summary(std::ostream &, const vgl_cylinder<T > &); \
72 template void vsl_b_read(vsl_b_istream &, vgl_cylinder<T > &); \
73 template void vsl_b_write(vsl_b_ostream &, const vgl_cylinder<T > &)
74 
75 #endif
Type length() const
Definition: vgl_cylinder.h:50
void set_length(Type len)
Definition: vgl_cylinder.h:56
void vsl_b_read(vsl_b_istream &is, vgl_cylinder< T > &cyl)
Binary load self from stream.
Represents a cartesian 3D point.
Definition: vgl_fwd.h:11
double length(v const &a)
Return the length of a vector.
Definition: vgl_vector_2d.h:94
void set_center(vgl_point_3d< Type > cntr)
setters.
Definition: vgl_cylinder.h:54
void vsl_print_summary(std::ostream &os, const vgl_cylinder< T > &cyl)
Print an ascii summary to the stream.
void set_radius(Type rad)
Definition: vgl_cylinder.h:55
Type radius() const
Definition: vgl_cylinder.h:49
vgl_vector_3d< Type > orientation() const
Definition: vgl_cylinder.h:51
void set_orientation(vgl_vector_3d< Type > orient)
Definition: vgl_cylinder.h:57
vgl_point_3d< Type > center() const
getters.
Definition: vgl_cylinder.h:48
Direction vector in Euclidean 3D space, templated by type of element.
Definition: vgl_fwd.h:13
defines a cylinder in 3D by a center point, radius, length and orientation
void vsl_b_write(vsl_b_ostream &os, const vgl_cylinder< T > &cyl)
Binary save self to stream.