KWWidgets
debian/tmp/usr/include/KWWidgets/vtkKWRenderWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWRenderWidget.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 vtkKWRenderWidget - a render widget
15 // .SECTION Description
16 // This class encapsulates a render window, a renderer and several other
17 // objects inside a single widget. Actors and props can be added,
18 // annotations can be set.
19 // .WARNING
20 // This widget set the camera to be in parallel projection mode.
21 // You can change this default (after Create()) by calling:
22 // renderwidget->GetRenderer()->GetActiveCamera()->ParallelProjectionOff();
23 
24 #ifndef __vtkKWRenderWidget_h
25 #define __vtkKWRenderWidget_h
26 
27 #include "vtkKWCompositeWidget.h"
28 #include "vtkWindows.h" // needed for RECT HDC
29 
30 class vtkCamera;
31 class vtkCornerAnnotation;
32 class vtkProp;
33 class vtkRenderWindow;
34 class vtkRenderer;
35 class vtkTextActor;
36 class vtkKWMenu;
37 class vtkKWRenderWidgetInternals;
38 class vtkRenderWindowInteractor;
39 
41 {
42 public:
43  static vtkKWRenderWidget* New();
44  vtkTypeRevisionMacro(vtkKWRenderWidget, vtkKWCompositeWidget);
45  void PrintSelf(ostream& os, vtkIndent indent);
46 
47  // Description:
48  // Close the widget.
49  // This method brings the widget back to an empty/clean state.
50  // It removes all the actors/props, removes the bindings, resets the
51  // annotations, etc.
52  virtual void Close();
53 
54  // Description:
55  // Render the scene.
56  virtual void Render();
57 
58  // Description:
59  // Enable/disable rendering.
60  vtkGetMacro(RenderState, int);
61  vtkSetClampMacro(RenderState, int, 0, 1);
62  vtkBooleanMacro(RenderState, int);
63 
64  // Description:
65  // Set/Get the rendering mode.
66  //BTX
67  enum
68  {
69  InteractiveRender = 0,
70  StillRender = 1,
71  DisabledRender = 2,
72  SingleRender = 3
73  };
74  //ETX
75  vtkSetClampMacro(RenderMode, int,
78  vtkGetMacro(RenderMode, int);
79  virtual void SetRenderModeToInteractive()
80  { this->SetRenderMode(vtkKWRenderWidget::InteractiveRender); };
81  virtual void SetRenderModeToStill()
82  { this->SetRenderMode(vtkKWRenderWidget::StillRender); };
83  virtual void SetRenderModeToSingle()
84  { this->SetRenderMode(vtkKWRenderWidget::SingleRender); };
85  virtual void SetRenderModeToDisabled()
86  { this->SetRenderMode(vtkKWRenderWidget::DisabledRender); };
87 
88  // Description:
89  // Set/Get the collapsing of renders. If this is set to true, then
90  // all call to Render() will be collapsed. Once this is set to false, if
91  // there are any pending render requests, the widget will render.
92  virtual void SetCollapsingRenders(int);
93  vtkBooleanMacro(CollapsingRenders, int);
94  vtkGetMacro(CollapsingRenders, int);
95 
96  // Description:
97  // Reset the widget.
98  // This implementation calls ResetCamera() and Render().
99  virtual void Reset();
100 
101  // Description:
102  // Reset the camera to display all the actors in the scene, or just
103  // the camera clipping range.
104  // This is done for each renderer (if multiple renderers are supported).
105  // Note that no default renderers exist before Create() is called.
106  virtual void ResetCamera();
107  virtual void ResetCameraClippingRange();
108 
109  // Description:
110  // Add/remove the widget bindings.
111  // The AddBindings() method sets up general bindings like the Expose or
112  // Configure events so that the scene is rendered properly when the widget
113  // is mapped to the screen. It also calls the AddInteractionBindings()
114  // which sets up interaction bindings like mouse events, keyboard events,
115  // etc. The AddBindings() method is called automatically when the widget
116  // is created by the Create() method. Yet, the methods are public so
117  // that one can temporarily enable or disable the bindings to limit
118  // the interaction with this widget.
119  virtual void AddBindings();
120  virtual void RemoveBindings();
121  virtual void AddInteractionBindings();
122  virtual void RemoveInteractionBindings();
123 
124  // Description:
125  // Convenience method to set the visibility of all annotations.
126  // Subclasses should override this method to propagate this visibility
127  // flag to their own annotations.
128  virtual void SetAnnotationsVisibility(int v);
129  vtkBooleanMacro(AnnotationsVisibility, int);
130 
131  // Description:
132  // Get and control the corner annotation. Turn SupportCornerAnnotation
133  // to off (on by default) if this widget should not support any corner
134  // annotation (i.e. never display it, and do not populate the annotation
135  // context menu with the corresponding entry).
136  virtual void SetCornerAnnotationVisibility(int v);
137  virtual int GetCornerAnnotationVisibility();
138  virtual void ToggleCornerAnnotationVisibility();
139  vtkBooleanMacro(CornerAnnotationVisibility, int);
140  virtual void SetCornerAnnotationColor(double r, double g, double b);
141  virtual void SetCornerAnnotationColor(double *rgb)
142  { this->SetCornerAnnotationColor(rgb[0], rgb[1], rgb[2]); };
143  virtual double* GetCornerAnnotationColor();
144  vtkGetObjectMacro(CornerAnnotation, vtkCornerAnnotation);
145  vtkGetMacro(SupportCornerAnnotation, int);
146  virtual void SetSupportCornerAnnotation(int);
147  vtkBooleanMacro(SupportCornerAnnotation, int);
148 
149  // Description:
150  // Get and control the header annotation.
151  virtual void SetHeaderAnnotationVisibility(int v);
152  virtual int GetHeaderAnnotationVisibility();
153  virtual void ToggleHeaderAnnotationVisibility();
154  vtkBooleanMacro(HeaderAnnotationVisibility, int);
155  virtual void SetHeaderAnnotationColor(double r, double g, double b);
156  virtual void SetHeaderAnnotationColor(double *rgb)
157  { this->SetHeaderAnnotationColor(rgb[0], rgb[1], rgb[2]); };
158  virtual double* GetHeaderAnnotationColor();
159  virtual void SetHeaderAnnotationText(const char*);
160  virtual char* GetHeaderAnnotationText();
161  vtkGetObjectMacro(HeaderAnnotation, vtkTextActor);
162 
163  // Description:
164  // Set/Get the distance units that pixel sizes are measured in
165  virtual void SetDistanceUnits(const char*);
166  vtkGetStringMacro(DistanceUnits);
167 
168  // Description:
169  // Get the render window, get the renderwindow interactor
170  vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
171  virtual vtkRenderWindowInteractor* GetRenderWindowInteractor();
172 
173  // Description:
174  // Get the VTK widget
175  vtkGetObjectMacro(VTKWidget, vtkKWCoreWidget);
176 
177  // Description:
178  // If the widget supports multiple renderers:
179  // GetNthRenderer() gets the Nth renderer (or NULL if it does not exist),
180  // GetRendererIndex() gets the id of a given renderer (or -1 if this renderer
181  // does not belong to this widget), i.e. its index/position in the list
182  // of renderers. AddRenderer() will add a renderer, RemoveAllRenderers will
183  // remove all renderers.
184  // Note that no default renderers exist before Create() is called.
185  virtual vtkRenderer* GetRenderer() { return this->GetNthRenderer(0); }
186  virtual vtkRenderer* GetNthRenderer(int index);
187  virtual int GetNumberOfRenderers();
188  virtual int GetRendererIndex(vtkRenderer*);
189  virtual void AddRenderer(vtkRenderer*);
190  virtual void RemoveRenderer(vtkRenderer*);
191  virtual void RemoveNthRenderer(int index);
192  virtual void RemoveAllRenderers();
193 
194  // Description:
195  // Get the overlay renderer.
196  // Note that no default overlay renderer exist before Create() is called.
197  virtual vtkRenderer* GetOverlayRenderer()
198  { return this->GetNthOverlayRenderer(0); }
199  virtual vtkRenderer* GetNthOverlayRenderer(int index);
200  virtual int GetNumberOfOverlayRenderers();
201  virtual int GetOverlayRendererIndex(vtkRenderer*);
202  virtual void AddOverlayRenderer(vtkRenderer*);
203  virtual void RemoveOverlayRenderer(vtkRenderer*);
204  virtual void RemoveNthOverlayRenderer(int index);
205  virtual void RemoveAllOverlayRenderers();
206 
207  // Description:
208  // Set the backgrounds color of the renderer(s) (not the overlay ones).
209  // Note that no default renderers exist before Create() is called.
210  virtual void GetRendererBackgroundColor(double *r, double *g, double *b);
211  virtual void SetRendererBackgroundColor(double r, double g, double b);
212  virtual void SetRendererBackgroundColor(double rgb[3])
213  { this->SetRendererBackgroundColor(rgb[0], rgb[1], rgb[2]); };
214  virtual void GetRendererBackgroundColor2(double *r, double *g, double *b);
215  virtual void SetRendererBackgroundColor2(double r, double g, double b);
216  virtual void SetRendererBackgroundColor2(double rgb[3])
217  { this->SetRendererBackgroundColor2(rgb[0], rgb[1], rgb[2]); };
218  virtual void SetRendererGradientBackground(int);
219  virtual int GetRendererGradientBackground();
220  virtual void ToggleRendererGradientBackground();
221 
222  // Description:
223  // Add props (actors) to *all* widget renderer(s) or *all* overlay
224  // renderer(s), or to specific ones.
225  // Note that no default renderers exist before Create() is called.
226  virtual void AddViewProp(vtkProp *prop);
227  virtual void AddViewPropToNthRenderer(vtkProp *p, int index);
228  virtual void AddOverlayViewProp(vtkProp *prop);
229  virtual void AddViewPropToNthOverlayRenderer(vtkProp *p, int index);
230 
231  // Description:
232  // Query/remove props (actors) from both renderer(s) and overlay renderer(s).
233  virtual int HasViewProp(vtkProp *prop);
234  virtual void RemoveViewProp(vtkProp *prop);
235  virtual void RemoveAllViewProps();
236 
237  // Description:
238  // The ComputeVisiblePropBounds() method returns the bounds of the
239  // visible props for a renderer (given its index). By default, it is just
240  // a call to vtkRenderer::ComputeVisiblePropBounds().
241  virtual void ComputeVisiblePropBounds(int index, double bounds[6]);
242 
243  // Description:
244  // Set/Get the printing flag (i.e., are we printing?)
245  virtual void SetPrinting(int arg);
246  vtkBooleanMacro(Printing, int);
247  vtkGetMacro(Printing, int);
248 
249  // Description:
250  // Set/Get offscreen rendering flag (e.g., for screenshots)
251  vtkBooleanMacro(OffScreenRendering, int);
252  virtual void SetOffScreenRendering(int);
253  virtual int GetOffScreenRendering();
254 
255  // Description:
256  // Use a context menu. It is posted by a right click, and allows
257  // properties and mode to be controlled.
258  vtkSetMacro(UseContextMenu, int);
259  vtkGetMacro(UseContextMenu, int);
260  vtkBooleanMacro(UseContextMenu, int);
261 
262  // Description:
263  // Update the "enable" state of the object and its internal parts.
264  // Depending on different Ivars (this->Enabled, the application's
265  // Limited Edition Mode, etc.), the "enable" state of the object is updated
266  // and propagated to its internal parts/subwidgets. This will, for example,
267  // enable/disable parts of the widget UI, enable/disable the visibility
268  // of 3D widgets, etc.
269  virtual void UpdateEnableState();
270 
271  // Description:
272  // Overridden for debugging purposes. This class is usually the center of the
273  // whole "a vtkTkRenderWidget is being destroyed before its render window"
274  // problem.
275  virtual void Register(vtkObjectBase* o);
276  virtual void UnRegister(vtkObjectBase* o);
277 
278  // Description:
279  // Setup print parameters
280 #if defined(_WIN32) && !defined(__CYGWIN__)
281  virtual void SetupPrint(RECT &rcDest, HDC ghdc,
282  int printerPageSizeX, int printerPageSizeY,
283  int printerDPIX, int printerDPIY,
284  float scaleX, float scaleY,
285  int screenSizeX, int screenSizeY);
286 #endif
287 
288  // Description:
289  // Get memory device context (when rendering to memory)
290  virtual void* GetMemoryDC();
291 
292  // Description:
293  // Add all the default observers needed by that object, or remove
294  // all the observers that were added through AddCallbackCommandObserver.
295  // Subclasses can override these methods to add/remove their own default
296  // observers, but should call the superclass too.
297  virtual void AddCallbackCommandObservers();
298  virtual void RemoveCallbackCommandObservers();
299 
300  // Description:
301  // Callbacks. Internal, do not use.
302  virtual void MouseMoveCallback(
303  int num, int x, int y, int ctrl, int shift, int alt);
304  virtual void MouseWheelCallback(
305  int delta, int ctrl, int shift, int alt);
306  virtual void MouseButtonPressCallback(
307  int num, int x, int y, int ctrl, int shift, int alt, int repeat);
308  virtual void MouseButtonReleaseCallback(
309  int num, int x, int y, int ctrl, int shift, int alt);
310  virtual void KeyPressCallback(
311  char key, int x, int y, int ctrl, int shift, int alt, char *keysym);
312  virtual void KeyReleaseCallback(
313  char key, int x, int y, int ctrl, int shift, int alt, char *keysym);
314  virtual void ConfigureCallback(int width, int height);
315  virtual void ExposeCallback();
316  virtual void EnterCallback(int x, int y);
317  virtual void LeaveCallback(int x, int y);
318  virtual void FocusInCallback();
319  virtual void FocusOutCallback();
320  virtual int RendererBackgroundColorCallback();
321  virtual int RendererBackgroundColor2Callback();
322  virtual void RendererGradientBackgroundCallback();
323 
324  // Description:
325  // Event list
326  //BTX
327  enum
328  {
329  CornerAnnotationVisibilityChangedEvent = 24000,
332  RendererBackgroundColor2ChangedEvent
333  };
334  //ETX
335 
336  // Description:
337  // Some constants
338  vtkGetStringMacro(RendererBackgroundColorRegKey);
339  vtkSetStringMacro(RendererBackgroundColorRegKey);
340  vtkGetStringMacro(RendererBackgroundColor2RegKey);
341  vtkSetStringMacro(RendererBackgroundColor2RegKey);
342  vtkGetStringMacro(RendererGradientBackgroundRegKey);
343  vtkSetStringMacro(RendererGradientBackgroundRegKey);
344 
345 protected:
348 
349  // Description:
350  // Create the widget.
351  virtual void CreateWidget();
352 
354  vtkRenderWindow *RenderWindow;
355  vtkCornerAnnotation *CornerAnnotation;
356  vtkTextActor *HeaderAnnotation;
357 
360  int InExpose;
362  int Printing;
363 
365 
368 
369  // Description:
370  // Create the default renderers inside the render window.
371  // Superclass can override to create different renderers.
372  // It is called by Create().
373  virtual void CreateDefaultRenderers();
374 
375  // Description:
376  // Install the renderers inside the render window.
377  // Superclass can override to install them in a different layout.
378  // It is called by Create().
379  virtual void InstallRenderers();
380 
381  // Description:
382  // Set the renderers default values (say, default background colors).
383  virtual void SetRenderersDefaultValues();
384 
385  // Description:
386  // Update the widget according to the units.
387  // Should be called when any units-related ivar has changed.
388  virtual void UpdateAccordingToUnits() {};
389 
390  // Description:
391  // Setup memory rendering
392  virtual void SetupMemoryRendering(int width, int height, void *cd);
393  virtual void ResumeScreenRendering();
394 
395  // Description:
396  // Processes the events that are passed through CallbackCommand (or others).
397  // Subclasses can oberride this method to process their own events, but
398  // should call the superclass too.
399  virtual void ProcessCallbackCommandEvents(
400  vtkObject *caller, unsigned long event, void *calldata);
401 
402  // Context menu
403 
406 
407  // Description:
408  // Populate the context menu that pops up when the user right-clicks on
409  // the render area.
410  // Superclass should override this method to populate this
411  // menu with the commands they feel comfortable exposing to the user.
412  // This implementation is actually split into several methods to help
413  // organizing the menu into several categories. It calls, in that order:
414  // - PopulateContextMenuWithInteractionEntries(): interaction mode
415  // - PopulateContextMenuWithAnnotationEntries(): annotations, 2d text
416  // - PopulateContextMenuWithOptionEntries(): misc. options
417  // - PopulateContextMenuWithCameraEntries(): camera, change viewpoints
418  // - PopulateContextMenuWithColorEntries(): background color, etc.
419  // Each method is passed a pointer to the context menu.
420  // A menu separator is added automatically between each non-empty section.
421  virtual void PopulateContextMenu(vtkKWMenu*);
423  virtual void PopulateContextMenuWithAnnotationEntries(vtkKWMenu*);
425  virtual void PopulateContextMenuWithCameraEntries(vtkKWMenu*);
426  virtual void PopulateContextMenuWithColorEntries(vtkKWMenu*);
427 
428  // Description:
429  // Update the render window interactor size
430  virtual void UpdateRenderWindowInteractorSize(int width, int height);
431 
432  // PIMPL Encapsulation for STL containers
433 
434  vtkKWRenderWidgetInternals *Internals;
435 
437 
438  // Description:
439  // Some constants
443 
444 private:
445  vtkKWRenderWidget(const vtkKWRenderWidget&); // Not implemented
446  void operator=(const vtkKWRenderWidget&); // Not implemented
447 };
448 
449 #endif
450