Skip to content

Commit ce6a7b7

Browse files
authored
Merge pull request OpenMS#5696 from cbielow/layer_refactor
Layer refactor #2
2 parents e03d584 + e1653b1 commit ce6a7b7

File tree

15 files changed

+150
-150
lines changed

15 files changed

+150
-150
lines changed

src/openms/include/OpenMS/MATH/MISC/MathFunctions.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ namespace OpenMS
5353
*/
5454
namespace Math
5555
{
56+
57+
/**
58+
@brief Given an interval/range and a new value, extend the range to include the new value if needed
59+
60+
@param min The current minimum of the range
61+
@param max The current maximum of the range
62+
@param value The new value which may extend the range
63+
@return true if the range was modified
64+
*/
65+
template<typename T>
66+
bool extendRange(T& min, T& max, const T& value)
67+
{
68+
if (value < min)
69+
{
70+
min = value;
71+
return true;
72+
}
73+
if (value > max)
74+
{
75+
max = value;
76+
return true;
77+
}
78+
return false;
79+
}
80+
81+
5682
/**
5783
@brief rounds @p x up to the next decimal power 10 ^ @p decPow
5884

src/openms/include/OpenMS/MATH/STATISTICS/StatisticFunctions.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,10 @@
3737
#include <OpenMS/CONCEPT/Exception.h>
3838
#include <OpenMS/CONCEPT/Types.h>
3939

40-
// array_wrapper needs to be included before it is used
41-
// only in boost1.64+. See issue #2790
42-
#if OPENMS_BOOST_VERSION_MINOR >= 64
43-
#include <boost/serialization/array_wrapper.hpp>
44-
#endif
45-
#include <boost/function/function_base.hpp>
46-
#include <boost/lambda/casts.hpp>
47-
#include <boost/lambda/lambda.hpp>
48-
40+
#include <algorithm>
41+
#include <cmath>
4942
#include <iterator>
5043
#include <numeric>
51-
#include <algorithm>
5244

5345
namespace OpenMS
5446
{
@@ -511,7 +503,7 @@ namespace OpenMS
511503
/* assure both ranges have the same number of elements */
512504
checkIteratorsEqual(iter_b, end_b);
513505

514-
return (tp * tn - fp * fn) / sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn));
506+
return (tp * tn - fp * fn) / std::sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn));
515507
}
516508

517509
/**
@@ -555,7 +547,7 @@ namespace OpenMS
555547
}
556548
/* assure both ranges have the same number of elements */
557549
checkIteratorsEqual(iter_b, end_b);
558-
return numerator / sqrt(denominator_a * denominator_b);
550+
return numerator / std::sqrt(denominator_a * denominator_b);
559551
}
560552

561553
/// Replaces the elements in vector @p w by their ranks
@@ -574,8 +566,7 @@ namespace OpenMS
574566
}
575567
//sort
576568
std::sort(w_idx.begin(), w_idx.end(),
577-
boost::lambda::ret<bool>((&boost::lambda::_1->*& std::pair<Size, Value>::second) <
578-
(&boost::lambda::_2->*& std::pair<Size, Value>::second)));
569+
[](const auto& pair1, const auto& pair2) { return pair1.second < pair2.second; });
579570
//replace pairs <orig_index, value> in w_idx by pairs <orig_index, rank>
580571
while (i < n)
581572
{
@@ -673,7 +664,7 @@ namespace OpenMS
673664
return 0;
674665
}
675666

676-
return sum_model_data / (sqrt(sqsum_data) * sqrt(sqsum_model));
667+
return sum_model_data / (std::sqrt(sqsum_data) * std::sqrt(sqsum_model));
677668
}
678669

679670
/// Helper class to gather (and dump) some statistics from a e.g. vector<double>.

