GetOrCreatePointLayer.cpp
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * A repertory of multi primitive-to-primitive (MP2P) ICP algorithms in C++
3  * Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
14 
15 mrpt::maps::CPointsMap::Ptr mp2p_icp_filters::GetOrCreatePointLayer(
16  mp2p_icp::metric_map_t& m, const std::string& layerName, bool allowEmptyName,
17  const std::string& classForLayerCreation)
18 {
19  mrpt::maps::CPointsMap::Ptr outPc;
20 
21  if (layerName.empty())
22  {
23  if (allowEmptyName)
24  return nullptr;
25  else
26  THROW_EXCEPTION("Layer name cannot be empty");
27  }
28 
29  if (auto itLy = m.layers.find(layerName); itLy != m.layers.end())
30  {
31  outPc = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(itLy->second);
32  if (!outPc)
33  THROW_EXCEPTION_FMT("Layer '%s' must be of point cloud type.", layerName.c_str());
34  }
35  else
36  {
37  auto o = mrpt::rtti::classFactory(classForLayerCreation);
38  ASSERTMSG_(
39  o, mrpt::format(
40  "Could not create layer of type '%s' (wrong or "
41  "unregistered class name?)",
42  classForLayerCreation.c_str()));
43 
44  auto newMap = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(o);
45  ASSERTMSG_(
46  newMap, mrpt::format(
47  "Provided class name '%s' seems not to be derived from "
48  "mrpt::maps::CPointsMap",
49  classForLayerCreation.c_str()));
50 
51  outPc = newMap;
52  m.layers[layerName] = newMap;
53  }
54  return outPc;
55 }
testing::internal::string
::std::string string
Definition: gtest.h:1979
mp2p_icp_filters::GetOrCreatePointLayer
mrpt::maps::CPointsMap::Ptr GetOrCreatePointLayer(mp2p_icp::metric_map_t &m, const std::string &layerName, bool allowEmptyName=true, const std::string &classForLayerCreation="mrpt::maps::CSimplePointsMap")
Definition: GetOrCreatePointLayer.cpp:15
GetOrCreatePointLayer.h
Auxiliary function GetOrCreatePointLayer.
mp2p_icp::metric_map_t
Generic container of pointcloud(s), extracted features and other maps.
Definition: metricmap.h:55
mp2p_icp::metric_map_t::layers
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
Definition: metricmap.h:82


mp2p_icp
Author(s):
autogenerated on Mon May 26 2025 02:45:48