libpappsomspp
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 30 of file maptrace.cpp.

31 {
32 }

◆ MapTrace() [2/5]

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

Definition at line 35 of file maptrace.cpp.

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

◆ MapTrace() [3/5]

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

Definition at line 45 of file maptrace.cpp.

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

◆ MapTrace() [4/5]

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

Definition at line 54 of file maptrace.cpp.

55  : std::map<pappso_double, pappso_double>(other)
56 {
57 }

◆ MapTrace() [5/5]

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

Definition at line 60 of file maptrace.cpp.

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

◆ ~MapTrace()

pappso::MapTrace::~MapTrace ( )
virtual

Definition at line 80 of file maptrace.cpp.

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

Member Function Documentation

◆ firstToVector()

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

Definition at line 167 of file maptrace.cpp.

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

Referenced by xValues().

◆ initialize() [1/2]

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

Definition at line 114 of file maptrace.cpp.

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

◆ initialize() [2/2]

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

Definition at line 88 of file maptrace.cpp.

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

◆ makeMapTraceCstSPtr()

MapTraceCstSPtr pappso::MapTrace::makeMapTraceCstSPtr ( ) const

Definition at line 160 of file maptrace.cpp.

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

◆ makeMapTraceSPtr()

MapTraceSPtr pappso::MapTrace::makeMapTraceSPtr ( ) const

Definition at line 153 of file maptrace.cpp.

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

◆ operator=()

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

Definition at line 132 of file maptrace.cpp.

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

◆ secondToVector()

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

Definition at line 179 of file maptrace.cpp.

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

Referenced by yValues().

◆ toString()

QString pappso::MapTrace::toString ( ) const

Definition at line 217 of file maptrace.cpp.

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

◆ toTrace()

Trace pappso::MapTrace::toTrace ( ) const

Definition at line 205 of file maptrace.cpp.

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

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

◆ xValues()

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

Definition at line 191 of file maptrace.cpp.

192 {
193  return firstToVector();
194 }

References firstToVector().

◆ yValues()

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

Definition at line 198 of file maptrace.cpp.

199 {
200  return secondToVector();
201 }

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:167
pappso::MapTrace::secondToVector
std::vector< pappso_double > secondToVector() const
Definition: maptrace.cpp:179