12 #include "../processing/combiners/tracepluscombiner.h"
13 #include "../processing/combiners/traceminuscombiner.h"
15 #include "../pappsoexception.h"
16 #include "../exception/exceptionoutofrange.h"
17 #include "../exception/exceptionnotpossible.h"
18 #include "../processing/filters/filterresample.h"
19 #include "../processing/filters/filterpass.h"
29 std::vector<DataPoint>::iterator
31 std::vector<DataPoint>::iterator end,
34 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
35 if(to_compare.
x < value)
43 std::vector<DataPoint>::const_iterator
45 std::vector<DataPoint>::const_iterator end,
48 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
49 if(to_compare.
x < value)
57 std::vector<DataPoint>::iterator
59 std::vector<DataPoint>::iterator end,
62 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
63 if(to_compare.
x > value)
71 std::vector<DataPoint>::const_iterator
73 std::vector<DataPoint>::const_iterator end,
76 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
77 if(to_compare.
x > value)
86 std::vector<DataPoint>::iterator
88 std::vector<DataPoint>::iterator end,
89 const double &y_value)
91 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
92 if(to_compare.
y != y_value)
100 std::vector<DataPoint>::const_iterator
102 std::vector<DataPoint>::const_iterator end,
103 const double &y_value)
105 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
106 if(to_compare.
y != y_value)
115 std::vector<DataPoint>::const_iterator
117 std::vector<DataPoint>::const_iterator end)
119 return std::min_element(
126 std::vector<DataPoint>::const_iterator
128 std::vector<DataPoint>::const_iterator end)
130 return std::max_element(
137 std::vector<DataPoint>::iterator
139 std::vector<DataPoint>::iterator end)
141 return std::max_element(
148 std::vector<DataPoint>::const_iterator
150 std::vector<DataPoint>::const_iterator begin)
152 if(begin == trace.end())
156 while((it != trace.end()) && (it->y <= result->y))
164 std::vector<DataPoint>::const_iterator
166 std::vector<DataPoint>::const_iterator begin)
168 if(begin == trace.begin())
172 while((it != trace.begin()) && (it->y <= result->y))
183 std::vector<DataPoint>::const_iterator end,
186 return std::accumulate(
187 begin, end, init, [](
double a,
const DataPoint &
b) {
return a +
b.y; });
192 std::vector<DataPoint>::const_iterator end)
197 QObject::tr(
"unable to compute mean on a trace of size 0"));
198 return (
sumYTrace(begin, end, 0) / nb_element);
203 std::vector<DataPoint>::const_iterator end)
208 QObject::tr(
"unable to compute median on a trace of size 0"));
210 std::vector<DataPoint> data(begin, end);
213 data.begin() + data.size() / 2,
216 return data[data.size() / 2].y;
221 std::vector<DataPoint>::const_iterator end)
226 auto previous = begin;
227 auto next = begin + 1;
231 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
241 std::vector<DataPoint>::const_iterator end,
244 Trace local_maxima_trace;
246 Trace single_peak_trace;
250 for(
auto iter = begin; iter != end; ++iter)
252 DataPoint iterated_data_point(iter->x, iter->y);
257 if(iterated_data_point.
y < y_floor)
261 if(single_peak_trace.size())
265 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
271 single_peak_trace.clear();
273 previous_data_point = iterated_data_point;
281 previous_data_point = iterated_data_point;
293 if(iterated_data_point.
y == previous_data_point.
y)
299 else if(iterated_data_point.
y > previous_data_point.
y)
308 single_peak_trace.push_back(iterated_data_point);
313 previous_data_point = iterated_data_point;
324 single_peak_trace.push_back(iterated_data_point);
329 previous_data_point = iterated_data_point;
341 if(single_peak_trace.size())
344 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
351 return local_maxima_trace;
361 const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
363 reserve(dataPoints.size());
365 for(
auto &dataPoint : dataPoints)
383 : std::vector<
DataPoint>(std::move(dataPoints))
391 for(
auto &&item : map_trace)
392 push_back(
DataPoint(item.first, item.second));
415 const std::vector<pappso_double> &yVector)
418 if(xVector.size() != yVector.size())
420 "trace.cpp -- ERROR xVector and yVector must have the same size.");
425 resize(xVector.size());
427 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
429 push_back(
DataPoint(xVector.at(iter), yVector.at(iter)));
445 for(
auto &&item : map)
447 push_back(
DataPoint(item.first, item.second));
466 assign(other.begin(), other.end());
475 vector<DataPoint>::operator=(std::move(other));
483 return std::make_shared<Trace>(*
this);
490 return std::make_shared<const Trace>(*
this);
494 std::vector<pappso_double>
497 std::vector<pappso_double> vector;
499 for(
auto &&dataPoint : *
this)
500 vector.push_back(dataPoint.x);
506 std::vector<pappso_double>
509 std::vector<pappso_double> vector;
511 for(
auto &&dataPoint : *
this)
512 vector.push_back(dataPoint.y);
518 std::map<pappso_double, pappso_double>
521 std::map<pappso_double, pappso_double> map;
523 std::pair<std::map<pappso_double, pappso_double>::iterator,
bool> ret;
525 for(
auto &&dataPoint : *
this)
528 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
530 if(ret.second ==
false)
532 qDebug() << __FILE__ <<
"@" << __LINE__ << __FUNCTION__ <<
"()"
533 <<
"It is odd that the Trace contains multiple same keys.";
536 ret.first->second += dataPoint.y;
565 std::vector<DataPoint>::iterator
569 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
570 return (dataPoint.
x == value);
577 std::vector<DataPoint>::const_iterator
581 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
582 return (dataPoint.
x == value);
592 std::vector<DataPoint>::const_iterator iterator =
595 if(iterator != end())
596 return std::distance(begin(), iterator);
598 return std::numeric_limits<std::size_t>::max();
605 auto iterator = std::find_if(
606 begin(), end(), [value, precision_p](
const DataPoint &data_point) {
611 if(data_point.
x >= (value - delta) && data_point.
x <= (value + delta))
618 return (data_point.
x == value);
622 if(iterator != end())
638 auto dataPoint = std::min_element(
643 if(dataPoint == end())
646 QObject::tr(
"unable to get min peak intensity on spectrum size %1")
657 auto dataPoint = std::max_element(
662 if(dataPoint == end())
665 QObject::tr(
"unable to get max peak intensity on spectrum size %1")
700 return std::accumulate(begin(),
704 return (
sum + dataPoint.
y);
721 std::vector<DataPoint>::const_iterator begin_it =
728 if(begin_it->y > max_y)
757 std::vector<pappso_double>
760 std::vector<pappso_double> values;
762 for(
auto &&dataPoint : *
this)
764 values.push_back(dataPoint.x);
771 std::vector<pappso_double>
774 std::vector<pappso_double> values;
776 for(
auto &&dataPoint : *
this)
778 values.push_back(dataPoint.y);
791 for(
auto &&dataPoint : *
this)
793 text.append(QString(
"%1 %2\n")
794 .arg(dataPoint.x, 0,
'f', 10)
795 .arg(dataPoint.y, 0,
'f', 10));