src/openms/source/KERNEL/FeatureMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ namespace OpenMS
263263
DBoundingBox<2> box = this->operator[](i).getConvexHull().getBoundingBox();
264264
if (!box.isEmpty())
265265
{
266-
//update RT
266+
// update RT
267267
if (box.minPosition()[Peak2D::RT] < this->pos_range_.minPosition()[Peak2D::RT])
268268
{
269269
this->pos_range_.setMinX(box.minPosition()[Peak2D::RT]);

src/openms_gui/include/OpenMS/VISUAL/LayerDataBase.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,15 @@ namespace OpenMS
408408
}
409409

410410
/**
411-
@brief Update ranges of all data structures
412-
413-
Updates ranges of all tracked data structures
414-
(spectra, chromatograms, features etc).
411+
@brief Update ranges of the underlying data
415412
*/
416-
void updateRanges();
413+
virtual void updateRanges() = 0;
417414

418415
/// Returns the minimum intensity of the internal data, depending on type
419-
float getMinIntensity() const;
416+
virtual float getMinIntensity() const = 0;
420417

421418
/// Returns the maximum intensity of the internal data, depending on type
422-
float getMaxIntensity() const;
419+
virtual float getMaxIntensity() const = 0;
423420

424421
/// updates the PeakAnnotations in the current PeptideHit with manually changed annotations
425422
/// if no PeptideIdentification or PeptideHit for the spectrum exist, it is generated
@@ -485,7 +482,7 @@ namespace OpenMS
485482
/// get name augmented with attributes, e.g. [flipped], or '*' if modified
486483
String getDecoratedName() const;
487484

488-
private:
485+
protected:
489486
/// Update current cached spectrum for easy retrieval
490487
void updateCache_();
491488

src/openms_gui/include/OpenMS/VISUAL/LayerDataChrom.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ namespace OpenMS
5858
LayerDataChrom(LayerDataChrom&& ld) = default;
5959
/// move assignment
6060
LayerDataChrom& operator=(LayerDataChrom&& ld) = default;
61+
62+
void updateRanges() override
63+
{
64+
peak_map_->updateRanges();
65+
// on_disc_peaks->updateRanges(); // note: this is not going to work since its on disk! We currently don't have a good way to access these ranges
66+
chromatogram_map_->updateRanges();
67+
cached_spectrum_.updateRanges();
68+
}
69+
70+
float getMinIntensity() const override
71+
{
72+
return getPeakData()->getMinInt();
73+
}
74+
75+
float getMaxIntensity() const override
76+
{
77+
return getPeakData()->getMaxInt();
78+
}
79+
6180
};
6281

6382
} //namespace

src/openms_gui/include/OpenMS/VISUAL/LayerDataConsensus.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ namespace OpenMS
5858
LayerDataConsensus(LayerDataConsensus&& ld) = default;
5959
/// move assignment
6060
LayerDataConsensus& operator=(LayerDataConsensus&& ld) = default;
61+
62+
void updateRanges() override
63+
{
64+
consensus_map_->updateRanges();
65+
}
66+
67+
float getMinIntensity() const override
68+
{
69+
return getConsensusMap()->getMinInt();
70+
}
71+
72+
float getMaxIntensity() const override
73+
{
74+
return getConsensusMap()->getMaxInt();
75+
}
6176
};
6277

6378
}// namespace OpenMS

src/openms_gui/include/OpenMS/VISUAL/LayerDataFeature.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,35 @@ namespace OpenMS
6060
/// move assignment
6161
LayerDataFeature& operator=(LayerDataFeature&& ld) = default;
6262

63+
void updateRanges() override
64+
{
65+
features_->updateRanges();
66+
}
67+
68+
float getMinIntensity() const override
69+
{
70+
return getFeatureMap()->getMinInt();
71+
}
72+
73+
float getMaxIntensity() const override
74+
{
75+
return getFeatureMap()->getMaxInt();
76+
}
6377

64-
virtual const PepIds& getPeptideIds() const override
78+
const PepIds& getPeptideIds() const override
6579
{
6680
return getFeatureMap()->getUnassignedPeptideIdentifications();
6781
}
68-
virtual PepIds& getPeptideIds() override
82+
PepIds& getPeptideIds() override
6983
{
7084
return getFeatureMap()->getUnassignedPeptideIdentifications();
7185
}
7286

73-
virtual void setPeptideIds(const PepIds& ids) override
87+
void setPeptideIds(const PepIds& ids) override
7488
{
7589
getFeatureMap()->getUnassignedPeptideIdentifications() = ids;
7690
}
77-
virtual void setPeptideIds(PepIds&& ids) override
91+
void setPeptideIds(PepIds&& ids) override
7892
{
7993
getFeatureMap()->getUnassignedPeptideIdentifications() = std::move(ids);
8094
}

src/openms_gui/include/OpenMS/VISUAL/LayerDataIdent.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,21 @@ namespace OpenMS
6060
/// move assignment
6161
LayerDataIdent& operator=(LayerDataIdent&& ld) = default;
6262

63-
63+
void updateRanges() override
64+
{
65+
// nothing to do...
66+
}
67+
68+
float getMinIntensity() const override
69+
{
70+
return -1;
71+
}
72+
73+
float getMaxIntensity() const override
74+
{
75+
return -1;
76+
}
77+
6478
virtual const PepIds& getPeptideIds() const override
6579
{
6680
return peptides_;

src/openms_gui/include/OpenMS/VISUAL/LayerDataPeak.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ namespace OpenMS
5858
LayerDataPeak(LayerDataPeak&& ld) = default;
5959
/// move assignment
6060
LayerDataPeak& operator=(LayerDataPeak&& ld) = default;
61+
62+
void updateRanges() override
63+
{
64+
peak_map_->updateRanges();
65+
// on_disc_peaks->updateRanges(); // note: this is not going to work since its on disk! We currently don't have a good way to access these ranges
66+
cached_spectrum_.updateRanges();
67+
}
68+
69+
float getMinIntensity() const override
70+
{
71+
return getPeakData()->getMinInt();
72+
}
73+
float getMaxIntensity() const override
74+
{
75+
return getPeakData()->getMaxInt();
76+
}
6177
};
6278

6379
}// namespace OpenMS

src/openms_gui/include/OpenMS/VISUAL/PlotCanvas.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -843,24 +843,24 @@ protected slots:
843843
QImage buffer_;
844844

845845
/// Stores the current action mode (Pick, Zoom, Translate)
846-
ActionModes action_mode_;
846+
ActionModes action_mode_ = AM_TRANSLATE;
847847

848848
/// Stores the used intensity mode function
849-
IntensityModes intensity_mode_;
849+
IntensityModes intensity_mode_ = IM_NONE;
850850

851851
/// Layer data
852852
LayerStack layers_;
853853

854854
/// Stores the mapping of m/z
855-
bool mz_to_x_axis_;
855+
bool mz_to_x_axis_ = true;
856856

857857
/**
858858
@brief Stores the currently visible area.
859859
860860
Dimension 0 is the m/z dimension.@n
861861
Dimension 1 is the RT dimension (2D and 3D view) or the intensity dimension (1D view).
862862
*/
863-
AreaType visible_area_;
863+
AreaType visible_area_ = AreaType::empty;
864864

865865
/**
866866
@brief Recalculates the overall_data_range_
@@ -880,15 +880,15 @@ protected slots:
880880
Dimension 1 is the RT dimension (2D and 3D view) or the intensity dimension (1D view).@n
881881
Dimension 2 is the intensity dimension (2D and 3D view) or the RT dimension (1D view).
882882
*/
883-
DRange<3> overall_data_range_;
883+
DRange<3> overall_data_range_ = DRange<3>::empty;
884884

885885
/// Stores whether or not to show a grid.
886-
bool show_grid_;
886+
bool show_grid_ = true;
887887

888888
/// The zoom stack.
889889
std::vector<AreaType> zoom_stack_;
890890
/// The current position in the zoom stack
891-
std::vector<AreaType>::iterator zoom_pos_;
891+
std::vector<AreaType>::iterator zoom_pos_ = zoom_stack_.end();
892892

893893
/**
894894
@brief Updates the displayed data
@@ -905,10 +905,10 @@ protected slots:
905905
void modificationStatus_(Size layer_index, bool modified);
906906

907907
/// Whether to recalculate the data in the buffer when repainting
908-
bool update_buffer_;
908+
bool update_buffer_ = false;
909909

910910
/// Back-pointer to the enclosing spectrum widget
911-
PlotWidget * spectrum_widget_;
911+
PlotWidget* spectrum_widget_ = nullptr;
912912

913913
/// start position of mouse actions
914914
QPoint last_mouse_pos_;
@@ -918,7 +918,7 @@ protected slots:
918918
919919
In this mode all layers are scaled to the same maximum.
920920
*/
921-
double percentage_factor_;
921+
double percentage_factor_ = 1.0;
922922

923923
/**
924924
@brief Intensity scaling factor for 'snap to maximum intensity mode'.
@@ -927,16 +927,16 @@ protected slots:
927927
928928
One entry per layer.
929929
*/
930-
std::vector<double> snap_factors_;
930+
std::vector<double> snap_factors_ = {1.0};
931931

932932
/// Rubber band for selected area
933933
QRubberBand rubber_band_;
934934

935935
/// External context menu extension
936-
QMenu* context_add_;
936+
QMenu* context_add_ = nullptr;
937937

938938
/// Flag that determines if timing data is printed to the command line
939-
bool show_timing_;
939+
bool show_timing_ = false;
940940

941941
/// selected peak
942942
PeakIndex selected_peak_;

0 commit comments

Comments
 (0)