42 likelihoodOpts.loadFromConfigFile(
source, sectionNamePrefix+
string(
"_likelihoodOpts") );
43 colourOpts.loadFromConfigFile(
source, sectionNamePrefix+
string(
"_colorOpts") );
48 this->insertionOpts.dumpToTextStream(out);
49 this->likelihoodOpts.dumpToTextStream(out);
50 this->colourOpts.dumpToTextStream(out);
69 # include <pcl/io/pcd_io.h> 70 # include <pcl/point_types.h> 77 CColouredPointsMap::CColouredPointsMap()
84 CColouredPointsMap::~CColouredPointsMap()
91 void CColouredPointsMap::reserve(
size_t newLength)
95 x.reserve( newLength );
96 y.reserve( newLength );
97 z.reserve( newLength );
98 m_color_R.reserve( newLength );
99 m_color_G.reserve( newLength );
100 m_color_B.reserve( newLength );
105 void CColouredPointsMap::resize(
size_t newLength)
107 this->reserve(newLength);
109 x.resize( newLength, 0 );
110 y.resize( newLength, 0 );
111 z.resize( newLength, 0 );
112 m_color_R.resize( newLength, 1 );
113 m_color_G.resize( newLength, 1 );
114 m_color_B.resize( newLength, 1 );
122 this->reserve(newLength);
124 x.assign( newLength, 0);
125 y.assign( newLength, 0);
126 z.assign( newLength, 0);
127 m_color_R.assign( newLength, 1 );
128 m_color_G.assign( newLength, 1 );
129 m_color_B.assign( newLength, 1 );
139 CPointsMap::base_copyFrom(
obj);
177 out << m_color_R << m_color_G << m_color_B;
179 out << genericMapParams;
180 insertionOptions.writeToStream(out);
181 likelihoodOptions.writeToStream(out);
207 in.ReadBufferFixEndianness(&
x[0],
n);
208 in.ReadBufferFixEndianness(&
y[0],
n);
209 in.ReadBufferFixEndianness(&
z[0],
n);
211 in >> m_color_R >> m_color_G >> m_color_B;
214 in >> genericMapParams;
217 bool disableSaveAs3DObject;
218 in >> disableSaveAs3DObject;
219 genericMapParams.enableSaveAs3DObject = !disableSaveAs3DObject;
221 insertionOptions.readFromStream(
in);
222 likelihoodOptions.readFromStream(
in);
244 in.ReadBufferFixEndianness(&
x[0],
n);
245 in.ReadBufferFixEndianness(&
y[0],
n);
246 in.ReadBufferFixEndianness(&
z[0],
n);
262 std::vector<uint32_t> dummy_pointWeight(
n);
263 in.ReadBufferFixEndianness(&dummy_pointWeight[0],
n);
268 std::vector<uint32_t> dummy_pointWeight(
n);
269 in.ReadBufferFixEndianness(&dummy_pointWeight[0],
n);
277 in >> insertionOptions.minDistBetweenLaserPoints
278 >> insertionOptions.addToExistingPointsMap
279 >> insertionOptions.also_interpolate
280 >> insertionOptions.disableDeletion
281 >> insertionOptions.fuseWithExisting
282 >> insertionOptions.isPlanarMap;
286 bool old_matchStaticPointsOnly;
287 in >> old_matchStaticPointsOnly;
290 in >> insertionOptions.maxDistForInterpolatePoints;
292 bool disableSaveAs3DObject;
293 in >> disableSaveAs3DObject;
294 genericMapParams.enableSaveAs3DObject = !disableSaveAs3DObject;
300 in >> insertionOptions.horizontalTolerance;
305 in >> m_color_R >> m_color_G >> m_color_B;
312 std::vector<float> dummy_dist;
318 m_color_R.assign(
x.size(),1.0f);
319 m_color_G.assign(
x.size(),1.0f);
320 m_color_B.assign(
x.size(),1.0f);
325 likelihoodOptions.readFromStream(
in);
328 in >> insertionOptions.insertInvalidPoints;
341 void CColouredPointsMap::internal_clear()
359 void CColouredPointsMap::setPoint(
size_t index,
float x,
float y,
float z,
float R,
float G,
float B)
361 if (
index>=this->x.size())
367 this->m_color_G[
index]=G;
368 this->m_color_B[
index]=B;
375 void CColouredPointsMap::setPointColor(
size_t index,
float R,
float G,
float B)
377 if (
index>=this->
x.size())
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(
float x,
float y,
float z,
float R,
float G,
float B )
399 this->x.push_back(
x);
400 this->y.push_back(
y);
401 this->z.push_back(
z);
402 m_color_R.push_back(
R);
403 m_color_G.push_back(G);
404 m_color_B.push_back(B);
412 void CColouredPointsMap::getAs3DObject( mrpt::opengl::CSetOfObjectsPtr &outObj )
const 416 if (!genericMapParams.enableSaveAs3DObject)
return;
418 opengl::CPointCloudColouredPtr
obj = opengl::CPointCloudColoured::Create();
420 obj->loadFromPointsMap(
this);
421 obj->setColor(1,1,1, 1.0);
431 CColouredPointsMap::TColourOptions::TColourOptions() :
432 scheme(cmFromHeightRelativeToSensor),
457 out.
printf(
"\n----------- [CColouredPointsMap::TColourOptions] ------------ \n\n");
459 out.
printf(
"scheme = %u\n", (
unsigned)scheme);
460 out.
printf(
"z_min = %f\n", z_min );
461 out.
printf(
"z_max = %f\n", z_max );
462 out.
printf(
"d_max = %f\n", d_max );
470 if (
index >= this->x.size())
485 if (
index >= this->x.size())
501 if (
index >= this->
x.size())
515 bool accept_points_behind
520 const double x = P.
x/P.
z;
521 const double y = P.
y/P.
z;
525 const double r4 =
square(r2);
526 const double r6 = r2*r4;
545 cameraPoseW = robotPose + cameraPoseR;
552 std::vector<TPixelCoordf> projectedPoints;
554 std::vector<size_t> p_idx;
555 std::vector<float> p_dist;
556 std::vector<unsigned int> p_proj;
564 for(
size_t k = 0; k < p_idx.size(); k++ )
566 float d = sqrt(p_dist[k]);
567 size_t idx = p_idx[k];
572 projectedPoints.push_back(px);
578 unsigned int chR,chG,chB;
580 else { chR = 0; chG = 1; chB = 2; }
582 unsigned int n_proj = 0;
583 const float factor = 1.0f/255;
587 for( itProPoints = projectedPoints.begin(), k = 0;
588 itProPoints != projectedPoints.end();
592 if( itProPoints->x >= 0 && itProPoints->x < imgW && itProPoints->y > 0 && itProPoints->y < imgH )
594 unsigned int ii = p_idx[p_proj[k]];
595 uint8_t *
p = obs.
image( (
unsigned int)itProPoints->x, (
unsigned int)itProPoints->y );
620 if (!f)
return false;
622 for (
unsigned int i=0;i<
x.size();i++)
645 this->
setPoint(idx,pt.
x,pt.
y,pt.
z,pt_color->
R,pt_color->
G,pt_color->
B);
675 const size_t nOther = anotherMap.
size();
682 for (
size_t i=0,j=nPreviousPoints;i<nOther;i++, j++)
695 pcl::PointCloud<pcl::PointXYZRGB> cloud;
697 const size_t nThis = this->
size();
702 cloud.is_dense =
false;
703 cloud.points.resize (cloud.width * cloud.height);
705 const float f = 255.f;
713 for (
size_t i = 0; i < nThis; ++i)
715 cloud.points[i].x =this->
x[i];
716 cloud.points[i].y =this->
y[i];
717 cloud.points[i].z =this->
z[i];
723 cloud.points[i].rgb = aux_val.f;
726 return 0 == pcl::io::savePCDFile(filename, cloud, save_as_binary);
749 lric.
fVars.resize(4);
760 const float rel_z = gz - lric.
HM.get_unsafe(2,3);
763 float & pR = lric.
fVars[0];
764 float & pG = lric.
fVars[1];
765 float & pB = lric.
fVars[2];
766 const float &Az_1_color = lric.
fVars[3];
776 if (
q<0)
q=0;
else if (
q>1)
q=1;
802 float & pR = lric.
fVars[0];
803 float & pG = lric.
fVars[1];
804 float & pB = lric.
fVars[2];
825 lric.
fVars.resize(9);
826 float &cx = lric.
fVars[5];
827 float &cy = lric.
fVars[6];
828 float &fx = lric.
fVars[7];
829 float &fy = lric.
fVars[8];
836 lric.
uVars.resize(4);
837 unsigned int & imgW = lric.
uVars[0];
838 unsigned int & imgH = lric.
uVars[1];
839 unsigned int & img_idx_x = lric.
uVars[2];
840 unsigned int & img_idx_y = lric.
uVars[3];
846 lric.
bVars.resize(3);
853 lric.
fVars[4] = 1.0f/255;
855 hasValidIntensityImage =
false;
864 hasValidIntensityImage =
true;
894 float &pR = lric.
fVars[0];
895 float &pG = lric.
fVars[1];
896 float &pB = lric.
fVars[2];
897 float &Az_1_color = lric.
fVars[3];
898 float &K_8u = lric.
fVars[4];
899 float &cx = lric.
fVars[5];
900 float &cy = lric.
fVars[6];
901 float &fx = lric.
fVars[7];
902 float &fy = lric.
fVars[8];
904 unsigned int & imgW = lric.
uVars[0];
905 unsigned int & imgH = lric.
uVars[1];
906 unsigned int & img_idx_x = lric.
uVars[2];
907 unsigned int & img_idx_y = lric.
uVars[3];
911 const uint8_t & simple_3d_to_color_relation = lric.
bVars[2];
914 const float rel_z = gz - lric.
HM.get_unsafe(2,3);
924 if (
q<0)
q=0;
else if (
q>1)
q=1;
939 bool hasValidColor =
false;
940 if (simple_3d_to_color_relation)
955 img_idx_x = cx + fx * pt.
x/pt.
z;
956 img_idx_y = cy + fy * pt.
y/pt.
z;
964 if (hasValidColor && hasColorIntensityImg)
972 if (hasValidColor && hasValidIntensityImage)
992 float &pR = lric.
fVars[0];
993 float &pG = lric.
fVars[1];
994 float &pB = lric.
fVars[2];
1008 unsigned int & imgW = lric.
uVars[0];
1009 unsigned int & img_idx_x = lric.
uVars[2];
1010 unsigned int & img_idx_y = lric.
uVars[3];
1012 const uint8_t & hasValidIntensityImage = lric.
bVars[0];
1013 const uint8_t & simple_3d_to_color_relation = lric.
bVars[2];
1016 if (simple_3d_to_color_relation && hasValidIntensityImage)
1018 if (++img_idx_x>=imgW)
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...
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 base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
TColouringMethod
The choices for coloring schemes:
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.
virtual void setSize(size_t newLength) MRPT_OVERRIDE
Resizes all point buffers so they can hold the given number of points, erasing all previous contents ...
void PLY_export_get_vertex(const size_t idx, mrpt::math::TPoint3Df &pt, bool &pt_has_color, mrpt::utils::TColorf &pt_color) const MRPT_OVERRIDE
In a base class, will be called after PLY_export_get_vertex_count() once for each exported point...
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string §ionNamePrefix) MRPT_OVERRIDE
Load all params from a config file/source.
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 BASE_IMPEXP void BASE_IMPEXP 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 THROW_EXCEPTION(msg)
GLdouble GLdouble GLdouble GLdouble q
virtual void loadFromRangeScan(const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose=NULL) MRPT_OVERRIDE
See CPointsMap::loadFromRangeScan()
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.
virtual void PLY_import_set_vertex_count(const size_t N) MRPT_OVERRIDE
In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex.
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
double z
X,Y,Z coordinates.
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...
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
void dumpToTextStream(mrpt::utils::CStream &out) const MRPT_OVERRIDE
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
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...
virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) MRPT_OVERRIDE
Auxiliary method called from within addFrom() automatically, to finish the copying of class-specific ...
TColourOptions colorScheme
The options employed when inserting laser scans in the map.
float scan_z
In internal_loadFromRangeScan3D_prepareOneRange, these are the local coordinates of the scan points b...
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...
virtual bool savePCDFile(const std::string &filename, bool save_as_binary) const MRPT_OVERRIDE
Save the point cloud as a PCL PCD file, in either ASCII or binary format.
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.
virtual void getPoint(size_t index, float &x, float &y, float &z, float &R, float &G, float &B) const MRPT_OVERRIDE
Retrieves a point and its color (colors range is [0,1])
mrpt::poses::CPose3D relativePoseIntensityWRTDepth
Relative pose of the intensity camera wrt the depth camera (which is the coordinates origin for this ...
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.
#define MRPT_LOAD_CONFIG_VAR_CAST(variableName, variableType, variableTypeCast, configFileObject, sectionNameStr)
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...
MAPS_IMPEXP float POINTSMAPS_3DOBJECT_POINTSIZE
The size of points when exporting with getAs3DObject() (default=3.0) Affects to:
std::vector< float > fVars
Extra variables to be used as desired by the derived class.
static void templ_loadFromRangeScan(Derived &obj, const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose)
mrpt::maps::CColouredPointsMap::TColourOptions colourOpts
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).
virtual void PLY_import_set_vertex(const size_t idx, const mrpt::math::TPoint3Df &pt, const mrpt::utils::TColorf *pt_color=NULL) MRPT_OVERRIDE
In a base class, will be called after PLY_import_set_vertex_count() once for each loaded point...
mrpt::maps::CPointsMap::TInsertionOptions insertionOpts
virtual void setPoint(size_t index, float x, float y, float z, float R, float G, float B) MRPT_OVERRIDE
Changes a given point from map.
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.
#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...
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.
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=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL) const
Computes the 3D point L such as .
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
#define ASSERT_NOT_EQUAL_(__A, __B)
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).
void resetPointsMinDist(float defValue=2000.0f)
Reset the minimum-observed-distance buffer for all the points to a predefined value.
bool hasIntensityImage
true means the field intensityImage contains valid data
void BASE_IMPEXP 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
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.
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...
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
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string §ion) MRPT_OVERRIDE
This method load the options from a ".ini"-like file or memory-stored string list.
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.
GLenum const GLfloat * params
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels.
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.
size_t getHeight() const MRPT_OVERRIDE
Returns the height of the image in pixels.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const MRPT_OVERRIDE
A general method to retrieve the sensor pose on the robot.
std::vector< unsigned int > uVars