MRPT  1.9.9
CObservationPointCloud.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-2019, 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 "maps-precomp.h" // Precomp header
11 
19 #include <mrpt/system/filesystem.h>
20 #include <iostream>
21 
22 using namespace mrpt::obs;
23 
25 
27 {
29  pointcloud->loadFromRangeScan(o);
30 }
31 
33  mrpt::poses::CPose3D& out_sensorPose) const
34 {
35  out_sensorPose = sensorPose;
36 }
38 {
39  sensorPose = p;
40 }
42 {
44  o << "Homogeneous matrix for the sensor pose wrt vehicle:\n";
46  << sensorPose << std::endl;
47 
48  o << "Pointcloud class: ";
49  if (!this->pointcloud)
50  {
51  o << "nullptr\n";
52  }
53  else
54  {
55  o << pointcloud->GetRuntimeClass()->className << "\n";
56  o << "Number of points: " << pointcloud->size() << "\n";
57  }
58 }
59 
63 {
64  out << sensorLabel << timestamp; // Base class data
65 
66  out << sensorPose;
67  out << static_cast<uint8_t>(m_externally_stored);
68 
69  if (isExternallyStored())
70  {
71  out << m_external_file;
72  }
73  else
74  {
75  out << pointcloud;
76  }
77 }
78 
81 {
82  switch (version)
83  {
84  case 0:
85  {
86  pointcloud.reset();
87  in >> sensorLabel >> timestamp; // Base class data
88 
89  in >> sensorPose;
91  static_cast<ExternalStorageFormat>(in.ReadPOD<uint8_t>());
92 
93  if (isExternallyStored())
94  {
96  }
97  else
98  {
99  m_external_file.clear();
100  in >> pointcloud;
101  }
102  }
103  break;
104  default:
106  };
107 }
108 
110 {
111  MRPT_START
112 
113  // Already loaded?
114  if (!isExternallyStored() || (isExternallyStored() && pointcloud)) return;
115 
116  const auto abs_filename = m_external_file;
117 
118  switch (m_externally_stored)
119  {
121  break;
123  {
125  bool ok = pts->loadFromKittiVelodyneFile(abs_filename);
126  ASSERTMSG_(
127  ok, mrpt::format(
128  "[kitti format] Error loading lazy-load point cloud "
129  "file: '%s'",
130  abs_filename.c_str()));
131  auto pc = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(pts);
132  const_cast<mrpt::maps::CPointsMap::Ptr&>(pointcloud) = pc;
133  }
134  break;
136  {
137  mrpt::io::CFileGZInputStream f(abs_filename);
139  auto obj = ar.ReadObject();
140  auto pc = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(obj);
141  const_cast<mrpt::maps::CPointsMap::Ptr&>(pointcloud) = pc;
142 
143  ASSERTMSG_(
145  "[mrpt-serialization format] Error loading "
146  "lazy-load point cloud file: %s",
147  abs_filename.c_str()));
148  }
149  break;
150  };
151 
152  MRPT_END
153 }
155 {
156  MRPT_START
158  {
159  // Free memory, saving to the file if it doesn't exist:
160  const auto abs_filename = m_external_file;
161  if (!mrpt::system::fileExists(abs_filename))
162  {
163  switch (m_externally_stored)
164  {
166  break;
168  {
169  THROW_EXCEPTION("Saving to kitti format not supported.");
170  }
171  // break;
173  {
174  mrpt::io::CFileGZOutputStream f(abs_filename);
176  ar << *pointcloud;
177  }
178  break;
179  };
180  }
181 
182  // Now we can safely free the mem:
183  pointcloud.reset();
184  }
185  MRPT_END
186 }
187 
189  const std::string& fileName,
191 {
192  MRPT_START
193  ASSERTMSG_(!isExternallyStored(), "Already marked as externally-stored.");
194  m_external_file = fileName;
195  m_externally_stored = fmt;
196 
197  MRPT_END
198 }
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
void load() const override
Makes sure all images and other fields which may be externally stored are loaded in memory...
#define MRPT_START
Definition: exceptions.h:241
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
An observation from any sensor that can be summarized as a pointcloud.
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
void setSensorPose(const mrpt::poses::CPose3D &p) override
A general method to change the sensor pose on the robot.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4085
mrpt::poses::CPose3D sensorPose
Sensor placement wrt the vehicle/robot.
unsigned char uint8_t
Definition: rptypes.h:44
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT&#39;s CStream, std::istream, std::ostream, std::stringstream.
Definition: CArchive.h:586
void unload() override
Unload all images, for the case they being delayed-load images stored in external files (othewise...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
Definition: CPointsMap.h:65
This namespace contains representation of robot actions and observations.
static Ptr Create(Args &&... args)
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:108
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const override
A general method to retrieve the sensor pose on the robot.
GLsizei const GLchar ** string
Definition: glext.h:4116
mrpt::maps::CPointsMap::Ptr pointcloud
The pointcloud.
IMPLEMENTS_SERIALIZABLE(CObservationPointCloud, CObservation, mrpt::obs)
std::string sensorLabel
An arbitrary label that can be used to identify the sensor.
Definition: CObservation.h:62
static Ptr Create(Args &&... args)
mrpt::system::TTimeStamp timestamp
The associated UTC time-stamp.
Definition: CObservation.h:60
void setAsExternalStorage(const std::string &fileName, const ExternalStorageFormat fmt)
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
#define MRPT_END
Definition: exceptions.h:245
GLuint in
Definition: glext.h:7391
Transparently opens a compressed "gz" file and reads uncompressed data from it.
MATRIX44 getHomogeneousMatrixVal() const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
Definition: CPoseOrPoint.h:278
Saves data to a file and transparently compress the data using the given compression level...
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
GLfloat GLfloat p
Definition: glext.h:6398
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019