InspectorsImpl.h
Go to the documentation of this file.
1 // kate: replace-tabs off; indent-width 4; indent-mode normal
2 // vim: ts=4:sw=4:noexpandtab
3 /*
4 
5 Copyright (c) 2010--2012,
6 François Pomerleau and Stephane Magnenat, ASL, ETHZ, Switzerland
7 You can contact the authors at <f dot pomerleau at gmail dot com> and
8 <stephane at magnenat dot net>
9 
10 All rights reserved.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright
17  notice, this list of conditions and the following disclaimer in the
18  documentation and/or other materials provided with the distribution.
19  * Neither the name of the <organization> nor the
20  names of its contributors may be used to endorse or promote products
21  derived from this software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
27 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef __POINTMATCHER_INSPECTORS_H
37 #define __POINTMATCHER_INSPECTORS_H
38 
39 #include "PointMatcher.h"
40 #include "Histogram.h"
41 
42 template<typename T>
44 {
50 
57  typedef typename PointMatcher<T>::Matrix Matrix;
58 
59  // Clearer name when no inspector is required
60  struct NullInspector: public Inspector
61  {
62  inline static const std::string description()
63  {
64  return "Does nothing.";
65  }
66 
67  // This constructor is not required. It make the attribute className == "NullInspector" instead of 'unknown'
68  NullInspector() : Inspector("NullInspector", ParametersDoc(), Parameters()) {}
69 
70  };
71 
72  struct PerformanceInspector: public Inspector
73  {
74  inline static const std::string description()
75  {
76  return "Keep statistics on performance.";
77  }
78  inline static const ParametersDoc availableParameters()
79  {
80  return {
81  {"baseFileName", "base file name for the statistics files (if empty, disabled)", ""},
82  {"dumpPerfOnExit", "dump performance statistics to stderr on exit", "0"},
83  {"dumpStats", "dump the statistics on first and last step", "0"}
84  };
85  }
86 
88  // Note: Prefix boolean variables with 'b' to avoid conflicts
89  // with similarly named functions.
90  const bool bDumpPerfOnExit;
91  const bool bDumpStats;
92 
93  protected:
95  typedef std::map<std::string, Histogram> HistogramMap;
96  HistogramMap stats;
97 
98  public:
99  PerformanceInspector(const std::string& className, const ParametersDoc paramsDoc, const Parameters& params);
100  PerformanceInspector(const Parameters& params);
101 
102  virtual void addStat(const std::string& name, double data);
103  virtual void dumpStats(std::ostream& stream);
104  virtual void dumpStatsHeader(std::ostream& stream);
105  };
106 
108  {
109 
110  protected:
111  virtual std::ostream* openStream(const std::string& role) = 0;
112  virtual std::ostream* openStream(const std::string& role, const size_t iterationNumber) = 0;
113  virtual void closeStream(std::ostream* stream) = 0;
114  void dumpDataPoints(const DataPoints& data, std::ostream& stream);
115  void dumpMeshNodes(const DataPoints& data, std::ostream& stream);
116  void dumpDataLinks(const DataPoints& ref, const DataPoints& reading, const Matches& matches, const OutlierWeights& featureOutlierWeights, std::ostream& stream);
117 
118  std::ostream* streamIter;
119  const bool bDumpIterationInfo;
120  const bool bDumpDataLinks;
121  const bool bDumpReading;
122  const bool bDumpReference;
123  const bool bWriteBinary;
124 
125  public:
126  AbstractVTKInspector(const std::string& className, const ParametersDoc paramsDoc, const Parameters& params);
127  virtual void init() {};
128  virtual void dumpDataPoints(const DataPoints& cloud, const std::string& name);
129  virtual void dumpMeshNodes(const DataPoints& cloud, const std::string& name);
130  virtual void dumpIteration(const size_t iterationNumber, const TransformationParameters& parameters, const DataPoints& filteredReference, const DataPoints& reading, const Matches& matches, const OutlierWeights& outlierWeights, const TransformationCheckers& transformationCheckers);
131  virtual void finish(const size_t iterationCount);
132 
133  private:
134  void buildGenericAttributeStream(std::ostream& stream, const std::string& attribute, const std::string& nameTag, const DataPoints& cloud, const int forcedDim);
135 
136  void buildScalarStream(std::ostream& stream, const std::string& name, const DataPoints& ref, const DataPoints& reading);
137  void buildScalarStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
138 
139  void buildNormalStream(std::ostream& stream, const std::string& name, const DataPoints& ref, const DataPoints& reading);
140  void buildNormalStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
141 
142  void buildVectorStream(std::ostream& stream, const std::string& name, const DataPoints& ref, const DataPoints& reading);
143  void buildVectorStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
144 
145  void buildTensorStream(std::ostream& stream, const std::string& name, const DataPoints& ref, const DataPoints& reading);
146  void buildTensorStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
147 
148  void buildColorStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
149 
150  void buildTimeStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
151 
152 
153 
154  Matrix padWithZeros(const Matrix m, const int expectedRow, const int expectedCols);
155  Matrix padWithOnes(const Matrix m, const int expectedRow, const int expectedCols);
156  };
157 
159  {
160  inline static const std::string description()
161  {
162  return "Dump the different steps into VTK files.";
163  }
164  inline static const ParametersDoc availableParameters()
165  {
166  return {
167  {"baseFileName", "base file name for the VTK files ", "point-matcher-output"},
168  {"dumpPerfOnExit", "dump performance statistics to stderr on exit", "0"},
169  {"dumpStats", "dump the statistics on first and last step", "0"},
170  {"dumpIterationInfo", "dump iteration info", "0"},
171  {"dumpDataLinks", "dump data links at each iteration", "0" },
172  {"dumpReading", "dump the reading cloud at each iteration", "0"},
173  {"dumpReference", "dump the reference cloud at each iteration", "0"},
174  {"writeBinary", "write binary VTK files", "0"}
175  };
176  }
177 
179  const bool bDumpIterationInfo;
180  const bool bDumpDataLinks;
181  const bool bDumpReading;
182  const bool bDumpReference;
183 
184  protected:
185  virtual std::ostream* openStream(const std::string& role);
186  virtual std::ostream* openStream(const std::string& role, const size_t iterationCount);
187  virtual void closeStream(std::ostream* stream);
188 
189  public:
190  VTKFileInspector(const Parameters& params = Parameters());
191  virtual void init();
192  virtual void finish(const size_t iterationCount);
193  };
194 }; // InspectorsImpl
195 
196 #endif // __POINTMATCHER_INSPECTORS_H
Matrix OutlierWeights
Weights of the associations between the points in Matches and the points in the reference.
Definition: PointMatcher.h:397
virtual void dumpStatsHeader(std::ostream &stream)
Dump header for all statistics.
Definition: Inspector.cpp:74
static const std::string description()
public interface
PointMatcherSupport::Parametrizable P
Parametrizable::Parameters Parameters
PointMatcherSupport::Histogram< double > Histogram
::std::string string
Definition: gtest.h:1979
PointMatcher< T >::DataPoints DataPoints
std::map< std::string, Histogram > HistogramMap
static const ParametersDoc availableParameters()
virtual void dumpStats(std::ostream &stream)
Dump all statistics in CSV format.
Definition: Inspector.cpp:69
static const std::string description()
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dense matrix over ScalarType.
Definition: PointMatcher.h:169
static const ParametersDoc availableParameters()
virtual void dumpIteration(const size_t iterationNumber, const TransformationParameters &parameters, const DataPoints &filteredReference, const DataPoints &reading, const Matches &matches, const OutlierWeights &outlierWeights, const TransformationCheckers &transformationCheckers)
Dump the state of a given iteration.
Definition: Inspector.cpp:81
static const std::string description()
Parametrizable::ParameterDoc ParameterDoc
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
Parametrizable::ParametersDoc ParametersDoc
An inspector allows to log data at the different steps, for analysis.
Definition: PointMatcher.h:621
PointMatcher< T >::Matrix Matrix
PointMatcher< T >::TransformationCheckers TransformationCheckers
PointMatcher< T >::OutlierWeights OutlierWeights
Result of the data-association step (Matcher::findClosests), before outlier rejection.
Definition: PointMatcher.h:371
Parameters parameters
parameters with their values encoded in string
virtual void init()
Start a new ICP operation or sequence.
The documentation of a parameter.
A chain of TransformationChecker.
Definition: PointMatcher.h:608
The superclass of classes that are constructed using generic parameters. This class provides the para...
std::vector< ParameterDoc > ParametersDoc
The documentation of all parameters.
PointMatcher< T >::Inspector Inspector
PointMatcher< T >::Matches Matches
const std::string className
name of the class
virtual void finish(const size_t iterationCount)
Tell the inspector the ICP operation is completed.
Definition: Inspector.cpp:86
virtual void init()
Start a new ICP operation or sequence.
Definition: Inspector.cpp:57
virtual void addStat(const std::string &name, double data)
Add a value for statistics name, create it if new.
Definition: Inspector.cpp:64
Matrix TransformationParameters
A matrix holding the parameters a transformation.
Definition: PointMatcher.h:182
PointMatcherSupport::Parametrizable Parametrizable
PointMatcher< T >::TransformationParameters TransformationParameters


mrpt_local_obstacles
Author(s): Jose-Luis Blanco-Claraco
autogenerated on Thu Jun 1 2023 03:06:43