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 Tracefilter (Trace &data_points) const =0
 
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 244 of file filterresample.cpp.

245{
246}

◆ FilterResampleKeepPointInPolygon() [2/4]

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

Definition at line 249 of file filterresample.cpp.

251{
252 // It is assumed that the selection polygon always has x:MZ and y:DT|RT
253 // depending on the spec data kind.
254
255 m_selectionPolygonSpecs.push_back(
256 SelectionPolygonSpec(selection_polygon, data_kind));
257
258 m_lowestMz =
259 m_selectionPolygonSpecs.front().selectionPolygon.getBottomMostPoint().y();
261 m_selectionPolygonSpecs.front().selectionPolygon.getTopMostPoint().y();
262}
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 265 of file filterresample.cpp.

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

References m_greatestMz, m_lowestMz, and m_selectionPolygonSpecs.

◆ FilterResampleKeepPointInPolygon() [4/4]

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

Definition at line 284 of file filterresample.cpp.

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

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 ( Trace data_points) const
virtual

◆ filter() [2/3]

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

Implements pappso::FilterInterface.

Definition at line 340 of file filterresample.cpp.

341{
342 qFatal("Programming error.");
343 return trace;
344}

◆ filter() [3/3]

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

Definition at line 348 of file filterresample.cpp.

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

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

References m_greatestMz, m_lowestMz, and m_selectionPolygonSpecs.

◆ operator=()

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

Definition at line 323 of file filterresample.cpp.

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

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: