VTK  9.3.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 "vtkObject.h"
25 #include "vtkRenderingParallelModule.h" // For export macro
26 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
27 #include "vtkUnsignedCharArray.h" // needed for vtkUnsignedCharArray.
28 
29 VTK_ABI_NAMESPACE_BEGIN
30 class vtkFXAAOptions;
31 class vtkRenderer;
35 class vtkOpenGLRenderer;
36 
37 class VTKRENDERINGPARALLEL_EXPORT vtkSynchronizedRenderers : public vtkObject
38 {
39 public:
40  static vtkSynchronizedRenderers* New();
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
45 
51  virtual void SetRenderer(vtkRenderer*);
52  virtual vtkRenderer* GetRenderer();
54 
56 
60  virtual void SetParallelController(vtkMultiProcessController*);
61  vtkGetObjectMacro(ParallelController, vtkMultiProcessController);
63 
65 
69  vtkSetMacro(ParallelRendering, bool);
70  vtkGetMacro(ParallelRendering, bool);
71  vtkBooleanMacro(ParallelRendering, bool);
73 
75 
78  vtkSetClampMacro(ImageReductionFactor, int, 1, 50);
79  vtkGetMacro(ImageReductionFactor, int);
81 
83 
88  vtkSetMacro(WriteBackImages, bool);
89  vtkGetMacro(WriteBackImages, bool);
90  vtkBooleanMacro(WriteBackImages, bool);
92 
94 
99  vtkSetMacro(RootProcessId, int);
100  vtkGetMacro(RootProcessId, int);
102 
110  void CollectiveExpandForVisiblePropBounds(double bounds[6]);
111 
113 
117  virtual void SetCaptureDelegate(vtkSynchronizedRenderers*);
118  vtkGetObjectMacro(CaptureDelegate, vtkSynchronizedRenderers);
120 
122 
129  vtkSetMacro(AutomaticEventHandling, bool);
130  vtkGetMacro(AutomaticEventHandling, bool);
131  vtkBooleanMacro(AutomaticEventHandling, bool);
133 
135 
146  vtkSetMacro(FixBackground, bool);
147  vtkGetMacro(FixBackground, bool);
148  vtkBooleanMacro(FixBackground, bool);
150 
151  enum
152  {
153  SYNC_RENDERER_TAG = 15101,
154  RESET_CAMERA_TAG = 15102,
155  COMPUTE_BOUNDS_TAG = 15103
156  };
157 
160  struct VTKRENDERINGPARALLEL_EXPORT vtkRawImage
161  {
162  public:
164  {
165  this->Valid = false;
166  this->Size[0] = this->Size[1] = 0;
168  }
169 
170  void Resize(int dx, int dy, int numcomps)
171  {
172  this->Valid = false;
173  this->Allocate(dx, dy, numcomps);
174  }
175 
179  void Initialize(int dx, int dy, vtkUnsignedCharArray* data);
180 
181  void MarkValid() { this->Valid = true; }
182  void MarkInValid() { this->Valid = false; }
183 
184  bool IsValid() { return this->Valid; }
185  int GetWidth() { return this->Size[0]; }
186  int GetHeight() { return this->Size[1]; }
187  vtkUnsignedCharArray* GetRawPtr() { return this->Data; }
188 
196  bool PushToViewport(vtkRenderer* renderer, bool blend = true);
197 
205  bool PushToFrameBuffer(vtkRenderer* ren, bool blend = true);
206 
207  // Captures the image from the viewport.
208  // This doesn't trigger a render, just captures what's currently there in
209  // the active buffer.
210  bool Capture(vtkRenderer*);
211 
212  // Save the image as a png. Useful for debugging.
213  void SaveAsPNG(VTK_FILEPATH const char* filename);
214 
215  private:
216  bool Valid;
217  int Size[2];
219 
220  void Allocate(int dx, int dy, int numcomps);
221  };
222 
223 protected:
225  ~vtkSynchronizedRenderers() override;
226 
228  {
230  int Draw;
232  double Viewport[4];
233  double CameraPosition[3];
234  double CameraFocalPoint[3];
235  double CameraViewUp[3];
236  double CameraWindowCenter[2];
237  double CameraClippingRange[2];
240  double EyeTransformMatrix[16];
241  double ModelTransformMatrix[16];
242 
243  // Save/restore the struct to/from a stream.
244  void Save(vtkMultiProcessStream& stream);
245  bool Restore(vtkMultiProcessStream& stream);
246 
247  void CopyFrom(vtkRenderer*);
248  void CopyTo(vtkRenderer*);
249  };
250 
251  // These methods are called on all processes as a consequence of corresponding
252  // events being called on the renderer.
253  virtual void HandleStartRender();
254  virtual void HandleEndRender();
255  virtual void HandleAbortRender() {}
256 
257  virtual void MasterStartRender();
258  virtual void SlaveStartRender();
259 
260  virtual void MasterEndRender();
261  virtual void SlaveEndRender();
262 
265 
271  virtual vtkRawImage& CaptureRenderedImage();
272 
277  virtual void PushImageToScreen();
278 
281 
287 
288 private:
290  void operator=(const vtkSynchronizedRenderers&) = delete;
291 
292  class vtkObserver;
293  vtkObserver* Observer;
294  friend class vtkObserver;
295 
296  bool UseFXAA;
297  vtkOpenGLFXAAFilter* FXAAFilter;
298 
299  double LastViewport[4];
300 
301  double LastBackground[3];
302  double LastBackgroundAlpha;
303  bool LastTexturedBackground;
304  bool LastGradientBackground;
305  bool FixBackground;
306 };
307 
308 VTK_ABI_NAMESPACE_END
309 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:61
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.
Configuration for FXAA implementations.
Multiprocessing communication superclass.