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,
17  bool allowEmptyName, 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(
34  "Layer '%s' must be of point cloud type.", layerName.c_str());
35  }
36  else
37  {
38  auto o = mrpt::rtti::classFactory(classForLayerCreation);
39  ASSERTMSG_(
40  o, mrpt::format(
41  "Could not create layer of type '%s' (wrong or "
42  "unregistered class name?)",
43  classForLayerCreation.c_str()));
44 
45  auto newMap = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(o);
46  ASSERTMSG_(
47  newMap, mrpt::format(
48  "Provided class name '%s' seems not to be derived from "
49  "mrpt::maps::CPointsMap",
50  classForLayerCreation.c_str()));
51 
52  outPc = newMap;
53  m.layers[layerName] = newMap;
54  }
55  return outPc;
56 }
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:49
mp2p_icp::metric_map_t::layers
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
Definition: metricmap.h:76


mp2p_icp
Author(s):
autogenerated on Sat Sep 14 2024 02:46:36