KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWParameterValueHermiteFunctionEditor.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 vtkKWParameterValueHermiteFunctionEditor - a hermite function editor 00015 // .SECTION Description 00016 // This widget implements and defines the interface needed to edit 00017 // an hermitian curve. On top of the superclass API that already 00018 // describes each control point of the curve, several pure virtual functions 00019 // are provided for subclasses to specify the midpoint and sharpness at each 00020 // control point. 00021 // .SECTION Thanks 00022 // This work is part of the National Alliance for Medical Image 00023 // Computing (NAMIC), funded by the National Institutes of Health 00024 // through the NIH Roadmap for Medical Research, Grant U54 EB005149. 00025 // Information on the National Centers for Biomedical Computing 00026 // can be obtained from http://nihroadmap.nih.gov/bioinformatics. 00027 00028 #ifndef __vtkKWParameterValueHermiteFunctionEditor_h 00029 #define __vtkKWParameterValueHermiteFunctionEditor_h 00030 00031 #include "vtkKWParameterValueFunctionEditor.h" 00032 00033 class vtkKWScaleWithEntry; 00034 00035 class KWWidgets_EXPORT vtkKWParameterValueHermiteFunctionEditor : public vtkKWParameterValueFunctionEditor 00036 { 00037 public: 00038 vtkTypeRevisionMacro(vtkKWParameterValueHermiteFunctionEditor,vtkKWParameterValueFunctionEditor); 00039 void PrintSelf(ostream& os, vtkIndent indent); 00040 00041 // Description: 00042 // Set/Get the midpoint entry UI visibility. 00043 // Not shown if superclass PointEntriesVisibility is set to Off 00044 // Note: set this parameter to the proper value before calling Create() in 00045 // order to minimize the footprint of the object. 00046 vtkBooleanMacro(MidPointEntryVisibility, int); 00047 virtual void SetMidPointEntryVisibility(int); 00048 vtkGetMacro(MidPointEntryVisibility, int); 00049 00050 // Description: 00051 // Access the parameter entry. 00052 virtual vtkKWScaleWithEntry* GetMidPointEntry(); 00053 00054 // Description: 00055 // Set/Get if the midpoint value should be displayed in the parameter 00056 // domain instead of the normalized [0.0, 1.0] domain. 00057 vtkBooleanMacro(DisplayMidPointValueInParameterDomain, int); 00058 virtual void SetDisplayMidPointValueInParameterDomain(int); 00059 vtkGetMacro(DisplayMidPointValueInParameterDomain, int); 00060 00061 // Description: 00062 // Set/Get the sharpness entry UI visibility. 00063 // Not shown if superclass PointEntriesVisibility is set to Off 00064 // Note: set this parameter to the proper value before calling Create() in 00065 // order to minimize the footprint of the object. 00066 vtkBooleanMacro(SharpnessEntryVisibility, int); 00067 virtual void SetSharpnessEntryVisibility(int); 00068 vtkGetMacro(SharpnessEntryVisibility, int); 00069 00070 // Description: 00071 // Access the parameter entry. 00072 virtual vtkKWScaleWithEntry* GetSharpnessEntry(); 00073 00074 // Description: 00075 // Set/Get the midpoint visibility in the canvas. 00076 // The style of the midpoint is a rectangle around the midpoint location. 00077 // Its color is controlled using MidPointColor. 00078 vtkBooleanMacro(MidPointVisibility, int); 00079 virtual void SetMidPointVisibility(int); 00080 vtkGetMacro(MidPointVisibility, int); 00081 00082 // Description: 00083 // Set/Get the midpoints color. 00084 vtkGetVector3Macro(MidPointColor, double); 00085 virtual void SetMidPointColor(double r, double g, double b); 00086 virtual void SetMidPointColor(double rgb[3]) 00087 { this->SetMidPointColor(rgb[0], rgb[1], rgb[2]); }; 00088 00089 // Description: 00090 // Set/Get the selected midpoint color. 00091 vtkGetVector3Macro(SelectedMidPointColor, double); 00092 virtual void SetSelectedMidPointColor(double r, double g, double b); 00093 virtual void SetSelectedMidPointColor(double rgb[3]) 00094 { this->SetSelectedMidPointColor(rgb[0], rgb[1], rgb[2]); }; 00095 00096 // Description: 00097 // Set/Get the midpoint guideline visibility in the canvas 00098 // (for ex: a vertical line at each midpoint). 00099 // The style of the midpoint guidelines is the same as the style of the 00100 // superclass point guideline (PointGuidelineStyle) for consistency. 00101 vtkBooleanMacro(MidPointGuidelineVisibility, int); 00102 virtual void SetMidPointGuidelineVisibility(int); 00103 vtkGetMacro(MidPointGuidelineVisibility, int); 00104 00105 // Description: 00106 // Set/Get the midpoint guideline value visibility in the canvas 00107 // (i.e., a value on top of the guideline). 00108 // Note that the value is not displayed if MidPointGuidelineVisibility is 00109 // set to Off (i.e. if we do not display the guideline itself, why displaying 00110 // the value ?). 00111 vtkBooleanMacro(MidPointGuidelineValueVisibility, int); 00112 virtual void SetMidPointGuidelineValueVisibility(int); 00113 vtkGetMacro(MidPointGuidelineValueVisibility, int); 00114 00115 // Description: 00116 // Set/Get the midpoint guideline value printf format. 00117 virtual void SetMidPointGuidelineValueFormat(const char *); 00118 vtkGetStringMacro(MidPointGuidelineValueFormat); 00119 00120 // Description: 00121 // Select/Deselect the midpoint between two adjacent points 'id' and 00122 // 'id + 1'. Retrieve the midpoint selection, clear it, etc. 00123 // (-1 if none selected) 00124 vtkGetMacro(SelectedMidPoint, int); 00125 virtual void SelectMidPoint(int id); 00126 virtual void ClearMidPointSelection(); 00127 virtual int HasMidPointSelection(); 00128 00129 // Description: 00130 // Select a point. 00131 // Override the superclass so that selecting a point will clear 00132 // the midpoint selection. 00133 virtual void SelectPoint(int id); 00134 00135 // Description: 00136 // Select next and previous point. 00137 // Override the superclass so that the mid-points are also selected (i.e. 00138 // it will iterator over point, mid-point, point, mid-point, etc.) 00139 virtual void SelectNextPoint(); 00140 virtual void SelectPreviousPoint(); 00141 00142 // Description: 00143 // Specifies selection-related commands to associate with the widget. 00144 // 'MidPointSelectionChangedCommand' is called whenever the midpoint 00145 // selection was changed or cleared. 00146 // The 'object' argument is the object that will have the method called on 00147 // it. The 'method' argument is the name of the method to be called and any 00148 // arguments in string form. If the object is NULL, the method is still 00149 // evaluated as a simple command. 00150 virtual void SetMidPointSelectionChangedCommand( 00151 vtkObject *object,const char *method); 00152 00153 // Description: 00154 // Events. Even though it is highly recommended to use the commands 00155 // framework defined above to specify the callback methods you want to be 00156 // invoked when specific event occur, you can also use the observer 00157 // framework and listen to the corresponding events: 00158 //BTX 00159 enum 00160 { 00161 MidPointSelectionChangedEvent = 11000 00162 }; 00163 //ETX 00164 00165 // Description: 00166 // Synchronize single selection between two editors A and B. 00167 // Override the superclass to take the midpoint selection into account 00168 // Return 1 on success, 0 otherwise. 00169 virtual int SynchronizeSingleSelection( 00170 vtkKWParameterValueFunctionEditor *b); 00171 virtual int DoNotSynchronizeSingleSelection( 00172 vtkKWParameterValueFunctionEditor *b); 00173 00174 // Description: 00175 // Synchronize same selection between two editors A and B. 00176 // Override the superclass to take the midpoint selection into account 00177 // Return 1 on success, 0 otherwise. 00178 virtual int SynchronizeSameSelection( 00179 vtkKWParameterValueFunctionEditor *b); 00180 virtual int DoNotSynchronizeSameSelection( 00181 vtkKWParameterValueFunctionEditor *b); 00182 00183 // Description: 00184 // Update the whole UI depending on the value of the Ivars 00185 virtual void Update(); 00186 00187 // Description: 00188 // Convenience method that will hide all elements but the histogram. 00189 virtual void DisplayHistogramOnly(); 00190 00191 // Description: 00192 // Update the "enable" state of the object and its internal parts. 00193 // Depending on different Ivars (this->Enabled, the application's 00194 // Limited Edition Mode, etc.), the "enable" state of the object is updated 00195 // and propagated to its internal parts/subwidgets. This will, for example, 00196 // enable/disable parts of the widget UI, enable/disable the visibility 00197 // of 3D widgets, etc. 00198 virtual void UpdateEnableState(); 00199 00200 // Description: 00201 // Some constants 00202 //BTX 00203 static const char *MidPointTag; 00204 static const char *MidPointGuidelineTag; 00205 static const char *MidPointSelectedTag; 00206 //ETX 00207 00208 // Description: 00209 // Callbacks. Internal, do not use. 00210 virtual void MidPointEntryChangedCallback(double value); 00211 virtual void MidPointEntryChangingCallback(double value); 00212 virtual void SharpnessEntryChangedCallback(double value); 00213 virtual void SharpnessEntryChangingCallback(double value); 00214 virtual void StartInteractionCallback(int x, int y, int shift); 00215 virtual void MoveMidPointCallback(int x, int y, int button); 00216 virtual void EndMidPointInteractionCallback(int x, int y); 00217 00218 protected: 00219 vtkKWParameterValueHermiteFunctionEditor(); 00220 ~vtkKWParameterValueHermiteFunctionEditor(); 00221 00222 // Description: 00223 // Create the widget. 00224 virtual void CreateWidget(); 00225 00226 // Description: 00227 // Retrieve the midpoint between two adjacent points 'id' and 'id + 1'. 00228 // The midpoint is the normalized distance between the two points at which 00229 // the interpolated value reaches the median value in the value space. 00230 // Return 1 on success (there is a midpoint at normalized position 'pos'), 00231 // 0 otherwise. 00232 // The default implementation here does not provide any midpoint. 00233 virtual int GetFunctionPointMidPoint(int id, double *pos) = 0; 00234 00235 // Description: 00236 // Set the midpoint between two adjacent points 'id' and 'id + 1'. 00237 // Return 1 on success (the midpoint was successfully set at normalized 00238 // position 'pos'), 0 otherwise. 00239 // The default implementation here does not provide any midpoint. 00240 virtual int SetFunctionPointMidPoint(int id, double pos) = 0; 00241 00242 // Description: 00243 // Return 1 if the 'midpoint' of the point 'id' is locked (can/should 00244 // not be changed/edited), 0 otherwise. 00245 virtual int FunctionPointMidPointIsLocked(int id); 00246 00247 // Description: 00248 // Retrieve the sharpness of the transition between two adjacent points 00249 // 'id' and 'id + 1'. 00250 // Return 1 on success (there is a sharpness defined for this point), 00251 // 0 otherwise. 00252 virtual int GetFunctionPointSharpness(int id, double *sharpness) = 0; 00253 00254 // Description: 00255 // Set the sharpness of the transition between two adjacent points 00256 // 'id' and 'id + 1'. 00257 // Return 1 on success (the sharpness was successfully set), 0 otherwise. 00258 virtual int SetFunctionPointSharpness(int id, double sharpness) = 0; 00259 00260 // Description: 00261 // Return 1 if the 'sharpness' of the point 'id' is locked (can/should 00262 // not be changed/edited), 0 otherwise. 00263 virtual int FunctionPointSharpnessIsLocked(int id); 00264 00265 // Description: 00266 // Update mi9dpoint entries 00267 virtual void UpdateMidPointEntries(int id); 00268 00269 // Description: 00270 // Higher-level methods to manipulate the function. 00271 virtual int GetMidPointCanvasCoordinates(int id, int *x, int *y, double *p); 00272 virtual int FindMidPointAtCanvasCoordinates( 00273 int x, int y, int *id, int *c_x, int *c_y); 00274 00275 int MidPointEntryVisibility; 00276 int DisplayMidPointValueInParameterDomain; 00277 int SharpnessEntryVisibility; 00278 int MidPointGuidelineVisibility; 00279 int MidPointGuidelineValueVisibility; 00280 double MidPointColor[3]; 00281 double SelectedMidPointColor[3]; 00282 int SelectedMidPoint; 00283 int LastMidPointSelectionCanvasCoordinateX; 00284 int LastMidPointSelectionCanvasCoordinateY; 00285 double LastMidPointSelectionSharpness; 00286 00287 char* MidPointGuidelineValueFormat; 00288 00289 // Commands 00290 00291 char *MidPointSelectionChangedCommand; 00292 00293 virtual void InvokeMidPointSelectionChangedCommand(); 00294 00295 // GUI 00296 00297 vtkKWScaleWithEntry *MidPointEntry; 00298 vtkKWScaleWithEntry *SharpnessEntry; 00299 00300 // Description: 00301 // Create some objects on the fly (lazy creation, to allow for a smaller 00302 // footprint) 00303 virtual void CreateMidPointEntry(); 00304 virtual void CreateSharpnessEntry(); 00305 virtual int IsPointEntriesFrameUsed(); 00306 virtual int IsGuidelineValueCanvasUsed(); 00307 00308 // Description: 00309 // Update the midpoint entry according to the midpoint of a point 00310 virtual void UpdateMidPointEntry(int id); 00311 00312 // Description: 00313 // Update the sharpness entry according to the sharpness of a point 00314 virtual void UpdateSharpnessEntry(int id); 00315 00316 // Description: 00317 // Merge the point 'editor_id' from another function editor 'editor' into 00318 // our instance. Override the super to pass the midpoint and sharpness too 00319 virtual int MergePointFromEditor( 00320 vtkKWParameterValueFunctionEditor *editor, int editor_id, int *new_id); 00321 00322 // Description: 00323 // Copy the point 'id' parameter and values from another function editor 00324 // 'editor' into the point 'id' in the instance. 00325 // Override the super to pass the midpoint and sharpness too 00326 virtual int CopyPointFromEditor( 00327 vtkKWParameterValueFunctionEditor *editor, int id); 00328 00329 // Description: 00330 // Redraw the whole function or a specific point, or 00331 // the line between two points. Overriden to take midpoints into account 00332 //BTX 00333 virtual void RedrawFunction(); 00334 virtual void RedrawFunctionDependentElements(); 00335 virtual void RedrawSinglePointDependentElements(int id); 00336 virtual void RedrawLine(int id1, int id2, vtksys_ios::ostream *tk_cmd = 0); 00337 //ETX 00338 00339 // Description: 00340 // Pack the widget 00341 virtual void PackPointEntries(); 00342 00343 // Description: 00344 // Bind/Unbind all widgets. 00345 virtual void Bind(); 00346 virtual void UnBind(); 00347 00348 // Synchronization callbacks 00349 00350 virtual void ProcessSynchronizationEvents( 00351 vtkObject *caller, unsigned long event, void *calldata); 00352 virtual void ProcessSynchronizationEvents2( 00353 vtkObject *caller, unsigned long event, void *calldata); 00354 00355 private: 00356 00357 int MidPointVisibility; 00358 00359 vtkKWParameterValueHermiteFunctionEditor(const vtkKWParameterValueHermiteFunctionEditor&); // Not implemented 00360 void operator=(const vtkKWParameterValueHermiteFunctionEditor&); // Not implemented 00361 }; 00362 00363 #endif 00364