libpappsomspp
Library for mass spectrometry
pappso::FilterResampleKeepPointInPolygon Class Reference

#include <filterresample.h>

Inheritance diagram for pappso::FilterResampleKeepPointInPolygon:
pappso::FilterInterface

Public Member Functions

 FilterResampleKeepPointInPolygon ()
 
 FilterResampleKeepPointInPolygon (const SelectionPolygon &selection_polygon, DataKind data_kind)
 
 FilterResampleKeepPointInPolygon (const SelectionPolygonSpecVector &selection_polygon_specs)
 
 FilterResampleKeepPointInPolygon (const FilterResampleKeepPointInPolygon &other)
 
virtual ~FilterResampleKeepPointInPolygon ()
 
void newSelectionPolygonSpec (const SelectionPolygonSpec &selection_polygon_spec)
 
FilterResampleKeepPointInPolygonoperator= (const FilterResampleKeepPointInPolygon &other)
 
Tracefilter (Trace &trace) const override
 
Tracefilter (Trace &trace, double dt_value, double rt_value) const
 
virtual Tracefilter (Trace &data_points) const=0
 
- Public Member Functions inherited from pappso::FilterInterface
virtual ~FilterInterface ()
 

Private Attributes

std::vector< SelectionPolygonSpecm_selectionPolygonSpecs
 
double m_lowestMz = std::numeric_limits<double>::max()
 
double m_greatestMz = std::numeric_limits<double>::min()
 

Detailed Description

Definition at line 105 of file filterresample.h.

Constructor & Destructor Documentation

◆ FilterResampleKeepPointInPolygon() [1/4]

pappso::FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon ( )

Definition at line 242 of file filterresample.cpp.

243 {
244 }

◆ FilterResampleKeepPointInPolygon() [2/4]

pappso::FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon ( const SelectionPolygon selection_polygon,
DataKind  data_kind 
)

Definition at line 247 of file filterresample.cpp.

249 {
250  // It is assumed that the selection polygon always has x:MZ and y:DT|RT
251  // depending on the spec data kind.
252 
253  m_selectionPolygonSpecs.push_back(
254  SelectionPolygonSpec(selection_polygon, data_kind));
255 
256  m_lowestMz =
257  m_selectionPolygonSpecs.front().selectionPolygon.getBottomMostPoint().y();
258  m_greatestMz =
259  m_selectionPolygonSpecs.front().selectionPolygon.getTopMostPoint().y();
260 }
std::vector< SelectionPolygonSpec > m_selectionPolygonSpecs

References m_greatestMz, m_lowestMz, and m_selectionPolygonSpecs.

◆ FilterResampleKeepPointInPolygon() [3/4]

pappso::FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon ( const SelectionPolygonSpecVector selection_polygon_specs)

Definition at line 263 of file filterresample.cpp.

265 {
266  qDebug();
267 
268  m_selectionPolygonSpecs.assign(selection_polygon_specs.begin(),
269  selection_polygon_specs.end());
270 
271  for(auto &&item : m_selectionPolygonSpecs)
272  {
273  m_lowestMz =
274  std::min(m_lowestMz, item.selectionPolygon.getBottomMostPoint().y());
275 
276  m_greatestMz =
277  std::max(m_greatestMz, item.selectionPolygon.getTopMostPoint().y());
278  }
279 }

References m_greatestMz, m_lowestMz, and m_selectionPolygonSpecs.

◆ FilterResampleKeepPointInPolygon() [4/4]

pappso::FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon ( const FilterResampleKeepPointInPolygon other)

Definition at line 282 of file filterresample.cpp.

284 {
285  qDebug();
286 
287  m_selectionPolygonSpecs.assign(other.m_selectionPolygonSpecs.begin(),
288  other.m_selectionPolygonSpecs.end());
289 
290  for(auto &&item : m_selectionPolygonSpecs)
291  {
292  m_lowestMz =
293  std::min(m_lowestMz, item.selectionPolygon.getBottomMostPoint().y());
294 
295  m_greatestMz =
296  std::max(m_greatestMz, item.selectionPolygon.getTopMostPoint().y());
297  }
298 }

References m_greatestMz, m_lowestMz, and m_selectionPolygonSpecs.

◆ ~FilterResampleKeepPointInPolygon()

virtual pappso::FilterResampleKeepPointInPolygon::~FilterResampleKeepPointInPolygon ( )
inlinevirtual

Definition at line 119 of file filterresample.h.

119 {};

Member Function Documentation

◆ filter() [1/3]

virtual Trace& pappso::FilterInterface::filter

◆ filter() [2/3]

Trace& pappso::FilterResampleKeepPointInPolygon::filter ( Trace trace) const
overridevirtual

◆ filter() [3/3]

Trace & pappso::FilterResampleKeepPointInPolygon::filter ( Trace trace,
double  dt_value,
double  rt_value 
) const

