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-2013.
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
39 #include <OpenMS/CONCEPT/Types.h>
40 #include <OpenMS/CONCEPT/Macros.h>
43 
44 //QT
45 #include <QtGui/QColor>
46 
47 //STL
48 #include <map>
49 #include <vector>
50 #include <cmath>
51 
52 namespace OpenMS
53 {
54 
65  class OPENMS_GUI_DLLAPI MultiGradient
66  {
67 public:
69  static MultiGradient getDefaultGradientLinearIntensityMode();
70 
72  static MultiGradient getDefaultGradientLogarithmicIntensityMode();
73 
76  {
78  IM_STAIRS
79  };
80 
82  MultiGradient();
83 
85  MultiGradient(const MultiGradient & multigradient);
86 
88  ~MultiGradient();
89 
91  MultiGradient & operator=(const MultiGradient & rhs);
92 
94  void insert(DoubleReal position, QColor color);
96  bool remove(DoubleReal position);
98  bool exists(DoubleReal position);
104  UInt position(UInt index);
110  QColor color(UInt index);
111 
112 
119  QColor interpolatedColorAt(DoubleReal position) const;
126  QColor interpolatedColorAt(DoubleReal position, DoubleReal min, DoubleReal max) const;
127 
129  void activatePrecalculationMode(DoubleReal min, DoubleReal max, UInt steps);
131  void deactivatePrecalculationMode();
132 
134  inline Int precalculatedColorIndex( DoubleReal position ) const
135  {
136  OPENMS_PRECONDITION(pre_.size() != 0, "MultiGradient::precalculatedColorIndex(DoubleReal): Precalculation mode not activated!");
137  OPENMS_PRECONDITION(position >= pre_min_, (String("MultiGradient::precalculatedColorIndex(DoubleReal): position ") + position + " out of specified range (" + pre_min_ + "-" + (pre_min_ + pre_size_) + ")!").c_str());
138 
139  Int index = (Int)((position - pre_min_) / pre_size_ * pre_steps_);
140 
141  return qBound( 0, index, (Int)pre_.size() - 1 );
142  }
143 
145  inline QColor precalculatedColorByIndex( Int index ) const
146  {
147  OPENMS_PRECONDITION(pre_.size() != 0, "MultiGradient::precalculatedColorByIndex(Int): Precalculation mode not activated!");
148  OPENMS_PRECONDITION( index >= 0, "MultiGradient::precalculatedColorByIndex(Int): negative indexes not allowed");
149  OPENMS_PRECONDITION( index < (Int)pre_.size(), (String("MultiGradient::indexedColor(Int): index ") + index + " out of specified range (0-" + pre_.size() + ")!").c_str());
150 
151  return pre_[index];
152  }
153 
161  inline QColor precalculatedColorAt(DoubleReal position) const
162  {
163  return precalculatedColorByIndex( precalculatedColorIndex( position ) );
164  }
165 
167  Size size() const;
168 
171  {
172  return pre_.size();
173  }
174 
176  void setInterpolationMode(InterpolationMode mode);
178  InterpolationMode getInterpolationMode() const;
179 
181  std::string toString() const;
197  void fromString(const std::string & gradient);
198 
199 protected:
201  std::map<DoubleReal, QColor> pos_col_;
205  std::vector<QColor> pre_;
212 
213  };
214 
215 }
216 #endif // OPENMS_VISUAL_MULTIGRADIENT_H
QColor precalculatedColorAt(DoubleReal position) const
Returns a precalculated color.
Definition: MultiGradient.h:161
InterpolationMode
Interploation mode.
Definition: MultiGradient.h:75
A more convenient string class.
Definition: String.h:56
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: Macros.h:107
InterpolationMode interpolation_mode_
Current interpolation mode.
Definition: MultiGradient.h:203
UInt pre_steps_
Steps of the precalculated color range.
Definition: MultiGradient.h:211
Int precalculatedColorIndex(DoubleReal position) const
index of color in precalculated table by position in gradient
Definition: MultiGradient.h:134
std::vector< QColor > pre_
Precalculated colors.
Definition: MultiGradient.h:205
IM_LINEAR returns the linear interploation (default).
Definition: MultiGradient.h:77
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
QColor precalculatedColorByIndex(Int index) const
precalculated color by its index in the table
Definition: MultiGradient.h:145
std::map< DoubleReal, QColor > pos_col_
Map of index and color.
Definition: MultiGradient.h:201
DoubleReal pre_min_
Minimum of the precalculated color range.
Definition: MultiGradient.h:207
Size precalculatedSize() const
size of precalculated colors table
Definition: MultiGradient.h:170
DoubleReal pre_size_
Width of the precalculated color range.
Definition: MultiGradient.h:209
A gradient of multiple colors and arbitrary distances between colors.
Definition: MultiGradient.h:65
int Int
Signed integer type.
Definition: Types.h:100

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:18 using doxygen 1.8.5