VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile$ 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00032 #ifndef __vtkSynchronizedRenderers_h 00033 #define __vtkSynchronizedRenderers_h 00034 00035 #include "vtkRenderingParallelModule.h" // For export macro 00036 #include "vtkObject.h" 00037 #include "vtkUnsignedCharArray.h" // needed for vtkUnsignedCharArray. 00038 #include "vtkSmartPointer.h" // needed for vtkSmartPointer. 00039 00040 class vtkRenderer; 00041 class vtkMultiProcessController; 00042 class vtkMultiProcessStream; 00043 class vtkOpenGLRenderer; 00044 00045 class VTKRENDERINGPARALLEL_EXPORT vtkSynchronizedRenderers : public vtkObject 00046 { 00047 public: 00048 static vtkSynchronizedRenderers* New(); 00049 vtkTypeMacro(vtkSynchronizedRenderers, vtkObject); 00050 void PrintSelf(ostream& os, vtkIndent indent); 00051 00053 00057 virtual void SetRenderer(vtkRenderer*); 00058 virtual vtkRenderer* GetRenderer(); 00060 00062 00064 virtual void SetParallelController(vtkMultiProcessController*); 00065 vtkGetObjectMacro(ParallelController, vtkMultiProcessController); 00067 00069 00071 vtkSetMacro(ParallelRendering, bool); 00072 vtkGetMacro(ParallelRendering, bool); 00073 vtkBooleanMacro(ParallelRendering, bool); 00075 00077 00078 vtkSetClampMacro(ImageReductionFactor, int, 1, 50); 00079 vtkGetMacro(ImageReductionFactor, int); 00081 00083 00086 vtkSetMacro(WriteBackImages, bool); 00087 vtkGetMacro(WriteBackImages, bool); 00088 vtkBooleanMacro(WriteBackImages, bool); 00090 00092 00096 vtkSetMacro(RootProcessId, int); 00097 vtkGetMacro(RootProcessId, int); 00099 00105 void CollectiveExpandForVisiblePropBounds(double bounds[6]); 00106 00108 00110 virtual void SetCaptureDelegate(vtkSynchronizedRenderers*); 00111 vtkGetObjectMacro(CaptureDelegate, vtkSynchronizedRenderers); 00113 00115 00121 vtkSetMacro(AutomaticEventHandling, bool); 00122 vtkGetMacro(AutomaticEventHandling, bool); 00123 vtkBooleanMacro(AutomaticEventHandling, bool); 00125 00126 //BTX 00127 enum 00128 { 00129 SYNC_RENDERER_TAG = 15101, 00130 RESET_CAMERA_TAG = 15102, 00131 COMPUTE_BOUNDS_TAG = 15103 00132 }; 00133 00136 struct VTKRENDERINGPARALLEL_EXPORT vtkRawImage 00137 { 00138 public: 00139 vtkRawImage() 00140 { 00141 this->Valid = false; 00142 this->Size[0] = this->Size[1] = 0; 00143 this->Data = vtkSmartPointer<vtkUnsignedCharArray>::New(); 00144 } 00145 00146 void Resize(int dx, int dy, int numcomps) 00147 { 00148 this->Valid = false; 00149 this->Allocate(dx, dy, numcomps); 00150 } 00151 00153 void Initialize(int dx, int dy, vtkUnsignedCharArray* data); 00154 00155 void MarkValid() { this->Valid = true; } 00156 void MarkInValid() { this->Valid = false; } 00157 00158 bool IsValid() { return this->Valid; } 00159 int GetWidth() { return this->Size[0];} 00160 int GetHeight() { return this->Size[1];} 00161 vtkUnsignedCharArray* GetRawPtr() 00162 { return this->Data; } 00163 00164 // Pushes the image to the viewport. 00165 bool PushToViewport(vtkRenderer*); 00166 00167 // This is a raw version of PushToViewport() that assumes that the 00168 // glViewport() has already been setup externally. 00169 bool PushToFrameBuffer(); 00170 00171 // Captures the image from the viewport. 00172 // This doesn't trigger a render, just captures what's currently there in 00173 // the active buffer. 00174 bool Capture(vtkRenderer*); 00175 00176 // Save the image as a png. Useful for debugging. 00177 void SaveAsPNG(const char* filename); 00178 00179 private: 00180 bool Valid; 00181 int Size[2]; 00182 vtkSmartPointer<vtkUnsignedCharArray> Data; 00183 00184 void Allocate(int dx, int dy, int numcomps); 00185 }; 00186 //ETX 00187 protected: 00188 vtkSynchronizedRenderers(); 00189 ~vtkSynchronizedRenderers(); 00190 00191 struct RendererInfo 00192 { 00193 int ImageReductionFactor; 00194 int Draw; 00195 int CameraParallelProjection; 00196 double Viewport[4]; 00197 double CameraPosition[3]; 00198 double CameraFocalPoint[3]; 00199 double CameraViewUp[3]; 00200 double CameraWindowCenter[2]; 00201 double CameraClippingRange[2]; 00202 double CameraViewAngle; 00203 double CameraParallelScale; 00204 double EyeTransformMatrix[16]; 00205 double ModelTransformMatrix[16]; 00206 00207 // Save/restore the struct to/from a stream. 00208 void Save(vtkMultiProcessStream& stream); 00209 bool Restore(vtkMultiProcessStream& stream); 00210 00211 void CopyFrom(vtkRenderer*); 00212 void CopyTo(vtkRenderer*); 00213 }; 00214 00215 // These methods are called on all processes as a consequence of corresponding 00216 // events being called on the renderer. 00217 virtual void HandleStartRender(); 00218 virtual void HandleEndRender(); 00219 virtual void HandleAbortRender() {} 00220 00221 virtual void MasterStartRender(); 00222 virtual void SlaveStartRender(); 00223 00224 virtual void MasterEndRender(); 00225 virtual void SlaveEndRender(); 00226 00227 vtkMultiProcessController* ParallelController; 00228 vtkOpenGLRenderer* Renderer; 00229 00235 virtual vtkRawImage& CaptureRenderedImage(); 00236 00240 void PushImageToScreen(); 00241 00242 vtkSynchronizedRenderers* CaptureDelegate; 00243 vtkRawImage ReducedImage; 00244 vtkRawImage FullImage; 00245 00246 bool ParallelRendering; 00247 int ImageReductionFactor; 00248 bool WriteBackImages; 00249 int RootProcessId; 00250 bool AutomaticEventHandling; 00251 00252 private: 00253 vtkSynchronizedRenderers(const vtkSynchronizedRenderers&); // Not implemented 00254 void operator=(const vtkSynchronizedRenderers&); // Not implemented 00255 00256 class vtkObserver; 00257 vtkObserver* Observer; 00258 friend class vtkObserver; 00259 00260 double LastViewport[4]; 00261 }; 00262 00263 #endif 00264