KWWidgets
vtkKWParameterValueHermiteFunctionEditor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWParameterValueHermiteFunctionEditor.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 vtkKWParameterValueHermiteFunctionEditor - a hermite function editor
15 // .SECTION Description
16 // This widget implements and defines the interface needed to edit
17 // an hermitian curve. On top of the superclass API that already
18 // describes each control point of the curve, several pure virtual functions
19 // are provided for subclasses to specify the midpoint and sharpness at each
20 // control point.
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 __vtkKWParameterValueHermiteFunctionEditor_h
29 #define __vtkKWParameterValueHermiteFunctionEditor_h
30 
32 
34 
36 {
37 public:
39  void PrintSelf(ostream& os, vtkIndent indent);
40 
41  // Description:
42  // Set/Get the midpoint entry UI visibility.
43  // Not shown if superclass PointEntriesVisibility is set to Off
44  // Note: set this parameter to the proper value before calling Create() in
45  // order to minimize the footprint of the object.
46  vtkBooleanMacro(MidPointEntryVisibility, int);
47  virtual void SetMidPointEntryVisibility(int);
48  vtkGetMacro(MidPointEntryVisibility, int);
49 
50  // Description:
51  // Access the parameter entry.
52  virtual vtkKWScaleWithEntry* GetMidPointEntry();
53 
54  // Description:
55  // Set/Get if the midpoint value should be displayed in the parameter
56  // domain instead of the normalized [0.0, 1.0] domain.
57  vtkBooleanMacro(DisplayMidPointValueInParameterDomain, int);
58  virtual void SetDisplayMidPointValueInParameterDomain(int);
59  vtkGetMacro(DisplayMidPointValueInParameterDomain, int);
60 
61  // Description:
62  // Set/Get the sharpness entry UI visibility.
63  // Not shown if superclass PointEntriesVisibility is set to Off
64  // Note: set this parameter to the proper value before calling Create() in
65  // order to minimize the footprint of the object.
66  vtkBooleanMacro(SharpnessEntryVisibility, int);
67  virtual void SetSharpnessEntryVisibility(int);
68  vtkGetMacro(SharpnessEntryVisibility, int);
69 
70  // Description:
71  // Access the parameter entry.
72  virtual vtkKWScaleWithEntry* GetSharpnessEntry();
73 
74  // Description:
75  // Set/Get the midpoint visibility in the canvas.
76  // The style of the midpoint is a rectangle around the midpoint location.
77  // Its color is controlled using MidPointColor.
78  vtkBooleanMacro(MidPointVisibility, int);
79  virtual void SetMidPointVisibility(int);
80  vtkGetMacro(MidPointVisibility, int);
81 
82  // Description:
83  // Set/Get the midpoints color.
84  vtkGetVector3Macro(MidPointColor, double);
85  virtual void SetMidPointColor(double r, double g, double b);
86  virtual void SetMidPointColor(double rgb[3])
87  { this->SetMidPointColor(rgb[0], rgb[1], rgb[2]); };
88 
89  // Description:
90  // Set/Get the selected midpoint color.
91  vtkGetVector3Macro(SelectedMidPointColor, double);
92  virtual void SetSelectedMidPointColor(double r, double g, double b);
93  virtual void SetSelectedMidPointColor(double rgb[3])
94  { this->SetSelectedMidPointColor(rgb[0], rgb[1], rgb[2]); };
95 
96  // Description:
97  // Set/Get the midpoint guideline visibility in the canvas
98  // (for ex: a vertical line at each midpoint).
99  // The style of the midpoint guidelines is the same as the style of the
100  // superclass point guideline (PointGuidelineStyle) for consistency.
101  vtkBooleanMacro(MidPointGuidelineVisibility, int);
102  virtual void SetMidPointGuidelineVisibility(int);
103  vtkGetMacro(MidPointGuidelineVisibility, int);
104 
105  // Description:
106  // Set/Get the midpoint guideline value visibility in the canvas
107  // (i.e., a value on top of the guideline).
108  // Note that the value is not displayed if MidPointGuidelineVisibility is
109  // set to Off (i.e. if we do not display the guideline itself, why displaying
110  // the value ?).
111  vtkBooleanMacro(MidPointGuidelineValueVisibility, int);
112  virtual void SetMidPointGuidelineValueVisibility(int);
113  vtkGetMacro(MidPointGuidelineValueVisibility, int);
114 
115  // Description:
116  // Set/Get the midpoint guideline value printf format.
117  virtual void SetMidPointGuidelineValueFormat(const char *);
118  vtkGetStringMacro(MidPointGuidelineValueFormat);
119 
120  // Description:
121  // Select/Deselect the midpoint between two adjacent points 'id' and
122  // 'id + 1'. Retrieve the midpoint selection, clear it, etc.
123  // (-1 if none selected)
124  vtkGetMacro(SelectedMidPoint, int);
125  virtual void SelectMidPoint(int id);
126  virtual void ClearMidPointSelection();
127  virtual int HasMidPointSelection();
128 
129  // Description:
130  // Select a point.
131  // Override the superclass so that selecting a point will clear
132  // the midpoint selection.
133  virtual void SelectPoint(int id);
134 
135  // Description:
136  // Select next and previous point.
137  // Override the superclass so that the mid-points are also selected (i.e.
138  // it will iterator over point, mid-point, point, mid-point, etc.)
139  virtual void SelectNextPoint();
140  virtual void SelectPreviousPoint();
141 
142  // Description:
143  // Specifies selection-related commands to associate with the widget.
144  // 'MidPointSelectionChangedCommand' is called whenever the midpoint
145  // selection was changed or cleared.
146  // The 'object' argument is the object that will have the method called on
147  // it. The 'method' argument is the name of the method to be called and any
148  // arguments in string form. If the object is NULL, the method is still
149  // evaluated as a simple command.
150  virtual void SetMidPointSelectionChangedCommand(
151  vtkObject *object,const char *method);
152 
153  // Description:
154  // Events. Even though it is highly recommended to use the commands
155  // framework defined above to specify the callback methods you want to be
156  // invoked when specific event occur, you can also use the observer
157  // framework and listen to the corresponding events:
158  //BTX
159  enum
160  {
161  MidPointSelectionChangedEvent = 11000
162  };
163  //ETX
164 
165  // Description:
166  // Synchronize single selection between two editors A and B.
167  // Override the superclass to take the midpoint selection into account
168  // Return 1 on success, 0 otherwise.
169  virtual int SynchronizeSingleSelection(
173 
174  // Description:
175  // Synchronize same selection between two editors A and B.
176  // Override the superclass to take the midpoint selection into account
177  // Return 1 on success, 0 otherwise.
178  virtual int SynchronizeSameSelection(
180  virtual int DoNotSynchronizeSameSelection(
182 
183  // Description:
184  // Update the whole UI depending on the value of the Ivars
185  virtual void Update();
186 
187  // Description:
188  // Convenience method that will hide all elements but the histogram.
189  virtual void DisplayHistogramOnly();
190 
191  // Description:
192  // Update the "enable" state of the object and its internal parts.
193  // Depending on different Ivars (this->Enabled, the application's
194  // Limited Edition Mode, etc.), the "enable" state of the object is updated
195  // and propagated to its internal parts/subwidgets. This will, for example,
196  // enable/disable parts of the widget UI, enable/disable the visibility
197  // of 3D widgets, etc.
198  virtual void UpdateEnableState();
199 
200  // Description:
201  // Some constants
202  //BTX
203  static const char *MidPointTag;
204  static const char *MidPointGuidelineTag;
205  static const char *MidPointSelectedTag;
206  //ETX
207 
208  // Description:
209  // Callbacks. Internal, do not use.
210  virtual void MidPointEntryChangedCallback(double value);
211  virtual void MidPointEntryChangingCallback(double value);
212  virtual void SharpnessEntryChangedCallback(double value);
213  virtual void SharpnessEntryChangingCallback(double value);
214  virtual void StartInteractionCallback(int x, int y, int shift);
215  virtual void MoveMidPointCallback(int x, int y, int button);
216  virtual void EndMidPointInteractionCallback(int x, int y);
217 
218 protected:
221 
222  // Description:
223  // Create the widget.
224  virtual void CreateWidget();
225 
226  // Description:
227  // Retrieve the midpoint between two adjacent points 'id' and 'id + 1'.
228  // The midpoint is the normalized distance between the two points at which
229  // the interpolated value reaches the median value in the value space.
230  // Return 1 on success (there is a midpoint at normalized position 'pos'),
231  // 0 otherwise.
232  // The default implementation here does not provide any midpoint.
233  virtual int GetFunctionPointMidPoint(int id, double *pos) = 0;
234 
235  // Description:
236  // Set the midpoint between two adjacent points 'id' and 'id + 1'.
237  // Return 1 on success (the midpoint was successfully set at normalized
238  // position 'pos'), 0 otherwise.
239  // The default implementation here does not provide any midpoint.
240  virtual int SetFunctionPointMidPoint(int id, double pos) = 0;
241 
242  // Description:
243  // Return 1 if the 'midpoint' of the point 'id' is locked (can/should
244  // not be changed/edited), 0 otherwise.
245  virtual int FunctionPointMidPointIsLocked(int id);
246 
247  // Description:
248  // Retrieve the sharpness of the transition between two adjacent points
249  // 'id' and 'id + 1'.
250  // Return 1 on success (there is a sharpness defined for this point),
251  // 0 otherwise.
252  virtual int GetFunctionPointSharpness(int id, double *sharpness) = 0;
253 
254  // Description:
255  // Set the sharpness of the transition between two adjacent points
256  // 'id' and 'id + 1'.
257  // Return 1 on success (the sharpness was successfully set), 0 otherwise.
258  virtual int SetFunctionPointSharpness(int id, double sharpness) = 0;
259 
260  // Description:
261  // Return 1 if the 'sharpness' of the point 'id' is locked (can/should
262  // not be changed/edited), 0 otherwise.
263  virtual int FunctionPointSharpnessIsLocked(int id);
264 
265  // Description:
266  // Update mi9dpoint entries
267  virtual void UpdateMidPointEntries(int id);
268 
269  // Description:
270  // Higher-level methods to manipulate the function.
271  virtual int GetMidPointCanvasCoordinates(int id, int *x, int *y, double *p);
272  virtual int FindMidPointAtCanvasCoordinates(
273  int x, int y, int *id, int *c_x, int *c_y);
274 
275  int MidPointEntryVisibility;
276  int DisplayMidPointValueInParameterDomain;
277  int SharpnessEntryVisibility;
278  int MidPointGuidelineVisibility;
279  int MidPointGuidelineValueVisibility;
280  double MidPointColor[3];
281  double SelectedMidPointColor[3];
282  int SelectedMidPoint;
283  int LastMidPointSelectionCanvasCoordinateX;
284  int LastMidPointSelectionCanvasCoordinateY;
285  double LastMidPointSelectionSharpness;
286 
287  char* MidPointGuidelineValueFormat;
288 
289  // Commands
290 
291  char *MidPointSelectionChangedCommand;
292 
293  virtual void InvokeMidPointSelectionChangedCommand();
294 
295  // GUI
296 
297  vtkKWScaleWithEntry *MidPointEntry;
298  vtkKWScaleWithEntry *SharpnessEntry;
299 
300  // Description:
301  // Create some objects on the fly (lazy creation, to allow for a smaller
302  // footprint)
303  virtual void CreateMidPointEntry();
304  virtual void CreateSharpnessEntry();
305  virtual int IsPointEntriesFrameUsed();
306  virtual int IsGuidelineValueCanvasUsed();
307 
308  // Description:
309  // Update the midpoint entry according to the midpoint of a point
310  virtual void UpdateMidPointEntry(int id);
311 
312  // Description:
313  // Update the sharpness entry according to the sharpness of a point
314  virtual void UpdateSharpnessEntry(int id);
315 
316  // Description:
317  // Merge the point 'editor_id' from another function editor 'editor' into
318  // our instance. Override the super to pass the midpoint and sharpness too
319  virtual int MergePointFromEditor(
320  vtkKWParameterValueFunctionEditor *editor, int editor_id, int *new_id);
321 
322  // Description:
323  // Copy the point 'id' parameter and values from another function editor
324  // 'editor' into the point 'id' in the instance.
325  // Override the super to pass the midpoint and sharpness too
326  virtual int CopyPointFromEditor(
327  vtkKWParameterValueFunctionEditor *editor, int id);
328 
329  // Description:
330  // Redraw the whole function or a specific point, or
331  // the line between two points. Overriden to take midpoints into account
332  //BTX
333  virtual void RedrawFunction();
334  virtual void RedrawFunctionDependentElements();
335  virtual void RedrawSinglePointDependentElements(int id);
336  virtual void RedrawLine(int id1, int id2, vtksys_ios::ostream *tk_cmd = 0);
337  //ETX
338 
339  // Description:
340  // Pack the widget
341  virtual void PackPointEntries();
342 
343  // Description:
344  // Bind/Unbind all widgets.
345  virtual void Bind();
346  virtual void UnBind();
347 
348  // Synchronization callbacks
349 
350  virtual void ProcessSynchronizationEvents(
351  vtkObject *caller, unsigned long event, void *calldata);
352  virtual void ProcessSynchronizationEvents2(
353  vtkObject *caller, unsigned long event, void *calldata);
354 
355 private:
356 
357  int MidPointVisibility;
358 
360  void operator=(const vtkKWParameterValueHermiteFunctionEditor&); // Not implemented
361 };
362 
363 #endif
364