OpenMS
MultiGradient.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Marc Sturm $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 // OpenMS_GUI config
12 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
13 
14 //OpenMS
15 #include <OpenMS/CONCEPT/Types.h>
16 #include <OpenMS/CONCEPT/Macros.h>
19 
20 //QT
21 #include <QtGui/QColor>
22 
23 //STL
24 #include <map>
25 #include <vector>
26 #include <cmath>
27 
28 namespace OpenMS
29 {
30 
41  class OPENMS_GUI_DLLAPI MultiGradient
42  {
43 public:
46 
49 
52  {
54  IM_STAIRS
55  };
56 
59 
61  MultiGradient(const MultiGradient & multigradient);
62 
65 
68 
70  void insert(double position, QColor color);
72  bool remove(double position);
74  bool exists(double position);
80  UInt position(UInt index);
86  QColor color(UInt index);
87 
88 
95  QColor interpolatedColorAt(double position) const;
102  QColor interpolatedColorAt(double position, double min, double max) const;
103 
105  void activatePrecalculationMode(double min, double max, UInt steps);
108 
110  inline Int precalculatedColorIndex( double position ) const
111  {
112  OPENMS_PRECONDITION(pre_.size() != 0, "MultiGradient::precalculatedColorIndex(double): Precalculation mode not activated!");
113  OPENMS_PRECONDITION(position >= pre_min_, (String("MultiGradient::precalculatedColorIndex(double): position ") + position + " out of specified range (" + pre_min_ + "-" + (pre_min_ + pre_size_) + ")!").c_str());
114 
115  Int index = (Int)((position - pre_min_) / pre_size_ * pre_steps_);
116 
117  return qBound( 0, index, (Int)pre_.size() - 1 );
118  }
119 
121  inline QColor precalculatedColorByIndex( Int index ) const
122  {
123  OPENMS_PRECONDITION(pre_.size() != 0, "MultiGradient::precalculatedColorByIndex(Int): Precalculation mode not activated!");
124  OPENMS_PRECONDITION( index >= 0, "MultiGradient::precalculatedColorByIndex(Int): negative indexes not allowed");
125  OPENMS_PRECONDITION( index < (Int)pre_.size(), (String("MultiGradient::indexedColor(Int): index ") + index + " out of specified range (0-" + pre_.size() + ")!").c_str());
126 
127  return pre_[index];
128  }
129 
137  inline QColor precalculatedColorAt(double position) const
138  {
139  return precalculatedColorByIndex( precalculatedColorIndex( position ) );
140  }
141 
143  Size size() const;
144 
147  {
148  return pre_.size();
149  }
150 
155 
157  std::string toString() const;
173  void fromString(const std::string & gradient);
174 
175 protected:
177  std::map<double, QColor> pos_col_;
181  std::vector<QColor> pre_;
183  double pre_min_;
185  double pre_size_;
188 
189  };
190 
191 }
A gradient of multiple colors and arbitrary distances between colors.
Definition: MultiGradient.h:42
static MultiGradient getDefaultGradientLinearIntensityMode()
Returns the default gradient for linear intensity mode.
MultiGradient & operator=(const MultiGradient &rhs)
Assignment operator.
static MultiGradient getDefaultGradientLogarithmicIntensityMode()
Returns the default gradient for logarithmic intensity mode.
void deactivatePrecalculationMode()
deactivates the precalculation of values ( and deletes the precalculated values)
std::string toString() const
convert to string representation
std::vector< QColor > pre_
Precalculated colors.
Definition: MultiGradient.h:181
Int precalculatedColorIndex(double position) const
index of color in precalculated table by position in gradient
Definition: MultiGradient.h:110
MultiGradient(const MultiGradient &multigradient)
Copy constructor.
bool exists(double position)
returns if a value for position position exists
Size precalculatedSize() const
size of precalculated colors table
Definition: MultiGradient.h:146
~MultiGradient()
Destructor.
std::map< double, QColor > pos_col_
Map of index and color.
Definition: MultiGradient.h:177
void insert(double position, QColor color)
sets or replaces the color at position position
UInt pre_steps_
Steps of the precalculated color range.
Definition: MultiGradient.h:187
bool remove(double position)
removes the color at position position
void fromString(const std::string &gradient)
QColor color(UInt index)
returns the color of the index -th point
MultiGradient()
Constructor.
double pre_size_
Width of the precalculated color range.
Definition: MultiGradient.h:185
QColor precalculatedColorByIndex(Int index) const
precalculated color by its index in the table
Definition: MultiGradient.h:121
void activatePrecalculationMode(double min, double max, UInt steps)
activates the precalculation of values (only approximate results are given)
Size size() const
return the number of color points
double pre_min_
Minimum of the precalculated color range.
Definition: MultiGradient.h:183
QColor interpolatedColorAt(double position) const
Returns the color as position.
QColor precalculatedColorAt(double position) const
Returns a precalculated color.
Definition: MultiGradient.h:137
QColor interpolatedColorAt(double position, double min, double max) const
returns the color as position with the gradient stretched between min and max.
InterpolationMode interpolation_mode_
Current interpolation mode.
Definition: MultiGradient.h:179
UInt position(UInt index)
returns the position of the index -th point
InterpolationMode
Interpolation mode.
Definition: MultiGradient.h:52
@ IM_LINEAR
IM_LINEAR returns the linear interpolation (default).
Definition: MultiGradient.h:53
void setInterpolationMode(InterpolationMode mode)
sets the interpolation mode (default or stairs). Default is linear
InterpolationMode getInterpolationMode() const
returns the interpolation mode
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:72
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:94
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19