Definition at line 346 of file filterresample.cpp.

349 {
350  // Each time a new selection polygon spec is added, the lowest and greatest
351  // m/z values are computed. We use these values to remove from the spectrum
352  // all the points that are outside of that lowest-gratest range.
353 
354  // Find the iterator to the most front of the DataPoint vector (mass
355  // spectrum).
356 
357  // Note that the m_lowestMz and m_greatestMz are set during construction of
358  // this FilterResampleKeepPointInPolygon filter using the
359  // selection polygon specs.
360 
361  qDebug() << "The lowest and greatest m/z values:" << m_lowestMz << "and"
362  << m_greatestMz;
363 
364  // Start by filtering away all the data points outside of the
365  // [m_lowestMz--m_greatestMz] range.
366 
367  FilterResampleKeepXRange the_filter(m_lowestMz, m_greatestMz);
368 
369  trace = the_filter.filter(trace);
370 
371  // Now iterate in all the data points remaining in the trace and for each
372  // point craft a "virtual" point using the dt|rt value and the m/z value of
373  // the data point (data_point.x).
374 
375  auto begin_it = trace.begin();
376  auto end_it = trace.end();
377 
378  qDebug() << "Iterating in the m/z range:" << begin_it->x << "-"
379  << std::prev(end_it)->x;
380 
381  // Start at the end of the range. The iter is outside of the requested range,
382  // in fact, as shown using iter-- below.
383  auto iter = end_it;
384 
385  while(iter > begin_it)
386  {
387  // Immediately go to the last data point of the desired iteration range of
388  // the trace that we need to filter. Remember that end() is not pointing
389  // to any vector item, but past the last one.
390  iter--;
391 
392  qDebug() << "Iterating in trace data point with m/z value:" << iter->x;
393 
394  // Now that we have the m/z value, we can check it, in combination with
395  // the value in the selection polygon spec (to make a point) against the
396  // various selection polygon specs in our member vector.
397 
398  double checked_value;
399 
400  for(auto &&spec : m_selectionPolygonSpecs)
401  {
402  // qDebug() << "Iterating in selection polygon spec:" <<
403  // spec.toString();
404 
405  if(spec.dataKind == DataKind::dt)
406  {
407  if(dt_value == -1)
408  qFatal("Programming error.");
409 
410  checked_value = dt_value;
411 
412  // qDebug() << "The data kind: dt.";
413  }
414  else if(spec.dataKind == DataKind::rt)
415  {
416  checked_value = rt_value;
417 
418  // qDebug() << "The data kind: rt.";
419  }
420  else
421  qFatal("Programming error.");
422 
423  // First version doing the whole computation on the basis of the
424  // selection polygon's all faces.
425  //
426  if(!spec.selectionPolygon.contains(QPointF(checked_value, iter->x)))
427  iter = trace.erase(iter);
428 
429 #if 0
430 
431  //This code does not work because depending on the orientation of the
432  //skewed selection polygon (left bottom to right top or left top to
433  //right bottom or or Or depending on the axes of the
434  //bi-dimensional colormap, requiring transposition or not), the
435  //notion of "left line" and of "right line" changes.
436 
437  // Second version checking that point is right of left vertical line
438  // of polygon and left of right vertical line.
439 
440  // double res = sideofline(XX;YY;xA;yA;xB;yB) =
441  // (xB-xA) * (YY-yA) - (yB-yA) * (XX-xA)
442 
443  // If res == 0, the point is on the line
444  // If rest < 0, the point is on the right of the line
445  // If rest > 0, the point is on the left of the line
446 
447  // Left vertical line of the polygon
448 
449  // Bottom point
450  double xA_left =
451  spec.selectionPolygon.getPoint(PointSpecs::BOTTOM_LEFT_POINT).x();
452  double yA_left =
453  spec.selectionPolygon.getPoint(PointSpecs::BOTTOM_LEFT_POINT).y();
454 
455  // Top point
456  double xB_left =
457  spec.selectionPolygon.getPoint(PointSpecs::TOP_LEFT_POINT).x();
458  double yB_left =
459  spec.selectionPolygon.getPoint(PointSpecs::TOP_LEFT_POINT).y();
460 
461  qDebug() << "The left line goes: (" << xA_left << "," << yA_left
462  << ")->(" << xB_left << "," << yB_left << ")";
463 
464  if((xB_left - xA_left) * (iter->x - yA_left) -
465  (yB_left - yA_left) * (checked_value - xA_left) >
466  0)
467  {
468  // The point is left of the left line. We can remove the point
469  // from the mass spectrum.
470 
471  qDebug() << qSetRealNumberPrecision(10)
472  << "Filtered out point (left of left line):"
473  << checked_value << "-" << iter->x;
474 
475  iter = trace.erase(iter);
476 
477  // No need to go on with the analysis, just go to the next (that
478  // is, previous, since we iterate backwards) data point.
479 
480  continue;
481  }
482  else
483  {
484  qDebug() << qSetRealNumberPrecision(10)
485  << "Kept point (right of left line):" << checked_value
486  << "-" << iter->x;
487  }
488 
489  // Right vertical line of the polygon
490 
491  // Bottom point
492  double xA_right =
493  spec.selectionPolygon.getPoint(PointSpecs::BOTTOM_RIGHT_POINT).x();
494  double yA_right =
495  spec.selectionPolygon.getPoint(PointSpecs::BOTTOM_RIGHT_POINT).y();
496 
497  // Top point
498  double xB_right =
499  spec.selectionPolygon.getPoint(PointSpecs::TOP_RIGHT_POINT).x();
500  double yB_right =
501  spec.selectionPolygon.getPoint(PointSpecs::TOP_RIGHT_POINT).y();
502 
503  qDebug() << "The right line goes: (" << xA_right << "," << yA_right
504  << ")->(" << xB_right << "," << yB_right << ")";
505 
506  if((xB_right - xA_right) * (iter->x - yA_right) -
507  (yB_right - yA_right) * (checked_value - xA_right) <
508  0)
509  {
510  qDebug() << qSetRealNumberPrecision(10)
511  << "Filtered out point (right of right line):"
512  << checked_value << "-" << iter->x;
513 
514  // The point is right of the right line. We can remove the point
515  // from the mass spectrum.
516  iter = trace.erase(iter);
517 
518  // Here, continue is implicit.
519  // No need to go on with the analysis, just go to the next (that
520  // is, previous, since we iterate backwards) data point.
521  // continue;
522  }
523  else
524  {
525  if(iter->x >= 449 && iter->x <= 450 && checked_value > 19.5 &&
526  checked_value < 20)
527  qDebug()
528  << qSetRealNumberPrecision(10)
529  << "SHOULD NOT Definitively kept point (left of right line):"
530  << checked_value << "-" << iter->x;
531  else
532  qDebug()
533  << qSetRealNumberPrecision(10)
534  << "MIGHT Definitively kept point (left of right line):"
535  << checked_value << "-" << iter->x;
536  }
537 #endif
538  }
539  // End of
540  // for(auto &&spec : m_selectionPolygonSpecs)
541  }
542  // End of
543  // while(iter > begin_it)
544 
545  return trace;
546 }
@ dt
Drift time.
@ rt
Retention time.

