VTK  9.7.1
vtkSynchronizedRenderers.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
21 #ifndef vtkSynchronizedRenderers_h
22 #define vtkSynchronizedRenderers_h
23 
24 #include "vtkIndependentViewerCollection.h" // needed for vtkIndependentViewerCollection
25 #include "vtkObject.h"
26 #include "vtkRenderingParallelModule.h" // For export macro
27 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
28 #include "vtkUnsignedCharArray.h" // needed for vtkUnsignedCharArray.
29 
30 #include <memory> // for std::unique_ptr
31 
32 VTK_ABI_NAMESPACE_BEGIN
33 class vtkFXAAOptions;
34 class vtkRenderer;
38 class vtkOpenGLRenderer;
39 
40 class VTKRENDERINGPARALLEL_EXPORT vtkSynchronizedRenderers : public vtkObject
41 {
42 public:
43  static vtkSynchronizedRenderers* New();
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
48 
54  virtual void SetRenderer(vtkRenderer*);
55  virtual vtkRenderer* GetRenderer();
57 
59 
64  vtkSetObjectMacro(IndependentViewers, vtkIndependentViewerCollection);
65  vtkGetObjectMacro(IndependentViewers, vtkIndependentViewerCollection);
67 
69 
73  virtual void SetParallelController(vtkMultiProcessController*);
74  vtkGetObjectMacro(ParallelController, vtkMultiProcessController);
76 
78 
82  vtkSetMacro(ParallelRendering, bool);
83  vtkGetMacro(ParallelRendering, bool);
84  vtkBooleanMacro(ParallelRendering, bool);
86 
88 
91  vtkSetClampMacro(ImageReductionFactor, int, 1, 50);
92  vtkGetMacro(ImageReductionFactor, int);
94 
96 
101  vtkSetMacro(WriteBackImages, bool);
102  vtkGetMacro(WriteBackImages, bool);
103  vtkBooleanMacro(WriteBackImages, bool);
105 
107 
112  vtkSetMacro(RootProcessId, int);
113  vtkGetMacro(RootProcessId, int);
115 
123  void CollectiveExpandForVisiblePropBounds(double bounds[6]);
124 
126 
130  virtual void SetCaptureDelegate(vtkSynchronizedRenderers*);
131  vtkGetObjectMacro(CaptureDelegate, vtkSynchronizedRenderers);
133 
135 
139  void EnableSynchronizableActors(bool);
141 
143 
150  vtkSetMacro(AutomaticEventHandling, bool);
151  vtkGetMacro(AutomaticEventHandling, bool);
152  vtkBooleanMacro(AutomaticEventHandling, bool);
154 
156 
167  vtkSetMacro(FixBackground, bool);
168  vtkGetMacro(FixBackground, bool);
169  vtkBooleanMacro(FixBackground, bool);
171 
172  enum
173  {
174  SYNC_RENDERER_TAG = 15101,
175  RESET_CAMERA_TAG = 15102,
176  COMPUTE_BOUNDS_TAG = 15103
177  };
178 
181  struct VTKRENDERINGPARALLEL_EXPORT vtkRawImage
182  {
183  public:
185  {
186  this->Valid = false;
187  this->Size[0] = this->Size[1] = 0;
189  }
190 
191  void Resize(int dx, int dy, int numcomps)
192  {
193  this->Valid = false;
194  this->Allocate(dx, dy, numcomps);
195  }
196 
200  void Initialize(int dx, int dy, vtkUnsignedCharArray* data);
201 
202  void MarkValid() { this->Valid = true; }
203  void MarkInValid() { this->Valid = false; }
204 
205  bool IsValid() { return this->Valid; }
206  int GetWidth() { return this->Size[0]; }
207  int GetHeight() { return this->Size[1]; }
208  vtkUnsignedCharArray* GetRawPtr() { return this->Data; }
209 
217  bool PushToViewport(vtkRenderer* renderer, bool blend = true);
218 
226  bool PushToFrameBuffer(vtkRenderer* ren, bool blend = true);
227 
228  // Captures the image from the viewport.
229  // This doesn't trigger a render, just captures what's currently there in
230  // the active buffer.
231  bool Capture(vtkRenderer*);
232 
233  // Save the image as a png. Useful for debugging.
234  void SaveAsPNG(VTK_FILEPATH const char* filename);
235 
236  private:
237  bool Valid;
238  int Size[2];
240 
241  void Allocate(int dx, int dy, int numcomps);
242  };
243 
244 protected:
246  ~vtkSynchronizedRenderers() override;
247 
249  {
251  int Draw;
253  double Viewport[4];
254  double CameraPosition[3];
255  double CameraFocalPoint[3];
256  double CameraViewUp[3];
257  double CameraWindowCenter[2];
258  double CameraClippingRange[2];
262  double EyeTransformMatrix[16];
263  double ModelTransformMatrix[16];
264 
265  // Save/restore the struct to/from a stream.
266  void Save(vtkMultiProcessStream& stream);
267  bool Restore(vtkMultiProcessStream& stream);
268 
269  void CopyFrom(vtkRenderer*);
270  void CopyTo(vtkRenderer*);
271  };
272 
273  // These methods are called on all processes as a consequence of corresponding
274  // events being called on the renderer.
275  virtual void HandleStartRender();
276  virtual void HandleEndRender();
277  virtual void HandleAbortRender() {}
278 
279  virtual void MasterStartRender();
280  virtual void SlaveStartRender();
281 
282  virtual void MasterEndRender();
283  virtual void SlaveEndRender();
284 
287  vtkIndependentViewerCollection* IndependentViewers = nullptr;
288 
294  virtual vtkRawImage& CaptureRenderedImage();
295 
300  virtual void PushImageToScreen();
301 
304 
310 
311 private:
313  void operator=(const vtkSynchronizedRenderers&) = delete;
314 
315  class vtkObserver;
316  vtkObserver* Observer;
317  friend class vtkObserver;
318 
319  bool UseFXAA;
320  vtkOpenGLFXAAFilter* FXAAFilter;
321 
322  double LastViewport[4];
323 
324  double LastBackground[3];
325  double LastBackgroundAlpha;
326  bool LastTexturedBackground;
327  bool LastGradientBackground;
328  bool FixBackground;
329 
330  class vtkInternals;
331  std::unique_ptr<vtkInternals> Internal;
332 };
333 
334 VTK_ABI_NAMESPACE_END
335 #endif
Store data for independent viewers.
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
stream used to pass data across processes using vtkMultiProcessController.
vtkSynchronizedRenderers * CaptureDelegate
abstract specification for renderers
Definition: vtkRenderer.h:63
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
vtkRawImage can be used to make it easier to deal with images for compositing/communicating over clie...
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkMultiProcessController * ParallelController
dynamic, self-adjusting array of unsigned char
void Resize(int dx, int dy, int numcomps)
#define VTK_FILEPATH
synchronizes renderers across processes.
Perform FXAA antialiasing on the current framebuffer.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
OpenGL renderer.
Cell is in a good state.
Configuration for FXAA implementations.
Multiprocessing communication superclass.