Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MultiGradient.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-2017.
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 #ifndef OPENMS_VISUAL_MULTIGRADIENT_H
36 #define OPENMS_VISUAL_MULTIGRADIENT_H
37 
38 // OpenMS_GUI config
39 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
40 
41 //OpenMS
42 #include <OpenMS/CONCEPT/Types.h>
43 #include <OpenMS/CONCEPT/Macros.h>
46 
47 //QT
48 #include <QtGui/QColor>
49 
50 //STL
51 #include <map>
52 #include <vector>
53 #include <cmath>
54 
55 namespace OpenMS
56 {
57 
68  class OPENMS_GUI_DLLAPI MultiGradient
69  {
70 public:
72  static MultiGradient getDefaultGradientLinearIntensityMode();
73 
75  static MultiGradient getDefaultGradientLogarithmicIntensityMode();
76 
79  {
81  IM_STAIRS
82  };
83 
85  MultiGradient();
86 
88  MultiGradient(const MultiGradient & multigradient);
89 
91  ~MultiGradient();
92 
94  MultiGradient & operator=(const MultiGradient & rhs);
95 
97  void insert(double position, QColor color);
99  bool remove(double position);
101  bool exists(double position);
107  UInt position(UInt index);
113  QColor color(UInt index);
114 
115 
122  QColor interpolatedColorAt(double position) const;
129  QColor interpolatedColorAt(double position, double min, double max) const;
130 
132  void activatePrecalculationMode(double min, double max, UInt steps);
134  void deactivatePrecalculationMode();
135 
137  inline Int precalculatedColorIndex( double position ) const
138  {
139  OPENMS_PRECONDITION(pre_.size() != 0, "MultiGradient::precalculatedColorIndex(double): Precalculation mode not activated!");
140  OPENMS_PRECONDITION(position >= pre_min_, (String("MultiGradient::precalculatedColorIndex(double): position ") + position + " out of specified range (" + pre_min_ + "-" + (pre_min_ + pre_size_) + ")!").c_str());
141 
142  Int index = (Int)((position - pre_min_) / pre_size_ * pre_steps_);
143 
144  return qBound( 0, index, (Int)pre_.size() - 1 );
145  }
146 
148  inline QColor precalculatedColorByIndex( Int index ) const
149  {
150  OPENMS_PRECONDITION(pre_.size() != 0, "MultiGradient::precalculatedColorByIndex(Int): Precalculation mode not activated!");
151  OPENMS_PRECONDITION( index >= 0, "MultiGradient::precalculatedColorByIndex(Int): negative indexes not allowed");
152  OPENMS_PRECONDITION( index < (Int)pre_.size(), (String("MultiGradient::indexedColor(Int): index ") + index + " out of specified range (0-" + pre_.size() + ")!").c_str());
153 
154  return pre_[index];
155  }
156 
164  inline QColor precalculatedColorAt(double position) const
165  {
166  return precalculatedColorByIndex( precalculatedColorIndex( position ) );
167  }
168 
170  Size size() const;
171 
174  {
175  return pre_.size();
176  }
177 
179  void setInterpolationMode(InterpolationMode mode);
181  InterpolationMode getInterpolationMode() const;
182 
184  std::string toString() const;
200  void fromString(const std::string & gradient);
201 
202 protected:
204  std::map<double, QColor> pos_col_;
208  std::vector<QColor> pre_;
210  double pre_min_;
212  double pre_size_;
215 
216  };
217 
218 }
219 #endif // OPENMS_VISUAL_MULTIGRADIENT_H
InterpolationMode
Interpolation mode.
Definition: MultiGradient.h:78
A more convenient string class.
Definition: String.h:57
QColor precalculatedColorAt(double position) const
Returns a precalculated color.
Definition: MultiGradient.h:164
Int precalculatedColorIndex(double position) const
index of color in precalculated table by position in gradient
Definition: MultiGradient.h:137
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
QColor precalculatedColorByIndex(Int index) const
precalculated color by its index in the table
Definition: MultiGradient.h:148
double pre_min_
Minimum of the precalculated color range.
Definition: MultiGradient.h:210
InterpolationMode interpolation_mode_
Current interpolation mode.
Definition: MultiGradient.h:206
UInt pre_steps_
Steps of the precalculated color range.
Definition: MultiGradient.h:214
Size precalculatedSize() const
size of precalculated colors table
Definition: MultiGradient.h:173
std::vector< QColor > pre_
Precalculated colors.
Definition: MultiGradient.h:208
IM_LINEAR returns the linear interpolation (default).
Definition: MultiGradient.h:80
std::map< double, QColor > pos_col_
Map of index and color.
Definition: MultiGradient.h:204
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:69
A gradient of multiple colors and arbitrary distances between colors.
Definition: MultiGradient.h:68
int Int
Signed integer type.
Definition: Types.h:103
double pre_size_
Width of the precalculated color range.
Definition: MultiGradient.h:212

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:02 using doxygen 1.8.13