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 #ifndef OPENMS_VISUAL_MULTIGRADIENT_H
00028 #define OPENMS_VISUAL_MULTIGRADIENT_H
00029
00030
00031 #include <OpenMS/CONCEPT/Types.h>
00032 #include <OpenMS/CONCEPT/Macros.h>
00033 #include <OpenMS/CONCEPT/Exception.h>
00034
00035
00036 #include <QtGui/QColor>
00037
00038
00039 #include <map>
00040 #include <vector>
00041 #include <cmath>
00042
00043 namespace OpenMS
00044 {
00045
00056 class MultiGradient
00057 {
00058 public:
00059
00061 enum InterpolationMode
00062 {
00063 IM_LINEAR,
00064 IM_STAIRS
00065 };
00066
00068 MultiGradient();
00070 ~MultiGradient();
00071
00073 void insert (Int position, const QColor& color);
00075 bool remove (Int position);
00077 bool exists (Int position);
00079 UInt position(UInt index) throw (Exception::IndexUnderflow,Exception::IndexOverflow);
00081 const QColor& color(UInt index) throw (Exception::IndexUnderflow,Exception::IndexOverflow);
00082
00083
00090 QColor interpolatedColorAt(DoubleReal position) const;
00097 QColor interpolatedColorAt(DoubleReal position, DoubleReal min, DoubleReal max) const;
00098
00100 void activatePrecalculationMode(DoubleReal min, DoubleReal max, UInt steps);
00102 void deactivatePrecalculationMode();
00110 inline const QColor& precalculatedColorAt(DoubleReal position) const
00111 {
00112 OPENMS_PRECONDITION(pre_.size()!=0,"MultiGradient::precalculatedColorAt(DoubleReal): Precalculation mode not activated!");
00113 OPENMS_PRECONDITION(position>=pre_min_,"MultiGradient::precalculatedColorAt(DoubleReal): Position out of specified range!");
00114 OPENMS_PRECONDITION(position<=pre_min_+pre_size_,"MultiGradient::precalculatedColorAt(DoubleReal): Position out of specified range!");
00115 return pre_[(UInt)((position - pre_min_) / pre_size_ * pre_steps_)];
00116 }
00117
00119 UInt size() const;
00120
00122 void setInterpolationMode(UInt mode);
00124 UInt getInterpolationMode() const;
00125
00127 std::string toString() const;
00143 void fromString(const std::string& gradient);
00144
00145 protected:
00147 std::map<UInt,QColor> pos_col_;
00149 UInt interpolation_mode_;
00151 std::vector<QColor> pre_;
00153 DoubleReal pre_min_;
00155 DoubleReal pre_size_;
00157 UInt pre_steps_;
00158
00159 };
00160
00161 }
00162 #endif // OPENMS_VISUAL_MULTIGRADIENT_H
00163