KWWidgets
vtkKWColorTransferFunctionEditor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWColorTransferFunctionEditor.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 vtkKWColorTransferFunctionEditor - a color tfunc function editor
15 // .SECTION Description
16 // A widget that allows the user to edit a color transfer function. Note that
17 // as a subclass of vtkKWParameterValueFunctionEditor, since the 'value' range
18 // is multi-dimensional (r, g, b), this widget only allows the 'parameter'
19 // of a function point to be changed (i.e., a point can only be moved
20 // horizontally).
21 // .SECTION Thanks
22 // This work is part of the National Alliance for Medical Image
23 // Computing (NAMIC), funded by the National Institutes of Health
24 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
25 // Information on the National Centers for Biomedical Computing
26 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
27 
28 #ifndef __vtkKWColorTransferFunctionEditor_h
29 #define __vtkKWColorTransferFunctionEditor_h
30 
32 
33 class vtkColorTransferFunction;
35 class vtkKWMenuButton;
36 
38 {
39 public:
42  void PrintSelf(ostream& os, vtkIndent indent);
43 
44  // Description:
45  // Get/Set the function
46  // Note that the whole parameter range is automatically reset to the
47  // function range.
48  vtkGetObjectMacro(ColorTransferFunction, vtkColorTransferFunction);
49  virtual void SetColorTransferFunction(vtkColorTransferFunction*);
50 
51  // Description:
52  // Set/Get a point color. Those methodes do not trigger any commands/events.
53  // Return 1 on success, 0 otherwise (if point does not exist for example)
54  virtual int GetPointColorAsRGB(int id, double rgb[3]);
55  virtual int GetPointColorAsHSV(int id, double hsv[3]);
56  virtual int SetPointColorAsRGB(int id, const double rgb[3]);
57  virtual int SetPointColorAsRGB(int id, double r, double g, double b);
58  virtual int SetPointColorAsHSV(int id, const double hsv[3]);
59  virtual int SetPointColorAsHSV(int id, double h, double s, double v);
60 
61  // Description:
62  // Set/Get the color ramp visibility.
63  vtkBooleanMacro(ColorRampVisibility, int);
64  virtual void SetColorRampVisibility(int);
65  vtkGetMacro(ColorRampVisibility, int);
66 
67  // Description:
68  // Get/Set a specific function to display in the color ramp. If not
69  // specified, the ColorTransferFunction will be used.
70  vtkGetObjectMacro(ColorRampTransferFunction, vtkColorTransferFunction);
71  virtual void SetColorRampTransferFunction(vtkColorTransferFunction*);
72 
73  // Description:
74  // Set/Get the color ramp height (in pixels).
75  virtual void SetColorRampHeight(int);
76  vtkGetMacro(ColorRampHeight, int);
77 
78  // Description:
79  // Display the color ramp at the default position (under the canvas), or
80  // in the canvas itself.
81  // The ColorRampVisibility parameter still has to be On for the ramp to be
82  // displayed.
83  //BTX
84  enum
85  {
86  ColorRampPositionDefault = 10,
87  ColorRampPositionCanvas
88  };
89  //ETX
90  virtual void SetColorRampPosition(int);
91  vtkGetMacro(ColorRampPosition, int);
92  virtual void SetColorRampPositionToDefault()
93  { this->SetColorRampPosition(
95  virtual void SetColorRampPositionToCanvas()
96  { this->SetColorRampPosition(
98 
99  // Description:
100  // Set/Get the color ramp outline style.
101  //BTX
102  enum
103  {
104  ColorRampOutlineStyleNone = 0,
105  ColorRampOutlineStyleSolid,
106  ColorRampOutlineStyleSunken
107  };
108  //ETX
109  virtual void SetColorRampOutlineStyle(int);
110  vtkGetMacro(ColorRampOutlineStyle, int);
111  virtual void SetColorRampOutlineStyleToNone()
112  { this->SetColorRampOutlineStyle(
114  virtual void SetColorRampOutlineStyleToSolid()
115  { this->SetColorRampOutlineStyle(
117  virtual void SetColorRampOutlineStyleToSunken()
118  { this->SetColorRampOutlineStyle(
120 
121  // Description:
122  // Set/Get the color space option menu visibility.
123  // Note: set this parameter to the proper value before calling Create() in
124  // order to minimize the footprint of the object.
125  virtual void SetColorSpaceOptionMenuVisibility(int);
126  vtkBooleanMacro(ColorSpaceOptionMenuVisibility, int);
127  vtkGetMacro(ColorSpaceOptionMenuVisibility, int);
128 
129  // Description:
130  // Set/Get the value entries UI visibility.
131  // Not shown if superclass PointEntriesVisibility is set to Off
132  // Note: set this parameter to the proper value before calling Create() in
133  // order to minimize the footprint of the object.
134  vtkBooleanMacro(ValueEntriesVisibility, int);
135  virtual void SetValueEntriesVisibility(int);
136  vtkGetMacro(ValueEntriesVisibility, int);
137 
138  // Description:
139  // Update the whole UI depending on the value of the Ivars
140  virtual void Update();
141 
142  // Description:
143  // Update the "enable" state of the object and its internal parts.
144  // Depending on different Ivars (this->Enabled, the application's
145  // Limited Edition Mode, etc.), the "enable" state of the object is updated
146  // and propagated to its internal parts/subwidgets. This will, for example,
147  // enable/disable parts of the widget UI, enable/disable the visibility
148  // of 3D widgets, etc.
149  virtual void UpdateEnableState();
150 
151  // Description:
152  // Proxy to the function.
153  // IMPLEMENT those functions in the subclasses.
154  // See protected: section too.
155  virtual int HasFunction();
156  virtual int GetFunctionSize();
157  virtual unsigned long GetFunctionMTime();
158  virtual int GetFunctionPointParameter(int id, double *parameter);
159  virtual int GetFunctionPointDimensionality();
160 
161  // Description:
162  // Callbacks. Internal, do not use.
163  virtual void ColorSpaceCallback();
164  virtual void ValueEntriesCallback(const char *value);
165  virtual void DoubleClickOnPointCallback(int x, int y);
166 
167 protected:
170 
171  // Description:
172  // Create the widget.
173  virtual void CreateWidget();
174 
175  // Description:
176  // Proxy to the function.
177  // Those are low-level manipulators, they do not check if points can
178  // be added/removed/locked, it is up to the higer-level methods to do it.
179  // IMPLEMENT those functions in the subclasses.
180  // See public: section too.
181  virtual int GetFunctionPointValues(int id, double *values);
182  virtual int SetFunctionPointValues(int id, const double *values);
183  virtual int InterpolateFunctionPointValues(double parameter, double *values);
184  virtual int AddFunctionPoint(
185  double parameter, const double *values, int *id);
186  virtual int SetFunctionPoint(int id, double parameter, const double *values);
187  virtual int RemoveFunctionPoint(int id);
188  virtual int GetFunctionPointMidPoint(int id, double *pos);
189  virtual int SetFunctionPointMidPoint(int id, double pos);
190  virtual int GetFunctionPointSharpness(int id, double *sharpness);
191  virtual int SetFunctionPointSharpness(int id, double sharpness);
192 
193  // Description:
194  // Higher-level methods to manipulate the function.
195  virtual int MoveFunctionPointInColorSpace(
196  int id, double parameter, const double *values, int colorspace);
197 
198  virtual void UpdatePointEntries(int id);
199 
200  vtkColorTransferFunction *ColorTransferFunction;
201  vtkColorTransferFunction *ColorRampTransferFunction;
202 
203  int ValueEntriesVisibility;
204  int ColorSpaceOptionMenuVisibility;
205  int ColorRampVisibility;
206  int ColorRampHeight;
207  int ColorRampPosition;
208  int ColorRampOutlineStyle;
209  unsigned long LastRedrawColorRampTime;
210 
211  // GUI
212 
213  vtkKWMenuButton *ColorSpaceOptionMenu;
214  vtkKWEntryWithLabel *ValueEntries[3];
215  vtkKWLabel *ColorRamp;
216 
217  // Description:
218  // Redraw
219  virtual void Redraw();
220  virtual void RedrawSizeDependentElements();
221  virtual void RedrawPanOnlyDependentElements();
222  virtual void RedrawFunctionDependentElements();
223  virtual void RedrawSinglePointDependentElements(int id);
224 
225  // Description:
226  // Redraw the histogram
227  //BTX
228  virtual void UpdateHistogramImageDescriptor(vtkKWHistogram::ImageDescriptor*);
229  //ETX
230 
231  // Description:
232  // Pack the widget
233  virtual void Pack();
234  virtual void PackPointEntries();
235 
236  // Description:
237  // Redraw the color ramp
238  virtual void RedrawColorRamp();
239  virtual int IsColorRampUpToDate();
240  virtual void GetColorRampOutlineSunkenColors(
241  unsigned char bg_rgb[3], unsigned char ds_rgb[3], unsigned char ls_rgb[3],
242  unsigned char hl_rgb[3]);
243 
244  // Description:
245  // Update the entries label (depending on the color space)
246  // and the color space menu
247  virtual void UpdatePointEntriesLabel();
248  virtual void UpdateColorSpaceOptionMenu();
249 
250  // Description:
251  // Create some objects on the fly (lazy creation, to allow for a smaller
252  // footprint)
253  virtual void CreateColorSpaceOptionMenu();
254  virtual void CreateColorRamp();
255  virtual void CreateValueEntries();
256  virtual int IsTopLeftFrameUsed();
257  virtual int IsPointEntriesFrameUsed();
258 
259  // Description:
260  // Redraw the histogram
261  virtual void RedrawHistogram();
262 
263  // Description:
264  // Processes the events that are passed through CallbackCommand (or others).
265  // Subclasses can oberride this method to process their own events, but
266  // should call the superclass too.
267  virtual void ProcessCallbackCommandEvents(
268  vtkObject *caller, unsigned long event, void *calldata);
269 
270 private:
272  void operator=(const vtkKWColorTransferFunctionEditor&); // Not implemented
273 };
274 
275 #endif
276