vtkSMViewProxy.h 11.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMViewProxy.h

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * @class   vtkSMViewProxy
 * @brief   Superclass for all view proxies.
 *
 * vtkSMViewProxy is a superclass for all view proxies. A view proxy
 * abstracts the logic to take one or more representation proxies and show then
 * in some viewport such as vtkRenderWindow.
 * This class may directly be used as the view proxy for views that do all the
 * rendering work at the GUI level. The VTKObject corresponding to this class
 * has to be a vtkView subclass.
 * @par Events:
 * \li vtkCommand::StartEvent(callData: int:0) -- start of StillRender().
 * \li vtkCommand::EndEvent(callData: int:0) -- end of StillRender().
 * \li vtkCommand::StartEvent(callData: int:1) -- start of InteractiveRender().
 * \li vtkCommand::EndEvent(callData: int:1) -- end of InteractiveRender().
*/
31

32 33
#ifndef vtkSMViewProxy_h
#define vtkSMViewProxy_h
34

35
#include "vtkPVServerManagerRenderingModule.h" //needed for exports
36 37
#include "vtkSMProxy.h"

38
class vtkImageData;
39
class vtkRenderer;
40
class vtkRenderWindow;
41
class vtkRenderWindowInteractor;
42
class vtkSMRepresentationProxy;
43
class vtkSMSourceProxy;
44
class vtkView;
45

46 47 48 49 50
namespace vtkSMViewProxyNS
{
class WindowToImageFilter;
}

