measurement.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
32 #include <mtt/measurement.h>
33 
35 {
36  id=0;
37 }
38 
40 {
41 // cout<<"deleted: measurement: "<<id<<endl;
42 // assigned_clusters.clear();
43 // points.clear();
44 }
45 
46 ostream& operator<<(ostream& o, Measurement& m)
47 {
48 // o<<"measurement: "<<m.id<<" centroid: "<<m.centroid<<" clusters: ";
49  o<<"measurement: "<<m.id<<" clusters: ";
50 
51  if(m.assigned_clusters.size()==0)
52  o<<"[]";
53 
54  for(uint c=0;c<m.assigned_clusters.size();c++)
55  {
56  o<<(m.assigned_clusters[c])->id;
57 
58  if(c<m.assigned_clusters.size()-1)
59  o<<", ";
60  }
61 
62  return o;
63 }
64 
66 {
67  id=rhs.id;
68  centroid=rhs.centroid;
69 
70  PointPtr p;
71 
72  for(uint i=0;i<rhs.points.size();i++)
73  {
74  p.reset(new Point);
75  *p=*(rhs.points[i]);
76 
77  points.push_back(p);
78  }
79 
80  return *this;
81 }
82 
84 {
89  double d = sqrt( pow(pt->x-pt_m1->x,2) + pow(pt->y-pt_m1->y,2));
90 
91  if(d>2.0)
92  return true;
93 
94  return false;
95 }
96 
98 {
99  centroid.setZero();
100 
101  for(uint i=0;i<points.size();i++)
102  centroid+=*points[i];
103 
104  centroid.scale(1./points.size());
105 }
106 
108 {
109  cout<<"calling this function"<<endl;
110  return this->id<m.id;
111 }
112 
114 {
115  return this->id>m.id;
116 }
117 
118 
119 ostream& operator<<(ostream& o,vector<MeasurementPtr>& m)
120 {
121  for(uint i=0;i<m.size();++i)
122  {
123  o<<"measurement: "<<m[i]->id<<" = ";
124 
125  if(m[i]->assigned_clusters.size()==0)
126  o<<"[]";
127 
128  for(uint c=0;c<m[i]->assigned_clusters.size();++c)
129  {
130  o<<m[i]->assigned_clusters[c];
131  if(c<m[i]->assigned_clusters.size()-1)
132  o<<" ,";
133  }
134  o<<endl;
135  }
136 
137  return o;
138 }
void setZero()
Set all the point fields to zero.
Definition: point.cpp:39
long id
Id of the measurement.
Definition: measurement.h:69
boost::shared_ptr< Point > PointPtr
Shared pointer to the Point class.
Definition: point.h:45
Point centroid
Centroid of the measurement.
Definition: measurement.h:67
Measurement & operator=(const Measurement &rhs)
Definition: measurement.cpp:65
Simple point class.
Definition: point.h:53
Measurement class type.
Definition: measurement.h:60
bool operator<(Measurement &)
Measurement class declaration.
ostream & operator<<(ostream &o, Measurement &m)
Definition: measurement.cpp:46
bool breakPointDetector(PointPtr &pt, PointPtr &pt_m1)
Break point detection used as clustering criterion.
Definition: measurement.cpp:83
void calculateCentroid(void)
Calculate the centroid of the cluster.
Definition: measurement.cpp:97
bool operator>(Measurement &)
void scale(double val)
Scale all point values by a factor.
Definition: point.cpp:61
vector< ClusterPtr > assigned_clusters
Hypotheses cluster association vector.
Definition: measurement.h:74
vector< PointPtr > points
Vector of the support points.
Definition: measurement.h:65


mtt
Author(s): Jorge Almeida
autogenerated on Mon Mar 2 2015 01:32:18