Bibliography.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 "Bibliography.h"
00037 
00038 #include <boost/typeof/typeof.hpp>
00039 #include <boost/lexical_cast.hpp>
00040 #define BOOST_ASSIGN_MAX_PARAMS 6
00041 #include <boost/assign/list_of.hpp>
00042 #include <iostream>
00043 #include <cassert>
00044 #include <stdexcept>
00045 
00046 namespace PointMatcherSupport
00047 {
00048         using namespace std;
00049         using boost::assign::map_list_of;
00050         
00051         template<typename M>
00052         bool contains(const M& m, const typename M::key_type& k)
00053         {
00054                 BOOST_AUTO(it,m.find(k));
00055                 return (it!=m.end());
00056         }
00057         
00058         template<typename M>
00059         const typename M::mapped_type& get(const M& m, const typename M::key_type& k)
00060         {
00061                 BOOST_AUTO(it,m.find(k));
00062                 if (it!=m.end())
00063                         return it->second;
00064                 else
00065                         throw std::runtime_error("unknown key");
00066         }
00067 
00068         // Hack: extra indirection to make nested map_list_of work with C++11
00069         template<typename T>
00070         StringMap makeMap(const T& mapInitializer)
00071         {
00072                 StringMap m = mapInitializer;
00073                 return m;
00074         }
00075         
00076         static Bibliography bibliography()
00077         {
00078                 return map_list_of<std::string, StringMap>
00079                         ( "Phillips2007VarTrimmed", makeMap(map_list_of
00080                                 ( "type", "inproceedings" )
00081                                 ( "title", "Outlier robust ICP for minimizing fractional RMSD" )
00082                                 ( "author", "Phillips, J.M. and Liu, R. and Tomasi, C." )
00083                                 ( "booktitle", "3-D Digital Imaging and Modeling, 2007. 3DIM '07. Sixth International Conference on" )
00084                                 ( "year", "2007" )
00085                                 ( "pages", "427--434" )
00086                                 ( "publisher", "IEEE Press" )
00087                                 ( "doi", "10.1109/3DIM.2007.39" )
00088                                 ( "fulltext", "http://x86.cs.duke.edu/~tomasi/papers/phillips/phillips3DIM07.pdf" )
00089                         ))
00090                         ( "Chetverikov2002Trimmed", makeMap(map_list_of
00091                                 ( "type", "inproceedings" )
00092                                 ( "title", "The Trimmed Iterative Closest Point Algorithm" )
00093                                 ( "author", "Chetverikov, D. and Svirko, D. and Stepanov, D. and Krsek, P." )
00094                                 ( "booktitle", "Pattern Recognition, 2002. Proceedings. 16th International Conference on" )
00095                                 ( "year", "2002" )
00096                                 ( "pages", "545--548" )
00097                                 ( "publisher", "IEEE Press" )
00098                                 ( "doi", "10.1109/ICPR.2002.1047997 " )
00099                                 ( "fulltext", "http://hci.iwr.uni-heidelberg.de/publications/dip/2002/ICPR2002/DATA/10_1_03.PDF" )
00100                         ))
00101                         ( "Besl1992Point2Point", makeMap(map_list_of
00102                                 ( "type", "inproceedings" )
00103                                 ( "title", "A Method for Registration of 3-D Shapes" )
00104                                 ( "author", "Besl, P.J. and McKay, H.D." )
00105                                 ( "booktitle", "Pattern Analysis and Machine Intelligence, IEEE Transactions" )
00106                                 ( "year", "1992" )
00107                                 ( "pages", "239--256" )
00108                                 ( "publisher", "IEEE Press" )
00109                                 ( "doi", "10.1109/34.121791" )
00110                                 ( "fulltext", "http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=121791")
00111                         ))
00112                         ( "Censi2007ICPCovariance", makeMap(map_list_of
00113                                 ( "type", "inproceedings" )
00114                                 ( "title", "An Accurate Closed-Form Estimate of {ICP}'s Covariance" )
00115                                 ( "author", "Censi, A." )
00116                                 ( "booktitle", "Proceedings of the {IEEE} International Conference on Robotics and Automation ({ICRA})" )
00117                                 ( "year", "2007" )
00118                                 ( "pages", "3167--3172" )
00119                                 ( "publisher", "IEEE Press" )
00120                                 ( "doi", "10.1109/ROBOT.2007.363961" )
00121                                 ( "fulltext", "http://purl.org/censi/research/2007-icra-icpcov.pdf")
00122                         ))
00123                         ( "Chen1991Point2Plane", makeMap(map_list_of
00124                                 ( "type", "inproceedings" )
00125                                 ( "title", "Object modeling by registration of multiple range images" )
00126                                 ( "author", "Chen, Y. and Medioni, G." )
00127                                 ( "booktitle", "Robotics and Automation, 1991. Proceedings., 1991 IEEE International Conference on" )
00128                                 ( "year", "1991" )
00129                                 ( "pages", "2724--2729" )
00130                                 ( "publisher", "IEEE Press" )
00131                                 ( "doi", "10.1109/ROBOT.1991.132043" )
00132                                 ( "fulltext", "http://ieeexplore.ieee.org/search/srchabstract.jsp?tp=&arnumber=132043")
00133                         ))
00134                         ( "Masuda1996Random", makeMap(map_list_of
00135                                 ( "type", "inproceedings" )
00136                                 ( "title", "Registration and integration of multiple range images for 3-D model construction" )
00137                                 ( "author", "Masuda, T. and Sakaue, K. and Yokoya, N." )
00138                                 ( "booktitle", "Pattern Recognition, 1996., Proceedings of the 13th International Conference on" )
00139                                 ( "year", "1996" )
00140                                 ( "pages", "879--883" )
00141                                 ( "publisher", "IEEE Press" )
00142                                 ( "doi", "10.1109/ICPR.1996.546150" )
00143                                 ( "fulltext", "http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=546150")
00144                         ))
00145                         ( "Diebel2004Median", makeMap(map_list_of
00146                                 ( "type", "inproceedings" )
00147                                 ( "title", "Simultaneous Localization and Mapping with Active Stereo Vision" )
00148                                 ( "author", "Diebel, J. and Reutersward, K. and Thrun, S. and Davis, J. and Gupta, R." )
00149                                 ( "booktitle", "Intelligent Robots and Systems, 2004. (IROS 2004). Proceedings. 2004 IEEE/RSJ International Conference on" )
00150                                 ( "year", "2004" )
00151                                 ( "pages", "3436--3443" )
00152                                 ( "publisher", "IEEE Press" )
00153                                 ( "doi", "10.1109/IROS.2004.1389948" )
00154                                 ( "fulltext", "http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1389948")
00155                         ))
00156                         ( "Pomerleau2012Noise", makeMap(map_list_of
00157                                 ( "type", "inproceedings" )
00158                                 ( "title", "Noise Characterization of Depth Sensors for Surface Inspections" )
00159                                 ( "author", "F. Pomerleau, A. Breitenmoser, M. Liu, F. Colas, R. Siegwart" )
00160                                 ( "booktitle", " International Conference on Applied Robotics for the Power Industry, 2012. (CARPI 2012). Proceedings of the IEEE" )
00161                                 ( "year", "2012" )
00162                                 ( "pages", "1--8" )
00163                                 ( "publisher", "IEEE Press" )
00164                                 ( "doi", "" )
00165                                 ( "fulltext", "")
00166                         ))
00167                 ;
00168         }
00169         
00170         CurrentBibliography::CurrentBibliography(Mode mode):
00171                 mode(mode)
00172         {}
00173         
00174         void CurrentBibliography::dump(std::ostream& os) const
00175         {
00176                 switch (mode)
00177                 {
00178                         case NORMAL: dumpText(os); break;
00179                         case ROSWIKI: dumpWiki(os); break;
00180                         case BIBTEX: dumpBibtex(os); break;
00181                         default: assert(false); break;
00182                 };
00183         }
00184         
00185         void CurrentBibliography::dumpText(std::ostream& os) const
00186         {
00187                 Bibliography biblio(bibliography());
00188                 for (size_t i = 0; i < entries.size(); ++i)
00189                 {
00190                         const string& entryName(entries[i]);
00191                         if (!contains(biblio, entryName))
00192                                 throw runtime_error(string("Broken bibliography, missing entry " + entryName));
00193                         const StringMap& entry(get(biblio, entryName));
00194                         
00195                         os << "[" << i+1 << "]";
00196                         if (contains(entry, "title"))
00197                                 os << " " << get(entry, "title") << ".";
00198                         if (contains(entry, "author"))
00199                                 os << " " << get(entry, "author") << "";
00200                         if (contains(entry, "booktitle"))
00201                                 os << " In " << get(entry, "booktitle") << ".";
00202                         if (contains(entry, "journal"))
00203                                 os << " " << get(entry, "journal") << ".";
00204                         if (contains(entry, "pages"))
00205                                 os << " " << get(entry, "pages") << ".";
00206                         if (contains(entry, "year"))
00207                                 os << " " << get(entry, "year") << ".";
00208                         os << endl << endl;
00209                 }
00210         }
00211 
00212         void CurrentBibliography::dumpWiki(std::ostream& os) const
00213         {
00214                 Bibliography biblio(bibliography());
00215                 for (size_t i = 0; i < entries.size(); ++i)
00216                 {
00217                         const string& entryName(entries[i]);
00218                         if (!contains(biblio, entryName))
00219                                 throw runtime_error(string("Broken bibliography, missing entry " + entryName));
00220                         const StringMap& entry(get(biblio, entryName));
00221                         
00222                         os << " * " << "<<Anchor(" << entryName << ")>>[" << i+1 << "] -";
00223                         if (contains(entry, "title"))
00224                                 os << " '''" << get(entry, "title") << ".'''";
00225                         if (contains(entry, "author"))
00226                                 os << " " << get(entry, "author") << "";
00227                         if (contains(entry, "booktitle"))
00228                                 os << " ''In " << get(entry, "booktitle") << ".''";
00229                         if (contains(entry, "journal"))
00230                                 os << " " << get(entry, "journal") << ".";
00231                         if (contains(entry, "pages"))
00232                                 os << " " << get(entry, "pages") << ".";
00233                         if (contains(entry, "year"))
00234                                 os << " " << get(entry, "year") << ".";
00235                         if (contains(entry, "doi"))
00236                                 os << " DOI: [[http://dx.doi.org/" << get(entry, "doi") << "|" << get(entry, "doi") << "]].";
00237                         if (contains(entry, "fulltext"))
00238                                 os << " [[" << get(entry, "fulltext") << "|full text]].";
00239                         os << endl;
00240                 }
00241         }
00242 
00243         void CurrentBibliography::dumpBibtex(std::ostream& os) const
00244         {
00245                 Bibliography biblio(bibliography());
00246                 for (size_t i = 0; i < entries.size(); ++i)
00247                 {
00248                         const string& entryName(entries[i]);
00249                         if (!contains(biblio, entryName))
00250                                 throw runtime_error(string("Broken bibliography, missing entry " + entryName));
00251                         const StringMap& entry(get(biblio, entryName));
00252                         
00253                         os << "@" << get(entry, "type") << "{" << entryName << endl;
00254                         if (contains(entry, "title"))
00255                                 os << "\ttitle={" << get(entry, "title") << "}," << endl;
00256                         if (contains(entry, "author"))
00257                                 os << "\tauthor={" << get(entry, "author") << "}," << endl;
00258                         if (contains(entry, "booktitle"))
00259                                 os << "\tbooktitle={" << get(entry, "booktitle") << "}," << endl;
00260                         if (contains(entry, "journal"))
00261                                 os << "\tjournal={" << get(entry, "journal") << "}," << endl;
00262                         if (contains(entry, "pages"))
00263                                 os << "\tpages={" << get(entry, "pages") << "}," << endl;
00264                         if (contains(entry, "year"))
00265                                 os << "\tyear={" << get(entry, "year") << "}," << endl;
00266                         os << "}" << endl << endl;
00267                 }
00268         }
00269         
00270         static StringVector splitString(const string& text, char delim)
00271         {
00272                 StringVector res;
00273                 size_t pos = 0;
00274                 while(true)
00275                 {
00276                         const size_t nextPos = text.find(delim, pos);
00277                         if (nextPos == text.npos)
00278                         {
00279                                 res.push_back(text.substr(pos));
00280                                 break;
00281                         }
00282                         else
00283                                 res.push_back(text.substr(pos, nextPos - pos));
00284                         pos = nextPos + 1;
00285                 }
00286                 return res;
00287         }
00288         
00289         std::string getAndReplaceBibEntries(const std::string& text, CurrentBibliography& curBib)
00290         {
00291                 CurrentBibliography::Mode mode(curBib.mode);
00292                 BibIndices& indices(curBib.indices);
00293                 StringVector& entries(curBib.entries);
00294                 
00295                 string newText;
00296                 const StringVector words(splitString(text, ' '));
00297                 for (size_t i = 0; i < words.size(); ++i)
00298                 {
00299                         const string& word(words[i]);
00300                         const size_t l(word.length());
00301                         const size_t p(word.find('}'));
00302                         if ((l > 7) && (word.substr(0, 6) == "\\cite{") && (p != string::npos))
00303                         {
00304                                 if (mode == CurrentBibliography::ROSWIKI)
00305                                         newText += "&#91;";
00306                                 else
00307                                         newText += '[';
00308                                 const StringVector keys(splitString(word.substr(6, p-6), ','));
00309                                 for (size_t j = 0; j < keys.size(); ++j)
00310                                 {
00311                                         const string key(keys[j]);
00312                                         if (mode == CurrentBibliography::ROSWIKI)
00313                                                 newText += "[[#" + key + "|";
00314                                         if (contains(indices, key))
00315                                         {
00316                                                 newText += boost::lexical_cast<string>(get(indices, key)+1);
00317                                         }
00318                                         else
00319                                         {
00320                                                 size_t index(entries.size());
00321                                                 entries.push_back(key);
00322                                                 indices[key] = index;
00323                                                 newText += boost::lexical_cast<string>(index+1);
00324                                         }
00325                                         if (mode == CurrentBibliography::ROSWIKI)
00326                                                 newText += "]]";
00327                                         if (j+1 != keys.size())
00328                                                 newText += ',';
00329                                 }
00330                                 if (mode == CurrentBibliography::ROSWIKI)
00331                                         newText += "&#93;";
00332                                 else
00333                                         newText += ']';
00334                                 newText += word.substr(p+1);
00335                         }
00336                         else
00337                                 newText += word;
00338                         if (i+1 != words.size())
00339                                 newText += ' ';
00340                 }
00341                 if (mode == CurrentBibliography::BIBTEX)
00342                         return text;
00343                 else
00344                         return newText;
00345         }
00346 }; // PointMatcherSupport


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:39