Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_VISUAL_MULTIGRADIENT_H
00036 #define OPENMS_VISUAL_MULTIGRADIENT_H
00037
00038
00039 #include <OpenMS/CONCEPT/Types.h>
00040 #include <OpenMS/CONCEPT/Macros.h>
00041 #include <OpenMS/CONCEPT/Exception.h>
00042 #include <OpenMS/DATASTRUCTURES/String.h>
00043
00044
00045 #include <QtGui/QColor>
00046
00047
00048 #include <map>
00049 #include <vector>
00050 #include <cmath>
00051
00052 namespace OpenMS
00053 {
00054
00065 class OPENMS_GUI_DLLAPI MultiGradient
00066 {
00067 public:
00069 static MultiGradient getDefaultGradientLinearIntensityMode();
00070
00072 static MultiGradient getDefaultGradientLogarithmicIntensityMode();
00073
00075 enum InterpolationMode
00076 {
00077 IM_LINEAR,
00078 IM_STAIRS
00079 };
00080
00082 MultiGradient();
00083
00085 MultiGradient(const MultiGradient & multigradient);
00086
00088 ~MultiGradient();
00089
00091 MultiGradient & operator=(const MultiGradient & rhs);
00092
00094 void insert(DoubleReal position, QColor color);
00096 bool remove(DoubleReal position);
00098 bool exists(DoubleReal position);
00104 UInt position(UInt index);
00110 QColor color(UInt index);
00111
00112
00119 QColor interpolatedColorAt(DoubleReal position) const;
00126 QColor interpolatedColorAt(DoubleReal position, DoubleReal min, DoubleReal max) const;
00127
00129 void activatePrecalculationMode(DoubleReal min, DoubleReal max, UInt steps);
00131 void deactivatePrecalculationMode();
00132
00134 inline Int precalculatedColorIndex( DoubleReal position ) const
00135 {
00136 OPENMS_PRECONDITION(pre_.size() != 0, "MultiGradient::precalculatedColorIndex(DoubleReal): Precalculation mode not activated!");
00137 OPENMS_PRECONDITION(position >= pre_min_, (String("MultiGradient::precalculatedColorIndex(DoubleReal): position ") + position + " out of specified range (" + pre_min_ + "-" + (pre_min_ + pre_size_) + ")!").c_str());
00138
00139 Int index = (Int)((position - pre_min_) / pre_size_ * pre_steps_);
00140
00141 return qBound( 0, index, (Int)pre_.size() - 1 );
00142 }
00143
00145 inline QColor precalculatedColorByIndex( Int index ) const
00146 {
00147 OPENMS_PRECONDITION(pre_.size() != 0, "MultiGradient::precalculatedColorByIndex(Int): Precalculation mode not activated!");
00148 OPENMS_PRECONDITION( index >= 0, "MultiGradient::precalculatedColorByIndex(Int): negative indexes not allowed");
00149 OPENMS_PRECONDITION( index < (Int)pre_.size(), (String("MultiGradient::indexedColor(Int): index ") + index + " out of specified range (0-" + pre_.size() + ")!").c_str());
00150
00151 return pre_[index];
00152 }
00153
00161 inline QColor precalculatedColorAt(DoubleReal position) const
00162 {
00163 return precalculatedColorByIndex( precalculatedColorIndex( position ) );
00164 }
00165
00167 Size size() const;
00168
00170 Size precalculatedSize() const
00171 {
00172 return pre_.size();
00173 }
00174
00176 void setInterpolationMode(InterpolationMode mode);
00178 InterpolationMode getInterpolationMode() const;
00179
00181 std::string toString() const;
00197 void fromString(const std::string & gradient);
00198
00199 protected:
00201 std::map<DoubleReal, QColor> pos_col_;
00203 InterpolationMode interpolation_mode_;
00205 std::vector<QColor> pre_;
00207 DoubleReal pre_min_;
00209 DoubleReal pre_size_;
00211 UInt pre_steps_;
00212
00213 };
00214
00215 }
00216 #endif // OPENMS_VISUAL_MULTIGRADIENT_H