VTK
vtkSynchronizedRenderers.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: $RCSfile$
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 =========================================================================*/
32 #ifndef __vtkSynchronizedRenderers_h
33 #define __vtkSynchronizedRenderers_h
34 
35 #include "vtkObject.h"
36 #include "vtkUnsignedCharArray.h" // needed for vtkUnsignedCharArray.
37 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
38 
39 class vtkRenderer;
42 
44 {
45 public:
46  static vtkSynchronizedRenderers* New();
48  void PrintSelf(ostream& os, vtkIndent indent);
49 
51 
55  virtual void SetRenderer(vtkRenderer*);
56  vtkGetObjectMacro(Renderer, vtkRenderer);
58 
60 
62  virtual void SetParallelController(vtkMultiProcessController*);
63  vtkGetObjectMacro(ParallelController, vtkMultiProcessController);
65 
67 
69  vtkSetMacro(ParallelRendering, bool);
70  vtkGetMacro(ParallelRendering, bool);
71  vtkBooleanMacro(ParallelRendering, bool);
73 
75 
76  vtkSetClampMacro(ImageReductionFactor, int, 1, 50);
77  vtkGetMacro(ImageReductionFactor, int);
79 
81 
84  vtkSetMacro(WriteBackImages, bool);
85  vtkGetMacro(WriteBackImages, bool);
86  vtkBooleanMacro(WriteBackImages, bool);
88 
90 
94  vtkSetMacro(RootProcessId, int);
95  vtkGetMacro(RootProcessId, int);
97 
103  void CollectiveExpandForVisiblePropBounds(double bounds[6]);
104 
106 
108  virtual void SetCaptureDelegate(vtkSynchronizedRenderers*);
109  vtkGetObjectMacro(CaptureDelegate, vtkSynchronizedRenderers);
111 
113 
119  vtkSetMacro(AutomaticEventHandling, bool);
120  vtkGetMacro(AutomaticEventHandling, bool);
121  vtkBooleanMacro(AutomaticEventHandling, bool);
123 
124 //BTX
125  enum
126  {
127  SYNC_RENDERER_TAG = 15101,
128  RESET_CAMERA_TAG = 15102,
129  COMPUTE_BOUNDS_TAG = 15103
130  };
131 
135  {
136  public:
138  {
139  this->Valid = false;
140  this->Size[0] = this->Size[1] = 0;
142  }
143 
144  void Resize(int dx, int dy, int numcomps)
145  {
146  this->Valid = false;
147  this->Allocate(dx, dy, numcomps);
148  }
149 
151  void Initialize(int dx, int dy, vtkUnsignedCharArray* data);
152 
153  void MarkValid() { this->Valid = true; }
154  void MarkInValid() { this->Valid = false; }
155 
156  bool IsValid() { return this->Valid; }
157  int GetWidth() { return this->Size[0];}
158  int GetHeight() { return this->Size[1];}
160  { return this->Data; }
161 
162  // Pushes the image to the viewport.
163  bool PushToViewport(vtkRenderer*);
164 
165  // This is a raw version of PushToViewport() that assumes that the
166  // glViewport() has already been setup externally.
167  bool PushToFrameBuffer();
168 
169  // Captures the image from the viewport.
170  // This doesn't trigger a render, just captures what's currently there in
171  // the active buffer.
172  bool Capture(vtkRenderer*);
173 
174  // Save the image as a png. Useful for debugging.
175  void SaveAsPNG(const char* filename);
176 
177  private:
178  bool Valid;
179  int Size[2];
181 
182  void Allocate(int dx, int dy, int numcomps);
183  };
184 //ETX
185 protected:
188 
190  {
192  int Draw;
194  double Viewport[4];
195  double CameraPosition[3];
196  double CameraFocalPoint[3];
197  double CameraViewUp[3];
198  double CameraWindowCenter[2];
199  double CameraClippingRange[2];
202 
203  // Save/restore the struct to/from a stream.
204  void Save(vtkMultiProcessStream& stream);
205  bool Restore(vtkMultiProcessStream& stream);
206 
207  void CopyFrom(vtkRenderer*);
208  void CopyTo(vtkRenderer*);
209  };
210 
211  // These methods are called on all processes as a consequence of corresponding
212  // events being called on the renderer.
213  virtual void HandleStartRender();
214  virtual void HandleEndRender();
215  virtual void HandleAbortRender() {}
216 
217  virtual void MasterStartRender();
218  virtual void SlaveStartRender();
219 
220  virtual void MasterEndRender();
221  virtual void SlaveEndRender();
222 
225 
231  virtual vtkRawImage& CaptureRenderedImage();
232 
236  void PushImageToScreen();
237 
241 
247 
248 private:
249  vtkSynchronizedRenderers(const vtkSynchronizedRenderers&); // Not implemented
250  void operator=(const vtkSynchronizedRenderers&); // Not implemented
251 
252  class vtkObserver;
253  vtkObserver* Observer;
254  friend class vtkObserver;
255 
256  double LastViewport[4];
257 };
258 
259 #endif
260 
abstract base class for most VTK objects
Definition: vtkObject.h:60
stream used to pass data across processes using vtkMultiProcessController.
vtkSynchronizedRenderers * CaptureDelegate
abstract specification for renderers
Definition: vtkRenderer.h:69
static vtkSmartPointer< T > New()
vtkRawImage can be used to make it easier to deal with images for compositing/communicating over clie...
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
vtkMultiProcessController * ParallelController
dynamic, self-adjusting array of unsigned char
void Resize(int dx, int dy, int numcomps)
#define VTK_PARALLEL_EXPORT
synchronizes renderers across processes.
static vtkObject * New()
Multiprocessing communication superclass.