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_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

◆ 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 }

◆ toString()

QString pappso::MapTrace::toString ( ) const

Definition at line 203 of file maptrace.cpp.

204 {
205  // Even if the spectrum is empty, we should return an empty string.
206  QString text;
207 
208  for(auto &&pair : *this)
209  {
210 // For debugging
211 #if 0
212 
213  QString new_data_point_text = QString("%1 %2\n")
214  .arg(pair.first, 0, 'f', 10)
215  .arg(pair.second, 0, 'f', 10);
216 
217  qDebug() << "new data point text:" << new_data_point_text;
218  text.append(new_data_point_text);
219 #endif
220 
221  text.append(QString("%1 %2\n")
222  .arg(pair.first, 0, 'f', 10)
223  .arg(pair.second, 0, 'f', 10));
224  }
225 
226  return text;
227 }

◆ toTrace()

Trace pappso::MapTrace::toTrace ( ) const

Definition at line 191 of file maptrace.cpp.

192 {
193  Trace trace;
194 
195  for(auto &&pair : *this)
196  trace.push_back(DataPoint(pair.first, pair.second));
197 
198  return trace;
199 }

Referenced by pappso::TraceMinusCombiner::combine(), and pappso::TracePlusCombiner::combine().

◆ xValues()

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

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 }

◆ yValues()

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

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 }

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