KWWidgets
vtkKWSimpleAnimationWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWSimpleAnimationWidget.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 vtkKWSimpleAnimationWidget - a simple animation widget
15 // .SECTION Description
16 // This widget provides some simple controls and means to create an
17 // animation for either a 3D or a 2D scene. It supports two animation
18 // type. The first one, 'Camera' provides a user interface to rotate the
19 // camera in the scene. The second one, 'Slice' provides a different user
20 // interface to slice through a volume for example (say, display all the
21 // slices along the sagittal axis of a medical dataset). No explicit reference
22 // is made to the dataset, but callbacks must be set so that this widget
23 // can set or get the slice value on the approriate external resource.
24 // .SECTION Thanks
25 // This work is part of the National Alliance for Medical Image
26 // Computing (NAMIC), funded by the National Institutes of Health
27 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
28 // Information on the National Centers for Biomedical Computing
29 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
30 
31 #ifndef __vtkKWSimpleAnimationWidget_h
32 #define __vtkKWSimpleAnimationWidget_h
33 
34 #include "vtkKWCompositeWidget.h"
35 
37 class vtkKWPushButtonSet;
39 class vtkKWRenderWidget;
40 
42 {
43 public:
46  void PrintSelf(ostream& os, vtkIndent indent);
47 
48  // Description:
49  // Set/Get the renderwidget to perform the animation on.
50  // It is not ref-counted.
51  vtkGetObjectMacro(RenderWidget, vtkKWRenderWidget);
52  virtual void SetRenderWidget(vtkKWRenderWidget*);
53 
54  // Description:
55  // Set the number of frames and maximum number of frames
56  virtual void SetMaximumNumberOfFrames(int max);
57  virtual void SetNumberOfFrames(int val);
58 
59  // Description:
60  // Set/Get the animation type.
61  // If set to 'camera', the widget will display controls to rotate the
62  // camera only the 3-axes.
63  // If set to 'slice', the widget will display controls to iterate over
64  // a range of slice. It is meant to actually slice through a 3D volume.
65  // This 'slice' modes requires several callbacks to be also defined.
66  //BTX
67  enum
68  {
69  AnimationTypeCamera = 0,
70  AnimationTypeSlice
71  };
72  //ETX
73  virtual void SetAnimationType(int);
74  vtkGetMacro(AnimationType, int);
75  virtual void SetAnimationTypeToCamera();
76  virtual void SetAnimationTypeToSlice();
77 
78  // Description:
79  // Set the slice range (i.e. the indices of the first and last slices
80  // available in the animation, when the animation type is Slice).
81  virtual void SetSliceRange(int min, int max);
82  virtual void SetSliceRange(const int range[2])
83  { this->SetSliceRange(range[0], range[1]); };
84 
85  // Description:
86  // Set the command to invoke to set the slice value on an external
87  // source when the animation is in 'slice' mode.
88  // This command is mandatory for the slice animation to work.
89  // The 'object' argument is the object that will have the method called on
90  // it. The 'method' argument is the name of the method to be called and any
91  // arguments in string form. If the object is NULL, the method is still
92  // evaluated as a simple command.
93  // The following parameters are also passed to the command:
94  // - the slice value: int
95  virtual void SetSliceSetCommand(vtkObject *object, const char *method);
96 
97  // Description:
98  // Set the command to invoke to get the slice value from an external
99  // source when the animation is in 'slice' mode.
100  // This command is optional for the slice animation to work but will
101  // guarantee that the slice is set back to its proper value once
102  // the animation has been performed.
103  // The 'object' argument is the object that will have the method called on
104  // it. The 'method' argument is the name of the method to be called and any
105  // arguments in string form. If the object is NULL, the method is still
106  // evaluated as a simple command.
107  // The following output is expected from the command:
108  // - the slice value: int
109  virtual void SetSliceGetCommand(vtkObject *object, const char *method);
110 
111  // Description:
112  // Set a command to be invoked after the slice animation has been
113  // created/previewed.
114  // This command is optional.
115  // The 'object' argument is the object that will have the method called on
116  // it. The 'method' argument is the name of the method to be called and any
117  // arguments in string form. If the object is NULL, the method is still
118  // evaluated as a simple command.
119  virtual void SetSlicePostAnimationCommand(
120  vtkObject *object, const char *method);
121 
122  // Description:
123  // Set the X start and total rotation.
124  virtual void SetXStart(double val);
125  virtual void SetXRotation(double val);
126 
127  // Description:
128  // Set the Y start and total rotation.
129  virtual void SetYStart(double val);
130  virtual void SetYRotation(double val);
131 
132  // Description:
133  // Set the Z start and total rotation.
134  virtual void SetZStart(double val);
135  virtual void SetZRotation(double val);
136 
137  // Description:
138  // Set the zoom start and factor.
139  virtual void SetZoomStart(double val);
140  virtual void SetZoomFactor(double val);
141 
142  // Description:
143  // Set a command to be invoked after the camera animation has been
144  // created/previewed.
145  // This command is optional.
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 SetCameraPostAnimationCommand(
151  vtkObject *object, const char *method);
152 
153  // Description:
154  // Preview and create camera animation
155  virtual void PreviewCameraAnimation();
156  virtual void CreateCameraAnimation(
157  const char *filename, int width, int height, int fps, const char *fourcc);
158 
159  // Description:
160  // Preview and create slice animation
161  virtual void PreviewSliceAnimation();
162  virtual void CreateSliceAnimation(
163  const char *filename, int width, int height, int fps, const char *fourcc);
164 
165  // Description:
166  // Update the whole UI depending on the value of the Ivars
167  virtual void Update();
168 
169  // Description:
170  // Update the "enable" state of the object and its internal parts.
171  // Depending on different Ivars (this->Enabled, the application's
172  // Limited Edition Mode, etc.), the "enable" state of the object is updated
173  // and propagated to its internal parts/subwidgets. This will, for example,
174  // enable/disable parts of the widget UI, enable/disable the visibility
175  // of 3D widgets, etc.
176  virtual void UpdateEnableState();
177 
178  // Description:
179  // Callbacks. Internal, do not use.
180  virtual void PreviewAnimationCallback();
181  virtual void CreateAnimationCallback();
182  virtual void CancelAnimationCallback();
183 
184 protected:
187 
188  // Description:
189  // Create the widget.
190  virtual void CreateWidget();
191 
192  vtkKWRenderWidget *RenderWidget;
193 
194  // GUI
195 
196  vtkKWScaleWithEntrySet *Parameters;
197  vtkKWPushButtonSet *AnimationButtonSet;
198  vtkKWLabelWithLabel *HelpLabel;
199 
200  int AnimationType;
201 
202  // Description:
203  // Animation status
204  //BTX
205  enum
206  {
207  AnimationDone = 0,
208  AnimationPreviewing = 1,
209  AnimationCreating = 2,
210  AnimationCanceled = 4,
211  AnimationFailed = 8
212  };
213  //ETX
214  int AnimationStatus;
215 
216  char *CameraPostAnimationCommand;
217  char *SlicePostAnimationCommand;
218  char *SliceGetCommand;
219  char *SliceSetCommand;
220 
221  virtual void InvokeSliceSetCommand(int);
222  virtual int InvokeSliceGetCommand();
223  virtual void InvokeSlicePostAnimationCommand();
224  virtual void InvokeCameraPostAnimationCommand();
225 
226  // Description:
227  // Fix animation size
228  virtual void FixAnimationSize(const char *filename, int *width, int *height);
229 
230  // Description:
231  // Enable/disable animation buttons
232  virtual void DisableButtonsButCancel();
233  virtual void EnableButtonsButCancel();
234 
235 private:
236  vtkKWSimpleAnimationWidget(const vtkKWSimpleAnimationWidget&); // Not implemented
237  void operator=(const vtkKWSimpleAnimationWidget&); // Not implemented
238 };
239 
240 #endif
241