OpenMS
Plot2DCanvas.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
44 
45 // QT
46 class QPainter;
47 class QMouseEvent;
48 class QAction;
49 class QMenu;
50 
51 namespace OpenMS
52 {
70  class OPENMS_GUI_DLLAPI Plot2DCanvas :
71  public PlotCanvas
72  {
73  Q_OBJECT
74 
75 public:
77  Plot2DCanvas() = delete;
78 
80  Plot2DCanvas(const Param& preferences, QWidget* parent = nullptr);
81 
83  ~Plot2DCanvas() override;
84 
85  // Docu in base class
86  void showCurrentLayerPreferences() override;
87 
90 
93 
95  void mergeIntoLayer(Size i, std::vector<PeptideIdentification>& peptides);
96 
99 
100 signals:
102  void showProjections(const LayerDataBase* source_layer);
106  void showSpectrumAsNew1D(int index);
107  void showChromatogramsAsNew1D(std::vector<int, std::allocator<int> > indices);
110 
111 public slots:
112  // Docu in base class
113  void activateLayer(Size layer_index) override;
114  // Docu in base class
115  void removeLayer(Size layer_index) override;
116  //docu in base class
117  void updateLayer(Size i) override;
118  // Docu in base class
119  void horizontalScrollBarChange(int value) override;
120  // Docu in base class
121  void verticalScrollBarChange(int value) override;
122 
125 
126 protected slots:
127 
130 
131 protected:
132  // Docu in base class
133  bool finishAdding_() override;
134 
136  bool collectFragmentScansInArea_(const RangeType& range, QAction* a, QMenu* msn_scans, QMenu* msn_meta);
137 
139  void drawCoordinates_(QPainter& painter, const PeakIndex& peak);
141  void drawDeltas_(QPainter& painter, const PeakIndex& start, const PeakIndex& end);
142 
145  void mousePressEvent(QMouseEvent* e) override;
146  void mouseReleaseEvent(QMouseEvent* e) override;
147  void mouseMoveEvent(QMouseEvent* e) override;
148  void paintEvent(QPaintEvent* e) override;
149  void contextMenuEvent(QContextMenuEvent* e) override;
150  void keyPressEvent(QKeyEvent* e) override;
151  void keyReleaseEvent(QKeyEvent* e) override;
152  void mouseDoubleClickEvent(QMouseEvent* e) override;
154 
155  // Docu in base class
156  void updateScrollbars_() override;
157 
158  // Docu in base class
159  void intensityModeChange_() override;
160  // Docu in base class
161  void recalculateSnapFactor_() override;
162 
168  Int precalculatedColorIndex_(float val, const MultiGradient& gradient, double snap_factor)
169  {
170  float gradientPos = val;
171  switch (intensity_mode_)
172  {
173  case IM_NONE:
174  gradientPos = val;
175  break;
176 
177  case IM_PERCENTAGE:
178  gradientPos = val * percentage_factor_;
179  break;
180 
181  case IM_SNAP:
182  gradientPos = val * snap_factor;
183  break;
184 
185  case IM_LOG:
186  gradientPos = std::log(val + 1);
187  break;
188  }
189  return gradient.precalculatedColorIndex(gradientPos);
190  }
191 
197  QColor heightColor_(float val, const MultiGradient& gradient, double snap_factor)
198  {
199  return gradient.precalculatedColorByIndex(precalculatedColorIndex_(val, gradient, snap_factor));
200  }
201 
213  double adaptPenScaling_(double ratio_data2pixel, double& pen_size) const;
214 
217 
219  void highlightPeak_(QPainter& p, const PeakIndex& peak);
220 
222  PeakIndex findNearestPeak_(const QPoint& pos);
223 
225  void paintIcon_(const QPoint& pos, const QRgb& color, const String& icon, Size s, QPainter& p) const;
226 
228  void translateVisibleArea_(double x_axis_rel, double y_axis_rel);
229 
238  QPoint dataToWidget_(double x, double y) const
239  {
240  QPoint point;
241  const auto& xy = visible_area_.getAreaXY();
242  point.setX(int((x - xy.minX()) / xy.width() * width()));
243  point.setY(int((xy.maxY() - y) / xy.height() * height()));
244  return point;
245  }
246 
247  QPoint dataToWidget_(const DPosition<2>& xy)
248  {
249  return dataToWidget_(xy.getX(), xy.getY());
250  }
251 
252  //docu in base class
253  void translateLeft_(Qt::KeyboardModifiers m) override;
254  //docu in base class
255  void translateRight_(Qt::KeyboardModifiers m) override;
256  //docu in base class
257  void translateForward_() override;
258  //docu in base class
259  void translateBackward_() override;
260 
262  void finishContextMenu_(QMenu* context_menu, QMenu* settings_menu);
263 
264  friend class Painter2DBase;
265  friend class Painter2DChrom;
266  friend class Painter2DConsensus;
267  friend class Painter2DIdent;
268  friend class Painter2DFeature;
269  friend class Painter2DIonMobility;
270  friend class Painter2DPeak;
271 
276 
279 
280  double pen_size_min_;
281  double pen_size_max_;
283  };
284 }
285 
CoordinateType getY() const
Name accessor for the second dimension. Only for DPosition<2>, for visualization.
Definition: DPosition.h:175
CoordinateType getX() const
Name accessor for the first dimension. Only for DPosition<2>, for visualization.
Definition: DPosition.h:168
Class that stores the data for one layer.
Definition: LayerDataBase.h:195
A gradient of multiple colors and arbitrary distances between colors.
Definition: MultiGradient.h:68
Int precalculatedColorIndex(double position) const
index of color in precalculated table by position in gradient
Definition: MultiGradient.h:136
QColor precalculatedColorByIndex(Int index) const
precalculated color by its index in the table
Definition: MultiGradient.h:147
A base class for painting all items from a data layer (as supported by class derived from here) onto ...
Definition: Painter2DBase.h:68
Painter2D for chromatograms.
Definition: Painter2DBase.h:157
Painter2D for ConsensusFeatures.
Definition: Painter2DBase.h:217
Painter2D for Features.
Definition: Painter2DBase.h:189
Painter2D for Identifications.
Definition: Painter2DBase.h:262
Painter2D for ion mobilograms.
Definition: Painter2DBase.h:173
Painter2D for spectra.
Definition: Painter2DBase.h:120
Management and storage of parameters / INI files.
Definition: Param.h:70
Canvas for 2D-visualization of peak map, feature map and consensus map data.
Definition: Plot2DCanvas.h:72
void translateForward_() override
Translation bound to the 'Up' key.
Plot2DCanvas()=delete
Default C'tor hidden.
double pen_size_max_
maximum number of pixels for one data point
Definition: Plot2DCanvas.h:281
void drawCoordinates_(QPainter &painter, const PeakIndex &peak)
Draws the coordinates (or coordinate deltas) to the widget's upper left corner.
void mergeIntoLayer(Size i, const ConsensusMapSharedPtrType &map)
Merges the consensus features in map into the features layer i.
void showSpectrumAsNew1D(int index)
Requests to display the spectrum with index index in 1D.
PeakIndex selected_peak_
the nearest peak/feature to the mouse cursor
Definition: Plot2DCanvas.h:273
double canvas_coverage_min_
minimum coverage of the canvas required; if lower, points are upscaled in size
Definition: Plot2DCanvas.h:282
bool finishAdding_() override
Method that is called when a new layer has been added.
void removeLayer(Size layer_index) override
void mousePressEvent(QMouseEvent *e) override
void horizontalScrollBarChange(int value) override
void toggleProjections()
Signal emitted when the projections are to be shown/hidden (e.g. via context menu)
void recalculateCurrentLayerDotGradient()
recalculates the dot gradient of the active layer
Plot2DCanvas(const Param &preferences, QWidget *parent=nullptr)
Constructor.
void mouseMoveEvent(QMouseEvent *e) override
void highlightPeak_(QPainter &p, const PeakIndex &peak)
Highlights a single peak and prints coordinates to screen.
void finishContextMenu_(QMenu *context_menu, QMenu *settings_menu)
Finishes context menu after customization to peaks, features or consensus features.
void mouseReleaseEvent(QMouseEvent *e) override
void keyReleaseEvent(QKeyEvent *e) override
void keyPressEvent(QKeyEvent *e) override
void updateScrollbars_() override
Updates the scroll bars.
void recalculateSnapFactor_() override
Recalculates the intensity scaling factor for 'snap to maximum intensity mode'.
void showCurrentLayerPreferences() override
Shows the preferences dialog of the active layer.
void translateLeft_(Qt::KeyboardModifiers m) override
Translation bound to the 'Left' key.
void currentLayerParametersChanged_()
Reacts on changed layer parameters.
void drawDeltas_(QPainter &painter, const PeakIndex &start, const PeakIndex &end)
Draws the coordinates (or coordinate deltas) to the widget's upper left corner.
void recalculateDotGradient_(Size layer)
Recalculates the dot gradient of a layer.
void mergeIntoLayer(Size i, const FeatureMapSharedPtrType &map)
Merges the features in map into the features layer i.
void showProjections(const LayerDataBase *source_layer)
Requests to show projections for the source_layer. Emitted after calling pickProjectionLayer().
void paintIcon_(const QPoint &pos, const QRgb &color, const String &icon, Size s, QPainter &p) const
Paints a peak icon for feature and consensus feature peaks.
void intensityModeChange_() override
This method is called whenever the intensity mode changes. Reimplement if you need to react on such c...
bool collectFragmentScansInArea_(const RangeType &range, QAction *a, QMenu *msn_scans, QMenu *msn_meta)
Collects fragment ion scans in the indicated RT/mz area and adds them to the indicated action.
Int precalculatedColorIndex_(float val, const MultiGradient &gradient, double snap_factor)
Returns the position on color gradient associated with given intensity.
Definition: Plot2DCanvas.h:168
double adaptPenScaling_(double ratio_data2pixel, double &pen_size) const
For a certain dimension: computes the size a data point would need, such that the image reaches a cer...
void activateLayer(Size layer_index) override
void translateRight_(Qt::KeyboardModifiers m) override
Translation bound to the 'Right' key.
void showChromatogramsAsNew1D(std::vector< int, std::allocator< int > > indices)
void updateLayer(Size i) override
void contextMenuEvent(QContextMenuEvent *e) override
double pen_size_min_
minimum number of pixels for one data point
Definition: Plot2DCanvas.h:280
~Plot2DCanvas() override
Destructor.
void mouseDoubleClickEvent(QMouseEvent *e) override
void verticalScrollBarChange(int value) override
void showCurrentPeaksAs3D()
Requests to display all spectra in 3D plot.
PeakIndex measurement_start_
start peak/feature of measuring mode
Definition: Plot2DCanvas.h:275
MultiGradient linear_gradient_
stores the linear color gradient for non-log modes
Definition: Plot2DCanvas.h:278
void pickProjectionLayer()
Picks an appropriate layer for projection and emits the signal showProjections(LayerDataBase*).
PeakIndex findNearestPeak_(const QPoint &pos)
Returns the nearest peak to position pos.
QPoint dataToWidget_(const DPosition< 2 > &xy)
Definition: Plot2DCanvas.h:247
void translateBackward_() override
Translation bound to the 'Down' key.
void translateVisibleArea_(double x_axis_rel, double y_axis_rel)
Translates the visible area by a given offset specified in fractions of current visible area.
QPoint dataToWidget_(double x, double y) const
Convert chart to widget coordinates.
Definition: Plot2DCanvas.h:238
QColor heightColor_(float val, const MultiGradient &gradient, double snap_factor)
Returns the color associated with val for the gradient gradient.
Definition: Plot2DCanvas.h:197
void paintEvent(QPaintEvent *e) override
void mergeIntoLayer(Size i, std::vector< PeptideIdentification > &peptides)
Merges the peptide identifications in peptides into the peptide layer i.
Base class for visualization canvas classes.
Definition: PlotCanvas.h:146
LayerDataBase::ConsensusMapSharedPtrType ConsensusMapSharedPtrType
Main managed data type (consensus features)
Definition: PlotCanvas.h:166
LayerDataBase::FeatureMapSharedPtrType FeatureMapSharedPtrType
Main managed data type (features)
Definition: PlotCanvas.h:162
A more convenient string class.
Definition: String.h:60
int Int
Signed integer type.
Definition: Types.h:102
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Index of a peak or feature.
Definition: PeakIndex.h:51