libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::MapTrace Class Reference

#include <maptrace.h>

Inheritance diagram for pappso::MapTrace:

Public Member Functions

 MapTrace ()
 MapTrace (const std::vector< std::pair< pappso_double, pappso_double > > &dataPoints)
 MapTrace (const std::vector< DataPoint > &dataPoints)
 MapTrace (const MapTrace &other)
 MapTrace (const Trace &trace)
virtual ~MapTrace ()
size_t initialize (const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
size_t initialize (const std::map< pappso_double, pappso_double > &map)
virtual MapTraceoperator= (const MapTrace &other)
MapTraceSPtr makeMapTraceSPtr () const
MapTraceCstSPtr makeMapTraceCstSPtr () const
std::vector< pappso_doublexValues ()
std::vector< pappso_doubleyValues ()
void insertOrUpdate (const DataPoint &data_point)
void insertOrUpdate (const Trace &trace)
Trace toTrace () const
QString toString () const

Detailed Description

Definition at line 35 of file maptrace.h.

Constructor & Destructor Documentation

◆ MapTrace() [1/5]

pappso::MapTrace::MapTrace ( )

Definition at line 29 of file maptrace.cpp.

30{
31}

Referenced by MapTrace(), and operator=().

◆ MapTrace() [2/5]

pappso::MapTrace::MapTrace ( const std::vector< std::pair< pappso_double, pappso_double > > & dataPoints)

Definition at line 34 of file maptrace.cpp.

35{
36 for(auto &dataPoint : dataPoints)
37 {
38 insert(dataPoint);
39 }
40}

◆ MapTrace() [3/5]

pappso::MapTrace::MapTrace ( const std::vector< DataPoint > & dataPoints)

Definition at line 43 of file maptrace.cpp.

44{
45 for(auto &dataPoint : dataPoints)
46 {
47 insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
48 }
49}

◆ MapTrace() [4/5]

pappso::MapTrace::MapTrace ( const MapTrace & other)

Definition at line 52 of file maptrace.cpp.

52 : std::map<pappso_double, pappso_double>(other)
53{
54}

References MapTrace().

◆ MapTrace() [5/5]

pappso::MapTrace::MapTrace ( const Trace & trace)

Definition at line 57 of file maptrace.cpp.

58{
59 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
60
61 for(auto &dataPoint : trace)
62 {
63 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << "
64 // () "
65 //<< std::setprecision(15)
66 //<< "Current data point: " << dataPoint.toString().toStdString() <<
67 // std::endl;
68
69 insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
70 }
71
72 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
73 //<< "After construction, map size: " << size();
74}

◆ ~MapTrace()

pappso::MapTrace::~MapTrace ( )
virtual

Definition at line 77 of file maptrace.cpp.

78{
79 // Calls the destructor for each DataPoint object in the vector.
80 clear();
81}

Member Function Documentation

◆ initialize() [1/2]

size_t pappso::MapTrace::initialize ( const std::map< pappso_double, pappso_double > & map)

Definition at line 110 of file maptrace.cpp.

111{
112
113 // Clear *this, because initialize supposes that *this will be identical to
114 // map.
115
116 clear();
117
118 for(auto &&pair : map)
119 {
120 insert(pair);
121 }
122
123 return size();
124}

◆ initialize() [2/2]

size_t pappso::MapTrace::initialize ( const std::vector< pappso_double > & xVector,
const std::vector< pappso_double > & yVector )

Definition at line 85 of file maptrace.cpp.

87{
88 // Clear *this, because initialize supposes that *this will contain only the
89 // data in the vectors.
90
91 clear();
92
93 // Sanity check
94 if(xVector.size() != yVector.size())
95 throw ExceptionNotPossible(
96 QObject::tr("Fatal error at msrundatasettreenode.cpp "
97 "-- ERROR xVector and yVector must have the same size."
98 "Program aborted."));
99
100 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
101 {
102 insert(std::pair<pappso_double, pappso_double>(xVector.at(iter), yVector.at(iter)));
103 }
104
105 return size();
106}

◆ insertOrUpdate() [1/2]

void pappso::MapTrace::insertOrUpdate ( const DataPoint & data_point)

Definition at line 187 of file maptrace.cpp.

188{
189
190 // Try to insert the data point into the map. Check if that was done or
191 // not.
192 std::pair<std::map<double, double>::iterator, bool> res =
193 insert(std::pair<double, double>(data_point.x, data_point.y));
194
195 if(!res.second)
196 {
197 // One other same (x,y) value pair was seen already. Only increment the y
198 // value.
199
200 res.first->second += data_point.y;
201 }
202}

References pappso::DataPoint::x, and pappso::DataPoint::y.

Referenced by insertOrUpdate().

◆ insertOrUpdate() [2/2]

void pappso::MapTrace::insertOrUpdate ( const Trace & trace)

Definition at line 206 of file maptrace.cpp.

207{
208 for(const DataPoint &data_point : trace)
209 insertOrUpdate(data_point);
210}
void insertOrUpdate(const DataPoint &data_point)
Definition maptrace.cpp:187

References insertOrUpdate().

◆ makeMapTraceCstSPtr()

MapTraceCstSPtr pappso::MapTrace::makeMapTraceCstSPtr ( ) const

Definition at line 156 of file maptrace.cpp.

157{
158 return std::make_shared<const MapTrace>(*this);
159}

◆ makeMapTraceSPtr()

MapTraceSPtr pappso::MapTrace::makeMapTraceSPtr ( ) const

Definition at line 149 of file maptrace.cpp.

150{
151 return std::make_shared<MapTrace>(*this);
152}

◆ operator=()

MapTrace & pappso::MapTrace::operator= ( const MapTrace & other)
virtual

Definition at line 128 of file maptrace.cpp.

129{
130
131 if(&other == this)
132 return *this;
133
134 // Clear *this, because initialize supposes that *this will be identical to
135 // other.
136
137 clear();
138
139 for(auto &pair : other)
140 {
141 insert(pair);
142 }
143
144 return *this;
145}

References MapTrace().

◆ toString()

QString pappso::MapTrace::toString ( ) const

Definition at line 226 of file maptrace.cpp.

227{
228 // Even if the spectrum is empty, we should return an empty string.
229 QString text;
230
231 for(auto &&pair : *this)
232 {
233// For debugging
234#if 0
235
236 QString new_data_point_text = QString("%1 %2\n")
237 .arg(pair.first, 0, 'f', 10)
238 .arg(pair.second, 0, 'f', 10);
239
240 qDebug() << "new data point text:" << new_data_point_text;
241 text.append(new_data_point_text);
242#endif
243
244 text.append(QString("%1 %2\n").arg(pair.first, 0, 'f', 10).arg(pair.second, 0, 'f', 10));
245 }
246
247 return text;
248}

◆ toTrace()

Trace pappso::MapTrace::toTrace ( ) const

Definition at line 214 of file maptrace.cpp.

215{
216 Trace trace;
217
218 for(auto &&pair : *this)
219 trace.push_back(DataPoint(pair.first, pair.second));
220
221 return trace;
222}

Referenced by pappso::TraceMinusCombiner::combine(), pappso::TracePlusCombiner::combine(), pappso::TimsData::getTicChromatogram(), and pappso::FilterLowIntensitySignalRemoval::reconstructTrace().

◆ xValues()

std::vector< pappso_double > pappso::MapTrace::xValues ( )

Definition at line 163 of file maptrace.cpp.

164{
165 std::vector<pappso_double> vector;
166
167 for(auto &&pair : *this)
168 vector.push_back(pair.first);
169
170 return vector;
171}

◆ yValues()

std::vector< pappso_double > pappso::MapTrace::yValues ( )

Definition at line 175 of file maptrace.cpp.

176{
177 std::vector<pappso_double> vector;
178
179 for(auto &&pair : *this)
180 vector.push_back(pair.second);
181
182 return vector;
183}

The documentation for this class was generated from the following files: