OpenMS
Plot2DWidget.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg$
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // OpenMS_GUI config
38 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
39 
40 // OpenMS
43 
44 class QGroupBox;
45 class QLabel;
46 class QCheckBox;
47 
48 namespace OpenMS
49 {
50  class Plot1DWidget;
51 
63  class OPENMS_GUI_DLLAPI Plot2DWidget :
64  public PlotWidget
65  {
66  Q_OBJECT
67 public:
70 
72  Plot2DWidget(const Param & preferences, QWidget * parent = nullptr);
74  ~Plot2DWidget() override = default;
75 
76  // docu in base class
77  Plot2DCanvas* canvas() const override
78  {
79  return static_cast<Plot2DCanvas*>(canvas_);
80  }
81 
86 
88  bool projectionsVisible() const;
89 
93  void setMapper(const DimMapper<2>& mapper) override
94  {
95  canvas_->setMapper(mapper); // update canvas
96  // ... and projections: the projected Dim becomes intensity
97  projection_onto_X_->setMapper(DimMapper<2>({mapper.getDim(DIM::X).getUnit(), DIM_UNIT::INT}));
98  projection_onto_Y_->setMapper(DimMapper<2>({DIM_UNIT::INT, mapper.getDim(DIM::Y).getUnit()}));
99 
100  // decide on default draw mode, depending on main axis unit (e.g. m/z or RT)
101  auto set_style = [&](const DIM_UNIT main_unit_1d, Plot1DCanvas* canvas) {
102  switch (main_unit_1d)
103  { // this may not be optimal for every unit. Feel free to change behavior.
104  case DIM_UNIT::MZ:
105  // to show isotope distributions as sticks
106  canvas->setDrawMode(Plot1DCanvas::DM_PEAKS);
107  canvas->setIntensityMode(PlotCanvas::IM_PERCENTAGE);
108  break;
109  // all other units
110  default:
111  canvas->setDrawMode(Plot1DCanvas::DM_CONNECTEDLINES);
112  canvas->setIntensityMode(PlotCanvas::IM_SNAP);
113  break;
114  }
115  };
116  set_style(mapper.getDim(DIM::X).getUnit(), projection_onto_Y_->canvas());
117  set_style(mapper.getDim(DIM::Y).getUnit(), projection_onto_X_->canvas());
118  }
119 
120 public slots:
121  // Docu in base class
122  void recalculateAxes_() override;
125  // Docu in base class
126  void showGoToDialog() override;
127 
128 signals:
136  void showSpectrumAsNew1D(int index);
137  void showChromatogramsAsNew1D(std::vector<int, std::allocator<int> > indices);
140 
141 protected:
143  void projectionInfo_(int peaks, double intensity, double max);
144 
150  QGroupBox * projection_box_;
154  QLabel * projection_sum_;
156  QLabel * projection_max_;
158  QCheckBox * projections_auto_;
161 
162 private slots:
164  void showProjections_(const LayerDataBase* source_layer);
167  };
168 }
169 
A D-dimensional half-open interval.
Definition: DRange.h:62
DIM_UNIT getUnit() const
The unit of the dimension.
Definition: DimMapper.h:155
const DimBase & getDim(DIM d) const
obtain unit/name for X/Y/Z dimension.
Definition: DimMapper.h:784
Class that stores the data for one layer.
Definition: LayerDataBase.h:195
Management and storage of parameters / INI files.
Definition: Param.h:70
Canvas for visualization of one or several spectra.
Definition: Plot1DCanvas.h:321
@ DM_PEAKS
draw data as peak
Definition: Plot1DCanvas.h:384
@ DM_CONNECTEDLINES
draw as connected lines
Definition: Plot1DCanvas.h:385
Widget for visualization of several spectra.
Definition: Plot1DWidget.h:67
Canvas for 2D-visualization of peak map, feature map and consensus map data.
Definition: Plot2DCanvas.h:72
Widget for 2D-visualization of peak map and feature map data.
Definition: Plot2DWidget.h:65
void recalculateAxes_() override
Plot2DWidget(const Param &preferences, QWidget *parent=nullptr)
Default constructor.
const Plot1DWidget * getProjectionOntoX() const
const reference to the horizontal projection
void showSpectrumAsNew1D(int index)
Requests to display the spectrum with index index in 1D.
~Plot2DWidget() override=default
Destructor.
bool projectionsVisible() const
Returns if one of the projections is visible (or both are visible)
void toggleProjections()
Shows/hides the projections.
void projectionInfo_(int peaks, double intensity, double max)
shows projections information
void visibleAreaChanged(DRange< 2 > area)
Signal emitted whenever the visible area changes.
QLabel * projection_sum_
Intensity sum of the projection.
Definition: Plot2DWidget.h:154
QTimer * projections_timer_
Timer that triggers auto-update of projections.
Definition: Plot2DWidget.h:160
void setMapper(const DimMapper< 2 > &mapper) override
Definition: Plot2DWidget.h:93
QCheckBox * projections_auto_
Checkbox that indicates that projections should be automatically updated (with a slight delay)
Definition: Plot2DWidget.h:158
void showProjections_(const LayerDataBase *source_layer)
extracts the projections from the source_layer and displays them
QLabel * projection_max_
Intensity maximum of the projection.
Definition: Plot2DWidget.h:156
Plot1DWidget * projection_onto_Y_
Horizontal projection widget.
Definition: Plot2DWidget.h:148
Plot2DCanvas * canvas() const override
Returns a pointer to canvas object.
Definition: Plot2DWidget.h:77
void showChromatogramsAsNew1D(std::vector< int, std::allocator< int > > indices)
Plot1DWidget * projection_onto_X_
Vertical projection widget.
Definition: Plot2DWidget.h:146
void showCurrentPeaksAs3D()
Requests to display all spectra as 1D.
QGroupBox * projection_box_
Group box that shows information about the projections.
Definition: Plot2DWidget.h:150
void showGoToDialog() override
const Plot1DWidget * getProjectionOntoY() const
const reference to the vertical projection
QLabel * projection_peaks_
Number of peaks of the projection.
Definition: Plot2DWidget.h:152
LayerDataBase::ExperimentSharedPtrType ExperimentSharedPtrType
Main managed data type (experiment)
Definition: Plot2DWidget.h:69
void autoUpdateProjections_()
slot that monitors the visible area changes and triggers the update of projections
@ IM_SNAP
Shows the maximum displayed intensity (across all layers) as if it was the overall maximum intensity.
Definition: PlotCanvas.h:206
@ IM_PERCENTAGE
Shows intensities normalized by each layer's maximum: f(x)=x/max(x)*100.
Definition: PlotCanvas.h:205
Base class for spectrum widgets.
Definition: PlotWidget.h:83
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
DIM_UNIT
Definition: CommonEnums.h:46
@ INT
intensity
boost::shared_ptr< ExperimentType > ExperimentSharedPtrType
SharedPtr on MSExperiment.
Definition: LayerDataBase.h:152