14 #include <mrpt/containers/yaml.h> 15 #include <mrpt/maps/CSimplePointsMap.h> 16 #include <mrpt/obs/CObservation2DRangeScan.h> 17 #include <mrpt/obs/CObservation3DRangeScan.h> 18 #include <mrpt/obs/CObservationPointCloud.h> 19 #include <mrpt/obs/CObservationRotatingScan.h> 20 #include <mrpt/obs/CObservationVelodyneScan.h> 21 #include <mrpt/obs/CSensoryFrame.h> 22 #include <mrpt/version.h> 32 MCP_LOAD_OPT(c, target_pointcloud_layer);
33 MCP_LOAD_OPT(c, process_class_names_regex);
34 MCP_LOAD_OPT(c, process_sensor_labels_regex);
35 MCP_LOAD_OPT(c, throw_on_unhandled_observation_class);
42 MRPT_LOG_DEBUG_STREAM(
"Loading these params:\n" << c);
61 "initialize() must be called once before using process().");
63 const auto obsClassName = o.GetRuntimeClass()->className;
69 bool processed =
false;
71 if (
auto o0 = dynamic_cast<const CObservationPointCloud*>(&o); o0)
73 ASSERT_(o0->pointcloud);
76 else if (
auto o1 = dynamic_cast<const CObservation2DRangeScan*>(&o); o1)
78 else if (
auto o2 = dynamic_cast<const CObservation3DRangeScan*>(&o); o2)
80 else if (
auto o3 = dynamic_cast<const CObservationVelodyneScan*>(&o); o3)
87 mrpt::maps::CPointsMap::Ptr outPc;
92 std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(itLy->second);
95 "Layer '%s' must be of point cloud type.",
100 outPc = mrpt::maps::CSimplePointsMap::Create();
104 if (!outPc) outPc = mrpt::maps::CSimplePointsMap::Create();
112 dynamic_cast<const mrpt::obs::CObservation3DRangeScan*>(&o);
113 obs3D && obs3D->points3D_x.empty())
115 mrpt::maps::CSimplePointsMap tmpMap;
117 mrpt::obs::T3DPointsProjectionParams pp;
118 pp.takeIntoAccountSensorPoseOnRobot =
true;
119 const_cast<mrpt::obs::CObservation3DRangeScan*
>(obs3D)
120 ->unprojectInto(tmpMap, pp);
122 outPc->insertAnotherMap(&tmpMap, mrpt::poses::CPose3D::Identity());
127 #if MRPT_VERSION >= 0x240 128 auto& thePc = *outPc;
130 auto* thePc = outPc.get();
132 const bool insertDone = o.insertObservationInto(thePc);
137 "Observation of type '%s' could not be converted into a " 138 "point cloud, and none of the specializations handled it, " 140 "do not know what to do with this observation!",
145 #if MRPT_VERSION >= 0x233 149 const_cast<mrpt::obs::CObservation&
>(o).unload();
157 [[maybe_unused]]
const mrpt::obs::CObservation2DRangeScan& pc,
164 [[maybe_unused]]
const mrpt::obs::CObservationVelodyneScan& pc,
171 [[maybe_unused]]
const mrpt::obs::CObservation3DRangeScan& pc,
181 mrpt::maps::CPointsMap::Ptr outPc;
185 outPc = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(itLy->second);
188 "Layer '%s' must be of point cloud type.",
193 outPc = mrpt::maps::CSimplePointsMap::Create();
197 outPc->insertAnotherMap(&pc, mrpt::poses::CPose3D::Identity());
203 [[maybe_unused]]
const mrpt::obs::CObservationRotatingScan& pc,
213 ASSERT_(!generators.empty());
214 for (
const auto& g : generators)
216 ASSERT_(g.get() !=
nullptr);
217 g->process(obs, output);
241 ASSERT_(!generators.empty());
242 for (
const auto& g : generators)
244 ASSERT_(g.get() !=
nullptr);
245 for (
const auto& obs : sf)
248 g->process(*obs, output);
254 const mrpt::containers::yaml& c,
const mrpt::system::VerbosityLevel& vLevel)
256 if (c.isNullNode())
return {};
258 ASSERT_(c.isSequence());
262 for (
const auto& entry : c.asSequence())
264 const auto& e = entry.asMap();
266 const auto sClass = e.at(
"class_name").as<
std::string>();
267 auto o = mrpt::rtti::classFactory(sClass);
270 auto f = std::dynamic_pointer_cast<
Generator>(o);
273 "`%s` class seems not to be derived from Generator",
276 f->setMinLoggingLevel(vLevel);
278 f->initialize(e.at(
"params"));
279 generators.push_back(
f);
286 const std::string& filename,
const mrpt::system::VerbosityLevel& vLevel)
288 const auto yamlContent = mrpt::containers::yaml::FromFile(filename);
291 yamlContent.has(
"generators") &&
292 yamlContent[
"generators"].isSequence());
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
virtual bool filterPointCloud(const mrpt::maps::CPointsMap &pc, mp2p_icp::metric_map_t &out) const
GeneratorSet generators_from_yaml_file(const std::string &filename, const mrpt::system::VerbosityLevel &vLevel=mrpt::system::LVL_INFO)
Generic container of pointcloud(s), extracted features and other maps.
std::vector< Generator::Ptr > GeneratorSet
virtual void initialize(const mrpt::containers::yaml &cfg_block)
std::string process_sensor_labels_regex
virtual bool filterScan2D(const mrpt::obs::CObservation2DRangeScan &pc, mp2p_icp::metric_map_t &out) const
std::string target_pointcloud_layer
Base virtual class for point cloud filters.
virtual bool filterRotatingScan(const mrpt::obs::CObservationRotatingScan &pc, mp2p_icp::metric_map_t &out) const
IMPLEMENTS_MRPT_OBJECT(metric_map_t, mrpt::serialization::CSerializable, mp2p_icp) using namespace mp2p_icp
bool throw_on_unhandled_observation_class
virtual bool filterVelodyneScan(const mrpt::obs::CObservationVelodyneScan &pc, mp2p_icp::metric_map_t &out) const
std::regex process_class_names_regex_
GeneratorSet generators_from_yaml(const mrpt::containers::yaml &c, const mrpt::system::VerbosityLevel &vLevel=mrpt::system::LVL_INFO)
static mp2p_icp_filters::GeneratorSet generators
virtual void process(const mrpt::obs::CObservation &input_raw, mp2p_icp::metric_map_t &inOut) const
void load_from_yaml(const mrpt::containers::yaml &c)
std::regex process_sensor_labels_regex_
virtual bool filterScan3D(const mrpt::obs::CObservation3DRangeScan &pc, mp2p_icp::metric_map_t &out) const
void apply_generators(const GeneratorSet &generators, const mrpt::obs::CObservation &obs, mp2p_icp::metric_map_t &output)
std::string process_class_names_regex