00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef __POINTMATCHER_INSPECTORS_H
00037 #define __POINTMATCHER_INSPECTORS_H
00038
00039 #include "PointMatcher.h"
00040 #include "Histogram.h"
00041
00042 template<typename T>
00043 struct InspectorsImpl
00044 {
00045 typedef PointMatcherSupport::Parametrizable Parametrizable;
00046 typedef PointMatcherSupport::Parametrizable P;
00047 typedef Parametrizable::Parameters Parameters;
00048 typedef Parametrizable::ParameterDoc ParameterDoc;
00049 typedef Parametrizable::ParametersDoc ParametersDoc;
00050
00051 typedef typename PointMatcher<T>::Inspector Inspector;
00052 typedef typename PointMatcher<T>::DataPoints DataPoints;
00053 typedef typename PointMatcher<T>::Matches Matches;
00054 typedef typename PointMatcher<T>::OutlierWeights OutlierWeights;
00055 typedef typename PointMatcher<T>::TransformationParameters TransformationParameters;
00056 typedef typename PointMatcher<T>::TransformationCheckers TransformationCheckers;
00057 typedef typename PointMatcher<T>::Matrix Matrix;
00058
00059
00060 struct NullInspector: public Inspector
00061 {
00062 inline static const std::string description()
00063 {
00064 return "Does nothing.";
00065 }
00066 };
00067
00068 struct PerformanceInspector: public Inspector
00069 {
00070 inline static const std::string description()
00071 {
00072 return "Keep statistics on performance.";
00073 }
00074 inline static const ParametersDoc availableParameters()
00075 {
00076 return boost::assign::list_of<ParameterDoc>
00077 ( "baseFileName", "base file name for the statistics files (if empty, disabled)", "" )
00078 ( "dumpPerfOnExit", "dump performance statistics to stderr on exit", "0" )
00079 ( "dumpStats", "dump the statistics on first and last step", "0" )
00080 ;
00081 }
00082
00083 const std::string baseFileName;
00084
00085
00086 const bool bDumpPerfOnExit;
00087 const bool bDumpStats;
00088
00089 protected:
00090 typedef PointMatcherSupport::Histogram<double> Histogram;
00091 typedef std::map<std::string, Histogram> HistogramMap;
00092 HistogramMap stats;
00093
00094 public:
00095 PerformanceInspector(const std::string& className, const ParametersDoc paramsDoc, const Parameters& params);
00096 PerformanceInspector(const Parameters& params);
00097
00098 virtual void addStat(const std::string& name, double data);
00099 virtual void dumpStats(std::ostream& stream);
00100 virtual void dumpStatsHeader(std::ostream& stream);
00101 };
00102
00103 struct AbstractVTKInspector: public PerformanceInspector
00104 {
00105
00106 protected:
00107 virtual std::ostream* openStream(const std::string& role) = 0;
00108 virtual std::ostream* openStream(const std::string& role, const size_t iterationNumber) = 0;
00109 virtual void closeStream(std::ostream* stream) = 0;
00110 void dumpDataPoints(const DataPoints& data, std::ostream& stream);
00111 void dumpMeshNodes(const DataPoints& data, std::ostream& stream);
00112 void dumpDataLinks(const DataPoints& ref, const DataPoints& reading, const Matches& matches, const OutlierWeights& featureOutlierWeights, std::ostream& stream);
00113
00114 std::ostream* streamIter;
00115 const bool bDumpIterationInfo;
00116 const bool bDumpDataLinks;
00117 const bool bDumpReading;
00118 const bool bDumpReference;
00119
00120 public:
00121 AbstractVTKInspector(const std::string& className, const ParametersDoc paramsDoc, const Parameters& params);
00122 virtual void init() {};
00123 virtual void dumpDataPoints(const DataPoints& cloud, const std::string& name);
00124 virtual void dumpMeshNodes(const DataPoints& cloud, const std::string& name);
00125 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);
00126 virtual void finish(const size_t iterationCount);
00127
00128 private:
00129 void buildGenericAttributeStream(std::ostream& stream, const std::string& attribute, const std::string& nameTag, const DataPoints& cloud, const int forcedDim);
00130
00131 void buildScalarStream(std::ostream& stream, const std::string& name, const DataPoints& ref, const DataPoints& reading);
00132 void buildScalarStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
00133
00134 void buildNormalStream(std::ostream& stream, const std::string& name, const DataPoints& ref, const DataPoints& reading);
00135 void buildNormalStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
00136
00137 void buildVectorStream(std::ostream& stream, const std::string& name, const DataPoints& ref, const DataPoints& reading);
00138 void buildVectorStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
00139
00140 void buildTensorStream(std::ostream& stream, const std::string& name, const DataPoints& ref, const DataPoints& reading);
00141 void buildTensorStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
00142
00143 void buildColorStream(std::ostream& stream, const std::string& name, const DataPoints& cloud);
00144
00145
00146
00147 Matrix padWithZeros(const Matrix m, const int expectedRow, const int expectedCols);
00148 Matrix padWithOnes(const Matrix m, const int expectedRow, const int expectedCols);
00149 };
00150
00151 struct VTKFileInspector: public AbstractVTKInspector
00152 {
00153 inline static const std::string description()
00154 {
00155 return "Dump the different steps into VTK files.";
00156 }
00157 inline static const ParametersDoc availableParameters()
00158 {
00159 return boost::assign::list_of<ParameterDoc>
00160 ( "baseFileName", "base file name for the VTK files ", "point-matcher-output" )
00161 ( "dumpPerfOnExit", "dump performance statistics to stderr on exit", "0" )
00162 ( "dumpStats", "dump the statistics on first and last step", "0" )
00163 ( "dumpIterationInfo", "dump iteration info", "0" )
00164 ( "dumpDataLinks", "dump data links at each iteration", "0" )
00165 ( "dumpReading", "dump the reading cloud at each iteration", "0" )
00166 ( "dumpReference", "dump the reference cloud at each iteration", "0" )
00167 ;
00168 }
00169
00170 const std::string baseFileName;
00171 const bool bDumpIterationInfo;
00172 const bool bDumpDataLinks;
00173 const bool bDumpReading;
00174 const bool bDumpReference;
00175
00176 protected:
00177 virtual std::ostream* openStream(const std::string& role);
00178 virtual std::ostream* openStream(const std::string& role, const size_t iterationCount);
00179 virtual void closeStream(std::ostream* stream);
00180
00181 public:
00182 VTKFileInspector(const Parameters& params = Parameters());
00183 virtual void init();
00184 virtual void finish(const size_t iterationCount);
00185 };
00186 };
00187
00188 #endif // __POINTMATCHER_INSPECTORS_H