KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWRenderWidget.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 vtkKWRenderWidget - a render widget 00015 // .SECTION Description 00016 // This class encapsulates a render window, a renderer and several other 00017 // objects inside a single widget. Actors and props can be added, 00018 // annotations can be set. 00019 // .WARNING 00020 // This widget set the camera to be in parallel projection mode. 00021 // You can change this default (after Create()) by calling: 00022 // renderwidget->GetRenderer()->GetActiveCamera()->ParallelProjectionOff(); 00023 00024 #ifndef __vtkKWRenderWidget_h 00025 #define __vtkKWRenderWidget_h 00026 00027 #include "vtkKWCompositeWidget.h" 00028 #include "vtkWindows.h" // needed for RECT HDC 00029 00030 class vtkCamera; 00031 class vtkCornerAnnotation; 00032 class vtkProp; 00033 class vtkRenderWindow; 00034 class vtkRenderer; 00035 class vtkTextActor; 00036 class vtkKWMenu; 00037 class vtkKWRenderWidgetInternals; 00038 class vtkRenderWindowInteractor; 00039 00040 class KWWidgets_EXPORT vtkKWRenderWidget : public vtkKWCompositeWidget 00041 { 00042 public: 00043 static vtkKWRenderWidget* New(); 00044 vtkTypeRevisionMacro(vtkKWRenderWidget, vtkKWCompositeWidget); 00045 void PrintSelf(ostream& os, vtkIndent indent); 00046 00047 // Description: 00048 // Close the widget. 00049 // This method brings the widget back to an empty/clean state. 00050 // It removes all the actors/props, removes the bindings, resets the 00051 // annotations, etc. 00052 virtual void Close(); 00053 00054 // Description: 00055 // Render the scene. 00056 virtual void Render(); 00057 00058 // Description: 00059 // Enable/disable rendering. 00060 vtkGetMacro(RenderState, int); 00061 vtkSetClampMacro(RenderState, int, 0, 1); 00062 vtkBooleanMacro(RenderState, int); 00063 00064 // Description: 00065 // Set/Get the rendering mode. 00066 //BTX 00067 enum 00068 { 00069 InteractiveRender = 0, 00070 StillRender = 1, 00071 DisabledRender = 2, 00072 SingleRender = 3 00073 }; 00074 //ETX 00075 vtkSetClampMacro(RenderMode, int, 00076 vtkKWRenderWidget::InteractiveRender, 00077 vtkKWRenderWidget::SingleRender); 00078 vtkGetMacro(RenderMode, int); 00079 virtual void SetRenderModeToInteractive() 00080 { this->SetRenderMode(vtkKWRenderWidget::InteractiveRender); }; 00081 virtual void SetRenderModeToStill() 00082 { this->SetRenderMode(vtkKWRenderWidget::StillRender); }; 00083 virtual void SetRenderModeToSingle() 00084 { this->SetRenderMode(vtkKWRenderWidget::SingleRender); }; 00085 virtual void SetRenderModeToDisabled() 00086 { this->SetRenderMode(vtkKWRenderWidget::DisabledRender); }; 00087 00088 // Description: 00089 // Set/Get the collapsing of renders. If this is set to true, then 00090 // all call to Render() will be collapsed. Once this is set to false, if 00091 // there are any pending render requests, the widget will render. 00092 virtual void SetCollapsingRenders(int); 00093 vtkBooleanMacro(CollapsingRenders, int); 00094 vtkGetMacro(CollapsingRenders, int); 00095 00096 // Description: 00097 // Reset the widget. 00098 // This implementation calls ResetCamera() and Render(). 00099 virtual void Reset(); 00100 00101 // Description: 00102 // Reset the camera to display all the actors in the scene, or just 00103 // the camera clipping range. 00104 // This is done for each renderer (if multiple renderers are supported). 00105 // Note that no default renderers exist before Create() is called. 00106 virtual void ResetCamera(); 00107 virtual void ResetCameraClippingRange(); 00108 00109 // Description: 00110 // Add/remove the widget bindings. 00111 // The AddBindings() method sets up general bindings like the Expose or 00112 // Configure events so that the scene is rendered properly when the widget 00113 // is mapped to the screen. It also calls the AddInteractionBindings() 00114 // which sets up interaction bindings like mouse events, keyboard events, 00115 // etc. The AddBindings() method is called automatically when the widget 00116 // is created by the Create() method. Yet, the methods are public so 00117 // that one can temporarily enable or disable the bindings to limit 00118 // the interaction with this widget. 00119 virtual void AddBindings(); 00120 virtual void RemoveBindings(); 00121 virtual void AddInteractionBindings(); 00122 virtual void RemoveInteractionBindings(); 00123 00124 // Description: 00125 // Convenience method to set the visibility of all annotations. 00126 // Subclasses should override this method to propagate this visibility 00127 // flag to their own annotations. 00128 virtual void SetAnnotationsVisibility(int v); 00129 vtkBooleanMacro(AnnotationsVisibility, int); 00130 00131 // Description: 00132 // Get and control the corner annotation. Turn SupportCornerAnnotation 00133 // to off (on by default) if this widget should not support any corner 00134 // annotation (i.e. never display it, and do not populate the annotation 00135 // context menu with the corresponding entry). 00136 virtual void SetCornerAnnotationVisibility(int v); 00137 virtual int GetCornerAnnotationVisibility(); 00138 virtual void ToggleCornerAnnotationVisibility(); 00139 vtkBooleanMacro(CornerAnnotationVisibility, int); 00140 virtual void SetCornerAnnotationColor(double r, double g, double b); 00141 virtual void SetCornerAnnotationColor(double *rgb) 00142 { this->SetCornerAnnotationColor(rgb[0], rgb[1], rgb[2]); }; 00143 virtual double* GetCornerAnnotationColor(); 00144 vtkGetObjectMacro(CornerAnnotation, vtkCornerAnnotation); 00145 vtkGetMacro(SupportCornerAnnotation, int); 00146 virtual void SetSupportCornerAnnotation(int); 00147 vtkBooleanMacro(SupportCornerAnnotation, int); 00148 00149 // Description: 00150 // Get and control the header annotation. 00151 virtual void SetHeaderAnnotationVisibility(int v); 00152 virtual int GetHeaderAnnotationVisibility(); 00153 virtual void ToggleHeaderAnnotationVisibility(); 00154 vtkBooleanMacro(HeaderAnnotationVisibility, int); 00155 virtual void SetHeaderAnnotationColor(double r, double g, double b); 00156 virtual void SetHeaderAnnotationColor(double *rgb) 00157 { this->SetHeaderAnnotationColor(rgb[0], rgb[1], rgb[2]); }; 00158 virtual double* GetHeaderAnnotationColor(); 00159 virtual void SetHeaderAnnotationText(const char*); 00160 virtual char* GetHeaderAnnotationText(); 00161 vtkGetObjectMacro(HeaderAnnotation, vtkTextActor); 00162 00163 // Description: 00164 // Set/Get the distance units that pixel sizes are measured in 00165 virtual void SetDistanceUnits(const char*); 00166 vtkGetStringMacro(DistanceUnits); 00167 00168 // Description: 00169 // Get the render window, get the renderwindow interactor 00170 vtkGetObjectMacro(RenderWindow, vtkRenderWindow); 00171 virtual vtkRenderWindowInteractor* GetRenderWindowInteractor(); 00172 00173 // Description: 00174 // Get the VTK widget 00175 vtkGetObjectMacro(VTKWidget, vtkKWCoreWidget); 00176 00177 // Description: 00178 // If the widget supports multiple renderers: 00179 // GetNthRenderer() gets the Nth renderer (or NULL if it does not exist), 00180 // GetRendererIndex() gets the id of a given renderer (or -1 if this renderer 00181 // does not belong to this widget), i.e. its index/position in the list 00182 // of renderers. AddRenderer() will add a renderer, RemoveAllRenderers will 00183 // remove all renderers. 00184 // Note that no default renderers exist before Create() is called. 00185 virtual vtkRenderer* GetRenderer() { return this->GetNthRenderer(0); } 00186 virtual vtkRenderer* GetNthRenderer(int index); 00187 virtual int GetNumberOfRenderers(); 00188 virtual int GetRendererIndex(vtkRenderer*); 00189 virtual void AddRenderer(vtkRenderer*); 00190 virtual void RemoveRenderer(vtkRenderer*); 00191 virtual void RemoveNthRenderer(int index); 00192 virtual void RemoveAllRenderers(); 00193 00194 // Description: 00195 // Get the overlay renderer. 00196 // Note that no default overlay renderer exist before Create() is called. 00197 virtual vtkRenderer* GetOverlayRenderer() 00198 { return this->GetNthOverlayRenderer(0); } 00199 virtual vtkRenderer* GetNthOverlayRenderer(int index); 00200 virtual int GetNumberOfOverlayRenderers(); 00201 virtual int GetOverlayRendererIndex(vtkRenderer*); 00202 virtual void AddOverlayRenderer(vtkRenderer*); 00203 virtual void RemoveOverlayRenderer(vtkRenderer*); 00204 virtual void RemoveNthOverlayRenderer(int index); 00205 virtual void RemoveAllOverlayRenderers(); 00206 00207 // Description: 00208 // Set the backgrounds color of the renderer(s) (not the overlay ones). 00209 // Note that no default renderers exist before Create() is called. 00210 virtual void GetRendererBackgroundColor(double *r, double *g, double *b); 00211 virtual void SetRendererBackgroundColor(double r, double g, double b); 00212 virtual void SetRendererBackgroundColor(double rgb[3]) 00213 { this->SetRendererBackgroundColor(rgb[0], rgb[1], rgb[2]); }; 00214 virtual void GetRendererBackgroundColor2(double *r, double *g, double *b); 00215 virtual void SetRendererBackgroundColor2(double r, double g, double b); 00216 virtual void SetRendererBackgroundColor2(double rgb[3]) 00217 { this->SetRendererBackgroundColor2(rgb[0], rgb[1], rgb[2]); }; 00218 virtual void SetRendererGradientBackground(int); 00219 virtual int GetRendererGradientBackground(); 00220 virtual void ToggleRendererGradientBackground(); 00221 00222 // Description: 00223 // Add props (actors) to *all* widget renderer(s) or *all* overlay 00224 // renderer(s), or to specific ones. 00225 // Note that no default renderers exist before Create() is called. 00226 virtual void AddViewProp(vtkProp *prop); 00227 virtual void AddViewPropToNthRenderer(vtkProp *p, int index); 00228 virtual void AddOverlayViewProp(vtkProp *prop); 00229 virtual void AddViewPropToNthOverlayRenderer(vtkProp *p, int index); 00230 00231 // Description: 00232 // Query/remove props (actors) from both renderer(s) and overlay renderer(s). 00233 virtual int HasViewProp(vtkProp *prop); 00234 virtual void RemoveViewProp(vtkProp *prop); 00235 virtual void RemoveAllViewProps(); 00236 00237 // Description: 00238 // The ComputeVisiblePropBounds() method returns the bounds of the 00239 // visible props for a renderer (given its index). By default, it is just 00240 // a call to vtkRenderer::ComputeVisiblePropBounds(). 00241 virtual void ComputeVisiblePropBounds(int index, double bounds[6]); 00242 00243 // Description: 00244 // Set/Get the printing flag (i.e., are we printing?) 00245 virtual void SetPrinting(int arg); 00246 vtkBooleanMacro(Printing, int); 00247 vtkGetMacro(Printing, int); 00248 00249 // Description: 00250 // Set/Get offscreen rendering flag (e.g., for screenshots) 00251 vtkBooleanMacro(OffScreenRendering, int); 00252 virtual void SetOffScreenRendering(int); 00253 virtual int GetOffScreenRendering(); 00254 00255 // Description: 00256 // Use a context menu. It is posted by a right click, and allows 00257 // properties and mode to be controlled. 00258 vtkSetMacro(UseContextMenu, int); 00259 vtkGetMacro(UseContextMenu, int); 00260 vtkBooleanMacro(UseContextMenu, int); 00261 00262 // Description: 00263 // Update the "enable" state of the object and its internal parts. 00264 // Depending on different Ivars (this->Enabled, the application's 00265 // Limited Edition Mode, etc.), the "enable" state of the object is updated 00266 // and propagated to its internal parts/subwidgets. This will, for example, 00267 // enable/disable parts of the widget UI, enable/disable the visibility 00268 // of 3D widgets, etc. 00269 virtual void UpdateEnableState(); 00270 00271 // Description: 00272 // Overridden for debugging purposes. This class is usually the center of the 00273 // whole "a vtkTkRenderWidget is being destroyed before its render window" 00274 // problem. 00275 virtual void Register(vtkObjectBase* o); 00276 virtual void UnRegister(vtkObjectBase* o); 00277 00278 // Description: 00279 // Setup print parameters 00280 #if defined(_WIN32) && !defined(__CYGWIN__) 00281 virtual void SetupPrint(RECT &rcDest, HDC ghdc, 00282 int printerPageSizeX, int printerPageSizeY, 00283 int printerDPIX, int printerDPIY, 00284 float scaleX, float scaleY, 00285 int screenSizeX, int screenSizeY); 00286 #endif 00287 00288 // Description: 00289 // Get memory device context (when rendering to memory) 00290 virtual void* GetMemoryDC(); 00291 00292 // Description: 00293 // Add all the default observers needed by that object, or remove 00294 // all the observers that were added through AddCallbackCommandObserver. 00295 // Subclasses can override these methods to add/remove their own default 00296 // observers, but should call the superclass too. 00297 virtual void AddCallbackCommandObservers(); 00298 virtual void RemoveCallbackCommandObservers(); 00299 00300 // Description: 00301 // Callbacks. Internal, do not use. 00302 virtual void MouseMoveCallback( 00303 int num, int x, int y, int ctrl, int shift, int alt); 00304 virtual void MouseWheelCallback( 00305 int delta, int ctrl, int shift, int alt); 00306 virtual void MouseButtonPressCallback( 00307 int num, int x, int y, int ctrl, int shift, int alt, int repeat); 00308 virtual void MouseButtonReleaseCallback( 00309 int num, int x, int y, int ctrl, int shift, int alt); 00310 virtual void KeyPressCallback( 00311 char key, int x, int y, int ctrl, int shift, int alt, char *keysym); 00312 virtual void KeyReleaseCallback( 00313 char key, int x, int y, int ctrl, int shift, int alt, char *keysym); 00314 virtual void ConfigureCallback(int width, int height); 00315 virtual void ExposeCallback(); 00316 virtual void EnterCallback(int x, int y); 00317 virtual void LeaveCallback(int x, int y); 00318 virtual void FocusInCallback(); 00319 virtual void FocusOutCallback(); 00320 virtual int RendererBackgroundColorCallback(); 00321 virtual int RendererBackgroundColor2Callback(); 00322 virtual void RendererGradientBackgroundCallback(); 00323 00324 // Description: 00325 // Event list 00326 //BTX 00327 enum 00328 { 00329 CornerAnnotationVisibilityChangedEvent = 24000, 00330 RendererGradientBackgroundChangedEvent, 00331 RendererBackgroundColorChangedEvent, 00332 RendererBackgroundColor2ChangedEvent 00333 }; 00334 //ETX 00335 00336 // Description: 00337 // Some constants 00338 vtkGetStringMacro(RendererBackgroundColorRegKey); 00339 vtkSetStringMacro(RendererBackgroundColorRegKey); 00340 vtkGetStringMacro(RendererBackgroundColor2RegKey); 00341 vtkSetStringMacro(RendererBackgroundColor2RegKey); 00342 vtkGetStringMacro(RendererGradientBackgroundRegKey); 00343 vtkSetStringMacro(RendererGradientBackgroundRegKey); 00344 00345 protected: 00346 vtkKWRenderWidget(); 00347 ~vtkKWRenderWidget(); 00348 00349 // Description: 00350 // Create the widget. 00351 virtual void CreateWidget(); 00352 00353 vtkKWCoreWidget *VTKWidget; 00354 vtkRenderWindow *RenderWindow; 00355 vtkCornerAnnotation *CornerAnnotation; 00356 vtkTextActor *HeaderAnnotation; 00357 00358 int RenderMode; 00359 int PreviousRenderMode; 00360 int InExpose; 00361 int RenderState; 00362 int Printing; 00363 00364 char *DistanceUnits; 00365 00366 int CollapsingRenders; 00367 int CollapsingRendersCount; 00368 00369 // Description: 00370 // Create the default renderers inside the render window. 00371 // Superclass can override to create different renderers. 00372 // It is called by Create(). 00373 virtual void CreateDefaultRenderers(); 00374 00375 // Description: 00376 // Install the renderers inside the render window. 00377 // Superclass can override to install them in a different layout. 00378 // It is called by Create(). 00379 virtual void InstallRenderers(); 00380 00381 // Description: 00382 // Set the renderers default values (say, default background colors). 00383 virtual void SetRenderersDefaultValues(); 00384 00385 // Description: 00386 // Update the widget according to the units. 00387 // Should be called when any units-related ivar has changed. 00388 virtual void UpdateAccordingToUnits() {}; 00389 00390 // Description: 00391 // Setup memory rendering 00392 virtual void SetupMemoryRendering(int width, int height, void *cd); 00393 virtual void ResumeScreenRendering(); 00394 00395 // Description: 00396 // Processes the events that are passed through CallbackCommand (or others). 00397 // Subclasses can oberride this method to process their own events, but 00398 // should call the superclass too. 00399 virtual void ProcessCallbackCommandEvents( 00400 vtkObject *caller, unsigned long event, void *calldata); 00401 00402 // Context menu 00403 00404 int UseContextMenu; 00405 vtkKWMenu *ContextMenu; 00406 00407 // Description: 00408 // Populate the context menu that pops up when the user right-clicks on 00409 // the render area. 00410 // Superclass should override this method to populate this 00411 // menu with the commands they feel comfortable exposing to the user. 00412 // This implementation is actually split into several methods to help 00413 // organizing the menu into several categories. It calls, in that order: 00414 // - PopulateContextMenuWithInteractionEntries(): interaction mode 00415 // - PopulateContextMenuWithAnnotationEntries(): annotations, 2d text 00416 // - PopulateContextMenuWithOptionEntries(): misc. options 00417 // - PopulateContextMenuWithCameraEntries(): camera, change viewpoints 00418 // - PopulateContextMenuWithColorEntries(): background color, etc. 00419 // Each method is passed a pointer to the context menu. 00420 // A menu separator is added automatically between each non-empty section. 00421 virtual void PopulateContextMenu(vtkKWMenu*); 00422 virtual void PopulateContextMenuWithInteractionEntries(vtkKWMenu*) {}; 00423 virtual void PopulateContextMenuWithAnnotationEntries(vtkKWMenu*); 00424 virtual void PopulateContextMenuWithOptionEntries(vtkKWMenu*) {}; 00425 virtual void PopulateContextMenuWithCameraEntries(vtkKWMenu*); 00426 virtual void PopulateContextMenuWithColorEntries(vtkKWMenu*); 00427 00428 // Description: 00429 // Update the render window interactor size 00430 virtual void UpdateRenderWindowInteractorSize(int width, int height); 00431 00432 // PIMPL Encapsulation for STL containers 00433 00434 vtkKWRenderWidgetInternals *Internals; 00435 00436 int SupportCornerAnnotation; 00437 00438 // Description: 00439 // Some constants 00440 char *RendererBackgroundColorRegKey; 00441 char *RendererBackgroundColor2RegKey; 00442 char *RendererGradientBackgroundRegKey; 00443 00444 private: 00445 vtkKWRenderWidget(const vtkKWRenderWidget&); // Not implemented 00446 void operator=(const vtkKWRenderWidget&); // Not implemented 00447 }; 00448 00449 #endif 00450