KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWVolumePropertyWidget.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkKWVolumePropertyWidget - a transfer function widget 00015 // .SECTION Description 00016 // This class contains the UI components and methods to edit a 00017 // ColorTransferFunction in concert with a PiecewiseFunction for opacity. 00018 // New control points can be added by clicking with the left mouse button 00019 // and they can be removed by dragging them out of the window. 00020 00021 #ifndef __vtkKWVolumePropertyWidget_h 00022 #define __vtkKWVolumePropertyWidget_h 00023 00024 #include "vtkKWCompositeWidget.h" 00025 00026 class vtkDataSet; 00027 class vtkKWCheckButton; 00028 class vtkKWColorTransferFunctionEditor; 00029 class vtkKWHSVColorSelector; 00030 class vtkKWHistogramSet; 00031 class vtkKWFrame; 00032 class vtkKWFrameWithLabel; 00033 class vtkKWMenuButtonWithLabel; 00034 class vtkKWScaleWithEntrySetWithLabel; 00035 class vtkKWMenuButton; 00036 class vtkKWPiecewiseFunctionEditor; 00037 class vtkKWScalarComponentSelectionWidget; 00038 class vtkKWScaleWithEntry; 00039 class vtkKWVolumeMaterialPropertyWidget; 00040 class vtkVolumeProperty; 00041 00042 class KWWidgets_EXPORT vtkKWVolumePropertyWidget : public vtkKWCompositeWidget 00043 { 00044 public: 00045 static vtkKWVolumePropertyWidget* New(); 00046 void PrintSelf(ostream& os, vtkIndent indent); 00047 vtkTypeRevisionMacro(vtkKWVolumePropertyWidget,vtkKWCompositeWidget); 00048 00049 // Description: 00050 // Get/Set the transfer function mapping scalar value to color 00051 vtkGetObjectMacro(VolumeProperty, vtkVolumeProperty); 00052 virtual void SetVolumeProperty(vtkVolumeProperty*); 00053 00054 // Description: 00055 // The data this volume property is used for. 00056 // Will be used to get the scalar range of the transfer functions for 00057 // example. 00058 vtkGetObjectMacro(DataSet, vtkDataSet); 00059 virtual void SetDataSet(vtkDataSet*); 00060 00061 // Description: 00062 // Set/Get the histograms for the data this volume property is used for. 00063 // Obviously those histograms must have been computed using the same 00064 // data as the DataSet Ivar above. 00065 vtkGetObjectMacro(HistogramSet, vtkKWHistogramSet); 00066 virtual void SetHistogramSet(vtkKWHistogramSet*); 00067 00068 // Description: 00069 // Set/Get the current component controlled by the widget 00070 virtual void SetSelectedComponent(int); 00071 vtkGetMacro(SelectedComponent, int); 00072 00073 // Description: 00074 // Set/Get the window/level for those transfer functions that support 00075 // this mode (SetInteractiveWindowLevel will trigger interactive events) 00076 // IsInWindowLevelMode return true if part of this widget is in 00077 // window/level mode. 00078 virtual void SetWindowLevel(double window, double level); 00079 virtual void SetInteractiveWindowLevel(double window, double level); 00080 virtual int IsInWindowLevelMode(); 00081 00082 // Description: 00083 // Set/Get if the widget is in "Interactive Apply" mode, i.e. 00084 // changes will be propagated during most/all interactions, not just 00085 // at the end of them. 00086 vtkBooleanMacro(InteractiveApplyMode, int); 00087 vtkSetMacro(InteractiveApplyMode, int); 00088 vtkGetMacro(InteractiveApplyMode, int); 00089 00090 // Description: 00091 // Set/Get the 'Interactive Apply' button visibility 00092 vtkBooleanMacro(InteractiveApplyButtonVisibility, int); 00093 virtual void SetInteractiveApplyButtonVisibility(int); 00094 vtkGetMacro(InteractiveApplyButtonVisibility, int); 00095 00096 // Description: 00097 // Set/Get the scalar opacity unit distance visibility 00098 vtkBooleanMacro(ScalarOpacityUnitDistanceVisibility, int); 00099 virtual void SetScalarOpacityUnitDistanceVisibility(int); 00100 vtkGetMacro(ScalarOpacityUnitDistanceVisibility, int); 00101 00102 // Description: 00103 // Set/Get the HSV color selector visibility 00104 vtkBooleanMacro(HSVColorSelectorVisibility, int); 00105 virtual void SetHSVColorSelectorVisibility(int); 00106 vtkGetMacro(HSVColorSelectorVisibility, int); 00107 00108 // Description: 00109 // Set/Get the component selection widget visibility 00110 vtkBooleanMacro(ComponentSelectionVisibility, int); 00111 virtual void SetComponentSelectionVisibility(int); 00112 vtkGetMacro(ComponentSelectionVisibility, int); 00113 00114 // Description: 00115 // Set/Get the interpolation type widget visibility 00116 vtkBooleanMacro(InterpolationTypeVisibility, int); 00117 virtual void SetInterpolationTypeVisibility(int); 00118 vtkGetMacro(InterpolationTypeVisibility, int); 00119 00120 // Description: 00121 // Get the bottom frame, a frame that is always packed at the bottom of 00122 // the whole widget, and can be used to add more user-defined widgets 00123 vtkGetObjectMacro(BottomFrame, vtkKWFrame); 00124 00125 // Description: 00126 // Get the main edit frame, so that it can be collapsed manually 00127 vtkGetObjectMacro(EditorFrame, vtkKWFrameWithLabel); 00128 00129 // Description: 00130 // Set/Get the material widget + enable shading visibility 00131 vtkBooleanMacro(MaterialPropertyVisibility, int); 00132 virtual void SetMaterialPropertyVisibility(int); 00133 vtkGetMacro(MaterialPropertyVisibility, int); 00134 00135 // Description: 00136 // Set the material property button position to the top frame (default) 00137 // or to the scalar opacity user frame, or color user frame. 00138 //BTX 00139 enum 00140 { 00141 MaterialPropertyPositionTop, 00142 MaterialPropertyPositionBottomFrame, 00143 MaterialPropertyPositionScalarOpacityUserFrame, 00144 MaterialPropertyPositionScalarColorUserFrame 00145 }; 00146 //ETX 00147 virtual void SetMaterialPropertyPosition(int); 00148 vtkGetMacro(MaterialPropertyPosition, int); 00149 virtual void SetMaterialPropertyPositionToTop(); 00150 virtual void SetMaterialPropertyPositionToBottomFrame(); 00151 virtual void SetMaterialPropertyPositionToScalarOpacityUserFrame(); 00152 virtual void SetMaterialPropertyPositionToScalarColorUserFrame(); 00153 00154 // Description: 00155 // Set/Get the gradient opacity function visibility 00156 vtkBooleanMacro(GradientOpacityFunctionVisibility, int); 00157 virtual void SetGradientOpacityFunctionVisibility(int); 00158 vtkGetMacro(GradientOpacityFunctionVisibility, int); 00159 00160 // Description: 00161 // Set/Get the component weight visibility 00162 vtkBooleanMacro(ComponentWeightsVisibility, int); 00163 virtual void SetComponentWeightsVisibility(int); 00164 vtkGetMacro(ComponentWeightsVisibility, int); 00165 00166 // Description: 00167 // If true, an "Enable Shading" checkbox will be displayed and will 00168 // control the shading flag of all components at once 00169 // (based on the first one). If false, the shading flag will be available 00170 // on a per-component basis in the shading dialog. 00171 vtkBooleanMacro(EnableShadingForAllComponents, int); 00172 virtual void SetEnableShadingForAllComponents(int); 00173 vtkGetMacro(EnableShadingForAllComponents, int); 00174 00175 // Description: 00176 // Update the whole UI depending on the value of the Ivars 00177 virtual void Update(); 00178 00179 // Description: 00180 // Set/Get if the scalar color transfer function should be used to color 00181 // each point in the scalar opacity editor. This also makes sure that 00182 // any changes made to one or the other will be propagated accordingly. 00183 // This also enables the user to pick a color by double-clicking on 00184 // the scalar opacity points. 00185 vtkBooleanMacro(UseScalarColorFunctionInScalarOpacityEditor, int); 00186 virtual void SetUseScalarColorFunctionInScalarOpacityEditor(int); 00187 vtkGetMacro(UseScalarColorFunctionInScalarOpacityEditor, int); 00188 00189 // Description: 00190 // Merge both scalar opacity and color editors. 00191 // This will put both editors in synchronized/locked mode, the scalar 00192 // color function in the editor will be hidden (only the color ramp will 00193 // remain), and the opacity editor will use the scalar color function 00194 // to color its points. Double clicking on a point will popup a color 00195 // selector. 00196 virtual void MergeScalarOpacityAndColorEditors(); 00197 00198 // Description: 00199 // Specifies commands to associate with the widget. 00200 // 'VolumePropertyChangedCommand' is invoked when the volume property has 00201 // changed (i.e. at the end of the user interaction), whereas 00202 // 'VolumePropertyChangingCommand' is invoked when the volume property is 00203 // changing (i.e. during the user interaction itself). 00204 // The need for a '...ChangedCommand' and '...ChangingCommand' can be 00205 // explained as follows: the former can be used to be notified about any 00206 // changes made to this widget *after* the corresponding user interaction has 00207 // been performed (say, after releasing the mouse button that was dragging 00208 // a slider, or after clicking on a checkbutton). The later can be set 00209 // *additionally* to be notified about the intermediate changes that 00210 // occur *during* the corresponding user interaction (say, *while* dragging 00211 // a slider). While setting '...ChangedCommand' is enough to be notified 00212 // about any changes, setting '...ChangingCommand' is an application-specific 00213 // choice that is likely to depend on how fast you want (or can) answer to 00214 // rapid changes occuring during a user interaction, if any. 00215 // The 'object' argument is the object that will have the method called on 00216 // it. The 'method' argument is the name of the method to be called and any 00217 // arguments in string form. If the object is NULL, the method is still 00218 // evaluated as a simple command. 00219 virtual void SetVolumePropertyChangedCommand( 00220 vtkObject *object,const char *method); 00221 virtual void SetVolumePropertyChangingCommand( 00222 vtkObject *object,const char *method); 00223 00224 // Description: 00225 // Set/Get whether the above commands should be called or not. 00226 vtkSetMacro(DisableCommands, int); 00227 vtkGetMacro(DisableCommands, int); 00228 vtkBooleanMacro(DisableCommands, int); 00229 00230 // Description: 00231 // Set the method used to compute the whole range of the various transfer 00232 // function editors. If set to Data, the scalar range of the data is used. 00233 // If no data is available or set to FunctionPoints, the range of the 00234 // function points already in the editor is used. If set to 00235 // DataAndFunctionPointsthe the largest of the two ranges mentioned 00236 // previously is used. 00237 //BTX 00238 enum 00239 { 00240 WholeRangeComputationMethodData = 1, 00241 WholeRangeComputationMethodFunctionPoints = 2, 00242 WholeRangeComputationMethodDataAndFunctionPoints = 3 00243 }; 00244 //ETX 00245 virtual void SetWholeRangeComputationMethod(int); 00246 vtkGetMacro(WholeRangeComputationMethod, int); 00247 virtual void SetWholeRangeComputationMethodToData(); 00248 virtual void SetWholeRangeComputationMethodToFunctionPoints(); 00249 virtual void SetWholeRangeComputationMethodToDataAndFunctionPoints(); 00250 00251 // Description: 00252 // Access the objects 00253 vtkGetObjectMacro(ScalarOpacityFunctionEditor, vtkKWPiecewiseFunctionEditor); 00254 vtkGetObjectMacro(ScalarColorFunctionEditor, vtkKWColorTransferFunctionEditor); 00255 vtkGetObjectMacro(GradientOpacityFunctionEditor, vtkKWPiecewiseFunctionEditor); 00256 vtkGetObjectMacro(ScalarOpacityUnitDistanceScale, vtkKWScaleWithEntry); 00257 vtkGetObjectMacro(HSVColorSelector, vtkKWHSVColorSelector); 00258 vtkGetObjectMacro(MaterialPropertyWidget, vtkKWVolumeMaterialPropertyWidget); 00259 00260 // Description: 00261 // Pack or repack the UI 00262 virtual void Pack(); 00263 00264 // Description: 00265 // Update the "enable" state of the object and its internal parts. 00266 // Depending on different Ivars (this->Enabled, the application's 00267 // Limited Edition Mode, etc.), the "enable" state of the object is updated 00268 // and propagated to its internal parts/subwidgets. This will, for example, 00269 // enable/disable parts of the widget UI, enable/disable the visibility 00270 // of 3D widgets, etc. 00271 virtual void UpdateEnableState(); 00272 00273 // Description: 00274 // Callbacks. Internal, do not use. 00275 virtual void SelectedComponentCallback(int); 00276 virtual void InterpolationTypeCallback(int type); 00277 virtual void EnableShadingCallback(int state); 00278 virtual void MaterialPropertyChangedCallback(); 00279 virtual void MaterialPropertyChangingCallback(); 00280 virtual void InteractiveApplyCallback(int state); 00281 virtual void ScalarOpacityFunctionChangedCallback(); 00282 virtual void ScalarOpacityFunctionChangingCallback(); 00283 virtual void DoubleClickOnScalarOpacityPointCallback(int id); 00284 virtual void WindowLevelModeCallback(int mode); 00285 virtual void LockOpacityAndColorCallback(int state); 00286 virtual void ScalarOpacityUnitDistanceChangedCallback(double value); 00287 virtual void ScalarOpacityUnitDistanceChangingCallback(double value); 00288 virtual void RGBTransferFunctionChangedCallback(); 00289 virtual void RGBTransferFunctionChangingCallback(); 00290 virtual void RGBTransferFunctionSelectionChangedCallback(); 00291 virtual void EnableGradientOpacityCallback(int val); 00292 virtual void GradientOpacityFunctionChangedCallback(); 00293 virtual void GradientOpacityFunctionChangingCallback(); 00294 virtual void HSVColorSelectionChangedCallback(double h, double s, double v); 00295 virtual void HSVColorSelectionChangingCallback(double h, double s, double v); 00296 virtual void ComponentWeightChangedCallback(int index, double value); 00297 virtual void ComponentWeightChangingCallback(int index, double value); 00298 00299 protected: 00300 vtkKWVolumePropertyWidget(); 00301 ~vtkKWVolumePropertyWidget(); 00302 00303 // Description: 00304 // Create the widget. 00305 virtual void CreateWidget(); 00306 00307 vtkVolumeProperty *VolumeProperty; 00308 vtkDataSet *DataSet; 00309 vtkKWHistogramSet *HistogramSet; 00310 00311 int SelectedComponent; 00312 int DisableCommands; 00313 int EnableShadingForAllComponents; 00314 int MaterialPropertyPosition; 00315 int WholeRangeComputationMethod; 00316 int InteractiveApplyMode; 00317 int InteractiveApplyButtonVisibility; 00318 int ScalarOpacityUnitDistanceVisibility; 00319 int HSVColorSelectorVisibility; 00320 int ComponentSelectionVisibility; 00321 int InterpolationTypeVisibility; 00322 int MaterialPropertyVisibility; 00323 int GradientOpacityFunctionVisibility; 00324 int ComponentWeightsVisibility; 00325 int UseScalarColorFunctionInScalarOpacityEditor; 00326 00327 // Commands 00328 00329 char *VolumePropertyChangedCommand; 00330 char *VolumePropertyChangingCommand; 00331 00332 virtual void InvokeObjectMethodCommand(const char *command); 00333 virtual void InvokeVolumePropertyChangedCommand(); 00334 virtual void InvokeVolumePropertyChangingCommand(); 00335 00336 // GUI 00337 00338 vtkKWFrameWithLabel *EditorFrame; 00339 vtkKWHSVColorSelector *HSVColorSelector; 00340 vtkKWFrame *InnerLeftFrame; 00341 vtkKWScalarComponentSelectionWidget *ComponentSelectionWidget; 00342 vtkKWMenuButtonWithLabel *InterpolationTypeOptionMenu; 00343 vtkKWVolumeMaterialPropertyWidget *MaterialPropertyWidget; 00344 vtkKWCheckButton *EnableShadingCheckButton; 00345 vtkKWCheckButton *InteractiveApplyCheckButton; 00346 vtkKWPiecewiseFunctionEditor *ScalarOpacityFunctionEditor; 00347 vtkKWScaleWithEntry *ScalarOpacityUnitDistanceScale; 00348 vtkKWColorTransferFunctionEditor *ScalarColorFunctionEditor; 00349 vtkKWCheckButton *LockOpacityAndColorCheckButton; 00350 vtkKWPiecewiseFunctionEditor *GradientOpacityFunctionEditor; 00351 vtkKWMenuButton *EnableGradientOpacityOptionMenu; 00352 vtkKWScaleWithEntrySetWithLabel *ComponentWeightScaleSet; 00353 vtkKWFrame *BottomFrame; 00354 00355 int LockOpacityAndColor[VTK_MAX_VRCOMP]; 00356 int WindowLevelMode[VTK_MAX_VRCOMP]; 00357 00358 // Are the components independent of each other? 00359 00360 virtual int GetIndependentComponents(); 00361 00362 // Update HSV selector 00363 00364 virtual void UpdateHSVColorSelectorFromScalarColorFunctionEditor(); 00365 00366 // This methods will be overriden in subclasses so that something 00367 // different than the DataSet ivar will be used to compute the 00368 // corresponding items 00369 virtual int GetNumberOfComponents(); 00370 virtual int GetDataSetScalarRange(int comp, double range[2]); 00371 virtual int GetDataSetAdjustedScalarRange(int comp, double range[2]); 00372 virtual const char* GetDataSetScalarName(); 00373 virtual int GetDataSetScalarOpacityUnitDistanceRangeAndResolution( 00374 double range[2], double *resolution); 00375 00376 private: 00377 vtkKWVolumePropertyWidget(const vtkKWVolumePropertyWidget&); // Not implemented 00378 void operator=(const vtkKWVolumePropertyWidget&); // Not implemented 00379 }; 00380 00381 #endif