MRPT  2.0.4
TStereoCamera.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "img-precomp.h" // Precompiled headers
11 
13 #include <mrpt/img/TStereoCamera.h>
15 
16 using namespace mrpt::img;
17 using namespace mrpt::math;
18 using namespace std;
19 
21 
22 /** Save as a config block:
23  */
24 void TStereoCamera::saveToConfigFile(
25  const std::string& section, mrpt::config::CConfigFileBase& cfg) const
26 {
27  // [<SECTION>_LEFT]
28  // ...
29  // [<SECTION>_RIGHT]
30  // ...
31  // [<SECTION>_LEFT2RIGHT_POSE]
32  // pose_quaternion = [x y z qr qx qy qz]
33 
34  leftCamera.saveToConfigFile(section + string("_LEFT"), cfg);
35  rightCamera.saveToConfigFile(section + string("_RIGHT"), cfg);
36 
37  cfg.write(
38  section + string("_LEFT2RIGHT_POSE"), "pose_quaternion",
39  rightCameraPose.asString());
40 }
41 
42 /** Load all the params from a config source, in the format described in
43  * saveToConfigFile()
44  */
46  const std::string& section, const mrpt::config::CConfigFileBase& cfg)
47 {
48  // [<SECTION>_LEFT]
49  // ...
50  // [<SECTION>_RIGHT]
51  // ...
52  // [<SECTION>_LEFT2RIGHT_POSE]
53  // pose_quaternion = [x y z qr qx qy qz]
54 
55  leftCamera.loadFromConfigFile(section + string("_LEFT"), cfg);
56  rightCamera.loadFromConfigFile(section + string("_RIGHT"), cfg);
57  rightCameraPose.fromString(cfg.read_string(
58  section + string("_LEFT2RIGHT_POSE"), "pose_quaternion", ""));
59 }
60 
61 uint8_t TStereoCamera::serializeGetVersion() const { return 2; }
63 {
64  // v1->v2: rightCameraPose changed from mrpt::poses::CPose3DQuat to
65  // mrpt::math::TPose3DQuat
66  out << leftCamera << rightCamera << rightCameraPose;
67 }
69  mrpt::serialization::CArchive& in, uint8_t version)
70 {
71  switch (version)
72  {
73  case 0:
74  case 1:
75  case 2:
76  {
77  if (version == 0)
78  {
79  uint8_t _model;
80  in >> _model; // unused now
81  }
82  if (version == 1)
83  {
84  // Emulate reading a CPose3DQuat object:
86  "backwards compatibility de-serialization not implemented "
87  "yet!");
88  }
89  in >> leftCamera >> rightCamera >> rightCameraPose;
90  }
91  break;
92  default:
94  }
95 }
96 
97 std::string TStereoCamera::dumpAsText() const
98 {
100  saveToConfigFile("", cfg);
101  return cfg.getContent();
102 }
CConfigFileMemory.h
TStereoCamera.h
mrpt::img::TStereoCamera::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: TStereoCamera.cpp:61
mrpt::img::TStereoCamera::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: TStereoCamera.cpp:68
out
mrpt::vision::TStereoCalibResults out
Definition: chessboard_stereo_camera_calib_unittest.cpp:25
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
mrpt::config::CConfigFileBase::read_string
std::string read_string(const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
Definition: CConfigFileBase.cpp:171
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::img
Definition: CCanvas.h:16
mrpt::img::TStereoCamera::loadFromConfigFile
void loadFromConfigFile(const std::string &section, const mrpt::config::CConfigFileBase &cfg)
Load all the params from a config source, in the same format that used in saveToConfigFile().
Definition: TStereoCamera.cpp:45
mrpt::img::TStereoCamera
Structure to hold the parameters of a pinhole stereo camera model.
Definition: TStereoCamera.h:23
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
img-precomp.h
mrpt::utils::CConfigFileBase
mrpt::config::CConfigFileBase CConfigFileBase
Definition: utils/CConfigFileBase.h:5
mrpt::config::CConfigFileMemory::getContent
void getContent(std::string &str) const
Return the current contents of the virtual "config file".
Definition: CConfigFileMemory.cpp:65
mrpt::img::TStereoCamera::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: TStereoCamera.cpp:62
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
Definition: CSerializable.h:166
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:11
mrpt::config::CConfigFileMemory
This class implements a config file-like interface over a memory-stored string list.
Definition: config/CConfigFileMemory.h:36
CArchive.h
mrpt::img::TStereoCamera::dumpAsText
std::string dumpAsText() const
Dumps all the parameters as a multi-line string, with the same format than saveToConfigFile.
Definition: TStereoCamera.cpp:97
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
mrpt::img::TStereoCamera::saveToConfigFile
void saveToConfigFile(const std::string &section, mrpt::config::CConfigFileBase &cfg) const
Save all params to a plain text config file in this format:
Definition: TStereoCamera.cpp:24



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 17:54:30 UTC 2020