Main MRPT website > C++ reference for MRPT 1.9.9
CRangeScanOps_impl.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef CRANGESCANOPS_IMPL_H
11 #define CRANGESCANOPS_IMPL_H
12 
13 namespace mrpt
14 {
15 namespace graphslam
16 {
17 namespace deciders
18 {
19 template <class GRAPH_T>
23  const mrpt::poses::CPose2D* initial_pose_in /* = nullptr */,
24  mrpt::slam::CICP::TReturnInfo* icp_info /* = nullptr */)
25 {
26  MRPT_START;
27 
29  float running_time;
31 
32  // have them initialized prior - and then just clear them
33  m1.insertObservation(&from);
34  m2.insertObservation(&to);
35 
36  // If given, use initial_pose_in as a first guess for the ICP
37  mrpt::poses::CPose2D initial_pose;
38  if (initial_pose_in)
39  {
40  initial_pose = *initial_pose_in;
41  }
42 
44  params.icp.Align(&m1, &m2, initial_pose, &running_time, (void*)&info);
45 
46  // return the edge regardless of the goodness of the alignment
47  rel_edge->copyFrom(*pdf);
48 
49  // if given, fill the TReturnInfo Struct
50  if (icp_info) *icp_info = info;
51 
52  MRPT_END;
53 }
54 template <class GRAPH_T>
58  const mrpt::poses::CPose2D* initial_pose_in /* =nullptr */,
59  mrpt::slam::CICP::TReturnInfo* icp_info /* =nullptr */)
60 {
61  MRPT_START;
62 
63  ASSERTMSG_(
64  from.hasRangeImage,
65  mrpt::format("Laser scan doesn't contain valid range image"));
66  ASSERTMSG_(
67  to.hasRangeImage,
68  mrpt::format("Laser scan doesn't contain valid range image"));
69 
70  // TODO - have this as a class member
72  float running_time;
74 
75  m1.insertObservation(&from);
76  m2.insertObservation(&to);
77 
78  // this->decimatePointsMap(&m1, [> keep every = */ 40, /* low_lim = <]
79  // 5000);
80  // this->decimatePointsMap(&m2, [> keep every = */ 40, /* low_lim = <]
81  // 5000);
82 
83  // If given, use initial_pose_in as a first guess for the ICP
84  mrpt::poses::CPose3D initial_pose;
85  if (initial_pose_in)
86  {
87  initial_pose = mrpt::poses::CPose3D(*initial_pose_in);
88  }
89 
91  params.icp.Align3D(&m1, &m2, initial_pose, &running_time, (void*)&info);
92 
93  // return the edge regardless of the goodness of the alignment
94  // copy from the 3D PDF
95  // NULLIFY contraint_t if Z displacement is high (normally this should be 0)
96  // since we are moving in 2D
97  if (fabs(pdf->getMeanVal().z()) < 0.1)
98  {
99  rel_edge->copyFrom(*pdf);
100  }
101  else
102  {
103  rel_edge = nullptr;
104  }
105 
106  // if given, fill the TReturnInfo Struct
107  if (icp_info) *icp_info = info;
108 
109  MRPT_END;
110 }
111 
112 template <class GRAPH_T>
114  mrpt::maps::CPointsMap* m, size_t keep_point_every, /* = 4 */
115  size_t low_lim /* = 8000 */)
116 {
117  MRPT_START;
118 
119  size_t map_size = m->size();
120 
121  if (low_lim)
122  {
123  // check if current keep_point_every variable is too large
124  size_t conservative_keep_point_every = map_size / low_lim;
125  keep_point_every =
126  std::min(keep_point_every, conservative_keep_point_every);
127  }
128 
129  // insert a false every "keep_point_every" points
130  std::vector<bool> deletion_mask(map_size, true);
131  for (size_t i = 0; i != map_size; ++i)
132  {
133  if (i % keep_point_every == 0)
134  {
135  deletion_mask[i] = false;
136  }
137  }
138  m->applyDeletionMask(deletion_mask);
139 
140  // std::cout << "Map size: " << map_size << " => " << m->size() <<
141  // std::endl;
142 
143  MRPT_END;
144 }
145 
146 template <class GRAPH_T>
149  mrpt::obs::CObservation2DRangeScan::Ptr* scan2D_out /*= NULL*/)
150 {
151  MRPT_START;
152 
153  bool success = false;
154  // if it doesn't exist, create it
155  if (!*scan2D_out)
156  {
157  *scan2D_out =
158  mrpt::make_aligned_shared<mrpt::obs::CObservation2DRangeScan>();
159  }
160 
161  if (scan3D_in->hasRangeImage)
162  {
163  scan3D_in->convertTo2DScan(**scan2D_out, params.conversion_params);
164  success = true;
165  }
166  else
167  {
168  std::cout << "No valid rangeImage found" << std::endl;
169  success = false;
170  }
171 
172  return success;
173  MRPT_END;
174 }
175 
176 // TParameter
177 // //////////////////////////////////
178 
179 template <class GRAPH_T>
181 {
182 }
183 
184 template <class GRAPH_T>
186 {
187 }
188 
189 template <class GRAPH_T>
191  mrpt::utils::CStream& out) const
192 {
193  MRPT_START;
194 
195  out.printf(
196  "3D=>2D LaserScan Conversion Sensor label = %s\n",
197  conversion_params.sensorLabel.c_str());
198  out.printf(
199  "3D=>2D LaserScan Conversion angle sup = %.2f deg\n",
200  mrpt::utils::RAD2DEG(conversion_params.angle_sup));
201  out.printf(
202  "3D=>2D LaserScan Conversion angle inf = %.2f deg\n",
203  mrpt::utils::RAD2DEG(conversion_params.angle_inf));
204  out.printf(
205  "3D=>2D LaserScan Conversion oversampling ratio = %.2f\n",
206  conversion_params.oversampling_ratio);
207  out.printf(
208  "3D=>2D LaserScan Conversion Z minimum = %.2f\n",
209  conversion_params.z_min);
210 
211  icp.options.dumpToTextStream(out);
212 
213  MRPT_END;
214 }
215 template <class GRAPH_T>
217  const mrpt::utils::CConfigFileBase& source, const std::string& section)
218 {
219  MRPT_START;
220 
221  conversion_params.sensorLabel = source.read_string(
222  section, "conversion_sensor_label", "KINECT_TO_2D_SCAN", false);
223  conversion_params.angle_sup = mrpt::utils::DEG2RAD(
224  source.read_double(section, "conversion_angle_sup", 10, false));
225  conversion_params.angle_inf = mrpt::utils::DEG2RAD(
226  source.read_double(section, "conversion_angle_inf", 10, false));
227  conversion_params.oversampling_ratio = source.read_double(
228  section, "conversion_oversampling_ratio", 1.1, false);
229  conversion_params.z_min = source.read_double(
230  section, "conversion_z_min", 0, false); // TODO - is this accurate?
231 
232  // load the icp parameters - from "ICP" section explicitly
233  icp.options.loadFromConfigFile(source, "ICP");
234 
235  has_read_config = true;
236 
237  MRPT_END;
238 }
239 }
240 }
241 } // end of namespaces
242 
243 #endif /* end of include guard: CRANGESCANOPS_IMPL_H */
#define min(a, b)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
double DEG2RAD(const double x)
Degrees to radians.
void getICPEdge(const mrpt::obs::CObservation2DRangeScan &from, const mrpt::obs::CObservation2DRangeScan &to, constraint_t *rel_edge, const mrpt::poses::CPose2D *initial_pose=nullptr, mrpt::slam::CICP::TReturnInfo *icp_info=nullptr)
Align the 2D range scans provided and fill the potential edge that can transform the one into the oth...
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.
std::shared_ptr< CObservation3DRangeScan > Ptr
void decimatePointsMap(mrpt::maps::CPointsMap *m, size_t keep_point_every=4, size_t low_lim=0)
Reduce the size of the given CPointsMap by keeping one out of "keep_point_every" points.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
void dumpToTextStream(mrpt::utils::CStream &out) const
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
std::shared_ptr< CObservation2DRangeScan > Ptr
This class allows loading and storing values and vectors of different types from a configuration text...
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section)
This method load the options from a ".ini"-like file or memory-stored string list.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
GRAPH_T::constraint_t constraint_t
Handy typedefs.
Definition: CRangeScanOps.h:89
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
Definition: CPointsMap.h:63
std::shared_ptr< CPosePDF > Ptr
Definition: CPosePDF.h:44
double RAD2DEG(const double x)
Radians to degrees.
#define MRPT_END
std::shared_ptr< CPose3DPDF > Ptr
Definition: CPose3DPDF.h:45
bool hasRangeImage
true means the field rangeImage contains valid data
GLsizei const GLchar ** string
Definition: glext.h:4101
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
bool convert3DTo2DRangeScan(mrpt::obs::CObservation3DRangeScan::Ptr &scan3D_in, mrpt::obs::CObservation2DRangeScan::Ptr *scan2D_out=nullptr)
Wrapper around the CObservation3DRangeScan::convertTo2DScan corresponding method. ...
The ICP algorithm return information.
Definition: CICP.h:195
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
size_t size() const
Returns the number of stored points in the map.
Definition: CPointsMap.h:385
#define ASSERTMSG_(f, __ERROR_MSG)
GLenum const GLfloat * params
Definition: glext.h:3534
bool insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=NULL)
Insert the observation information into this map.
Definition: CMetricMap.cpp:95
void applyDeletionMask(const std::vector< bool > &mask)
Remove from the map the points marked in a bool&#39;s array as "true".
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
Definition: CStream.cpp:597



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019