KWWidgets
vtkKWVolumePropertyWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWVolumePropertyWidget.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWVolumePropertyWidget - a transfer function widget
15 // .SECTION Description
16 // This class contains the UI components and methods to edit a
17 // ColorTransferFunction in concert with a PiecewiseFunction for opacity.
18 // New control points can be added by clicking with the left mouse button
19 // and they can be removed by dragging them out of the window.
20 
21 #ifndef __vtkKWVolumePropertyWidget_h
22 #define __vtkKWVolumePropertyWidget_h
23 
24 #include "vtkKWCompositeWidget.h"
25 
26 class vtkDataSet;
27 class vtkKWCheckButton;
30 class vtkKWHistogramSet;
31 class vtkKWFrame;
35 class vtkKWMenuButton;
40 class vtkVolumeProperty;
41 
43 {
44 public:
46  void PrintSelf(ostream& os, vtkIndent indent);
48 
49  // Description:
50  // Get/Set the transfer function mapping scalar value to color
51  vtkGetObjectMacro(VolumeProperty, vtkVolumeProperty);
52  virtual void SetVolumeProperty(vtkVolumeProperty*);
53 
54  // Description:
55  // The data this volume property is used for.
56  // Will be used to get the scalar range of the transfer functions for
57  // example.
58  vtkGetObjectMacro(DataSet, vtkDataSet);
59  virtual void SetDataSet(vtkDataSet*);
60 
61  // Description:
62  // Set/Get the histograms for the data this volume property is used for.
63  // Obviously those histograms must have been computed using the same
64  // data as the DataSet Ivar above.
65  vtkGetObjectMacro(HistogramSet, vtkKWHistogramSet);
66  virtual void SetHistogramSet(vtkKWHistogramSet*);
67 
68  // Description:
69  // Set/Get the current component controlled by the widget
70  virtual void SetSelectedComponent(int);
71  vtkGetMacro(SelectedComponent, int);
72 
73  // Description:
74  // Set/Get the window/level for those transfer functions that support
75  // this mode (SetInteractiveWindowLevel will trigger interactive events)
76  // IsInWindowLevelMode return true if part of this widget is in
77  // window/level mode.
78  virtual void SetWindowLevel(double window, double level);
79  virtual void SetInteractiveWindowLevel(double window, double level);
80  virtual int IsInWindowLevelMode();
81 
82  // Description:
83  // Set/Get if the widget is in "Interactive Apply" mode, i.e.
84  // changes will be propagated during most/all interactions, not just
85  // at the end of them.
86  vtkBooleanMacro(InteractiveApplyMode, int);
87  vtkSetMacro(InteractiveApplyMode, int);
88  vtkGetMacro(InteractiveApplyMode, int);
89 
90  // Description:
91  // Set/Get the 'Interactive Apply' button visibility
92  vtkBooleanMacro(InteractiveApplyButtonVisibility, int);
93  virtual void SetInteractiveApplyButtonVisibility(int);
94  vtkGetMacro(InteractiveApplyButtonVisibility, int);
95 
96  // Description:
97  // Set/Get the scalar opacity unit distance visibility
98  vtkBooleanMacro(ScalarOpacityUnitDistanceVisibility, int);
99  virtual void SetScalarOpacityUnitDistanceVisibility(int);
100  vtkGetMacro(ScalarOpacityUnitDistanceVisibility, int);
101 
102  // Description:
103  // Set/Get the HSV color selector visibility
104  vtkBooleanMacro(HSVColorSelectorVisibility, int);
105  virtual void SetHSVColorSelectorVisibility(int);
106  vtkGetMacro(HSVColorSelectorVisibility, int);
107 
108  // Description:
109  // Set/Get the component selection widget visibility
110  vtkBooleanMacro(ComponentSelectionVisibility, int);
111  virtual void SetComponentSelectionVisibility(int);
112  vtkGetMacro(ComponentSelectionVisibility, int);
113 
114  // Description:
115  // Set/Get the interpolation type widget visibility
116  vtkBooleanMacro(InterpolationTypeVisibility, int);
117  virtual void SetInterpolationTypeVisibility(int);
118  vtkGetMacro(InterpolationTypeVisibility, int);
119 
120  // Description:
121  // Get the bottom frame, a frame that is always packed at the bottom of
122  // the whole widget, and can be used to add more user-defined widgets
123  vtkGetObjectMacro(BottomFrame, vtkKWFrame);
124 
125  // Description:
126  // Get the main edit frame, so that it can be collapsed manually
127  vtkGetObjectMacro(EditorFrame, vtkKWFrameWithLabel);
128 
129  // Description:
130  // Set/Get the material widget + enable shading visibility
131  vtkBooleanMacro(MaterialPropertyVisibility, int);
132  virtual void SetMaterialPropertyVisibility(int);
133  vtkGetMacro(MaterialPropertyVisibility, int);
134 
135  // Description:
136  // Set the material property button position to the top frame (default)
137  // or to the scalar opacity user frame, or color user frame.
138  //BTX
139  enum
140  {
141  MaterialPropertyPositionTop,
142  MaterialPropertyPositionBottomFrame,
143  MaterialPropertyPositionScalarOpacityUserFrame,
144  MaterialPropertyPositionScalarColorUserFrame
145  };
146  //ETX
147  virtual void SetMaterialPropertyPosition(int);
148  vtkGetMacro(MaterialPropertyPosition, int);
149  virtual void SetMaterialPropertyPositionToTop();
150  virtual void SetMaterialPropertyPositionToBottomFrame();
151  virtual void SetMaterialPropertyPositionToScalarOpacityUserFrame();
152  virtual void SetMaterialPropertyPositionToScalarColorUserFrame();
153 
154  // Description:
155  // Set/Get the gradient opacity function visibility
156  vtkBooleanMacro(GradientOpacityFunctionVisibility, int);
157  virtual void SetGradientOpacityFunctionVisibility(int);
158  vtkGetMacro(GradientOpacityFunctionVisibility, int);
159 
160  // Description:
161  // Set/Get the component weight visibility
162  vtkBooleanMacro(ComponentWeightsVisibility, int);
163  virtual void SetComponentWeightsVisibility(int);
164  vtkGetMacro(ComponentWeightsVisibility, int);
165 
166  // Description:
167  // If true, an "Enable Shading" checkbox will be displayed and will
168  // control the shading flag of all components at once
169  // (based on the first one). If false, the shading flag will be available
170  // on a per-component basis in the shading dialog.
171  vtkBooleanMacro(EnableShadingForAllComponents, int);
172  virtual void SetEnableShadingForAllComponents(int);
173  vtkGetMacro(EnableShadingForAllComponents, int);
174 
175  // Description:
176  // Update the whole UI depending on the value of the Ivars
177  virtual void Update();
178 
179  // Description:
180  // Set/Get if the scalar color transfer function should be used to color
181  // each point in the scalar opacity editor. This also makes sure that
182  // any changes made to one or the other will be propagated accordingly.
183  // This also enables the user to pick a color by double-clicking on
184  // the scalar opacity points.
185  vtkBooleanMacro(UseScalarColorFunctionInScalarOpacityEditor, int);
186  virtual void SetUseScalarColorFunctionInScalarOpacityEditor(int);
187  vtkGetMacro(UseScalarColorFunctionInScalarOpacityEditor, int);
188 
189  // Description:
190  // Merge both scalar opacity and color editors.
191  // This will put both editors in synchronized/locked mode, the scalar
192  // color function in the editor will be hidden (only the color ramp will
193  // remain), and the opacity editor will use the scalar color function
194  // to color its points. Double clicking on a point will popup a color
195  // selector.
196  virtual void MergeScalarOpacityAndColorEditors();
197 
198  // Description:
199  // Specifies commands to associate with the widget.
200  // 'VolumePropertyChangedCommand' is invoked when the volume property has
201  // changed (i.e. at the end of the user interaction), whereas
202  // 'VolumePropertyChangingCommand' is invoked when the volume property is
203  // changing (i.e. during the user interaction itself).
204  // The need for a '...ChangedCommand' and '...ChangingCommand' can be
205  // explained as follows: the former can be used to be notified about any
206  // changes made to this widget *after* the corresponding user interaction has
207  // been performed (say, after releasing the mouse button that was dragging
208  // a slider, or after clicking on a checkbutton). The later can be set
209  // *additionally* to be notified about the intermediate changes that
210  // occur *during* the corresponding user interaction (say, *while* dragging
211  // a slider). While setting '...ChangedCommand' is enough to be notified
212  // about any changes, setting '...ChangingCommand' is an application-specific
213  // choice that is likely to depend on how fast you want (or can) answer to
214  // rapid changes occuring during a user interaction, if any.
215  // The 'object' argument is the object that will have the method called on
216  // it. The 'method' argument is the name of the method to be called and any
217  // arguments in string form. If the object is NULL, the method is still
218  // evaluated as a simple command.
219  virtual void SetVolumePropertyChangedCommand(
220  vtkObject *object,const char *method);
221  virtual void SetVolumePropertyChangingCommand(
222  vtkObject *object,const char *method);
223 
224  // Description:
225  // Set/Get whether the above commands should be called or not.
226  vtkSetMacro(DisableCommands, int);
227  vtkGetMacro(DisableCommands, int);
228  vtkBooleanMacro(DisableCommands, int);
229 
230  // Description:
231  // Set the method used to compute the whole range of the various transfer
232  // function editors. If set to Data, the scalar range of the data is used.
233  // If no data is available or set to FunctionPoints, the range of the
234  // function points already in the editor is used. If set to
235  // DataAndFunctionPointsthe the largest of the two ranges mentioned
236  // previously is used.
237  //BTX
238  enum
239  {
240  WholeRangeComputationMethodData = 1,
241  WholeRangeComputationMethodFunctionPoints = 2,
242  WholeRangeComputationMethodDataAndFunctionPoints = 3
243  };
244  //ETX
245  virtual void SetWholeRangeComputationMethod(int);
246  vtkGetMacro(WholeRangeComputationMethod, int);
247  virtual void SetWholeRangeComputationMethodToData();
248  virtual void SetWholeRangeComputationMethodToFunctionPoints();
249  virtual void SetWholeRangeComputationMethodToDataAndFunctionPoints();
250 
251  // Description:
252  // Access the objects
253  vtkGetObjectMacro(ScalarOpacityFunctionEditor, vtkKWPiecewiseFunctionEditor);
254  vtkGetObjectMacro(ScalarColorFunctionEditor, vtkKWColorTransferFunctionEditor);
255  vtkGetObjectMacro(GradientOpacityFunctionEditor, vtkKWPiecewiseFunctionEditor);
256  vtkGetObjectMacro(ScalarOpacityUnitDistanceScale, vtkKWScaleWithEntry);
257  vtkGetObjectMacro(HSVColorSelector, vtkKWHSVColorSelector);
258  vtkGetObjectMacro(MaterialPropertyWidget, vtkKWVolumeMaterialPropertyWidget);
259 
260  // Description:
261  // Pack or repack the UI
262  virtual void Pack();
263 
264  // Description:
265  // Update the "enable" state of the object and its internal parts.
266  // Depending on different Ivars (this->Enabled, the application's
267  // Limited Edition Mode, etc.), the "enable" state of the object is updated
268  // and propagated to its internal parts/subwidgets. This will, for example,
269  // enable/disable parts of the widget UI, enable/disable the visibility
270  // of 3D widgets, etc.
271  virtual void UpdateEnableState();
272 
273  // Description:
274  // Callbacks. Internal, do not use.
275  virtual void SelectedComponentCallback(int);
276  virtual void InterpolationTypeCallback(int type);
277  virtual void EnableShadingCallback(int state);
278  virtual void MaterialPropertyChangedCallback();
279  virtual void MaterialPropertyChangingCallback();
280  virtual void InteractiveApplyCallback(int state);
281  virtual void ScalarOpacityFunctionChangedCallback();
282  virtual void ScalarOpacityFunctionChangingCallback();
283  virtual void DoubleClickOnScalarOpacityPointCallback(int id);
284  virtual void WindowLevelModeCallback(int mode);
285  virtual void LockOpacityAndColorCallback(int state);
286  virtual void ScalarOpacityUnitDistanceChangedCallback(double value);
287  virtual void ScalarOpacityUnitDistanceChangingCallback(double value);
288  virtual void RGBTransferFunctionChangedCallback();
289  virtual void RGBTransferFunctionChangingCallback();
290  virtual void RGBTransferFunctionSelectionChangedCallback();
291  virtual void EnableGradientOpacityCallback(int val);
292  virtual void GradientOpacityFunctionChangedCallback();
293  virtual void GradientOpacityFunctionChangingCallback();
294  virtual void HSVColorSelectionChangedCallback(double h, double s, double v);
295  virtual void HSVColorSelectionChangingCallback(double h, double s, double v);
296  virtual void ComponentWeightChangedCallback(int index, double value);
297  virtual void ComponentWeightChangingCallback(int index, double value);
298 
299 protected:
302 
303  // Description:
304  // Create the widget.
305  virtual void CreateWidget();
306 
307  vtkVolumeProperty *VolumeProperty;
308  vtkDataSet *DataSet;
309  vtkKWHistogramSet *HistogramSet;
310 
311  int SelectedComponent;
312  int DisableCommands;
313  int EnableShadingForAllComponents;
314  int MaterialPropertyPosition;
315  int WholeRangeComputationMethod;
316  int InteractiveApplyMode;
317  int InteractiveApplyButtonVisibility;
318  int ScalarOpacityUnitDistanceVisibility;
319  int HSVColorSelectorVisibility;
320  int ComponentSelectionVisibility;
321  int InterpolationTypeVisibility;
322  int MaterialPropertyVisibility;
323  int GradientOpacityFunctionVisibility;
324  int ComponentWeightsVisibility;
325  int UseScalarColorFunctionInScalarOpacityEditor;
326 
327  // Commands
328 
329  char *VolumePropertyChangedCommand;
330  char *VolumePropertyChangingCommand;
331 
332  virtual void InvokeObjectMethodCommand(const char *command);
333  virtual void InvokeVolumePropertyChangedCommand();
334  virtual void InvokeVolumePropertyChangingCommand();
335 
336  // GUI
337 
338  vtkKWFrameWithLabel *EditorFrame;
339  vtkKWHSVColorSelector *HSVColorSelector;
340  vtkKWFrame *InnerLeftFrame;
341  vtkKWScalarComponentSelectionWidget *ComponentSelectionWidget;
342  vtkKWMenuButtonWithLabel *InterpolationTypeOptionMenu;
343  vtkKWVolumeMaterialPropertyWidget *MaterialPropertyWidget;
344  vtkKWCheckButton *EnableShadingCheckButton;
345  vtkKWCheckButton *InteractiveApplyCheckButton;
346  vtkKWPiecewiseFunctionEditor *ScalarOpacityFunctionEditor;
347  vtkKWScaleWithEntry *ScalarOpacityUnitDistanceScale;
348  vtkKWColorTransferFunctionEditor *ScalarColorFunctionEditor;
349  vtkKWCheckButton *LockOpacityAndColorCheckButton;
350  vtkKWPiecewiseFunctionEditor *GradientOpacityFunctionEditor;
351  vtkKWMenuButton *EnableGradientOpacityOptionMenu;
352  vtkKWScaleWithEntrySetWithLabel *ComponentWeightScaleSet;
353  vtkKWFrame *BottomFrame;
354 
355  int LockOpacityAndColor[VTK_MAX_VRCOMP];
356  int WindowLevelMode[VTK_MAX_VRCOMP];
357 
358  // Are the components independent of each other?
359 
360  virtual int GetIndependentComponents();
361 
362  // Update HSV selector
363 
364  virtual void UpdateHSVColorSelectorFromScalarColorFunctionEditor();
365 
366  // This methods will be overriden in subclasses so that something
367  // different than the DataSet ivar will be used to compute the
368  // corresponding items
369  virtual int GetNumberOfComponents();
370  virtual int GetDataSetScalarRange(int comp, double range[2]);
371  virtual int GetDataSetAdjustedScalarRange(int comp, double range[2]);
372  virtual const char* GetDataSetScalarName();
373  virtual int GetDataSetScalarOpacityUnitDistanceRangeAndResolution(
374  double range[2], double *resolution);
375 
376 private:
377  vtkKWVolumePropertyWidget(const vtkKWVolumePropertyWidget&); // Not implemented
378  void operator=(const vtkKWVolumePropertyWidget&); // Not implemented
379 };
380 
381 #endif