Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

MultiGradient.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Timo Sachsenberg $
00032 // $Authors: Marc Sturm $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_VISUAL_MULTIGRADIENT_H
00036 #define OPENMS_VISUAL_MULTIGRADIENT_H
00037 
00038 //OpenMS
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 //QT
00045 #include <QtGui/QColor>
00046 
00047 //STL
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

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:42 using doxygen 1.7.1