1 /**
2  * File: FeatureVector.cpp
3  * Date: November 2011
4  * Author: Dorian Galvez-Lopez
5  * Description: feature vector
6  * License: see the LICENSE.txt file
7  *
8  */
9 
10 #include "FeatureVector.h"
11 #include <map>
12 #include <vector>
13 #include <iostream>
14 
15 namespace DBoW2 {
16 
17 // ---------------------------------------------------------------------------
18 
FeatureVector(void)19 FeatureVector::FeatureVector(void)
20 {
21 }
22 
23 // ---------------------------------------------------------------------------
24 
~FeatureVector(void)25 FeatureVector::~FeatureVector(void)
26 {
27 }
28 
29 // ---------------------------------------------------------------------------
30 
addFeature(NodeId id,unsigned int i_feature)31 void FeatureVector::addFeature(NodeId id, unsigned int i_feature)
32 {
33   FeatureVector::iterator vit = this->lower_bound(id);
34 
35   if(vit != this->end() && vit->first == id)
36   {
37     vit->second.push_back(i_feature);
38   }
39   else
40   {
41     vit = this->insert(vit, FeatureVector::value_type(id,
42       std::vector<unsigned int>() ));
43     vit->second.push_back(i_feature);
44   }
45 }
46 
47 // ---------------------------------------------------------------------------
48 
operator <<(std::ostream & out,const FeatureVector & v)49 std::ostream& operator<<(std::ostream &out,
50   const FeatureVector &v)
51 {
52   if(!v.empty())
53   {
54     FeatureVector::const_iterator vit = v.begin();
55 
56     const std::vector<unsigned int>* f = &vit->second;
57 
58     out << "<" << vit->first << ": [";
59     if(!f->empty()) out << (*f)[0];
60     for(unsigned int i = 1; i < f->size(); ++i)
61     {
62       out << ", " << (*f)[i];
63     }
64     out << "]>";
65 
66     for(++vit; vit != v.end(); ++vit)
67     {
68       f = &vit->second;
69 
70       out << ", <" << vit->first << ": [";
71       if(!f->empty()) out << (*f)[0];
72       for(unsigned int i = 1; i < f->size(); ++i)
73       {
74         out << ", " << (*f)[i];
75       }
76       out << "]>";
77     }
78   }
79 
80   return out;
81 }
82 
83 // ---------------------------------------------------------------------------
84 
85 } // namespace DBoW2
86