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  _refImageMapId(-1),
78  _loopClosureId(0),
82  _stamp(0.0f),
84 {
86 }
87 
89 {
90 }
91 
92 // name format = "Grp/Name/unit"
93 void Statistics::addStatistic(const std::string & name, float value)
94 {
95  uInsert(_data, std::pair<std::string, float>(name, value));
96 }
97 
98 //deprecated
99 void Statistics::setLastSignatureData(const Signature & data)
100 {
101  _signaturesData.insert(std::make_pair(data.id(), data));
102 }
103 
104 }
f
std::map< std::string, float > _data
Definition: Statistics.h:336
float UTILITE_EXP uStr2Float(const std::string &str)
Some conversion functions.
const std::map< std::string, float > & data() const
Definition: Statistics.h:295
Wrappers of STL for convenient functions.
std::list< std::string > uSplit(const std::string &str, char separator=' ')
Definition: UStl.h:566
static std::map< std::string, float > _defaultData
Definition: Statistics.h:337
static std::string serializeData(const std::map< std::string, float > &data)
Definition: Statistics.cpp:42
static bool _defaultDataInitialized
Definition: Statistics.h:338
virtual ~Statistics()
Definition: Statistics.cpp:88
std::map< int, Signature > _signaturesData
Definition: Statistics.h:308
std::string UTILITE_EXP uReplaceChar(const std::string &str, char before, char after)
Definition: UConversion.cpp:33
static const std::map< std::string, float > & defaultData()
Definition: Statistics.cpp:36
int id() const
Definition: Signature.h:70
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:91
void addStatistic(const std::string &name, float value)
Definition: Statistics.cpp:93
void uInsert(std::map< K, V > &map, const std::pair< K, V > &pair)
Definition: UStl.h:443


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:38:57