| OpenMS 2.5.0

Spectrum2DCanvas.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-2020.
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
41 #include <OpenMS/VISUAL/SpectrumCanvas.h>
42 #include <OpenMS/VISUAL/Spectrum1DCanvas.h>
43 #include <OpenMS/KERNEL/PeakIndex.h>
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 Spectrum2DCanvas :
71 public SpectrumCanvas
72 {
73 Q_OBJECT
74
75 public:
77 Spectrum2DCanvas(const Param& preferences, QWidget* parent = nullptr);
78
80 ~Spectrum2DCanvas() override;
81
82 // Docu in base class
83 void showCurrentLayerPreferences() override;
84
85 // Docu in base class
86 void saveCurrentLayer(bool visible) override;
87
89 void mergeIntoLayer(Size i, FeatureMapSharedPtrType map);
90
92 void mergeIntoLayer(Size i, ConsensusMapSharedPtrType map);
93
95 void mergeIntoLayer(Size i, std::vector<PeptideIdentification>& peptides);
96
98 void recalculateCurrentLayerDotGradient();
99
100 signals:
102 void showProjectionHorizontal(ExperimentSharedPtrType);
104 void showProjectionVertical(ExperimentSharedPtrType);
106 void showProjectionInfo(int, double, double);
108 void toggleProjections();
110 void showSpectrumAs1D(int index);
111 void showSpectrumAs1D(std::vector<int, std::allocator<int> > indices);
113 void showCurrentPeaksAs3D();
114
115 public slots:
116 // Docu in base class
117 void activateLayer(Size layer_index) override;
118 // Docu in base class
119 void removeLayer(Size layer_index) override;
120 //docu in base class
121 void updateLayer(Size i) override;
122 // Docu in base class
123 void horizontalScrollBarChange(int value) override;
124 // Docu in base class
125 void verticalScrollBarChange(int value) override;
126
136 void updateProjections();
137
138 protected slots:
139
141 void currentLayerParametersChanged_();
142
143 protected:
144 // Docu in base class
145 bool finishAdding_() override;
146
148 bool collectFragmentScansInArea(double rt_min, double rt_max, double mz_min, double mz_max, QAction* a, QMenu * msn_scans, QMenu * msn_meta);
149
151 void drawCoordinates_(QPainter& painter, const PeakIndex& peak);
153 void drawDeltas_(QPainter& painter, const PeakIndex& start, const PeakIndex& end);
154
157 void mousePressEvent(QMouseEvent* e) override;
158 void mouseReleaseEvent(QMouseEvent* e) override;
159 void mouseMoveEvent(QMouseEvent* e) override;
160 void paintEvent(QPaintEvent* e) override;
161 void contextMenuEvent(QContextMenuEvent* e) override;
162 void keyPressEvent(QKeyEvent* e) override;
163 void keyReleaseEvent(QKeyEvent* e) override;
164 void mouseDoubleClickEvent(QMouseEvent* e) override;
166
167 // Docu in base class
168 void updateScrollbars_() override;
169
178 void paintDots_(Size layer_index, QPainter& p);
179
180 void paintAllIntensities_(Size layer_index, double pen_width, QPainter& painter);
181
193 void paintMaximumIntensities_(Size layer_index, Size rt_pixel_count, Size mz_pixel_count, QPainter& p);
194
201 void paintPrecursorPeaks_(Size layer_index, QPainter& painter);
202
209 void paintFeatureData_(Size layer_index, QPainter& p);
210
217 void paintTraceConvexHulls_(Size layer_index, QPainter& p);
218
225 void paintFeatureConvexHulls_(Size layer_index, QPainter& p);
226
233 void paintIdentifications_(Size layer_index, QPainter& p);
234
241 void paintConsensusElements_(Size layer_index, QPainter& p);
242
251 void paintConsensusElement_(Size layer_index, const ConsensusFeature& cf, QPainter& p, bool use_buffer);
252
259 bool isConsensusFeatureVisible_(const ConsensusFeature& ce, Size layer_index);
260
267 void paintConvexHulls_(const std::vector<ConvexHull2D>& hulls, bool hasIdentifications, QPainter& p);
268
269 // Docu in base class
270 void intensityModeChange_() override;
271 // DOcu in base class
272 void recalculateSnapFactor_() override;
273
279 inline Int precalculatedColorIndex_(float val, const MultiGradient& gradient, double snap_factor)
280 {
281 float gradientPos = val;
282 switch (intensity_mode_)
283 {
284 case IM_NONE:
285 gradientPos = val;
286 break;
287
288 case IM_PERCENTAGE:
289 gradientPos = val * percentage_factor_;
290 break;
291
292 case IM_SNAP:
293 gradientPos = val * snap_factor;
294 break;
295
296 case IM_LOG:
297 gradientPos = std::log(val + 1);
298 break;
299 }
300 return gradient.precalculatedColorIndex(gradientPos);
301 }
302
308 inline QColor heightColor_(float val, const MultiGradient& gradient, double snap_factor)
309 {
310 return gradient.precalculatedColorByIndex(precalculatedColorIndex_(val, gradient, snap_factor));
311 }
312
321 inline void dataToWidget_(double x, double y, QPoint& point)
322 {
323 if (!isMzToXAxis())
324 {
325 point.setX(int((y - visible_area_.minY()) / visible_area_.height() * width()));
326 point.setY(height() - int((x - visible_area_.minX()) / visible_area_.width() * height()));
327 }
328 else
329 {
330 point.setX(int((x - visible_area_.minX()) / visible_area_.width() * width()));
331 point.setY(height() - int((y - visible_area_.minY()) / visible_area_.height() * height()));
332 }
333 }
334
346 double adaptPenScaling_(double ratio_data2pixel, double& pen_size) const;
347
349 void recalculateDotGradient_(Size layer);
350
352 void highlightPeak_(QPainter& p, const PeakIndex& peak);
353
355 PeakIndex findNearestPeak_(const QPoint& pos);
356
358 void paintIcon_(const QPoint& pos, const QRgb& color, const String& icon, Size s, QPainter& p) const;
359
361 virtual void translateVisibleArea_(double mzShiftRel, double rtShiftRel);
362
363 //docu in base class
364 void translateLeft_(Qt::KeyboardModifiers m) override;
365 //docu in base class
366 void translateRight_(Qt::KeyboardModifiers m) override;
367 //docu in base class
368 void translateForward_() override;
369 //docu in base class
370 void translateBackward_() override;
371
373 void finishContextMenu_(QMenu* context_menu, QMenu* settings_menu);
374
376 ExperimentType projection_mz_;
378 ExperimentType projection_rt_;
379
381 PeakIndex selected_peak_;
383 PeakIndex measurement_start_;
384
386 MultiGradient linear_gradient_;
387
388 double pen_size_min_;
389 double pen_size_max_;
390 double canvas_coverage_min_;
391
392 private:
394 Spectrum2DCanvas();
395
396 };
397 }
398
OpenMS::Spectrum2DCanvas::projection_mz_
ExperimentType projection_mz_
m/z projection data
Definition: Spectrum2DCanvas.h:376
OpenMS::String
A more convenient string class.
Definition: String.h:58
QWidget
OpenMS::IM_NONE
no ion mobility
Definition: FileConverter.cpp:155
OpenMS::Spectrum2DCanvas::selected_peak_
PeakIndex selected_peak_
the nearest peak/feature to the mouse cursor
Definition: Spectrum2DCanvas.h:381
OpenMS::Spectrum2DCanvas::precalculatedColorIndex_
Int precalculatedColorIndex_(float val, const MultiGradient &gradient, double snap_factor)
Returns the position on color gradient associated with given intensity.
Definition: Spectrum2DCanvas.h:279
OpenMS::Spectrum2DCanvas::projection_rt_
ExperimentType projection_rt_
RT projection data.
Definition: Spectrum2DCanvas.h:378
OpenMS::Spectrum2DCanvas::pen_size_max_
double pen_size_max_
maximum number of pixels for one data point
Definition: Spectrum2DCanvas.h:389
OpenMS::SpectrumCanvas::FeatureMapSharedPtrType
LayerData::FeatureMapSharedPtrType FeatureMapSharedPtrType
Main managed data type (features)
Definition: SpectrumCanvas.h:117
OpenMS::Spectrum2DCanvas
Canvas for 2D-visualization of peak map, feature map and consensus map data.
Definition: Spectrum2DCanvas.h:70
OpenMS::ConsensusFeature
A consensus feature spanning multiple LC-MS/MS experiments.
Definition: ConsensusFeature.h:69
OpenMS::SpectrumCanvas
Base class for visualization canvas classes.
Definition: SpectrumCanvas.h:98
OpenMS::Spectrum2DCanvas::canvas_coverage_min_
double canvas_coverage_min_
minimum coverage of the canvas required; if lower, points are upscaled in size
Definition: Spectrum2DCanvas.h:390
OpenMS::Spectrum2DCanvas::measurement_start_
PeakIndex measurement_start_
start peak/feature of measuring mode
Definition: Spectrum2DCanvas.h:383
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
SpectrumCanvas.h
OpenMS::MultiGradient
A gradient of multiple colors and arbitrary distances between colors.
Definition: MultiGradient.h:67
OpenMS::MultiGradient::precalculatedColorByIndex
QColor precalculatedColorByIndex(Int index) const
precalculated color by its index in the table
Definition: MultiGradient.h:147
OpenMS::SpectrumCanvas::ExperimentSharedPtrType
LayerData::ExperimentSharedPtrType ExperimentSharedPtrType
Main managed data type (experiment)
Definition: SpectrumCanvas.h:111
OpenMS::Spectrum2DCanvas::dataToWidget_
void dataToWidget_(double x, double y, QPoint &point)
Convert chart to widget coordinates.
Definition: Spectrum2DCanvas.h:321
PeakIndex.h
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::PeakIndex
Index of a peak or feature.
Definition: PeakIndex.h:50
int
Spectrum1DCanvas.h
OpenMS::SpectrumCanvas::ConsensusMapSharedPtrType
LayerData::ConsensusMapSharedPtrType ConsensusMapSharedPtrType
Main managed data type (consensus features)
Definition: SpectrumCanvas.h:121
OpenMS::Spectrum2DCanvas::pen_size_min_
double pen_size_min_
minimum number of pixels for one data point
Definition: Spectrum2DCanvas.h:388
OpenMS::Spectrum2DCanvas::heightColor_
QColor heightColor_(float val, const MultiGradient &gradient, double snap_factor)
Returns the color associated with val for the gradient gradient.
Definition: Spectrum2DCanvas.h:308
OpenMS::Spectrum2DCanvas::linear_gradient_
MultiGradient linear_gradient_
stores the linear color gradient for non-log modes
Definition: Spectrum2DCanvas.h:386
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::MultiGradient::precalculatedColorIndex
Int precalculatedColorIndex(double position) const
index of color in precalculated table by position in gradient
Definition: MultiGradient.h:136