casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinPlotWidget.qo.h
Go to the documentation of this file.
1 //# Copyright (C) 2005
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
25 #ifndef BINPLOTWIDGET_QO_H
26 #define BINPLOTWIDGET_QO_H
27 
28 #include <QWidget>
29 
30 #include <guitools/Histogram/BinPlotWidget.ui.h>
34 #include <casa/aips.h>
35 #include <casa/aipstype.h>
36 #include <qwt_plot.h>
37 #include <qwt_plot_picker.h>
38 #include <vector>
39 #include <QDebug>
40 #include <QMenu>
41 
42 using namespace std;
43 
44 class QwtPlotMarker;
45 class QwtPlotCurve;
46 class QwtLinearColorMap;
47 class QWidgetAction;
48 
49 namespace casacore{
50 
51 template <class T> class ImageInterface;
52 template <class T> class Vector;
53 }
54 
55 namespace casa {
56 
57 class FitWidget;
58 class RangePicker;
59 class ToolTipPicker;
60 class Histogram;
61 class HistogramMarkerGaussian;
62 class HistogramMarkerPoisson;
63 class RangeControlsWidget;
64 class BinCountWidget;
65 class ChannelRangeWidget;
66 class ZoomWidget;
67 
68 
81 class BinPlotWidget : public QWidget, public HeightSource{
82  Q_OBJECT
83 
84 friend class RangePicker;
85 
86 public:
93  BinPlotWidget( bool fitControls, bool rangeControls, bool plotModeControls,
94  QWidget* parent);
95 
96  bool setImage( const std::shared_ptr<const casacore::ImageInterface<float> > img, bool waitOnHistogram = false );
97  bool setImageRegion( casacore::ImageRegion* imageRegion, int id );
98  void deleteImageRegion( int id );
99  void imageRegionSelected( int id );
100  virtual void postMessage( const QString& msg );
101 
102  std::vector<float> getXValues() const;
103  pair<double,double> getMinMaxValues() const;
104  void setMinMaxValues( double minValue, double maxValue, bool updateGraph=true );
105 
106  //Customizing the display
107  void hideMaximumRange();
108  void setColorLookups( const casacore::Vector<casacore::uInt> & lookups );
109  void setColorMap( QwtLinearColorMap* colorMap );
110  void setColorScaleMax( int max );
111  void setMultiColored( bool multipleColors );
112  void setLineMode( bool lineMode );
113  void setDisplayPlotTitle( bool display );
114  void setDisplayAxisTitles( bool display );
115  void setHistogramColor( QColor color );
116  void setFitEstimateColor( QColor color );
117  void setFitCurveColor( QColor color );
118  void setMultipleHistogramColors( const QList<QColor>& colors );
119  void setAxisLabelFont( int size );
120  void setChannelCount( int count );
121  void setChannelValue( int value );
122  void addZoomActions( bool rangeControl, QMenu* zoomMenu );
123  void addDisplayActions( QMenu* menu, QWidgetAction* binCountAction );
124  void addPlotModeActions( QMenu* menu, QWidgetAction* channelRangeAction=NULL,
125  QWidgetAction* footPrintAction = NULL );
126  void setPlotMode( int mode );
127  bool isEmpty() const;
128  ~BinPlotWidget();
129 
130 signals:
131  void postStatusMessage( const QString& msg );
132  void rangeChanged();
133 
134 
135 public slots:
136  void fitModeChanged();
137  void plotModeChanged( int mode );
138  void setDisplayStep( bool display );
139  void setDisplayLogY( bool display );
140  void clearFit();
141  void clearAll();
142 
143  //Saving the Histogram
144  void toAscii( const QString& filePath );
145  void toPing( const QString& filtPath, int width, int height );
146 
147  //The channel has changed value.
148  void channelRangeChanged( int minValue, int maxValue, bool allChannels, bool automatic, int specIndex=-1 );
149 
150  //Histogramming an image versus a region.
151  void imageModeSelected( bool enabled );
152  void regionModeSelected( bool enabled );
153 
154 protected:
155  virtual void resizeEvent( QResizeEvent* event );
156  virtual void keyPressEvent( QKeyEvent* event );
157  /*Overriden because we weren't getting the first "Shift" to bring
158  * up the context menu when the mouse first entered the histogram.
159  * We set the focus on this widget when the mouse enters so it will
160  * get that first "Shift" without having to do a click first.
161  */
162  virtual void enterEvent( QEvent* event );
163  virtual void mousePressEvent( QMouseEvent* event );
164 
165 
166 private slots:
167  void lineMoved( const QPoint& pt );
168  void lineSelected();
169  void clearRange();
170  void defineCurve( int id, const QColor& curveColor, bool clear=true);
171  void minMaxChanged();
172  void showContextMenu( const QPoint& pt );
173  void centerPeakSpecified();
174  void lambdaSpecified();
175  void fwhmSpecified();
176  void fitDone( const QString& msg );
177  void zoomContextFinished();
178  void zoomMenuFinished();
179  void resetGaussianFitMarker();
180  void resetPoissonFitMarker();
181 
182  void zoomNeutral();
183  //Zoom based on an intensity range specified by the user using the range controls widget
184  void zoomRange();
185  //Zoom based on an intensity range specified by the user using the zoom context menu.
186  void zoomPercentage( float minValue, float maxValue);
187  void binCountChanged( int count );
188 
189  void regionAllModeSelected( bool enabled );
190 
191 private:
192  BinPlotWidget( const BinPlotWidget& );
194  void initializeFitWidget( bool fitControls );
195  void initializeDisplayActions();
196  void initializeZoomControls( bool rangeControls );
197  void initializePlotModeControls( bool enable );
198  void initializeGaussianFitMarker();
199  void initializePoissonFitMarker();
200  void initializeRangeControls( bool rangeControls);
201  void connectZoomActions( ZoomWidget* zoomWidget );
202  void clearGaussianFitMarker();
203  void clearPoissonFitMarker();
204  void clearHistograms();
205  void clearCurves();
206  void makeHistogram( int id, const QColor& histogramColor, bool clearCurve=true);
207  void rectangleSizeChanged();
208  void resetAxisTitles();
209  void resetPlotTitle();
210  void reset();
211  bool resetImage( bool waitOnHistogram = false );
212  void resetRegion();
213  void resetRectangleMarker();
214  void defineCurveLine( int id, const QColor& lineColor );
215  void defineCurveHistogram( int id, const QColor& histogramColor );
216  QwtPlotCurve* addCurve( QVector<double>& xValues, QVector<double>& yValues, const QColor& curveColor );
217  bool isPrintOut( int id ) const;
218  bool isPrincipalHistogram( int id ) const;
219  bool isPlotContains( int x, int y );
220  virtual int getCanvasHeight();
221  Histogram* findHistogramFor( int id );
222  int getSelectedId() const;
223  QColor getPieceColor( int index, const QColor& defaultColor ) const;
224 
225  void zoom( float percent );
226  void zoomRangeMarker( double startValue, double endValue );
227  Ui::BinPlotWidgetClass ui;
228 
229  enum ContextMenuMode{ ZOOM_CONTEXT,DISPLAY_CONTEXT,FIT_CONTEXT };
231 
239 
240  QColor curveColor;
244  QList<QColor> multipleHistogramColors;
245  QwtLinearColorMap* colorMap;
248 
249  //Histogram & data
250  QList<QwtPlotCurve*> curves;
251  QMap<int,Histogram*> histogramMap;
252  std::shared_ptr<const casacore::ImageInterface<float> > image;
253  QwtPlot binPlot;
254  const QString NO_DATA;
255  const QString NO_DATA_MESSAGE;
256  const int IMAGE_ID;
258 
259  //Specifying a range with the histogram
260  QwtPlotPicker* dragLine;
265 
266  QWidgetAction* zoomActionContext;
268  QWidgetAction* zoomActionMenu;
270  double rectX;
271  double rectWidth;
272 
273  //Fitting the histogram
274  QAction lambdaAction;
276  QAction fwhmAction;
277  QMenu contextMenu;
279  QwtPlotCurve* fitCurve;
280  QPoint fitPosition;
283 
284  //Plot Display
285  const QString LOG_COUNT;
289  QAction logActionY;
290  QAction clearAction;
291  enum HistogramOptions{HISTOGRAM_FILLED,HISTOGRAM_OUTLINE,HISTOGRAM_LINE};
294 
295  //Plot Control
296  //We should be able to use just one binCountAction and binCountWidget
297  //However, to appear, the constructor has to take the appropriate
298  //menu as a parent.
299  QWidgetAction* binCountActionContext;
301  QWidgetAction* footPrintActionContext;
302 
303  QWidgetAction* binCountActionMenu;
304  QWidgetAction* channelRangeActionMenu;
305  QWidgetAction* footPrintActionMenu;
306 
310 
316 };
317 
318 }
319 
320 #endif // THRESHOLDINGBINPLOTWIDGET_H
QList< QColor > multipleHistogramColors
RangeControlsWidget * rangeControlWidget
std::vector< double > Vector
Definition: ds9context.h:24
HistogramMarkerGaussian * fitEstimateMarkerGaussian
QWidgetAction * zoomActionContext
virtual void reset()
Overrides PlotTool::reset().
QwtPlotPicker * dragLine
Specifying a range with the histogram.
#define max(a, b)
Definition: hio.h:44
Ui::BinPlotWidgetClass ui
RangePicker * rectMarker
Generates and Manages the data corresponding to a histogram.
Definition: Histogram.h:51
QList< QwtPlotCurve * > curves
Histogram &amp; data.
PtrHolder< T > & operator=(const PtrHolder< T > &other)
QWidgetAction * footPrintActionContext
size_t size() const
void rangeChanged()
Slot for when the set range changes.
Marks initial (center,peak) and FWHM Gaussian estimates on the histogram.
QMap< int, Histogram * > histogramMap
ChannelRangeWidget * channelRangeWidgetContext
Main class for handling the pluggable fit functionality for the histogram.
Definition: FitWidget.qo.h:44
QWidgetAction * footPrintActionMenu
BinCountWidget * binCountWidgetMenu
ZoomWidget * zoomWidgetContext
Display a histogram of intensity vs count.
casacore::Vector< casacore::uInt > colorLookups
QWidgetAction * binCountActionMenu
QWidgetAction * zoomActionMenu
ChannelRangeWidget * channelRangeWidgetMenu
QWidgetAction * channelRangeActionMenu
ToolTipPicker * toolTipPicker
FootPrintWidget * footPrintWidgetMenu
Marks a lambda estimate on the graph.
Class to hold a region of interest in an image.
Definition: ImageRegion.h:86
Handles drawing the range selection rectangle for the bin plot.
Definition: RangePicker.h:40
QWidgetAction * channelRangeActionContext
QAction lambdaAction
Fitting the histogram.
std::shared_ptr< const casacore::ImageInterface< float > > image
QwtLinearColorMap * colorMap
const QString LOG_COUNT
Plot Display.
HistogramMarkerPoisson * fitEstimateMarkerPoisson
FootPrintWidget::PlotMode plotMode
QwtPlotCurve * fitCurve
Pluggable functionality that allows users to specify a range on the histogram.
QWidgetAction * binCountActionContext
Plot Control We should be able to use just one binCountAction and binCountWidget However, to appear, the constructor has to take the appropriate menu as a parent.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the color(i.e.,"000000"for black) and
const QString NO_DATA_MESSAGE
ZoomWidget * zoomWidgetMenu
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
FootPrintWidget * footPrintWidgetContext
BinCountWidget * binCountWidgetContext
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
ContextMenuMode contextMenuMode