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>::iterator
128 std::vector<DataPoint>::iterator end)
130 return std::min_element(
137 std::vector<DataPoint>::const_iterator
139 std::vector<DataPoint>::const_iterator end)
141 return std::max_element(
148 std::vector<DataPoint>::iterator
150 std::vector<DataPoint>::iterator end)
152 return std::max_element(
159 std::vector<DataPoint>::const_iterator
161 std::vector<DataPoint>::const_iterator begin)
163 if(begin == trace.end())
167 while((it != trace.end()) && (it->y <= result->y))
175 std::vector<DataPoint>::const_iterator
177 std::vector<DataPoint>::const_iterator begin)
179 if(begin == trace.begin())
183 while((it != trace.begin()) && (it->y <= result->y))
194 std::vector<DataPoint>::const_iterator end,
197 return std::accumulate(
198 begin, end, init, [](
double a,
const DataPoint &
b) {
return a +
b.y; });
203 std::vector<DataPoint>::const_iterator end)
208 QObject::tr(
"unable to compute mean on a trace of size 0"));
209 return (
sumYTrace(begin, end, 0) / nb_element);
214 std::vector<DataPoint>::const_iterator end)
219 QObject::tr(
"unable to compute median on a trace of size 0"));
221 std::vector<DataPoint> data(begin, end);
224 data.begin() + data.size() / 2,
227 return data[data.size() / 2].y;
232 std::vector<DataPoint>::const_iterator end)
237 auto previous = begin;
238 auto next = begin + 1;
242 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
252 std::vector<DataPoint>::const_iterator end,
255 Trace local_maxima_trace;
257 Trace single_peak_trace;
261 for(
auto iter = begin; iter != end; ++iter)
263 DataPoint iterated_data_point(iter->x, iter->y);
268 if(iterated_data_point.
y < y_floor)
272 if(single_peak_trace.size())
276 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
282 single_peak_trace.clear();
284 previous_data_point = iterated_data_point;
292 previous_data_point = iterated_data_point;
304 if(iterated_data_point.
y == previous_data_point.
y)
310 else if(iterated_data_point.
y > previous_data_point.
y)
319 single_peak_trace.push_back(iterated_data_point);
324 previous_data_point = iterated_data_point;
335 single_peak_trace.push_back(iterated_data_point);
340 previous_data_point = iterated_data_point;
352 if(single_peak_trace.size())
355 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
362 return local_maxima_trace;
372 const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
374 reserve(dataPoints.size());
376 for(
auto &dataPoint : dataPoints)
394 : std::vector<
DataPoint>(std::move(dataPoints))
402 for(
auto &&item : map_trace)
403 push_back(
DataPoint(item.first, item.second));
426 const std::vector<pappso_double> &yVector)
429 if(xVector.size() != yVector.size())
431 "trace.cpp -- ERROR xVector and yVector must have the same size.");
436 resize(xVector.size());
438 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
440 push_back(
DataPoint(xVector.at(iter), yVector.at(iter)));
456 for(
auto &&item : map)
458 push_back(
DataPoint(item.first, item.second));
477 assign(other.begin(), other.end());
486 vector<DataPoint>::operator=(std::move(other));
494 return std::make_shared<Trace>(*
this);
501 return std::make_shared<const Trace>(*
this);
505 std::vector<pappso_double>
508 std::vector<pappso_double> vector;
510 for(
auto &&dataPoint : *
this)
511 vector.push_back(dataPoint.x);
517 std::vector<pappso_double>
520 std::vector<pappso_double> vector;
522 for(
auto &&dataPoint : *
this)
523 vector.push_back(dataPoint.y);
529 std::map<pappso_double, pappso_double>
532 std::map<pappso_double, pappso_double> map;
534 std::pair<std::map<pappso_double, pappso_double>::iterator,
bool> ret;
536 for(
auto &&dataPoint : *
this)
539 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
541 if(ret.second ==
false)
543 qDebug() << __FILE__ <<
"@" << __LINE__ << __FUNCTION__ <<
"()"
544 <<
"It is odd that the Trace contains multiple same keys.";
547 ret.first->second += dataPoint.y;
576 std::vector<DataPoint>::iterator
580 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
581 return (dataPoint.
x == value);
588 std::vector<DataPoint>::const_iterator
592 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
593 return (dataPoint.
x == value);
603 std::vector<DataPoint>::const_iterator iterator =
606 if(iterator != end())
607 return std::distance(begin(), iterator);
609 return std::numeric_limits<std::size_t>::max();
616 auto iterator = std::find_if(
617 begin(), end(), [value, precision_p](
const DataPoint &data_point) {
622 if(data_point.
x >= (value - delta) && data_point.
x <= (value + delta))
629 return (data_point.
x == value);
633 if(iterator != end())
649 auto dataPoint = std::min_element(
654 if(dataPoint == end())
657 QObject::tr(
"unable to get min peak intensity on spectrum size %1")
668 auto dataPoint = std::max_element(
673 if(dataPoint == end())
676 QObject::tr(
"unable to get max peak intensity on spectrum size %1")
711 return std::accumulate(begin(),
715 return (
sum + dataPoint.
y);
732 std::vector<DataPoint>::const_iterator begin_it =
739 if(begin_it->y > max_y)
768 std::vector<pappso_double>
771 std::vector<pappso_double> values;
773 for(
auto &&dataPoint : *
this)
775 values.push_back(dataPoint.x);
782 std::vector<pappso_double>
785 std::vector<pappso_double> values;
787 for(
auto &&dataPoint : *
this)
789 values.push_back(dataPoint.y);
802 for(
auto &&dataPoint : *
this)
804 text.append(QString(
"%1 %2\n")
805 .arg(dataPoint.x, 0,
'f', 10)
806 .arg(dataPoint.y, 0,
'f', 10));