38 CPointsMapXYZI::TMapDefinition::TMapDefinition() =
default;
40 void CPointsMapXYZI::TMapDefinition::loadFromConfigFile_map_specific(
43 insertionOpts.loadFromConfigFile(
44 source, sectionNamePrefix +
string(
"_insertOpts"));
45 likelihoodOpts.loadFromConfigFile(
46 source, sectionNamePrefix +
string(
"_likelihoodOpts"));
49 void CPointsMapXYZI::TMapDefinition::dumpToTextStream_map_specific(
50 std::ostream& out)
const 52 this->insertionOpts.dumpToTextStream(out);
53 this->likelihoodOpts.dumpToTextStream(out);
71 #include <pcl/io/pcd_io.h> 72 #include <pcl/point_types.h> 75 void CPointsMapXYZI::reserve(
size_t newLength)
77 m_x.reserve(newLength);
78 m_y.reserve(newLength);
79 m_z.reserve(newLength);
80 m_intensity.reserve(newLength);
86 void CPointsMapXYZI::resize(
size_t newLength)
88 m_x.resize(newLength, 0);
89 m_y.resize(newLength, 0);
90 m_z.resize(newLength, 0);
91 m_intensity.resize(newLength, 1);
98 void CPointsMapXYZI::setSize(
size_t newLength)
100 m_x.assign(newLength, 0);
101 m_y.assign(newLength, 0);
102 m_z.assign(newLength, 0);
103 m_intensity.assign(newLength, 0);
110 CPointsMap::base_copyFrom(
obj);
116 uint8_t CPointsMapXYZI::serializeGetVersion()
const {
return 0; }
131 insertionOptions.writeToStream(out);
132 likelihoodOptions.writeToStream(out);
135 void CPointsMapXYZI::serializeFrom(
150 in.ReadBufferFixEndianness(&m_x[0],
n);
151 in.ReadBufferFixEndianness(&m_y[0],
n);
152 in.ReadBufferFixEndianness(&m_z[0],
n);
153 in.ReadBufferFixEndianness(&m_intensity[0],
n);
155 insertionOptions.readFromStream(
in);
156 likelihoodOptions.readFromStream(
in);
164 void CPointsMapXYZI::internal_clear()
173 void CPointsMapXYZI::setPointRGB(
174 size_t index,
float x,
float y,
float z,
float R,
float G,
float B)
184 void CPointsMapXYZI::setPointIntensity(
size_t index,
float I)
187 this->m_intensity[
index] = I;
191 void CPointsMapXYZI::insertPointFast(
float x,
float y,
float z)
196 m_intensity.push_back(0);
200 void CPointsMapXYZI::insertPointRGB(
201 float x,
float y,
float z,
float R_intensity,
float G_ignored,
207 m_intensity.push_back(R_intensity);
211 void CPointsMapXYZI::getAs3DObject(
216 if (!genericMapParams.enableSaveAs3DObject)
return;
220 obj->loadFromPointsMap(
this);
221 obj->setColor(1, 1, 1, 1.0);
222 obj->setPointSize(this->renderOptions.point_size);
227 void CPointsMapXYZI::getPointRGB(
228 size_t index,
float&
x,
float&
y,
float&
z,
float&
R,
float&
G,
236 R =
G = B = m_intensity[
index];
239 float CPointsMapXYZI::getPointIntensity(
size_t index)
const 242 return m_intensity[
index];
245 bool CPointsMapXYZI::saveXYZI_to_text_file(
const std::string& file)
const 248 if (!f)
return false;
249 for (
unsigned int i = 0; i < m_x.size(); i++)
250 os::fprintf(f,
"%f %f %f %f\n", m_x[i], m_y[i], m_z[i], m_intensity[i]);
258 void CPointsMapXYZI::addFrom_classSpecific(
259 const CPointsMap& anotherMap,
const size_t nPreviousPoints)
261 const size_t nOther = anotherMap.
size();
264 const auto* anotheMap_col =
269 for (
size_t i = 0, j = nPreviousPoints; i < nOther; i++, j++)
276 bool CPointsMapXYZI::savePCDFile(
277 const std::string& filename,
bool save_as_binary)
const 280 pcl::PointCloud<pcl::PointXYZI> cloud;
282 const size_t nThis = this->
size();
287 cloud.is_dense =
false;
288 cloud.points.resize(cloud.width * cloud.height);
290 for (
size_t i = 0; i < nThis; ++i)
292 cloud.points[i].x = m_x[i];
293 cloud.points[i].y = m_y[i];
294 cloud.points[i].z = m_z[i];
295 cloud.points[i].intensity = this->m_intensity[i];
298 return 0 == pcl::io::savePCDFile(filename, cloud, save_as_binary);
303 THROW_EXCEPTION(
"Operation not available: MRPT was built without PCL");
328 CPointsMapXYZI& me,
const float gx,
const float gy,
const float gz,
360 CPointsMapXYZI& me,
const float gx,
const float gy,
const float gz,
375 const float pI = 1.0f;
390 void CPointsMapXYZI::loadFromRangeScan(
394 CPointsMapXYZI>::templ_loadFromRangeScan(*
this, rangeScan, robotPose);
398 void CPointsMapXYZI::loadFromRangeScan(
402 CPointsMapXYZI>::templ_loadFromRangeScan(*
this, rangeScan, robotPose);
406 void CPointsMapXYZI::PLY_import_set_vertex_count(
const size_t N)
411 void CPointsMapXYZI::PLY_import_set_vertex(
416 idx, pt.
x, pt.
y, pt.
z, pt_color->
R, pt_color->
G, pt_color->
B);
418 this->setPoint(idx, pt.
x, pt.
y, pt.
z);
421 void CPointsMapXYZI::PLY_export_get_vertex(
430 pt_color.
R = pt_color.
G = pt_color.
B = m_intensity[idx];
433 bool CPointsMapXYZI::loadFromKittiVelodyneFile(
const std::string& filename)
443 if (f_gz.
open(filename)) f = &f_gz;
447 if (f_normal.
open(filename)) f = &f_normal;
451 "Could not open thefile: `%s`", filename.c_str());
454 this->reserve(10000);
458 constexpr std::size_t nToRead =
sizeof(float) * 4;
460 std::size_t nRead = f->
Read(&xyzi, nToRead);
463 else if (nRead == nToRead)
465 m_x.push_back(xyzi[0]);
466 m_y.push_back(xyzi[1]);
467 m_z.push_back(xyzi[2]);
468 m_intensity.push_back(xyzi[3]);
471 throw std::runtime_error(
472 "Unexpected EOF at the middle of a XYZI record " 473 "(truncated or corrupted file?)");
475 this->mark_as_modified();
478 catch (
const std::exception& e)
480 std::cerr <<
"[loadFromKittiVelodyneFile] " << e.what() << std::endl;
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
static Ptr Create(Args &&... args)
#define THROW_EXCEPTION(msg)
int void fclose(FILE *f)
An OS-independent version of fclose.
mrpt::maps::CPointsMap::TLikelihoodOptions likelihoodOpts
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
mrpt::aligned_std_vector< float > m_intensity
The intensity/reflectance data.
virtual size_t Read(void *Buffer, size_t Count)=0
Introduces a pure virtual method responsible for reading from the stream.
static void internal_loadFromRangeScan3D_prepareOneRange(CPointsMapXYZI &me, const float gx, const float gy, const float gz, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called once pe...
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
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.
static void internal_loadFromRangeScan3D_postOneRange(CPointsMapXYZI &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called once pe...
GLsizei GLsizei GLuint * obj
static void internal_loadFromRangeScan3D_init(CPointsMapXYZI &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called only on...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
static void internal_loadFromRangeScan2D_init(CPointsMapXYZI &me, mrpt::maps::CPointsMap::TLaserRange2DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called only on...
#define ASSERT_(f)
Defines an assertion mechanism.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
This class allows loading and storing values and vectors of different types from a configuration text...
This base provides a set of functions for maths stuff.
Lightweight 3D point (float version).
This namespace contains representation of robot actions and observations.
static void internal_loadFromRangeScan2D_postPushBack(CPointsMapXYZI &me, mrpt::maps::CPointsMap::TLaserRange2DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called after e...
std::string extractFileExtension(const std::string &filePath, bool ignore_gz=false)
Extract the extension of a filename.
static void internal_loadFromRangeScan3D_postPushBack(CPointsMapXYZI &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called after e...
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
A map of 3D points with reflectance/intensity (float).
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define MAP_DEFINITION_REGISTER(_CLASSNAME_STRINGS, _CLASSNAME_WITH_NS)
Registers one map class into TMetricMapInitializer factory.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Virtual base class for "archives": classes abstracting I/O streams.
void vector_strong_clear(VECTOR_T &v)
Like calling a std::vector<>'s clear() method, but really forcing deallocating the memory...
Declares a virtual base class for all metric maps storage classes.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
A RGB color - floats in the range [0,1].
GLsizei GLsizei GLchar * source
Helper struct used for internal_loadFromRangeScan3D_prepareOneRange()
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
static void internal_loadFromRangeScan2D_prepareOneRange(CPointsMapXYZI &me, const float gx, const float gy, const float gz, mrpt::maps::CPointsMap::TLaserRange2DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called once pe...
mrpt::maps::CPointsMap::TInsertionOptions insertionOpts
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
unsigned __int32 uint32_t
size_t size() const
Returns the number of stored points in the map.
void clear()
Clear the contents of this container.
Helper struct used for internal_loadFromRangeScan2D_prepareOneRange()
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.