InspectorsImpl.h
Go to the documentation of this file.
00001 // kate: replace-tabs off; indent-width 4; indent-mode normal
00002 // vim: ts=4:sw=4:noexpandtab
00003 /*
00004 
00005 Copyright (c) 2010--2012,
00006 François Pomerleau and Stephane Magnenat, ASL, ETHZ, Switzerland
00007 You can contact the authors at <f dot pomerleau at gmail dot com> and
00008 <stephane at magnenat dot net>
00009 
00010 All rights reserved.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014     * Redistributions of source code must retain the above copyright
00015       notice, this list of conditions and the following disclaimer.
00016     * Redistributions in binary form must reproduce the above copyright
00017       notice, this list of conditions and the following disclaimer in the
00018       documentation and/or other materials provided with the distribution.
00019     * Neither the name of the <organization> nor the
00020       names of its contributors may be used to endorse or promote products
00021       derived from this software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
00027 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00030 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         // Clearer name when no inspector is required
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                 // Note: Prefix boolean variables with 'b' to avoid conflicts 
00085                 // with similarly named functions.
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 }; // InspectorsImpl
00187 
00188 #endif // __POINTMATCHER_INSPECTORS_H


libpointmatcher
Author(s):
autogenerated on Mon Sep 14 2015 02:59:06