list_modules.cpp
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 #include "pointmatcher/PointMatcher.h"
00037 #include "pointmatcher/Bibliography.h"
00038 
00039 using namespace std;
00040 using namespace PointMatcherSupport;
00041 
00042 typedef PointMatcherSupport::Parametrizable::ParametersDoc ParametersDoc;
00043 typedef PointMatcher<float> PM;
00044 
00045 void printBibliographyHeader(const CurrentBibliography::Mode mode)
00046 {
00047         switch (mode)
00048         {
00049                 case CurrentBibliography::NORMAL:
00050                 cout << "* Bibliography *" << endl << endl;
00051                 break;
00052                 
00053                 case CurrentBibliography::ROSWIKI:
00054                 cout << "=== Bibliography ===" << endl << endl;
00055                 break;
00056                 
00057                 default:
00058                 break;
00059         }
00060 }
00061 
00062 void dumpWiki(const ParametersDoc& paramsDoc)
00063 {
00064         cout << endl;
00065         if (!paramsDoc.empty())
00066                 for (BOOST_AUTO(it, paramsDoc.begin()); it != paramsDoc.end(); ++it)
00067                 {
00068                         cout << "`" << it->name << "` (default: `" << it->defaultValue << "`";
00069                         if (!it->minValue.empty())
00070                                 cout << ", min: `" << it->minValue << "`";
00071                         if (!it->maxValue.empty())
00072                                 cout << ", max: `" << it->maxValue << "`";
00073                         cout << ")" << endl;
00074                         cout << endl;
00075                         cout << " . " << it->doc << endl;
00076                         cout << endl;
00077                 }
00078         else
00079                 cout << " . no parameters" << endl;
00080 }
00081 
00082 template<typename R>
00083 void dumpRegistrar(const PM& pm, const R& registrar, const std::string& name, CurrentBibliography& bib)
00084 {
00085         if (bib.mode == CurrentBibliography::ROSWIKI)
00086                 cout << "=== " << name << " ===\n" << endl;
00087         else
00088                 cout << "* " << name << " *\n" << endl;
00089         for (BOOST_AUTO(it, registrar.begin()); it != registrar.end(); ++it)
00090         {
00091                 if (bib.mode == CurrentBibliography::ROSWIKI)
00092                         cout << "==== " << it->first << " ====\n" << endl;
00093                 else
00094                         cout << it->first << endl;
00095                 
00096                 cout << getAndReplaceBibEntries(it->second->description(), bib) << endl;
00097                 if (bib.mode == CurrentBibliography::ROSWIKI)
00098                         dumpWiki(it->second->availableParameters());
00099                 else
00100                         cout << it->second->availableParameters();
00101                 cout << endl;
00102         }
00103         cout << endl;
00104 }
00105 
00106 
00107 #define DUMP_REGISTRAR_CONTENT(pm, name, bib) \
00108         dumpRegistrar(pm, pm.REG(name), # name, bib);
00109 
00110 void listModulesFull(const CurrentBibliography::Mode mode)
00111 {
00112         CurrentBibliography bib(mode);
00113         
00114         DUMP_REGISTRAR_CONTENT(PM::get(), Transformation, bib)
00115         DUMP_REGISTRAR_CONTENT(PM::get(), DataPointsFilter, bib)
00116         DUMP_REGISTRAR_CONTENT(PM::get(), Matcher, bib)
00117         DUMP_REGISTRAR_CONTENT(PM::get(), OutlierFilter, bib)
00118         DUMP_REGISTRAR_CONTENT(PM::get(), ErrorMinimizer, bib)
00119         DUMP_REGISTRAR_CONTENT(PM::get(), TransformationChecker, bib)
00120         DUMP_REGISTRAR_CONTENT(PM::get(), Inspector, bib)
00121         DUMP_REGISTRAR_CONTENT(PM::get(), Logger, bib)
00122         
00123         printBibliographyHeader(mode);
00124         bib.dump(cout);
00125 }
00126 
00127 
00128 typedef vector<string> ModuleNameList;
00129 
00130 template<typename R>
00131 void dumpRegistrarSummary(const PM& pm, const R& registrar, const std::string& name, ModuleNameList& nameList)
00132 {
00133         nameList.push_back(name);
00134         for (BOOST_AUTO(it, registrar.begin()); it != registrar.end(); ++it)
00135         {
00136                 // TODO: remove title
00137                 nameList.push_back(it->first);
00138         }
00139 }
00140 
00141 #define DUMP_REGISTRAR_SUMMARY(pm, name, nameList) \
00142         dumpRegistrarSummary(pm, pm.REG(name), # name, nameList);
00143 
00144 void listModulesSummary(const CurrentBibliography::Mode mode)
00145 {
00146         typedef vector<ModuleNameList> ModulesNames;
00147         
00148         ModulesNames modulesNames;
00149         modulesNames.resize(7);
00150         
00151         DUMP_REGISTRAR_SUMMARY(PM::get(), DataPointsFilter, modulesNames[0])
00152         DUMP_REGISTRAR_SUMMARY(PM::get(), Matcher, modulesNames[1])
00153         DUMP_REGISTRAR_SUMMARY(PM::get(), OutlierFilter, modulesNames[2])
00154         DUMP_REGISTRAR_SUMMARY(PM::get(), ErrorMinimizer, modulesNames[3])
00155         DUMP_REGISTRAR_SUMMARY(PM::get(), TransformationChecker, modulesNames[4])
00156         DUMP_REGISTRAR_SUMMARY(PM::get(), Inspector, modulesNames[5])
00157         DUMP_REGISTRAR_SUMMARY(PM::get(), Logger, modulesNames[6])
00158         
00159         // strip names and count
00160         ModulesNames strippedModulesNames;
00161         strippedModulesNames.resize(modulesNames.size());
00162         unsigned maxCount(0);
00163         for (size_t i(0); i < modulesNames.size(); ++i)
00164         {
00165                 unsigned count(0);
00166                 for (BOOST_AUTO(jt, modulesNames[i].begin()); jt != modulesNames[i].end(); ++jt)
00167                 {
00168                         const string& name(*jt);
00169                         if (jt == modulesNames[i].begin())
00170                         {
00171                                 strippedModulesNames[i].push_back(name);
00172                                 count++;
00173                         }
00174                         else
00175                         {
00176                                 string strippedName(name.substr(0, name.length() - (modulesNames[i][0].length())));
00177                                 if ((strippedName != "Null") && (strippedName != "Identity"))
00178                                 {
00179                                         strippedModulesNames[i].push_back(strippedName);
00180                                         count++;
00181                                 }
00182                         }
00183                 }
00184                 maxCount = max(count, maxCount);
00185         }
00186         
00187         // header
00188         cout << "\\begin{tabularx}{\\textwidth}{";
00189         for (size_t i(0); i<strippedModulesNames.size(); ++i)
00190                 cout << "l";
00191         cout << "}\n\\toprule\n";
00192         for (unsigned row(0); row < maxCount; ++row)
00193         {
00194                 for (BOOST_AUTO(it, strippedModulesNames.begin()); it != strippedModulesNames.end(); ++it)
00195                 {
00196                         if (row < it->size())
00197                         {
00198                                 const string& name((*it)[row]);
00199                                 cout << name;
00200                         }
00201                         if (it+1 != strippedModulesNames.end())
00202                                 cout << " & ";
00203                 }
00204                 if (row == 0)
00205                         cout << "\\\\\n\\midrule\n";
00206                 else
00207                         cout << "\\\\\n";
00208         }
00209         // footer
00210         cout << "\\bottomrule\n\\end{tabularx}\n";
00211 }
00212 
00213 int main(int argc, char *argv[])
00214 {
00215         // choose bibliography mode
00216         CurrentBibliography::Mode mode(CurrentBibliography::NORMAL);
00217         if (argc == 2)
00218         {
00219                 const string cmd(argv[1]);
00220                 if (cmd == "--latexsummary")
00221                 {
00222                         mode = CurrentBibliography::BIBTEX;
00223                         listModulesSummary(mode);
00224                 }
00225                 else if (cmd == "--roswiki")
00226                 {
00227                         mode = CurrentBibliography::ROSWIKI;
00228                         listModulesFull(mode);
00229                 }
00230                 else if (cmd == "--bibtex")
00231                 {
00232                         mode = CurrentBibliography::BIBTEX;
00233                         listModulesFull(mode);
00234                 }
00235                 else
00236                 {
00237                         cerr << "Invalid command " << cmd << endl;
00238                         return 1;
00239                 }
00240         }
00241         else
00242                 listModulesFull(mode);
00243         
00244         return 0;
00245 }


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