vpgl_io_lvcs.cxx
Go to the documentation of this file.
1 #include "vpgl_io_lvcs.h"
2 //:
3 // \file
4 #include <vpgl/vpgl_lvcs.h>
6 
7 void vsl_b_write(vsl_b_ostream & os, vpgl_lvcs const& lvcs)
8 {
9  if (!os) return;
10  unsigned version = 1;
11  vsl_b_write(os, version);
12  auto csn = static_cast<unsigned>(lvcs.get_cs_name());
13  vsl_b_write(os, csn);
14  double lat, lon, elev;
15  lvcs.get_origin(lat, lon, elev);
16  vsl_b_write(os, lat);
17  vsl_b_write(os, lon);
18  vsl_b_write(os, elev);
19  double lat_scale, lon_scale;
20  lvcs.get_scale(lat_scale, lon_scale);
21  vsl_b_write(os, lat_scale);
22  vsl_b_write(os, lon_scale);
23  auto gaunit = static_cast<unsigned>(lvcs.geo_angle_unit());
24  vsl_b_write(os, gaunit);
25  auto xyzunit = static_cast<unsigned>(lvcs.local_length_unit());
26  vsl_b_write(os, xyzunit);
27  double lox, loy, theta;
28  lvcs.get_transform(lox, loy, theta);
29  vsl_b_write(os, lox);
30  vsl_b_write(os, loy);
31  vsl_b_write(os, theta);
32 }
33 
34 //: Binary load lvcs from stream.
36 {
37  if (!is) return;
38  short ver;
39  vsl_b_read(is, ver);
40  switch (ver)
41  {
42  case 1:
43  {
44  unsigned cs_name;
45  vsl_b_read(is, cs_name);
46  auto name = static_cast<vpgl_lvcs::cs_names>(cs_name);
47  double lat, lon, elev, lat_scale, lon_scale;
48  vsl_b_read(is, lat);
49  vsl_b_read(is, lon);
50  vsl_b_read(is, elev);
51  vsl_b_read(is, lat_scale);
52  vsl_b_read(is, lon_scale);
53  unsigned gaunit;
54  vsl_b_read(is, gaunit);
55  auto geo_angle_unit = static_cast<vpgl_lvcs::AngUnits>(gaunit);
56  unsigned lunit;
57  vsl_b_read(is, lunit);
58  auto localXYZUnit = static_cast<vpgl_lvcs::LenUnits>(lunit);
59  double lox, loy, theta;
60  vsl_b_read(is, lox);
61  vsl_b_read(is, loy);
62  vsl_b_read(is, theta);
63  vpgl_lvcs temp(lat, lon, elev, name, lat_scale, lon_scale,
64  geo_angle_unit, localXYZUnit, lox, loy, theta);
65  lvcs = temp;
66  break;
67  }
68  default:
69  std::cerr << "I/O ERROR: vpgl_lvcs::b_read(vsl_b_istream&)\n"
70  << " Unknown version number "<< ver << '\n';
71  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
72  return;
73  }
74 }
75 
76 //: Print human readable summary of object to a stream
77 void vsl_print_summary(std::ostream& os,const vpgl_lvcs & c)
78 {
79  os << c << '\n';
80 }
81 
82 //: Binary save lvcs sptr to stream
83 void vsl_b_write(vsl_b_ostream & os, vpgl_lvcs_sptr const& lvcs_sptr)
84 {
85  if (!lvcs_sptr) return;
86  vpgl_lvcs* lvcs = lvcs_sptr.ptr();
87  vsl_b_write(os, *lvcs);
88 }
89 
90 //: Binary load lvcs sptr from stream.
91 void vsl_b_read(vsl_b_istream & is, vpgl_lvcs_sptr &lvcs_sptr)
92 {
93  vpgl_lvcs* lvcs = nullptr;
94  vsl_b_read(is, *lvcs);
95  lvcs_sptr = lvcs;
96 }
A geographic coordinate system.
AngUnits geo_angle_unit() const
Definition: vpgl_lvcs.h:123
LenUnits local_length_unit() const
Definition: vpgl_lvcs.h:122
void vsl_print_summary(std::ostream &os, const vpgl_lvcs &c)
Print human readable summary of object to a stream.
std::istream & is() const
void get_scale(double &lat, double &lon) const
return the scale for lat lon and elevation.
Definition: vpgl_lvcs.h:177
void vsl_b_read(vsl_b_istream &is, vpgl_lvcs &lvcs)
Binary load lvcs from stream.
void get_origin(double &lat, double &lon, double &elev) const
return the origin of the local system.
Definition: vpgl_lvcs.h:189
void get_transform(double &lox, double &loy, double &theta) const
Return the compass alignment transform.
Definition: vpgl_lvcs.h:206
void vsl_b_write(vsl_b_ostream &os, vpgl_lvcs const &lvcs)
Binary save lvcs to stream.
Definition: vpgl_io_lvcs.cxx:7
T * ptr() const
cs_names get_cs_name() const
return the coordinate system.
Definition: vpgl_lvcs.h:184