12 #include "../processing/combiners/tracepluscombiner.h"
13 #include "../processing/combiners/traceminuscombiner.h"
15 #include "../pappsoexception.h"
16 #include "../exception/exceptionoutofrange.h"
17 #include "../processing/filters/filterresample.h"
18 #include "../processing/filters/filterpass.h"
28 std::vector<DataPoint>::iterator
30 std::vector<DataPoint>::iterator end,
33 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
34 if(to_compare.
x < value)
42 std::vector<DataPoint>::const_iterator
44 std::vector<DataPoint>::const_iterator end,
47 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
48 if(to_compare.
x < value)
56 std::vector<DataPoint>::iterator
58 std::vector<DataPoint>::iterator end,
61 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
62 if(to_compare.
x > value)
70 std::vector<DataPoint>::const_iterator
72 std::vector<DataPoint>::const_iterator end,
75 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
76 if(to_compare.
x > value)
85 std::vector<DataPoint>::iterator
87 std::vector<DataPoint>::iterator end,
88 const double &y_value)
90 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
91 if(to_compare.
y != y_value)
99 std::vector<DataPoint>::const_iterator
101 std::vector<DataPoint>::const_iterator end,
102 const double &y_value)
104 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
105 if(to_compare.
y != y_value)
114 std::vector<DataPoint>::const_iterator
116 std::vector<DataPoint>::const_iterator end)
118 return std::min_element(
125 std::vector<DataPoint>::const_iterator
127 std::vector<DataPoint>::const_iterator end)
129 return std::max_element(
136 std::vector<DataPoint>::iterator
138 std::vector<DataPoint>::iterator end)
140 return std::max_element(
147 std::vector<DataPoint>::const_iterator
149 std::vector<DataPoint>::const_iterator begin)
151 if(begin == trace.end())
155 while((it != trace.end()) && (it->y <= result->y))
163 std::vector<DataPoint>::const_iterator
165 std::vector<DataPoint>::const_iterator begin)
167 if(begin == trace.begin())
171 while((it != trace.begin()) && (it->y <= result->y))
182 std::vector<DataPoint>::const_iterator end,
185 return std::accumulate(
186 begin, end, init, [](
double a,
const DataPoint &
b) {
return a +
b.y; });
191 std::vector<DataPoint>::const_iterator end)
196 QObject::tr(
"unable to compute mean on a trace of size 0"));
197 return (
sumYTrace(begin, end, 0) / nb_element);
202 std::vector<DataPoint>::const_iterator end)
207 QObject::tr(
"unable to compute median on a trace of size 0"));
209 std::vector<DataPoint> data(begin, end);
212 data.begin() + data.size() / 2,
215 return data[data.size() / 2].y;
220 std::vector<DataPoint>::const_iterator end)
225 auto previous = begin;
226 auto next = begin + 1;
230 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
240 std::vector<DataPoint>::const_iterator end,
243 Trace local_maxima_trace;
245 Trace single_peak_trace;
249 for(
auto iter = begin; iter != end; ++iter)
251 DataPoint iterated_data_point(iter->x, iter->y);
256 if(iterated_data_point.
y < y_floor)
260 if(single_peak_trace.size())
264 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
270 single_peak_trace.clear();
272 previous_data_point = iterated_data_point;
280 previous_data_point = iterated_data_point;
292 if(iterated_data_point.
y == previous_data_point.
y)
298 else if(iterated_data_point.
y > previous_data_point.
y)
307 single_peak_trace.push_back(iterated_data_point);
312 previous_data_point = iterated_data_point;
323 single_peak_trace.push_back(iterated_data_point);
328 previous_data_point = iterated_data_point;
340 if(single_peak_trace.size())
343 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
350 return local_maxima_trace;
360 const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
362 reserve(dataPoints.size());
364 for(
auto &dataPoint : dataPoints)
382 : std::vector<
DataPoint>(std::move(dataPoints))
390 for(
auto &&item : map_trace)
391 push_back(
DataPoint(item.first, item.second));
414 const std::vector<pappso_double> &yVector)
417 if(xVector.size() != yVector.size())
419 "Fatal error at %s@%d -- %s(). "
420 "xVector and yVector must have the same size."
429 resize(xVector.size());
431 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
433 push_back(
DataPoint(xVector.at(iter), yVector.at(iter)));
449 for(
auto &&item : map)
451 push_back(
DataPoint(item.first, item.second));
470 assign(other.begin(), other.end());
479 vector<DataPoint>::operator=(std::move(other));
487 return std::make_shared<Trace>(*
this);
494 return std::make_shared<const Trace>(*
this);
498 std::vector<pappso_double>
501 std::vector<pappso_double> vector;
503 for(
auto &&dataPoint : *
this)
504 vector.push_back(dataPoint.x);
510 std::vector<pappso_double>
513 std::vector<pappso_double> vector;
515 for(
auto &&dataPoint : *
this)
516 vector.push_back(dataPoint.y);
522 std::map<pappso_double, pappso_double>
525 std::map<pappso_double, pappso_double> map;
527 std::pair<std::map<pappso_double, pappso_double>::iterator,
bool> ret;
529 for(
auto &&dataPoint : *
this)
532 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
534 if(ret.second ==
false)
536 qDebug() << __FILE__ <<
"@" << __LINE__ << __FUNCTION__ <<
"()"
537 <<
"It is odd that the Trace contains multiple same keys.";
540 ret.first->second += dataPoint.y;
569 std::vector<DataPoint>::iterator
573 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
574 return (dataPoint.
x == value);
581 std::vector<DataPoint>::const_iterator
585 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
586 return (dataPoint.
x == value);
596 std::vector<DataPoint>::const_iterator iterator =
599 if(iterator != end())
600 return std::distance(begin(), iterator);
602 return std::numeric_limits<std::size_t>::max();
609 auto iterator = std::find_if(
610 begin(), end(), [value, precision_p](
const DataPoint &data_point) {
615 if(data_point.
x >= (value - delta) && data_point.
x <= (value + delta))
622 return (data_point.
x == value);
626 if(iterator != end())
642 auto dataPoint = std::min_element(
647 if(dataPoint == end())
650 QObject::tr(
"unable to get min peak intensity on spectrum size %1")
661 auto dataPoint = std::max_element(
666 if(dataPoint == end())
669 QObject::tr(
"unable to get max peak intensity on spectrum size %1")
704 return std::accumulate(begin(),
708 return (
sum + dataPoint.
y);
725 std::vector<DataPoint>::const_iterator begin_it =
730 while(begin_it != this->end())
732 if(begin_it->y > max_y)
761 std::vector<pappso_double>
764 std::vector<pappso_double> values;
766 for(
auto &&dataPoint : *
this)
768 values.push_back(dataPoint.x);
775 std::vector<pappso_double>
778 std::vector<pappso_double> values;
780 for(
auto &&dataPoint : *
this)
782 values.push_back(dataPoint.y);
795 for(
auto &&dataPoint : *
this)
797 text.append(QString(
"%1 %2\n")
798 .arg(dataPoint.x, 0,
'f', 10)
799 .arg(dataPoint.y, 0,
'f', 10));