References pappso::BOTTOM_LEFT_POINT, pappso::BOTTOM_RIGHT_POINT, pappso::dt, pappso::FilterResampleKeepXRange::filter(), m_greatestMz, m_lowestMz, m_selectionPolygonSpecs, pappso::rt, pappso::TOP_LEFT_POINT, and pappso::TOP_RIGHT_POINT.

◆ newSelectionPolygonSpec()

void pappso::FilterResampleKeepPointInPolygon::newSelectionPolygonSpec ( const SelectionPolygonSpec selection_polygon_spec)

Definition at line 302 of file filterresample.cpp.

304 {
305  // It is assumed that the selection polygon always has x:MZ and y:DT|RT
306  // depending on the spec data kind.
307 
308  m_selectionPolygonSpecs.push_back(selection_polygon_spec);
309 
310  m_lowestMz = std::min(
311  m_lowestMz,
312  m_selectionPolygonSpecs.back().selectionPolygon.getBottomMostPoint().y());
313 
314  m_greatestMz = std::max(
315  m_greatestMz,
316  m_selectionPolygonSpecs.back().selectionPolygon.getTopMostPoint().y());
317 }

References m_greatestMz, m_lowestMz, and m_selectionPolygonSpecs.

◆ operator=()

FilterResampleKeepPointInPolygon & pappso::FilterResampleKeepPointInPolygon::operator= ( const FilterResampleKeepPointInPolygon other)

Definition at line 321 of file filterresample.cpp.

323 {
324  if(this == &other)
325  return *this;
326 
327  m_selectionPolygonSpecs.assign(other.m_selectionPolygonSpecs.begin(),
328  other.m_selectionPolygonSpecs.end());
329 
330  m_lowestMz = other.m_lowestMz;
331  m_greatestMz = other.m_greatestMz;
332 
333  return *this;
334 }

References m_greatestMz, m_lowestMz, and m_selectionPolygonSpecs.

Member Data Documentation

◆ m_greatestMz

double pappso::FilterResampleKeepPointInPolygon::m_greatestMz = std::numeric_limits<double>::min()
private

◆ m_lowestMz

double pappso::FilterResampleKeepPointInPolygon::m_lowestMz = std::numeric_limits<double>::max()
private

◆ m_selectionPolygonSpecs

std::vector<SelectionPolygonSpec> pappso::FilterResampleKeepPointInPolygon::m_selectionPolygonSpecs
private

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