SMILX  1.01
milxQtPlot.h
1 /*=========================================================================
2  The Software is copyright (c) Commonwealth Scientific and Industrial Research Organisation (CSIRO)
3  ABN 41 687 119 230.
4  All rights reserved.
5 
6  Licensed under the CSIRO BSD 3-Clause License
7  You may not use this file except in compliance with the License.
8  You may obtain a copy of the License in the file LICENSE.md or at
9 
10  https://stash.csiro.au/projects/SMILI/repos/smili/browse/license.txt
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 =========================================================================*/
18 #ifndef MILXQTPLOT_H
19 #define MILXQTPLOT_H
20 
21 //VTK
22 #include <vtkChartXY.h>
23 #include <vtkSmartVolumeMapper.h>
24 #include <vtkVolume.h>
25 
26 #include "milxQtModel.h"
27 
67 {
68  Q_OBJECT
69 
70 public:
75  milxQtPlot(QWidget *theParent = 0, bool contextSystem = true);
80  virtual ~milxQtPlot();
81 
82  void setPlotType2D(const int indexX = 0, const int indexY = 1)
83  {
84  plotType2D = true;
85  plotType3D = false;
86  plotTypeSurface = false;
87  plotTypeVolume = false;
88  xIndex = indexX;
89  yIndex = indexY;
90  }
91  void setPlotType3D(const int indexX = 0, const int indexY = 1, const int indexZ = 2)
92  {
93  plotType2D = false;
94  plotType3D = true;
95  plotTypeSurface = false;
96  plotTypeVolume = false;
97  xIndex = indexX;
98  yIndex = indexY;
99  zIndex = indexZ;
100  }
101  inline void setPlotTypeSurface(const int zAxis = 2)
102  {
103  plotTypeSurface = true;
104  plotTypeVolume = false;
105  plotType2D = false;
106  plotType3D = false;
107  displaceAxis = zAxis;
108  }
109  inline void setPlotTypeVolume()
110  {
111  plotTypeVolume = true;
112  plotTypeSurface = false;
113  plotType2D = false;
114  plotType3D = false;
115  }
116 
121  void SetSource(vtkSmartPointer<vtkImageData> img, const bool eightbit, const bool useGPU = false)
122  {
123  imageData = vtkSmartPointer<vtkImageData>::New();
124  imageData->DeepCopy(img);
125  sourceLoaded = true;
126  sourceEightbit = eightbit;
127  plotTypeGPU = useGPU;
128  }
133  void SetSource(vtkSmartPointer<vtkTable> tbl)
134  {
135  table->DeepCopy(tbl);
136  printDebug("Source Table is " + QString::number(table->GetNumberOfRows()) + "x" + QString::number(table->GetNumberOfColumns()));
137  sourceLoaded = true;
138  }
143  inline vtkSmartPointer<vtkTable> GetSource()
144  {
145  return table;
146  }
151  inline vtkSmartPointer<vtkImageData> GetSourceImage()
152  {
153  return imageData;
154  }
158  inline virtual vtkDataSet* GetDataSet()
159  {
160  if(plotTypeSurface)
161  return model.Result();
162 
163  return imageData;
164  }
165 
166  inline void setOpacityTransferValues(std::vector<float> values)
167  {
168  opacityTransferValues = values;
169  }
170  inline std::vector<float> getOpacityTransferValues()
171  {
172  return opacityTransferValues;
173  }
174  inline void setColourTransferValues(std::vector<float> values)
175  {
176  colourTransferValues = values;
177  }
178  inline std::vector<float> getColourTransferValues()
179  {
180  return colourTransferValues;
181  }
182 
183 public slots:
188  inline void refresh()
189  {
191  }
196  virtual void createMenu(QMenu *menu);
197 
202  void generatePlot();
203 
208  void scatterPlot(vtkSmartPointer<vtkTable> table, const int xColumn, const int yColumn);
213  void scatterPlot(vtkSmartPointer<vtkTable> table, const int xColumn, const int yColumn, const int zColumn);
220  void surfacePlot(vtkSmartPointer<vtkImageData> img, const int zDirection = 2);
225  void surfacePlot(vtkSmartPointer<vtkTable> table);
232  void volumePlot(vtkSmartPointer<vtkImageData> img, const bool eightbit, const bool quiet = false);
233 
238  void renameAxes(QString xLabel = "", QString yLabel = "", QString zLabel = "");
243  void renameTitle(QString newTitle = "");
248  void points(const bool showIt = true);
253  void logScale(const bool showIt = true);
258  void legend(const bool showIt = true);
263  void enableScale(QString title = "");
268  void scaleDisplay();
273  virtual void updateCoords(vtkObject *obj);
278  virtual void updateLookupTable();
283  virtual void updateVolumePlot(int value);
284 
285 signals:
286 
287 protected:
290  bool plotType2D;
291  bool plotType3D;
294  bool plotTypeGPU;
295  bool plotted;
296  int xIndex;
297  int yIndex;
298  int zIndex;
300 
301  vtkSmartPointer<vtkTable> table;
302  vtkSmartPointer<vtkImageData> imageData;
303  vtkSmartPointer<vtkChartXY> templateChart;
304  vtkSmartPointer<vtkVolume> volume;
305  vtkSmartPointer<vtkSmartVolumeMapper> volumeFixedMapper;
306 
307  //------------------
308  //Context Menu
309  QAction* xAxisName;
310  QAction* titleName;
311  QAction* pointsAct;
312  QAction* logScaleAct;
313  QAction* legendAct;
314 
315  std::vector<float> opacityTransferValues;
316  std::vector<float> colourTransferValues;
317 
322  void createActions();
327  void createConnections();
332  void contextMenuEvent(QContextMenuEvent *event);
333 
334 private:
335  size_t tickNumber;
336  float slideInterval;
337 
338  QSlider *lowSldr;
339  QSlider *highSldr;
340 };
341 
342 #endif // MILXQTPLOT_H
bool logScale
Using custom scalar bar?
std::vector< float > opacityTransferValues
values for volume rendering opacity transfer function
Definition: milxQtPlot.h:315
virtual void createMenu(QMenu *menu)
Create the menu for the data in this object. Used for context menu and file menus.
void contextMenuEvent(QContextMenuEvent *event)
The context menu setup member.
bool plotTypeGPU
Use GPU whenever possible?
Definition: milxQtPlot.h:294
vtkSmartPointer< vtkTable > GetSource()
Returns the current table source for plot held.
Definition: milxQtPlot.h:143
void createActions()
Create the actions for context menu etc.
QAction * titleName
Action for title name.
Definition: milxQtPlot.h:310
bool plotType2D
2D plot type?
Definition: milxQtPlot.h:290
void createConnections()
Create the connections for context menu etc.
vtkSmartPointer< vtkSmartVolumeMapper > volumeFixedMapper
Maintains volume rendering when needed.
Definition: milxQtPlot.h:305
void printDebug(QString msg)
Debug message wrapper for console.
This class represents the MILX Qt Model/Mesh Display object using VTK.
Definition: milxQtModel.h:115
std::vector< float > colourTransferValues
values for volume rendering colour transfer function
Definition: milxQtPlot.h:316
virtual void scaleDisplay(const bool forceDisplay=false)
Toggles the scale bar display.
bool plotType3D
3D plot type?
Definition: milxQtPlot.h:291
bool sourceEightbit
Table/data loaded is eightbit?
Definition: milxQtPlot.h:289
virtual void enableScale(QString title="", const bool quiet=false, double minRange=0.0, double maxRange=0.0, int noOfLabels=3)
Enable scale bar display with the title provided.
#define MILXQT_EXPORT
Define Windows DLL importing.
Definition: milxQtAliases.h:80
vtkSmartPointer< vtkChartXY > templateChart
chart (used only for xy scatter plot)
Definition: milxQtPlot.h:303
The class provides 1D/2D and 3D plotting capability. This includes scatter and surface plots...
Definition: milxQtPlot.h:66
void SetSource(vtkSmartPointer< vtkTable > tbl)
Assigns the table provided to the class, preparing for plot. Call generatePlot() and then show() to d...
Definition: milxQtPlot.h:133
QAction * legendAct
Action for showing legend.
Definition: milxQtPlot.h:313
vtkSmartPointer< vtkTable > table
data presented as a table
Definition: milxQtPlot.h:301
QAction * logScaleAct
Action for showing a log scale.
Definition: milxQtPlot.h:312
virtual void updateCoords(vtkObject *obj)
Picks the coordinates and pixel value from the current mouse position in the window.
virtual void updateLookupTable()
Sets the necessary LUTs to model view.
bool plotted
plot done?
Definition: milxQtPlot.h:295
int xIndex
x axis index of table
Definition: milxQtPlot.h:296
int displaceAxis
warp axis for surface plots
Definition: milxQtPlot.h:299
int yIndex
y axis index of table
Definition: milxQtPlot.h:297
vtkSmartPointer< vtkImageData > imageData
data presented as a image
Definition: milxQtPlot.h:302
bool sourceLoaded
Table/data loaded in class?
Definition: milxQtPlot.h:288
QAction * xAxisName
Action for x-axis name.
Definition: milxQtPlot.h:309
int zIndex
z axis index of table
Definition: milxQtPlot.h:298
QAction * pointsAct
Action for showing line points.
Definition: milxQtPlot.h:311
void SetSource(vtkSmartPointer< vtkImageData > img, const bool eightbit, const bool useGPU=false)
Assigns the image provided to the class, preparing for plot. Call generatePlot() and then show() to d...
Definition: milxQtPlot.h:121
void refresh()
Refresh the display of the model including widgets. Camera remains as is.
bool plotTypeVolume
2D plot type?
Definition: milxQtPlot.h:293
bool plotTypeSurface
2D plot type?
Definition: milxQtPlot.h:292
void refresh()
Refresh the display of the window.
Definition: milxQtPlot.h:188
vtkSmartPointer< vtkImageData > GetSourceImage()
Returns the current image source for plot held.
Definition: milxQtPlot.h:151
virtual vtkDataSet * GetDataSet()
Get the underlying data, return the vtkImageData object if volume plot else polydata, useful for getting scalar range etc.
Definition: milxQtPlot.h:158