51
class VTKPVSERVERMANAGERRENDERING_EXPORT vtkSMViewProxy : public vtkSMProxy
52 53 54
{
public:
  static vtkSMViewProxy* New();
55
  vtkTypeMacro(vtkSMViewProxy, vtkSMProxy);
56
  void PrintSelf(ostream& os, vtkIndent indent) override;
57

58 59 60 61
  //@{
  /**
   * Enable/Disable a view.
   */
62 63 64
  vtkSetMacro(Enable, bool);
  vtkGetMacro(Enable, bool);
  vtkBooleanMacro(Enable, bool);
65
  //@}
66

67 68 69
  /**
   * Renders the view using full resolution.
   */
70
  virtual void StillRender();
71

72 73 74
  /**
   * Renders the view using lower resolution is possible.
   */
75
  virtual void InteractiveRender();
76

77 78 79
  /**
   * Called vtkPVView::Update on the server-side.
   */
80
  virtual void Update();
81

82 83 84 85 86
  /**
   * Returns true if the view can display the data produced by the producer's
   * port. Internally calls GetRepresentationType() and returns true only if the
   * type is valid a representation proxy of that type can be created.
   */
87 88
  virtual bool CanDisplayData(vtkSMSourceProxy* producer, int outputPort);

89 90 91 92 93 94 95 96
  /**
   * Create a default representation for the given source proxy.
   * Returns a new proxy.
   * In version 4.1 and earlier, subclasses overrode this method. Since 4.2, the
   * preferred way is to simply override GetRepresentationType(). That
   * ensures that CreateDefaultRepresentation() and CanDisplayData() both
   * work as expected.
   */
Kitware Robot's avatar
Kitware Robot committed
97
  virtual vtkSMRepresentationProxy* CreateDefaultRepresentation(vtkSMProxy*, int);
98

99 100 101 102 103 104 105 106 107
  /**
   * Returns the xml name of the representation proxy to create to show the data
   * produced in this view, if any. Default implementation checks if the
   * producer has any "Hints" that define the representation to create in this
   * view and if so, returns that.
   * Or if this->DefaultRepresentationName is set and its Input property
   * can accept the data produced, returns this->DefaultRepresentationName.
   * Subclasses should override this method.
   */
Kitware Robot's avatar
Kitware Robot committed
108
  virtual const char* GetRepresentationType(vtkSMSourceProxy* producer, int outputPort);
109

110 111 112 113
  /**
   * Finds the representation proxy showing the data produced by the provided
   * producer, if any. Note the representation may not necessarily be visible.
   */
114 115
  virtual vtkSMRepresentationProxy* FindRepresentation(vtkSMSourceProxy* producer, int outputPort);

116
  //@{
117 118 119 120 121
  /**
   * Captures a image from this view. Default implementation returns NULL.
   * Subclasses should override CaptureWindowInternal() to do the actual image
   * capture.
   */
122 123 124 125 126 127
  vtkImageData* CaptureWindow(int magnification)
  {
    return this->CaptureWindow(magnification, magnification);
  }
  vtkImageData* CaptureWindow(int magnificationX, int magnificationY);
  //@}
128 129 130
  /**
   * Returns the client-side vtkView, if any.
   */
131
  vtkView* GetClientSideView();
132

133 134 135 136
  /**
   * Saves a screenshot of the view to disk. The writerName argument specifies
   * the vtkImageWriter subclass to use.
   */
Kitware Robot's avatar
Kitware Robot committed
137
  int WriteImage(const char* filename, const char* writerName, int magnification = 1);
138 139
  int WriteImage(
    const char* filename, const char* writerName, int magnificationX, int magnificationY);
140

141
  /**
luz paz's avatar
luz paz committed
142
   * Return true any internal representation is dirty. This can be useful to
143 144 145
   * know if the internal geometry has changed.
   * DEPRECATED: Use GetNeedsUpdate() instead.
   */
146 147
  virtual bool HasDirtyRepresentation() { return this->GetNeedsUpdate(); }

148 149 150 151 152 153
  //@{
  /**
   * Returns true if the subsequent call to Update() will result in an actual
   * update. If returned true, it means that the view thinks its rendering is
   * obsolete and needs to be re-generated.
   */
154
  vtkGetMacro(NeedsUpdate, bool);
155 156 157 158 159 160 161 162 163 164
  //@}

  /**
   * Return the vtkRenderWindow used by this view, if any. Note, views like
   * vtkSMComparativeViewProxy can have more than 1 render window in play, in
   * which case, using this method alone may yield incorrect results. Also,
   * certain views don't use a vtkRenderWindow at all (e.g. Spreadsheet View),
   * in which case, this method will return NULL. Default implementation returns
   * NULL.
   */
165
  virtual vtkRenderWindow* GetRenderWindow() { return NULL; }
166

167 168 169 170 171
  /**
   * Returns the interactor. Note, that views may not use vtkRenderWindow at all
   * in which case they will not have any interactor and will return NULL.
   * Default implementation returns NULL.
   */
172 173
  virtual vtkRenderWindowInteractor* GetInteractor() { return NULL; }

174 175 176 177 178 179 180 181 182
  /**
   * A client process need to set the interactor to enable interactivity. Use
   * this method to set the interactor and initialize it as needed by the
   * RenderView. This include changing the interactor style as well as
   * overriding VTK rendering to use the Proxy/ViewProxy API instead.
   * Default implementation does nothing. Views that support interaction using
   * vtkRenderWindowInteractor should override this method to set the interactor
   * up.
   */
Kitware Robot's avatar
Kitware Robot committed
183
  virtual void SetupInteractor(vtkRenderWindowInteractor* iren) { (void)iren; }
184

185 186 187 188 189 190 191
  /**
   * Creates a default render window interactor for the vtkRenderWindow and sets
   * it up on the local process if the local process supports interaction. This
   * should not be used when putting the render window in a QVTKWidget as that
   * may cause issues. One should let the QVTKWidget create the interactor and
   * then call SetupInteractor().
   */
Kitware Robot's avatar
Kitware Robot committed
192
  virtual bool MakeRenderWindowInteractor(bool quiet = false);
193

194 195 196 197
  //@{
  /**
   * Sets whether screenshots have a transparent background.
   */
198
  static void SetTransparentBackground(bool val);
199
  static bool GetTransparentBackground();
200 201 202 203 204
  //@}

  //@{
  /**
   * Method used to hide other representations if the view has a
205
   * `<ShowOneRepresentationAtATime/>` hint.
206 207
   * This only affects other representations that have data inputs, not non-data
   * representations.
208 209 210
   *
   * @returns true if any representations were hidden by this call, otherwise
   *         returns false.
211
   */
212 213
  virtual bool HideOtherRepresentationsIfNeeded(vtkSMProxy* repr);
  static bool HideOtherRepresentationsIfNeeded(vtkSMViewProxy* self, vtkSMProxy* repr)
Kitware Robot's avatar
Kitware Robot committed
214 215 216
  {
    return self ? self->HideOtherRepresentationsIfNeeded(repr) : false;
  }
217
  //@}
218

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
  //@{
  /**
   * Certain views maintain properties (or other state) that should be updated
   * when visibility of representations is changed e.g. SpreadSheetView needs to
   * update the value of the "FieldAssociation" when a new data representation
   * is being shown in the view. Subclasses can override this method to perform
   * such updates to View properties. This is called explicitly by the
   * `vtkSMParaViewPipelineControllerWithRendering` after changing
   * representation visibility. Changes to representation visibility outside of
   * `vtkSMParaViewPipelineControllerWithRendering` will require calling this
   * method explicitly.
   *
   * Default implementation does not do anything.
   */
  virtual void RepresentationVisibilityChanged(vtkSMProxy* repr, bool new_visibility);
  static void RepresentationVisibilityChanged(
    vtkSMViewProxy* self, vtkSMProxy* repr, bool new_visibility)
  {
    if (self)
    {
      self->RepresentationVisibilityChanged(repr, new_visibility);
    }
  }
  //@}
243 244
protected:
  vtkSMViewProxy();
245
  ~vtkSMViewProxy() override;
246

247
  /**
248 249 250 251
   * Capture an image from the view's render window. Default implementation
   * simply captures the image from the render window for the view. Subclasses
   * may override this for cases where that's not sufficient.
   *
252 253
   * @param[in] magnificationX The X magnification factor to use for generating the image.
   * @param[in] magnificationY The Y magnification factor to use for generating the image.
254 255 256
   * @returns A new vtkImageData instance or nullptr. Caller is responsible for
   *          calling `vtkImageData::Delete()` on the returned non-null value.
   */
257
  virtual vtkImageData* CaptureWindowInternal(int magnificationX, int magnificationY);
258 259 260 261

  /**
   * This method is called whenever the view wants to render to during image
   * capture. The default implementation simply calls this->StillRender().
262
   */
263
  virtual void RenderForImageCapture() { this->StillRender(); }
264

Kitware Robot's avatar
Kitware Robot committed
265
  virtual vtkTypeUInt32 PreRender(bool vtkNotUsed(interactive)) { return this->GetLocation(); }
266
  virtual void PostRender(bool vtkNotUsed(interactive)) {}
267

268 269 270 271 272 273 274 275 276
  /**
   * Subclasses should override this method and return false if the rendering
   * context is not ready for rendering at this moment. This method is called in
   * StillRender() and InteractiveRender() calls before the actual render to
   * ensure that we don't attempt to render when the rendering context is not
   * ready.
   * Default implementation uses this->GetRenderWindow() and checks if that
   * window is drawable.
   */
277 278
  virtual bool IsContextReadyForRendering();

279 280 281
  /**
   * Called at the end of CreateVTKObjects().
   */
282
  void CreateVTKObjects() override;
283

284 285 286
  /**
   * Read attributes from an XML element.
   */
287
  int ReadXMLAttributes(vtkSMSessionProxyManager* pm, vtkPVXMLElement* element) override;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
288

289 290 291 292
  /**
   * Convenience method to call
   * vtkPVView::SafeDownCast(this->GetClientSideObject())->GetLocalProcessSupportsInteraction();
   */
293 294
  bool GetLocalProcessSupportsInteraction();

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
295 296
  vtkSetStringMacro(DefaultRepresentationName);
  char* DefaultRepresentationName;
297

298
  bool Enable;
299

300
private:
301 302
  vtkSMViewProxy(const vtkSMViewProxy&) = delete;
  void operator=(const vtkSMViewProxy&) = delete;
303

304 305
  static bool TransparentBackground;

306 307 308 309
  // When view's time changes, there's no way for the client-side proxies to
  // know that they may re-execute and their data info is invalid. So mark those
  // dirty explicitly.
  void ViewTimeChanged();
310 311

  // Actual logic for taking a screenshot.
312
  vtkImageData* CaptureWindowSingle(int magnificationX, int magnificationY);
313 314 315
  class vtkRendererSaveInfo;
  vtkRendererSaveInfo* PrepareRendererBackground(vtkRenderer*, double, double, double, bool);
  void RestoreRendererBackground(vtkRenderer*, vtkRendererSaveInfo*);
316 317

  friend class vtkSMViewProxyNS::WindowToImageFilter;
318 319 320
};

#endif