MRPT  1.9.9
CIncrementalMapPartitioner.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-2018, 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 #pragma once
11 
16 #include <mrpt/maps/CSimpleMap.h>
18 #include <mrpt/poses/poses_frwds.h>
20 #include <functional>
21 #include <limits>
22 
23 namespace mrpt::slam
24 {
25 
26 /** For use in CIncrementalMapPartitioner
27  * \ingroup mrpt_slam_grp */
29 {
33 };
34 
35 /** Map keyframe, comprising raw observations and they as a metric map.
36  * For use in CIncrementalMapPartitioner
37  * \ingroup mrpt_slam_grp */
39 {
43 };
44 
45 
46 /** Type of similarity evaluator for map keyframes.
47 * For use in CIncrementalMapPartitioner
48 * \ingroup mrpt_slam_grp */
49 using similarity_func_t = std::function<double(
50  const map_keyframe_t &kf1,
51  const map_keyframe_t &kf2,
52  const mrpt::poses::CPose3D &relPose2wrt1
53  )>;
54 
55 /** Finds partitions in metric maps based on N-cut graph partition theory.
56  * \ingroup mrpt_slam_grp
57  */
60 {
61  // This must be added to any CSerializable derived class:
63 
64  public:
65  /** ctor */
66  CIncrementalMapPartitioner() : COutputLogger("CIncrementalMapPartitioner") {}
67 
68  /** Configuration parameters */
70  {
71  void loadFromConfigFile(
73  const std::string& section) override;
75  const std::string& section) const;
76 
77  /**!< N-cut partition threshold [0,2] (default=1) */
78  double partitionThreshold{ 1.0 };
79 
80  /** These parameters are loaded/saved to config files
81  * with the prefix "mrp.{param_name}" */
83 
84  /* Force bisection (true) or automatically determine
85  * number of partitions (false=default).
86  */
87  bool forceBisectionOnly{ false };
88 
89  /** Defines the method for determining the adjacency matrix values.
90  * \sa CIncrementalMapPartitioner::setSimilarityMethod()
91  */
93 
94  /** If a partition leads to a cluster with less elements than this, it
95  * will be rejected even if had a good Ncut (default=1).
96  */
98 
99  /** Type and parameters of metric map(s) to build for each keyframe.
100  * Parameters can be loaded from a config file from sections
101  * with the prefix of this "TOptions" section + ".metricmap".
102  * Default: a CSimplePointsMap */
104 
105  /** Maximum distance, in KF identifier numbers, to check for similarity.
106  * Default=Infinite. Can be used to constraint the wrong detection of clusters
107  * after loop closures but before correcting global poses. */
108  uint64_t maxKeyFrameDistanceToEval{std::numeric_limits<uint64_t>::max()};
109 
110  TOptions();
111  };
112 
113  /** \name Main map partition API
114  * @{ */
115 
116  /** Algorithm parameters */
118 
119  /* Reset the internal state to an empty map */
120  void clear();
121 
122  /**\brief Insert a new keyframe to the graph.
123  *
124  * Call this method each time a new observation is added to the map/graph.
125  * Afterwards, call updatePartitions() to get the updated partitions.
126  *
127  * \param frame The sensed data
128  * \param robotPose An estimation of the robot global pose.
129  *
130  * \return The index of the new pose in the graph, which can be used to
131  * refer to this pose in the future.
132  *
133  * \sa updatePartitions
134  */
136  const mrpt::obs::CSensoryFrame& frame,
137  const mrpt::poses::CPose3DPDF& robotPose3D);
138 
139  /** Recalculate the map/graph partitions. \sa addMapFrame() */
140  void updatePartitions(std::vector<std::vector<uint32_t>>& partitions);
141 
142  /**Get the total node count currently in the internal map/graph. */
143  size_t getNodesCount();
144 
145  /** Remove a list of keyframes, with indices as returned by addMapFrame()
146  * \param changeCoordsRef If true, coordinates are changed to leave the first
147  * node at (0,0,0).
148  */
149  void removeSetOfNodes(
150  std::vector<uint32_t> indexesToRemove, bool changeCoordsRef = true);
151 
152  /**\name Change Coordinates System
153  * \brief Change the coordinate origin of all stored poses
154  *
155  * Used for consistency with future new poses to enter in the system.
156  */
157  void changeCoordinatesOrigin(const mrpt::poses::CPose3D& newOrigin);
158  /**\brief The new origin is given by the index of the pose that is to
159  * become the new origin.
160  */
161  void changeCoordinatesOriginPoseIndex(unsigned int newOriginPose);
162 
163  /** Select the similarity method to use for newly inserted keyframes */
165  options.simil_method = method;
166  }
167 
168  /** Sets a custom function for the similarity of new keyframes */
171  m_sim_func = func;
172  }
173  /** @} */
174 
175  /** \name Access API to internal graph data
176  * @{ */
177  /**Return a 3D representation of the graph: poses & links between them.
178  * The previous contents of "objs" will be discarded
179  */
180  void getAs3DScene(
182  const std::map<uint32_t, int64_t>* renameIndexes = NULL) const;
183 
184  /** Return a copy of the adjacency matrix. */
185  template <class MATRIX>
186  void getAdjacencyMatrix(MATRIX& outMatrix) const
187  {
188  outMatrix = m_A;
189  }
190 
191  /** Return a const ref to the internal adjacency matrix. */
193 
194  /** Read-only access to the sequence of Sensory Frames */
196  {
197  return &m_individualFrames;
198  }
199 
200  /** Access to the sequence of Sensory Frames */
202  {
203  return &m_individualFrames;
204  }
205  /** @} */
206 
207  private:
209  std::deque<mrpt::maps::CMultiMetricMap::Ptr> m_individualMaps;
210 
211  /** Adjacency matrix */
213 
214  /** The last partition */
215  std::vector<std::vector<uint32_t>> m_last_partition;
216 
217  /** This will be true after adding new observations, and before an
218  * "updatePartitions" is invoked. */
220 
222 
223 }; // End of class def.
224 }
230 
231 
232 
MRPT_FILL_ENUM_MEMBER(mrpt::slam, smMETRIC_MAP_MATCHING)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define MRPT_ENUM_TYPE_END()
Definition: TEnumType.h:78
#define MRPT_ENUM_TYPE_BEGIN(_ENUM_TYPE_WITH_NS)
Definition: TEnumType.h:62
This class allows loading and storing values and vectors of different types from a configuration text...
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
std::shared_ptr< CMultiMetricMap > Ptr
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
Definition: CSimpleMap.h:34
A set of TMetricMapInitializer structures, passed to the constructor CMultiMetricMap::CMultiMetricMap...
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
Definition: CMatrixD.h:24
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:53
std::shared_ptr< CSensoryFrame > Ptr
Definition: CSensoryFrame.h:54
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:28
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:87
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually).
Definition: CPose3DPDF.h:42
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:31
Finds partitions in metric maps based on N-cut graph partition theory.
void updatePartitions(std::vector< std::vector< uint32_t >> &partitions)
Recalculate the map/graph partitions.
void setSimilarityMethod(similarity_method_t method)
Select the similarity method to use for newly inserted keyframes.
const mrpt::math::CMatrixDouble & getAdjacencyMatrix() const
Return a const ref to the internal adjacency matrix.
mrpt::math::CMatrixD m_A
Adjacency matrix.
const mrpt::maps::CSimpleMap * getSequenceOfFrames() const
Read-only access to the sequence of Sensory Frames.
void removeSetOfNodes(std::vector< uint32_t > indexesToRemove, bool changeCoordsRef=true)
Remove a list of keyframes, with indices as returned by addMapFrame()
mrpt::maps::CSimpleMap * getSequenceOfFrames()
Access to the sequence of Sensory Frames.
void setSimilarityMethod(similarity_func_t func)
Sets a custom function for the similarity of new keyframes.
void getAdjacencyMatrix(MATRIX &outMatrix) const
Return a copy of the adjacency matrix.
size_t getNodesCount()
Get the total node count currently in the internal map/graph.
bool m_last_last_partition_are_new_ones
This will be true after adding new observations, and before an "updatePartitions" is invoked.
void changeCoordinatesOriginPoseIndex(unsigned int newOriginPose)
The new origin is given by the index of the pose that is to become the new origin.
void getAs3DScene(mrpt::opengl::CSetOfObjects::Ptr &objs, const std::map< uint32_t, int64_t > *renameIndexes=NULL) const
Return a 3D representation of the graph: poses & links between them.
uint32_t addMapFrame(const mrpt::obs::CSensoryFrame &frame, const mrpt::poses::CPose3DPDF &robotPose3D)
Insert a new keyframe to the graph.
std::deque< mrpt::maps::CMultiMetricMap::Ptr > m_individualMaps
void changeCoordinatesOrigin(const mrpt::poses::CPose3D &newOrigin)
std::vector< std::vector< uint32_t > > m_last_partition
The last partition.
Versatile class for consistent logging and management of output messages.
COutputLogger()
Default class constructor.
GLsizei const GLchar ** string
Definition: glext.h:4101
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
std::function< double(const map_keyframe_t &kf1, const map_keyframe_t &kf2, const mrpt::poses::CPose3D &relPose2wrt1)> similarity_func_t
Type of similarity evaluator for map keyframes.
similarity_method_t
For use in CIncrementalMapPartitioner <>
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned __int32 uint32_t
Definition: rptypes.h:47
unsigned char uint8_t
Definition: rptypes.h:41
unsigned __int64 uint64_t
Definition: rptypes.h:50
Parameters for CMetricMap::compute3DMatchingRatio()
uint64_t maxKeyFrameDistanceToEval
Maximum distance, in KF identifier numbers, to check for similarity.
mrpt::maps::TSetOfMetricMapInitializers metricmap
Type and parameters of metric map(s) to build for each keyframe.
double partitionThreshold
!< N-cut partition threshold [0,2] (default=1)
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &section) override
This method load the options from a ".ini"-like file or memory-stored string list.
void saveToConfigFile(mrpt::config::CConfigFileBase &target, const std::string &section) const
This method saves the options to a ".ini"-like file or memory-stored string list.
mrpt::maps::TMatchingRatioParams mrp
These parameters are loaded/saved to config files with the prefix "mrp.{param_name}".
similarity_method_t simil_method
Defines the method for determining the adjacency matrix values.
uint64_t minimumNumberElementsEachCluster
If a partition leads to a cluster with less elements than this, it will be rejected even if had a goo...
Map keyframe, comprising raw observations and they as a metric map.
mrpt::maps::CMultiMetricMap::Ptr metric_map
mrpt::obs::CSensoryFrame::Ptr raw_observations



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST