00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00032 #include <mtt/measurement.h> 00033 00034 Measurement::Measurement() 00035 { 00036 id=0; 00037 } 00038 00039 Measurement::~Measurement() 00040 { 00041 // cout<<"deleted: measurement: "<<id<<endl; 00042 // assigned_clusters.clear(); 00043 // points.clear(); 00044 } 00045 00046 ostream& operator<<(ostream& o, Measurement& m) 00047 { 00048 // o<<"measurement: "<<m.id<<" centroid: "<<m.centroid<<" clusters: "; 00049 o<<"measurement: "<<m.id<<" clusters: "; 00050 00051 if(m.assigned_clusters.size()==0) 00052 o<<"[]"; 00053 00054 for(uint c=0;c<m.assigned_clusters.size();c++) 00055 { 00056 o<<(m.assigned_clusters[c])->id; 00057 00058 if(c<m.assigned_clusters.size()-1) 00059 o<<", "; 00060 } 00061 00062 return o; 00063 } 00064 00065 Measurement& Measurement::operator=(const Measurement &rhs) 00066 { 00067 id=rhs.id; 00068 centroid=rhs.centroid; 00069 00070 PointPtr p; 00071 00072 for(uint i=0;i<rhs.points.size();i++) 00073 { 00074 p.reset(new Point); 00075 *p=*(rhs.points[i]); 00076 00077 points.push_back(p); 00078 } 00079 00080 return *this; 00081 } 00082 00083 bool Measurement::breakPointDetector(PointPtr&pt,PointPtr&pt_m1) 00084 { 00089 double d = sqrt( pow(pt->x-pt_m1->x,2) + pow(pt->y-pt_m1->y,2)); 00090 00091 if(d>2.0) 00092 return true; 00093 00094 return false; 00095 } 00096 00097 void Measurement::calculateCentroid(void) 00098 { 00099 centroid.setZero(); 00100 00101 for(uint i=0;i<points.size();i++) 00102 centroid+=*points[i]; 00103 00104 centroid.scale(1./points.size()); 00105 } 00106 00107 bool Measurement::operator<(Measurement &m) 00108 { 00109 cout<<"calling this function"<<endl; 00110 return this->id<m.id; 00111 } 00112 00113 bool Measurement::operator>(Measurement &m) 00114 { 00115 return this->id>m.id; 00116 } 00117 00118 00119 ostream& operator<<(ostream& o,vector<MeasurementPtr>& m) 00120 { 00121 for(uint i=0;i<m.size();++i) 00122 { 00123 o<<"measurement: "<<m[i]->id<<" = "; 00124 00125 if(m[i]->assigned_clusters.size()==0) 00126 o<<"[]"; 00127 00128 for(uint c=0;c<m[i]->assigned_clusters.size();++c) 00129 { 00130 o<<m[i]->assigned_clusters[c]; 00131 if(c<m[i]->assigned_clusters.size()-1) 00132 o<<" ,"; 00133 } 00134 o<<endl; 00135 } 00136 00137 return o; 00138 }