VTK
vtkSynchronizedRenderers.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSynchronizedRenderers.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
33 #ifndef vtkSynchronizedRenderers_h
34 #define vtkSynchronizedRenderers_h
35 
36 #include "vtkRenderingParallelModule.h" // For export macro
37 #include "vtkObject.h"
38 #include "vtkUnsignedCharArray.h" // needed for vtkUnsignedCharArray.
39 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
40 
41 class vtkFXAAOptions;
42 class vtkRenderer;
46 class vtkOpenGLRenderer;
47 
48 class VTKRENDERINGPARALLEL_EXPORT vtkSynchronizedRenderers : public vtkObject
49 {
50 public:
51  static vtkSynchronizedRenderers* New();
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
56 
62  virtual void SetRenderer(vtkRenderer*);
63  virtual vtkRenderer* GetRenderer();
65 
67 
71  virtual void SetParallelController(vtkMultiProcessController*);
72  vtkGetObjectMacro(ParallelController, vtkMultiProcessController);
74 
76 
80  vtkSetMacro(ParallelRendering, bool);
81  vtkGetMacro(ParallelRendering, bool);
82  vtkBooleanMacro(ParallelRendering, bool);
84 
86 
89  vtkSetClampMacro(ImageReductionFactor, int, 1, 50);
90  vtkGetMacro(ImageReductionFactor, int);
92 
94 
99  vtkSetMacro(WriteBackImages, bool);
100  vtkGetMacro(WriteBackImages, bool);
101  vtkBooleanMacro(WriteBackImages, bool);
103 
105 
110  vtkSetMacro(RootProcessId, int);
111  vtkGetMacro(RootProcessId, int);
113 
121  void CollectiveExpandForVisiblePropBounds(double bounds[6]);
122 
124 
128  virtual void SetCaptureDelegate(vtkSynchronizedRenderers*);
129  vtkGetObjectMacro(CaptureDelegate, vtkSynchronizedRenderers);
131 
133 
140  vtkSetMacro(AutomaticEventHandling, bool);
141  vtkGetMacro(AutomaticEventHandling, bool);
142  vtkBooleanMacro(AutomaticEventHandling, bool);
144 
145  enum
146  {
147  SYNC_RENDERER_TAG = 15101,
148  RESET_CAMERA_TAG = 15102,
149  COMPUTE_BOUNDS_TAG = 15103
150  };
151 
154  struct VTKRENDERINGPARALLEL_EXPORT vtkRawImage
155  {
156  public:
158  {
159  this->Valid = false;
160  this->Size[0] = this->Size[1] = 0;
162  }
163 
164  void Resize(int dx, int dy, int numcomps)
165  {
166  this->Valid = false;
167  this->Allocate(dx, dy, numcomps);
168  }
169 
173  void Initialize(int dx, int dy, vtkUnsignedCharArray* data);
174 
175  void MarkValid() { this->Valid = true; }
176  void MarkInValid() { this->Valid = false; }
177 
178  bool IsValid() { return this->Valid; }
179  int GetWidth() { return this->Size[0];}
180  int GetHeight() { return this->Size[1];}
182  { return this->Data; }
183 
184  // Pushes the image to the viewport.
185  bool PushToViewport(vtkRenderer*);
186 
187  // This is a raw version of PushToViewport() that assumes that the
188  // glViewport() has already been setup externally.
189  // the argument is optional for backwards compat with old OpenGL
190  bool PushToFrameBuffer(vtkRenderer *ren = nullptr);
191 
192  // Captures the image from the viewport.
193  // This doesn't trigger a render, just captures what's currently there in
194  // the active buffer.
195  bool Capture(vtkRenderer*);
196 
197  // Save the image as a png. Useful for debugging.
198  void SaveAsPNG(const char* filename);
199 
200  private:
201  bool Valid;
202  int Size[2];
204 
205  void Allocate(int dx, int dy, int numcomps);
206  };
207 
208 protected:
210  ~vtkSynchronizedRenderers() override;
211 
213  {
215  int Draw;
217  double Viewport[4];
218  double CameraPosition[3];
219  double CameraFocalPoint[3];
220  double CameraViewUp[3];
221  double CameraWindowCenter[2];
222  double CameraClippingRange[2];
225  double EyeTransformMatrix[16];
226  double ModelTransformMatrix[16];
227 
228  // Save/restore the struct to/from a stream.
229  void Save(vtkMultiProcessStream& stream);
230  bool Restore(vtkMultiProcessStream& stream);
231 
232  void CopyFrom(vtkRenderer*);
233  void CopyTo(vtkRenderer*);
234  };
235 
236  // These methods are called on all processes as a consequence of corresponding
237  // events being called on the renderer.
238  virtual void HandleStartRender();
239  virtual void HandleEndRender();
240  virtual void HandleAbortRender() {}
241 
242  virtual void MasterStartRender();
243  virtual void SlaveStartRender();
244 
245  virtual void MasterEndRender();
246  virtual void SlaveEndRender();
247 
250 
258  virtual vtkRawImage& CaptureRenderedImage();
259 
265  virtual void PushImageToScreen();
266 
270 
276 
277 private:
279  void operator=(const vtkSynchronizedRenderers&) = delete;
280 
281  class vtkObserver;
282  vtkObserver* Observer;
283  friend class vtkObserver;
284 
285  bool UseFXAA;
286  vtkOpenGLFXAAFilter* FXAAFilter;
287 
288  double LastViewport[4];
289 };
290 
291 #endif
292 
abstract base class for most VTK objects
Definition: vtkObject.h:59
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:39
vtkMultiProcessController * ParallelController
dynamic, self-adjusting array of unsigned char
void Resize(int dx, int dy, int numcomps)
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.