pappsomspp
Library for mass spectrometry
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_doublefirstToVector () const
 
std::vector< pappso_doublesecondToVector () const
 
std::vector< pappso_doublexValues ()
 
std::vector< pappso_doubleyValues ()
 
Trace toTrace () const
 
QString toString () const
 

Detailed Description

Definition at line 32 of file maptrace.h.

Constructor & Destructor Documentation

◆ MapTrace() [1/5]

pappso::MapTrace::MapTrace ( )

Definition at line 28 of file maptrace.cpp.

29 {
30 }

◆ MapTrace() [2/5]

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

Definition at line 33 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.

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

◆ MapTrace() [5/5]

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

Definition at line 58 of file maptrace.cpp.

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

◆ ~MapTrace()

pappso::MapTrace::~MapTrace ( )
virtual

Definition at line 78 of file maptrace.cpp.

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

Member Function Documentation

◆ firstToVector()

std::vector< pappso_double > pappso::MapTrace::firstToVector ( ) const

Definition at line 168 of file maptrace.cpp.

169 {
170  std::vector<pappso_double> vector;
171 
172  for(auto &&pair : *this)
173  vector.push_back(pair.first);
174 
175  return vector;
176 }

Referenced by xValues().

◆ initialize() [1/2]

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

Definition at line 115 of file maptrace.cpp.

116 {
117 
118  // Clear *this, because initialize supposes that *this will be identical to
119  // map.
120 
121  clear();
122 
123  for(auto &&pair : map)
124  {
125  insert(pair);
126  }
127 
128  return size();
129 }

◆ initialize() [2/2]

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

Definition at line 86 of file maptrace.cpp.

88 {
89  // Clear *this, because initialize supposes that *this will contain only the
90  // data in the vectors.
91 
92  clear();
93 
94  // Sanity check
95  if(xVector.size() != yVector.size())
96  qFatal(
97  "Fatal error at %s@%d -- %s(). "
98  "xVector and yVector must have the same size."
99  "Program aborted.",
100  __FILE__,
101  __LINE__,
102  __FUNCTION__);
103 
104  for(std::size_t iter = 0; iter < xVector.size(); ++iter)
105  {
106  insert(std::pair<pappso_double, pappso_double>(xVector.at(iter),
107  yVector.at(iter)));
108  }
109 
110  return size();
111 }

◆ makeMapTraceCstSPtr()

MapTraceCstSPtr pappso::MapTrace::makeMapTraceCstSPtr ( ) const

Definition at line 161 of file maptrace.cpp.

162 {
163  return std::make_shared<const MapTrace>(*this);
164 }

◆ makeMapTraceSPtr()

MapTraceSPtr pappso::MapTrace::makeMapTraceSPtr ( ) const

Definition at line 154 of file maptrace.cpp.

155 {
156  return std::make_shared<MapTrace>(*this);
157 }

◆ operator=()

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

Definition at line 133 of file maptrace.cpp.

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

◆ secondToVector()

std::vector< pappso_double > pappso::MapTrace::secondToVector ( ) const

Definition at line 180 of file maptrace.cpp.

181 {
182  std::vector<pappso_double> vector;
183 
184  for(auto &&pair : *this)
185  vector.push_back(pair.second);
186 
187  return vector;
188 }

Referenced by yValues().

◆ toString()

QString pappso::MapTrace::toString ( ) const

Definition at line 218 of file maptrace.cpp.

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

◆ toTrace()

Trace pappso::MapTrace::toTrace ( ) const

Definition at line 206 of file maptrace.cpp.

207 {
208  Trace trace;
209 
210  for(auto &&pair : *this)
211  trace.push_back(DataPoint(pair.first, pair.second));
212 
213  return trace;
214 }

Referenced by pappso::TracePlusCombiner::combine().

◆ xValues()

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

Definition at line 192 of file maptrace.cpp.

193 {
194  return firstToVector();
195 }

References firstToVector().

◆ yValues()

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

Definition at line 199 of file maptrace.cpp.

200 {
201  return secondToVector();
202 }

References secondToVector().


The documentation for this class was generated from the following files:
pappso::MapTrace::firstToVector
std::vector< pappso_double > firstToVector() const
Definition: maptrace.cpp:168
pappso::MapTrace::secondToVector
std::vector< pappso_double > secondToVector() const
Definition: maptrace.cpp:180