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

SpectrumCanvas.h (Maintainer: Marc Sturm)

Go to the documentation of this file.
00001 // vi: set ts=2:
00002 //
00003 // --------------------------------------------------------------------------
00004 //                   OpenMS Mass Spectrometry Framework 
00005 // --------------------------------------------------------------------------
00006 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00007 //
00008 //  This library is free software; you can redistribute it and/or
00009 //  modify it under the terms of the GNU Lesser General Public
00010 //  License as published by the Free Software Foundation; either
00011 //  version 2.1 of the License, or (at your option) any later version.
00012 //
00013 //  This library is distributed in the hope that it will be useful,
00014 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //  Lesser General Public License for more details.
00017 //
00018 //  You should have received a copy of the GNU Lesser General Public
00019 //  License along with this library; if not, write to the Free Software
00020 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 //
00022 // --------------------------------------------------------------------------
00023 // $Maintainer: Marc Sturm $
00024 // --------------------------------------------------------------------------
00025 
00026 
00027 #ifndef OPENMS_VISUAL_SPECTRUMCANVAS_H
00028 #define OPENMS_VISUAL_SPECTRUMCANVAS_H
00029 
00030 //OpenMS
00031 #include <OpenMS/CONCEPT/Types.h>
00032 #include <OpenMS/DATASTRUCTURES/DRange.h>
00033 #include <OpenMS/VISUAL/LayerData.h>
00034 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
00035 
00036 //QT
00037 #include <QtGui/QWidget>
00038 #include <QtGui/QRubberBand>
00039 
00040 //STL
00041 #include <stack>
00042 #include <vector>
00043 
00044 namespace OpenMS
00045 {
00046   class SpectrumWidget;
00047   
00062   class SpectrumCanvas 
00063     : public QWidget,
00064       public DefaultParamHandler
00065   {
00066     Q_OBJECT
00067   
00068   public:
00071     
00073     typedef LayerData::ExperimentType ExperimentType;
00075     typedef LayerData::FeatureMapType FeatureMapType;
00077     typedef ExperimentType::SpectrumType SpectrumType;
00079     typedef SpectrumType::Iterator SpectrumIteratorType;
00081     typedef SpectrumType::PeakType PeakType;
00083     typedef FeatureMapType::FeatureType FeatureType;
00084 
00086     typedef DPosition<2> PointType;
00088     typedef DRange<2> AreaType;
00089     
00090     
00092     enum ActionModes 
00093     {
00094       AM_SELECT,    
00095       AM_ZOOM       
00096     };
00097     
00099     enum IntensityModes
00100     {
00101       IM_NONE,        
00102       IM_PERCENTAGE,  
00103       IM_SNAP         
00104     };
00105     
00107 
00109     SpectrumCanvas(const Param& preferences, QWidget* parent = 0);
00110 
00112     ~SpectrumCanvas();
00113     
00121     inline void setSpectrumWidget(SpectrumWidget* widget) 
00122     { 
00123       spectrum_widget_ = widget; 
00124     }
00125     
00132     inline SpectrumWidget* getSpectrumWidget() const 
00133     { 
00134       return spectrum_widget_; 
00135     }
00136     
00143     inline Int getActionMode() const 
00144     { 
00145       return action_mode_;
00146     }
00147     
00154     inline void setActionMode(ActionModes mode) 
00155     { 
00156       action_mode_ = mode;
00157       switch (mode)
00158       {
00159         case AM_ZOOM:
00160           setCursor(Qt::CrossCursor);
00161           break;
00162         default:
00163           setCursor(Qt::ArrowCursor);
00164       }
00165     }
00166     
00174     inline Int getIntensityMode() const 
00175     { 
00176       return intensity_mode_; 
00177     }
00178     
00188     inline void setIntensityMode(IntensityModes mod) 
00189     {
00190       intensity_mode_ = mod;
00191       intensityModeChange_();
00192     }
00193     
00199     inline bool gridLinesShown() const 
00200     { 
00201       return show_grid_; 
00202     }
00204     inline const LayerData& getLayer(UInt index) const
00205     {
00206       OPENMS_PRECONDITION(index < layers_.size(), "SpectrumCanvas::getLayer(index) index overflow");
00207       return layers_[index];
00208     }
00209     
00211     inline const LayerData& getCurrentLayer() const
00212     {
00213       OPENMS_PRECONDITION(current_layer_ < layers_.size(), "SpectrumCanvas::getCurrentLayer() index overflow");
00214       return layers_[current_layer_];
00215     }
00216 
00218     bool getLayerFlag(LayerData::Flags f) const
00219     {
00220       OPENMS_PRECONDITION(current_layer_ < layers_.size(), "SpectrumCanvas::getLayerFlag() index overflow");
00221       switch(f)
00222       {
00223         case LayerData::F_HULLS:
00224           return layers_[current_layer_].f1;
00225         case LayerData::F_NUMBERS:
00226           return layers_[current_layer_].f2;
00227         case LayerData::F_HULL:
00228           return layers_[current_layer_].f3;
00229         case LayerData::P_PRECURSORS:
00230           return layers_[current_layer_].f1;
00231         case LayerData::P_PROJECTIONS:
00232           return layers_[current_layer_].f2;
00233       }
00234       std::cout << "Error: SpectrumCanvas::getLayerFlag -- unknown flag '" << f << "'!" << std::endl;
00235       return false;
00236     }
00237 
00239     void setLayerFlag(LayerData::Flags f, bool value)
00240     {
00241       OPENMS_PRECONDITION(current_layer_ < layers_.size(), "SpectrumCanvas::setLayerFlag() index overflow");
00242       switch(f)
00243       {
00244         case LayerData::F_HULLS:
00245           layers_[current_layer_].f1 = value;
00246           break;
00247         case LayerData::F_NUMBERS:
00248           layers_[current_layer_].f2 = value;
00249           break;
00250         case LayerData::F_HULL:
00251           layers_[current_layer_].f3 = value;
00252           break;
00253         case LayerData::P_PRECURSORS:
00254           layers_[current_layer_].f1 = value;
00255           break;
00256         case LayerData::P_PROJECTIONS:
00257           layers_[current_layer_].f2 = value;
00258           break;
00259       }
00260       update_buffer_ = true;
00261       update();
00262     }
00263 
00265     bool getLayerFlag(UInt layer, LayerData::Flags f) const
00266     {
00267       OPENMS_PRECONDITION(layer < layers_.size(), "SpectrumCanvas::getLayerFlag() index overflow");
00268       switch(f)
00269       {
00270         case LayerData::F_HULLS:
00271           return layers_[layer].f1;
00272         case LayerData::F_NUMBERS:
00273           return layers_[layer].f2;
00274         case LayerData::F_HULL:
00275           return layers_[layer].f3;
00276         case LayerData::P_PRECURSORS:
00277           return layers_[layer].f1;
00278         case LayerData::P_PROJECTIONS:
00279           return layers_[layer].f2;
00280       }
00281       std::cout << "Error: SpectrumCanvas::getLayerFlag -- unknown flag '" << f << "'!" << std::endl;
00282       return false;
00283     }
00284 
00286     void setLayerFlag(UInt layer, LayerData::Flags f, bool value)
00287     {
00288       OPENMS_PRECONDITION(layer < layers_.size(), "SpectrumCanvas::setLayerFlag() index overflow");
00289       switch(f)
00290       {
00291         case LayerData::F_HULLS:
00292           layers_[layer].f1 = value;
00293           break;
00294         case LayerData::F_NUMBERS:
00295           layers_[layer].f2 = value;
00296           break;
00297         case LayerData::F_HULL:
00298           layers_[layer].f3 = value;
00299           break;
00300         case LayerData::P_PRECURSORS:
00301           layers_[layer].f1 = value;
00302           break;
00303         case LayerData::P_PROJECTIONS:
00304           layers_[layer].f2 = value;
00305           break;
00306       }
00307       update_buffer_ = true;
00308       update();
00309     }
00310 
00317     inline const AreaType& getVisibleArea() 
00318     { 
00319       return visible_area_;
00320     }
00321     
00325     virtual void setFilters(const DataFilters& filters);
00326     
00328     bool isMzToXAxis();
00329     
00331     void mzToXAxis(bool mz_to_x_axis);
00332 
00339 
00340     inline UInt getLayerCount() const
00341     {
00342       return layers_.size();
00343     }
00344       
00346     UInt activeLayerIndex() const;
00348     virtual void activateLayer(int layer_index)=0;
00350     virtual void removeLayer(int layer_index)=0;
00358     ExperimentType& addEmptyPeakLayer();
00367     virtual Int finishAdding() = 0;
00373     Int addLayer(const ExperimentType&);
00374 
00383     Int addLayer(const FeatureMapType& map, bool pairs);
00384     
00386     
00388     inline double getCurrentMinIntensity() const 
00389     { 
00390       if (getCurrentLayer().type==LayerData::DT_PEAK)
00391       {
00392         return getCurrentLayer().peaks.getMinInt(); 
00393       }
00394       else
00395       {
00396         return getCurrentLayer().features.getMinInt(); 
00397       }
00398     }
00399 
00401     inline double getCurrentMaxIntensity() const 
00402     { 
00403       if (getCurrentLayer().type==LayerData::DT_PEAK)
00404       {
00405         return getCurrentLayer().peaks.getMaxInt(); 
00406       }
00407       else
00408       {
00409         return getCurrentLayer().features.getMaxInt(); 
00410       }
00411     }
00412 
00414     inline double getMinIntensity(UInt index) const 
00415     { 
00416       if (getLayer(index).type==LayerData::DT_PEAK)
00417       {
00418         return getCurrentLayer().peaks.getMinInt(); 
00419       }
00420       else
00421       {
00422         return getLayer(index).features.getMinInt(); 
00423       }
00424     }
00425 
00427     void setLayerName(UInt i, const String& name);
00428 
00430     inline void setCurrentLayerParameters(const Param& param) 
00431     { 
00432       getCurrentLayer_().param = param;
00433       currentLayerParamtersChanged_();
00434     }
00435 
00437     inline double getMaxIntensity(UInt index) const 
00438     { 
00439       if (getLayer(index).type==LayerData::DT_PEAK)
00440       {
00441         return getLayer(index).peaks.getMaxInt(); 
00442       }
00443       else
00444       {
00445         return getLayer(index).features.getMaxInt(); 
00446       }
00447     }
00448 
00454     const DRange<3>& getDataRange();  
00455 
00461     double getSnapFactor();
00462     
00464     virtual void showCurrentLayerPreferences() = 0;
00465 
00471     virtual void saveCurrentLayer(bool visible)=0;
00472     
00473   public slots:
00480     void changeVisibility(int i, bool b);
00481 
00488     void showGridLines(bool show);
00489     
00495     void resetZoom();
00496     
00503     void setVisibleArea(AreaType area);
00504 
00510     virtual void horizontalScrollBarChange(int value);
00511 
00517     virtual void verticalScrollBarChange(int value);
00518     
00519   signals:
00521     void layerActivated(QWidget* w);
00522     
00529     void visibleAreaChanged(DRange<2> area); //Do not change this to AreaType! QT needs the exact type...
00530         
00532     void sendCursorStatus(double mz=-1.0, double intens=-1.0, double rt=-1.0);
00533 
00535     void sendStatusMessage(std::string, OpenMS::UInt);
00536       
00538     void recalculateAxes();
00539     
00541     void updateVScrollbar(float,float,float,float);
00542 
00544     void updateHScrollbar(float,float,float,float);
00545     
00547     void changeLegendVisibility();
00548 
00549   protected:
00550     inline LayerData& getLayer_(UInt index)
00551     {
00552       OPENMS_PRECONDITION(index < layers_.size(), "SpectrumCanvas::getLayer_(index) index overflow");
00553       return layers_[index];
00554     }
00555 
00556     inline LayerData& getCurrentLayer_()
00557     {
00558       return getLayer_(current_layer_);
00559     }
00560     
00562     inline ExperimentType& currentPeakData_()
00563     {
00564       return getCurrentLayer_().peaks;
00565     }
00566   
00568     void resizeEvent(QResizeEvent* e);
00569     
00575     virtual void currentLayerParamtersChanged_();
00576 
00578     virtual void intensityModeChange_();
00579     
00580     
00590     virtual void changeVisibleArea_(const AreaType& new_area, bool add_to_stack = false);
00591 
00597     virtual void recalculateSnapFactor_();
00598     
00604     void zoomBack_();
00605     
00611     virtual void updateScrollbars_();
00612     
00621     inline PointType widgetToData_(float x, float y)
00622     {
00623       if (!isMzToXAxis())
00624       {
00625         return PointType(
00626                 visible_area_.minX() + (height() - y) / height()  * visible_area_.width(),
00627                 visible_area_.minY() + x  / width() * visible_area_.height() 
00628                 );
00629       }
00630       else
00631       {
00632         return PointType(
00633                 visible_area_.minX() + x / width() * visible_area_.width(),
00634                 visible_area_.minY() + (height() - y) / height() * visible_area_.height() 
00635                 );      
00636       }   
00637     }
00638 
00640     inline PointType widgetToData_(const QPoint& pos)
00641     {
00642       return widgetToData_(pos.x(), pos.y());
00643     }
00644         
00653     inline void dataToWidget_(float x, float y, QPoint& point)
00654     {
00655       if (!isMzToXAxis())
00656       {
00657         point.setX( static_cast<int>((y - visible_area_.minY()) / visible_area_.height() * width()));
00658         point.setY(height() - static_cast<int>((x - visible_area_.minX()) / visible_area_.width() * height()));
00659       }
00660       else
00661       {
00662         point.setX( static_cast<int>((x - visible_area_.minX()) / visible_area_.width() * width()));
00663         point.setY( height() - static_cast<int>((y - visible_area_.minY()) / visible_area_.height() * height()));
00664       }
00665     }
00666     
00668     void paintGridLines_(QPainter& painter);
00669     
00671     QPixmap buffer_;
00672     
00674     ActionModes action_mode_;
00675     
00677     IntensityModes intensity_mode_;
00678     
00680     std::vector< LayerData > layers_;
00681     
00683     bool mz_to_x_axis_;
00684     
00686     AreaType visible_area_;
00687     
00699     void recalculateRanges_(UInt mz_dim, UInt rt_dim, UInt it_dim);
00700     
00702     DRange<3> overall_data_range_;
00703     
00705     bool show_grid_;
00706     
00708     std::stack<AreaType> zoom_stack_;
00709 
00719     virtual void update_(const char* caller_name);
00720 
00722     bool update_buffer_;
00723 
00725     UInt current_layer_;
00726 
00728     void adjustBuffer_();
00729     
00731     SpectrumWidget* spectrum_widget_;
00732 
00734     QPoint last_mouse_pos_;
00735     
00741     double percentage_factor_;
00742     
00748     double snap_factor_;
00749     
00751     QRubberBand rubber_band_;
00752   };
00753 }
00754 
00755 #endif

Generated Tue Apr 1 15:36:38 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1