Statistics.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
29 #include <rtabmap/utilite/UStl.h>
31 
32 namespace rtabmap {
33 std::map<std::string, float> Statistics::_defaultData;
35 
36 const std::map<std::string, float> & Statistics::defaultData()
37 {
38  Statistics stat;
39  return _defaultData;
40 }
41 
42 std::string Statistics::serializeData(const std::map<std::string, float> & data)
43 {
44  std::stringstream output;
45  for(std::map<std::string, float>::const_iterator iter=data.begin(); iter!=data.end(); ++iter)
46  {
47  if(iter != data.begin())
48  {
49  output << ";";
50  }
51  // make sure there are no commas instead of dots
52  output << iter->first << ":" << uReplaceChar(uNumber2Str(iter->second), ',', '.');
53  }
54  return output.str();
55 }
56 
57 std::map<std::string, float> Statistics::deserializeData(const std::string & data)
58 {
59  std::map<std::string, float> output;
60  std::list<std::string> tuplets = uSplit(data, ';');
61  for(std::list<std::string>::iterator iter=tuplets.begin(); iter!=tuplets.end(); ++iter)
62  {
63  std::list<std::string> p = uSplit(*iter, ':');
64  if(p.size() == 2)
65  {
66  std::string key = p.front();
67  std::string value = p.back();
68  uInsert(output, std::make_pair(key, uStr2Float(value)));
69  }
70  }
71  return output;
72 }
73 
75  _extended(0),
76  _refImageId(0),
77  _loopClosureId(0),
79  _stamp(0.0f),
81 {
83 }
84 
86 {
87 }
88 
89 // name format = "Grp/Name/unit"
90 void Statistics::addStatistic(const std::string & name, float value)
91 {
92  uInsert(_data, std::pair<std::string, float>(name, value));
93 }
94 
95 }
f
std::map< std::string, float > _data
Definition: Statistics.h:256
float UTILITE_EXP uStr2Float(const std::string &str)
Some conversion functions.
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
Definition: UStl.h:566
Wrappers of STL for convenient functions.
const std::map< std::string, float > & data() const
Definition: Statistics.h:223
static std::map< std::string, float > _defaultData
Definition: Statistics.h:257
static std::string serializeData(const std::map< std::string, float > &data)
Definition: Statistics.cpp:42
static bool _defaultDataInitialized
Definition: Statistics.h:258
virtual ~Statistics()
Definition: Statistics.cpp:85
std::string UTILITE_EXP uReplaceChar(const std::string &str, char before, char after)
Definition: UConversion.cpp:32
static const std::map< std::string, float > & defaultData()
Definition: Statistics.cpp:36
static std::map< std::string, float > deserializeData(const std::string &data)
Definition: Statistics.cpp:57
std::string UTILITE_EXP uNumber2Str(unsigned int number)
Definition: UConversion.cpp:90
void addStatistic(const std::string &name, float value)
Definition: Statistics.cpp:90
void uInsert(std::map< K, V > &map, const std::pair< K, V > &pair)
Definition: UStl.h:443


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:43:40