svgui  1.9
Colour3DPlotLayer.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam and QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _COLOUR_3D_PLOT_H_
00017 #define _COLOUR_3D_PLOT_H_
00018 
00019 #include "SliceableLayer.h"
00020 
00021 #include "data/model/DenseThreeDimensionalModel.h"
00022 
00023 class View;
00024 class QPainter;
00025 class QImage;
00026 
00040 class Colour3DPlotLayer : public SliceableLayer
00041 {
00042     Q_OBJECT
00043 
00044 public:
00045     Colour3DPlotLayer();
00046     ~Colour3DPlotLayer();
00047 
00048     virtual const ZoomConstraint *getZoomConstraint() const {
00049         return m_model ? m_model->getZoomConstraint() : 0;
00050     }
00051     virtual const Model *getModel() const { return m_model; }
00052     virtual void paint(View *v, QPainter &paint, QRect rect) const;
00053 
00054     virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const;
00055     virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const;
00056 
00057     virtual QString getFeatureDescription(View *v, QPoint &) const;
00058 
00059     virtual bool snapToFeatureFrame(View *v, int &frame, 
00060                                     int &resolution,
00061                                     SnapType snap) const;
00062 
00063     virtual void setLayerDormant(const View *v, bool dormant);
00064 
00065     virtual bool isLayerScrollable(const View *v) const;
00066 
00067     virtual ColourSignificance getLayerColourSignificance() const {
00068         return ColourHasMeaningfulValue;
00069     }
00070 
00071     void setModel(const DenseThreeDimensionalModel *model);
00072 
00073     virtual int getCompletion(View *) const { return m_model->getCompletion(); }
00074 
00075     virtual PropertyList getProperties() const;
00076     virtual PropertyType getPropertyType(const PropertyName &) const;
00077     virtual QString getPropertyLabel(const PropertyName &) const;
00078     virtual QString getPropertyIconName(const PropertyName &) const;
00079     virtual QString getPropertyGroupName(const PropertyName &) const;
00080     virtual int getPropertyRangeAndValue(const PropertyName &,
00081                                          int *min, int *max, int *deflt) const;
00082     virtual QString getPropertyValueLabel(const PropertyName &,
00083                                           int value) const;
00084     virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
00085     virtual void setProperty(const PropertyName &, int value);
00086     virtual void setProperties(const QXmlAttributes &);
00087     
00088     enum ColourScale {
00089         LinearScale,
00090         LogScale,
00091         PlusMinusOneScale,
00092         AbsoluteScale
00093     };
00094 
00095     void setColourScale(ColourScale);
00096     ColourScale getColourScale() const { return m_colourScale; }
00097 
00098     void setColourMap(int map);
00099     int getColourMap() const;
00100 
00105     void setGain(float gain);
00106     float getGain() const;
00107 
00108     enum BinScale {
00109         LinearBinScale,
00110         LogBinScale
00111     };
00112     
00116     void setBinScale(BinScale);
00117     BinScale getBinScale() const;
00118 
00123     void setNormalizeColumns(bool n);
00124     bool getNormalizeColumns() const;
00125 
00129     void setNormalizeVisibleArea(bool n);
00130     bool getNormalizeVisibleArea() const;
00131 
00136     void setNormalizeHybrid(bool n);
00137     bool getNormalizeHybrid() const;
00138 
00139     void setInvertVertical(bool i);
00140     bool getInvertVertical() const;
00141 
00142     void setOpaque(bool i);
00143     bool getOpaque() const;
00144 
00145     void setSmooth(bool i);
00146     bool getSmooth() const;
00147 
00148     virtual bool getValueExtents(float &min, float &max,
00149                                  bool &logarithmic, QString &unit) const;
00150 
00151     virtual bool getDisplayExtents(float &min, float &max) const;
00152     virtual bool setDisplayExtents(float min, float max);
00153 
00154     virtual bool getYScaleValue(const View *, int /* y */,
00155                                 float &/* value */, QString &/* unit */) const;
00156 
00157     virtual int getVerticalZoomSteps(int &defaultStep) const;
00158     virtual int getCurrentVerticalZoomStep() const;
00159     virtual void setVerticalZoomStep(int);
00160     virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
00161 
00162     virtual const Model *getSliceableModel() const { return m_model; }
00163 
00164     virtual void toXml(QTextStream &stream, QString indent = "",
00165                        QString extraAttributes = "") const;
00166 
00167 protected slots:
00168     void cacheInvalid();
00169     void cacheInvalid(int startFrame, int endFrame);
00170     void modelChanged();
00171     void modelChangedWithin(int, int);
00172 
00173 protected:
00174     const DenseThreeDimensionalModel *m_model; // I do not own this
00175     
00176     mutable QImage *m_cache;
00177     mutable QImage *m_peaksCache;
00178     mutable int m_cacheValidStart;
00179     mutable int m_cacheValidEnd;
00180 
00181     ColourScale m_colourScale;
00182     bool        m_colourScaleSet;
00183     int         m_colourMap;
00184     float       m_gain;
00185     BinScale    m_binScale;
00186     bool        m_normalizeColumns;
00187     bool        m_normalizeVisibleArea;
00188     bool        m_normalizeHybrid;
00189     bool        m_invertVertical;
00190     bool        m_opaque;
00191     bool        m_smooth;
00192     int         m_peakResolution;
00193 
00194     // Minimum and maximum bin numbers visible within the view. We
00195     // always snap to whole bins at view edges.
00196     int         m_miny;
00197     int         m_maxy;
00198 
00205     float getYForBin(View *, float bin) const;
00206 
00213     float getBinForY(View *, float y) const;
00214     
00215     DenseThreeDimensionalModel::Column getColumn(int col) const;
00216 
00222     bool shouldPaintDenseIn(const View *) const; 
00223 
00224     int getColourScaleWidth(QPainter &) const;
00225     void fillCache(int firstBin, int lastBin) const;
00226     void paintDense(View *v, QPainter &paint, QRect rect) const;
00227 };
00228 
00229 #endif