36 void CColouredPointsMap::TMapDefinition::loadFromConfigFile_map_specific(
41 source, sectionNamePrefix +
string(
"_insertOpts"));
42 likelihoodOpts.loadFromConfigFile(
43 source, sectionNamePrefix +
string(
"_likelihoodOpts"));
44 colourOpts.loadFromConfigFile(
45 source, sectionNamePrefix +
string(
"_colorOpts"));
48 void CColouredPointsMap::TMapDefinition::dumpToTextStream_map_specific(
51 this->insertionOpts.dumpToTextStream(out);
52 this->likelihoodOpts.dumpToTextStream(out);
53 this->colourOpts.dumpToTextStream(out);
72 #include <pcl/io/pcd_io.h> 73 #include <pcl/point_types.h> 80 CColouredPointsMap::CColouredPointsMap() {}
84 CColouredPointsMap::~CColouredPointsMap() {}
88 void CColouredPointsMap::reserve(
size_t newLength)
95 m_color_R.reserve(newLength);
96 m_color_G.reserve(newLength);
97 m_color_B.reserve(newLength);
103 void CColouredPointsMap::resize(
size_t newLength)
105 this->reserve(newLength);
107 x.resize(newLength, 0);
108 y.resize(newLength, 0);
109 z.resize(newLength, 0);
110 m_color_R.resize(newLength, 1);
111 m_color_G.resize(newLength, 1);
112 m_color_B.resize(newLength, 1);
121 this->reserve(newLength);
123 x.assign(newLength, 0);
124 y.assign(newLength, 0);
125 z.assign(newLength, 0);
126 m_color_R.assign(newLength, 1);
127 m_color_G.assign(newLength, 1);
128 m_color_B.assign(newLength, 1);
137 CPointsMap::base_copyFrom(
156 void CColouredPointsMap::writeToStream(
174 out << m_color_R << m_color_G << m_color_B;
176 out << genericMapParams;
177 insertionOptions.writeToStream(
179 likelihoodOptions.writeToStream(out);
205 in.ReadBufferFixEndianness(&
x[0],
n);
206 in.ReadBufferFixEndianness(&
y[0],
n);
207 in.ReadBufferFixEndianness(&
z[0],
n);
209 in >> m_color_R >> m_color_G >> m_color_B;
212 in >> genericMapParams;
215 bool disableSaveAs3DObject;
216 in >> disableSaveAs3DObject;
217 genericMapParams.enableSaveAs3DObject = !disableSaveAs3DObject;
219 insertionOptions.readFromStream(
in);
220 likelihoodOptions.readFromStream(
in);
243 in.ReadBufferFixEndianness(&
x[0],
n);
244 in.ReadBufferFixEndianness(&
y[0],
n);
245 in.ReadBufferFixEndianness(&
z[0],
n);
264 std::vector<uint32_t> dummy_pointWeight(
n);
265 in.ReadBufferFixEndianness(
266 &dummy_pointWeight[0],
n);
271 std::vector<uint32_t> dummy_pointWeight(
n);
272 in.ReadBufferFixEndianness(&dummy_pointWeight[0],
n);
280 in >> insertionOptions.minDistBetweenLaserPoints >>
281 insertionOptions.addToExistingPointsMap >>
282 insertionOptions.also_interpolate >>
283 insertionOptions.disableDeletion >>
284 insertionOptions.fuseWithExisting >>
285 insertionOptions.isPlanarMap;
289 bool old_matchStaticPointsOnly;
290 in >> old_matchStaticPointsOnly;
293 in >> insertionOptions.maxDistForInterpolatePoints;
295 bool disableSaveAs3DObject;
296 in >> disableSaveAs3DObject;
297 genericMapParams.enableSaveAs3DObject =
298 !disableSaveAs3DObject;
304 in >> insertionOptions.horizontalTolerance;
309 in >> m_color_R >> m_color_G >> m_color_B;
316 std::vector<float> dummy_dist;
322 m_color_R.assign(
x.size(), 1.0f);
323 m_color_G.assign(
x.size(), 1.0f);
324 m_color_B.assign(
x.size(), 1.0f);
329 likelihoodOptions.readFromStream(
in);
332 in >> insertionOptions.insertInvalidPoints;
343 void CColouredPointsMap::internal_clear()
360 void CColouredPointsMap::setPoint(
361 size_t index,
float x,
float y,
float z,
float R,
float G,
float B)
367 this->m_color_R[
index] =
R;
368 this->m_color_G[
index] = G;
369 this->m_color_B[
index] = B;
376 void CColouredPointsMap::setPointColor(
size_t index,
float R,
float G,
float B)
379 this->m_color_R[
index] =
R;
380 this->m_color_G[
index] = G;
381 this->m_color_B[
index] = B;
385 void CColouredPointsMap::insertPointFast(
float x,
float y,
float z)
387 this->x.push_back(
x);
388 this->y.push_back(
y);
389 this->z.push_back(
z);
390 m_color_R.push_back(1);
391 m_color_G.push_back(1);
392 m_color_B.push_back(1);
397 void CColouredPointsMap::insertPoint(
398 float x,
float y,
float z,
float R,
float G,
float B)
400 this->x.push_back(
x);
401 this->y.push_back(
y);
402 this->z.push_back(
z);
403 m_color_R.push_back(
R);
404 m_color_G.push_back(G);
405 m_color_B.push_back(B);
413 void CColouredPointsMap::getAs3DObject(
418 if (!genericMapParams.enableSaveAs3DObject)
return;
421 mrpt::make_aligned_shared<opengl::CPointCloudColoured>();
423 obj->loadFromPointsMap(
this);
424 obj->setColor(1, 1, 1, 1.0);
434 CColouredPointsMap::TColourOptions::TColourOptions()
435 : scheme(cmFromHeightRelativeToSensor), z_min(-10), z_max(10), d_max(5)
442 scheme =
source.read_enum(section,
"scheme", scheme);
452 "\n----------- [CColouredPointsMap::TColourOptions] ------------ \n\n");
455 "scheme = %u\n", (
unsigned)scheme);
456 out.
printf(
"z_min = %f\n", z_min);
457 out.
printf(
"z_max = %f\n", z_max);
458 out.
printf(
"d_max = %f\n", d_max);
465 size_t index,
float&
x,
float&
y,
float&
z)
const 480 size_t index,
float&
x,
float&
y,
float&
z,
float&
R,
float& G,
497 size_t index,
float&
R,
float& G,
float& B)
const 515 const double x = P.
x / P.
z;
516 const double y = P.
y / P.
z;
520 const double r4 =
square(r2);
521 const double r6 = r2 * r4;
548 cameraPoseW = robotPose + cameraPoseR;
555 std::vector<TPixelCoordf>
559 std::vector<size_t> p_idx;
560 std::vector<float> p_dist;
561 std::vector<unsigned int> p_proj;
565 cameraPoseW.
x(), cameraPoseW.
y(),
570 for (
size_t k = 0; k < p_idx.size(); k++)
572 float d = sqrt(p_dist[k]);
573 size_t idx = p_idx[k];
579 projectedPoints.push_back(px);
585 unsigned int chR, chG, chB;
599 unsigned int n_proj = 0;
600 const float factor = 1.0f / 255;
604 for (itProPoints = projectedPoints.begin(), k = 0;
605 itProPoints != projectedPoints.end(); ++itProPoints, ++k)
608 if (itProPoints->x >= 0 && itProPoints->x < imgW &&
609 itProPoints->y > 0 && itProPoints->y < imgH)
611 unsigned int ii = p_idx[p_proj[k]];
613 (
unsigned int)itProPoints->x, (
unsigned int)itProPoints->y);
637 if (!f)
return false;
639 for (
unsigned int i = 0; i <
x.size(); i++)
641 f,
"%f %f %f %d %d %d\n",
x[i],
y[i],
z[i],
672 idx, pt.
x, pt.
y, pt.
z, pt_color->
R, pt_color->
G, pt_color->
B);
701 const CPointsMap& anotherMap,
const size_t nPreviousPoints)
703 const size_t nOther = anotherMap.
size();
711 for (
size_t i = 0, j = nPreviousPoints; i < nOther; i++, j++)
723 const std::string& filename,
bool save_as_binary)
const 726 pcl::PointCloud<pcl::PointXYZRGB> cloud;
728 const size_t nThis = this->
size();
733 cloud.is_dense =
false;
734 cloud.points.resize(cloud.width * cloud.height);
736 const float f = 255.f;
743 for (
size_t i = 0; i < nThis; ++i)
745 cloud.points[i].x = this->
x[i];
746 cloud.points[i].y = this->
y[i];
747 cloud.points[i].z = this->
z[i];
753 cloud.points[i].rgb = aux_val.f;
756 return 0 == pcl::io::savePCDFile(filename, cloud, save_as_binary);
789 lric.
fVars.resize(4);
804 const float rel_z = gz - lric.
HM.get_unsafe(2, 3);
807 float& pR = lric.
fVars[0];
808 float& pG = lric.
fVars[1];
809 float& pB = lric.
fVars[2];
810 const float& Az_1_color = lric.
fVars[3];
853 float& pR = lric.
fVars[0];
854 float& pG = lric.
fVars[1];
855 float& pB = lric.
fVars[2];
880 lric.
fVars.resize(9);
881 float& cx = lric.
fVars[5];
882 float& cy = lric.
fVars[6];
883 float& fx = lric.
fVars[7];
884 float& fy = lric.
fVars[8];
891 lric.
uVars.resize(4);
892 unsigned int& imgW = lric.
uVars[0];
893 unsigned int& imgH = lric.
uVars[1];
894 unsigned int& img_idx_x = lric.
uVars[2];
895 unsigned int& img_idx_y = lric.
uVars[3];
901 lric.
bVars.resize(3);
909 lric.
fVars[4] = 1.0f / 255;
911 hasValidIntensityImage =
false;
922 hasValidIntensityImage =
true;
928 hasColorIntensityImg =
937 simple_3d_to_color_relation =
959 float& pR = lric.
fVars[0];
960 float& pG = lric.
fVars[1];
961 float& pB = lric.
fVars[2];
962 float& Az_1_color = lric.
fVars[3];
963 float& K_8u = lric.
fVars[4];
964 float& cx = lric.
fVars[5];
965 float& cy = lric.
fVars[6];
966 float& fx = lric.
fVars[7];
967 float& fy = lric.
fVars[8];
969 unsigned int& imgW = lric.
uVars[0];
970 unsigned int& imgH = lric.
uVars[1];
971 unsigned int& img_idx_x = lric.
uVars[2];
972 unsigned int& img_idx_y = lric.
uVars[3];
976 const uint8_t& simple_3d_to_color_relation = lric.
bVars[2];
979 const float rel_z = gz - lric.
HM.get_unsafe(2, 3);
1008 bool hasValidColor =
false;
1009 if (simple_3d_to_color_relation)
1011 hasValidColor =
true;
1025 img_idx_x = cx + fx * pt.
x / pt.
z;
1026 img_idx_y = cy + fy * pt.
y / pt.
z;
1028 hasValidColor = img_idx_x < imgW &&
1035 if (hasValidColor && hasColorIntensityImg)
1038 img_idx_x, img_idx_y, 0);
1043 else if (hasValidColor && hasValidIntensityImage)
1046 img_idx_x, img_idx_y, 0);
1047 pR = pG = pB =
c * K_8u;
1067 float& pR = lric.
fVars[0];
1068 float& pG = lric.
fVars[1];
1069 float& pB = lric.
fVars[2];
1086 unsigned int& imgW = lric.
uVars[0];
1087 unsigned int& img_idx_x = lric.
uVars[2];
1088 unsigned int& img_idx_y = lric.
uVars[3];
1091 const uint8_t& simple_3d_to_color_relation = lric.
bVars[2];
1095 if (simple_3d_to_color_relation && hasValidIntensityImage)
1097 if (++img_idx_x >= imgW)
virtual void getPoint(size_t index, float &x, float &y, float &z, float &R, float &G, float &B) const override
Retrieves a point and its color (colors range is [0,1])
static void internal_loadFromRangeScan3D_prepareOneRange(CColouredPointsMap &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...
virtual void setSize(size_t newLength) override
Resizes all point buffers so they can hold the given number of points, erasing all previous contents ...
std::vector< float > m_color_G
A pair (x,y) of pixel coordinates (subpixel resolution).
double x() const
Common members of all points & poses classes.
virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) override
Auxiliary method called from within addFrom() automatically, to finish the copying of class-specific ...
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
bool save3D_and_colour_to_text_file(const std::string &file) const
Save to a text file.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
const mrpt::obs::CObservation3DRangeScan & rangeScan
mrpt::utils::TCamera cameraParamsIntensity
Projection parameters of the intensity (graylevel or RGB) camera.
int void fclose(FILE *f)
An OS-independent version of fclose.
void aux_projectPoint_with_distortion(const mrpt::math::TPoint3D &P, const mrpt::utils::TCamera ¶ms, mrpt::utils::TPixelCoordf &pixel, bool accept_points_behind)
mrpt::utils::TCamera cameraParams
Intrinsic and distortion parameters of the camera.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define THROW_EXCEPTION(msg)
GLdouble GLdouble GLdouble GLdouble q
double cy() const
Get the value of the principal point y-coordinate (in pixels).
const char * getChannelsOrder() const
Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering.
std::vector< float > m_color_B
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 kdTreeNClosestPoint2DIdx(float x0, float y0, size_t knn, std::vector< size_t > &out_idx, std::vector< float > &out_dist_sqr) const
KD Tree-based search for the N closest point to some given 2D coordinates and returns their indexes...
GLsizei GLsizei GLuint * obj
static void internal_loadFromRangeScan2D_prepareOneRange(CColouredPointsMap &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...
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string §ion) override
This method load the options from a ".ini"-like file or memory-stored string list.
TColourOptions colorScheme
The options employed when inserting laser scans in the map.
This class allows loading and storing values and vectors of different types from a configuration text...
T square(const T x)
Inline function for the square of a number.
mrpt::maps::CPointsMap::TLikelihoodOptions likelihoodOpts
double fx() const
Get the value of the focal length x-value (in pixels).
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
double fy() const
Get the value of the focal length y-value (in pixels).
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
This base provides a set of functions for maths stuff.
size_t getWidth() const override
Returns the width of the image in pixels.
mrpt::poses::CPose3D relativePoseIntensityWRTDepth
Relative pose of the intensity camera wrt the depth camera (which is the coordinates origin for this ...
void dumpToTextStream(mrpt::utils::CStream &out) const override
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
Lightweight 3D point (float version).
T length2length4N(T len)
Returns the smaller number >=len such that it's a multiple of 4.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
double norm() const
Returns the euclidean norm of vector: .
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
mrpt::math::CMatrixDouble44 HM
Homog matrix of the local sensor pose within the robot.
virtual void PLY_import_set_vertex(const size_t idx, const mrpt::math::TPoint3Df &pt, const mrpt::utils::TColorf *pt_color=nullptr) override
In a base class, will be called after PLY_import_set_vertex_count() once for each loaded point...
size_t getHeight() const override
Returns the height of the image in pixels.
float scan_x
In internal_loadFromRangeScan3D_prepareOneRange, these are the local coordinates of the scan points b...
void PLY_export_get_vertex(const size_t idx, mrpt::math::TPoint3Df &pt, bool &pt_has_color, mrpt::utils::TColorf &pt_color) const override
In a base class, will be called after PLY_export_get_vertex_count() once for each exported point...
std::shared_ptr< CSetOfObjects > Ptr
static void internal_loadFromRangeScan2D_init(CColouredPointsMap &me, mrpt::maps::CPointsMap::TLaserRange2DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called only on...
This namespace contains representation of robot actions and observations.
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
virtual void PLY_import_set_vertex_count(const size_t N) override
In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex.
std::vector< float > fVars
Extra variables to be used as desired by the derived class.
double x
X,Y,Z coordinates.
static void templ_loadFromRangeScan(Derived &obj, const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose)
mrpt::maps::CColouredPointsMap::TColourOptions colourOpts
virtual bool savePCDFile(const std::string &filename, bool save_as_binary) const override
Save the point cloud as a PCL PCD file, in either ASCII or binary format.
static void internal_loadFromRangeScan3D_postPushBack(CColouredPointsMap &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called after e...
A map of 2D/3D points with individual colours (RGB).
mrpt::maps::CPointsMap::TInsertionOptions insertionOpts
GLsizei const GLchar ** string
double cx() const
Get the value of the principal point x-coordinate (in pixels).
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
std::vector< float > fVars
Extra variables to be used as desired by the derived class.
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string §ionNamePrefix) override
Load all params from a config file/source.
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
void vector_strong_clear(VECTOR_T &v)
Like calling a std::vector<>'s clear() method, but really forcing deallocating the memory...
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...
#define ASSERT_NOT_EQUAL_(__A, __B)
void POINTSMAPS_3DOBJECT_POINTSIZE(float value)
The size of points when exporting with getAs3DObject() (default=3.0) Affects to:
Declares a virtual base class for all metric maps storage classes.
virtual void setPoint(size_t index, float x, float y, float z, float R, float G, float B) override
Changes a given point from map.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void resetPointsMinDist(float defValue=2000.0f)
Reset the minimum-observed-distance buffer for all the points to a predefined value.
virtual void loadFromRangeScan(const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose=nullptr) override
See CPointsMap::loadFromRangeScan()
bool hasIntensityImage
true means the field intensityImage contains valid data
void jet2rgb(const float color_index, float &r, float &g, float &b)
Computes the RGB color components (range [0,1]) for the corresponding color index in the range [0...
std::vector< uint8_t > bVars
std::vector< float > points3D_x
If hasPoints3D=true, the (X,Y,Z) coordinates of the 3D point cloud detected by the camera...
GLsizei GLsizei GLchar * source
A RGB color - floats in the range [0,1].
mrpt::utils::CImage image
The image captured by the camera, that is, the main piece of information of this observation.
Helper struct used for internal_loadFromRangeScan3D_prepareOneRange()
std::vector< float > m_color_R
The color data.
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const override
A general method to retrieve the sensor pose on the robot.
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
unsigned char * get_unsafe(unsigned int col, unsigned int row, unsigned int channel=0) const
Access to pixels without checking boundaries - Use normally the () operator better, which checks the coordinates.
static void internal_loadFromRangeScan2D_postPushBack(CColouredPointsMap &me, mrpt::maps::CPointsMap::TLaserRange2DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called after e...
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
mrpt::utils::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage"...
mrpt::math::CMatrixDouble44 HM
Homog matrix of the local sensor pose within the robot.
unsigned __int32 uint32_t
bool colourFromObservation(const mrpt::obs::CObservationImage &obs, const mrpt::poses::CPose3D &robotPose)
Colour a set of points from a CObservationImage and the global pose of the robot. ...
size_t size() const
Returns the number of stored points in the map.
std::shared_ptr< CPointCloudColoured > Ptr
GLenum const GLfloat * params
void getPointColor(size_t index, float &R, float &G, float &B) const
Retrieves a point color (colors range is [0,1])
static void internal_loadFromRangeScan3D_postOneRange(CColouredPointsMap &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called once pe...
Helper struct used for internal_loadFromRangeScan2D_prepareOneRange()
static void internal_loadFromRangeScan3D_init(CColouredPointsMap &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called only on...
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
Structure to hold the parameters of a pinhole camera model.
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr) const
Computes the 3D point L such as .
std::vector< unsigned int > uVars