VTK
dox/Parallel/vtkParallelRenderManager.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkParallelRenderManager.h
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   Copyright 2003 Sandia Corporation. Under the terms of Contract
00011   DE-AC04-94AL85000, there is a non-exclusive license for use of this work by
00012   or on behalf of the U.S. Government. Redistribution and use in source and
00013   binary forms, with or without modification, are permitted provided that this
00014   Notice and any statement of authorship are reproduced on all copies.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00018      PURPOSE.  See the above copyright notice for more information.
00019 
00020 =========================================================================*/
00049 #ifndef __vtkParallelRenderManager_h
00050 #define __vtkParallelRenderManager_h
00051 
00052 #include "vtkObject.h"
00053 
00054 class vtkDoubleArray;
00055 class vtkMultiProcessController;
00056 class vtkMultiProcessStream;
00057 class vtkRenderer;
00058 class vtkRendererCollection;
00059 class vtkRenderWindow;
00060 class vtkTimerLog;
00061 class vtkUnsignedCharArray;
00062 
00063 class VTK_PARALLEL_EXPORT vtkParallelRenderManager : public vtkObject
00064 {
00065 public:
00066   vtkTypeMacro(vtkParallelRenderManager, vtkObject);
00067   virtual void PrintSelf(ostream &os, vtkIndent indent);
00068 
00074   virtual vtkRenderWindow *MakeRenderWindow();
00075 
00080   virtual vtkRenderer *MakeRenderer();
00081 
00083 
00085   vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
00086   virtual void SetRenderWindow(vtkRenderWindow *renWin);
00088 
00090 
00092   vtkGetObjectMacro(Controller, vtkMultiProcessController);
00093   virtual void SetController(vtkMultiProcessController *controller);
00095 
00098   virtual void InitializePieces();
00099 
00105   virtual void InitializeOffScreen();
00106 
00111   virtual void StartInteractor();
00112 
00115   virtual void StartServices();
00116 
00118   virtual void StopServices();
00119 
00121 
00122   virtual void StartRender();
00123   virtual void EndRender();
00124   virtual void SatelliteStartRender();
00125   virtual void SatelliteEndRender();
00126   virtual void RenderRMI();
00127   virtual void ResetCamera(vtkRenderer *ren);
00128   virtual void ResetCameraClippingRange(vtkRenderer *ren);
00129   virtual void ComputeVisiblePropBoundsRMI(int renderId);
00131 
00132   virtual void InitializeRMIs();
00133 
00137   virtual void ResetAllCameras();
00138 
00140   virtual void ComputeVisiblePropBounds(vtkRenderer *ren, double bounds[6]);
00141 
00143 
00147   vtkSetMacro(ParallelRendering, int);
00148   vtkGetMacro(ParallelRendering, int);
00149   vtkBooleanMacro(ParallelRendering, int);
00151 
00153 
00157   vtkSetMacro(RenderEventPropagation, int);
00158   vtkGetMacro(RenderEventPropagation, int);
00159   vtkBooleanMacro(RenderEventPropagation, int);
00161 
00163 
00166   static void SetDefaultRenderEventPropagation(bool val)
00167     { vtkParallelRenderManager::DefaultRenderEventPropagation = val; }
00168   static bool GetDefaultRenderEventPropagation()
00169     { return vtkParallelRenderManager::DefaultRenderEventPropagation; }
00171 
00173 
00176   vtkSetMacro(UseCompositing, int);
00177   vtkGetMacro(UseCompositing, int);
00178   vtkBooleanMacro(UseCompositing, int);
00180 
00182 
00193   virtual void SetImageReductionFactor(double factor);
00194   vtkGetMacro(ImageReductionFactor, double);
00196 
00197   vtkSetMacro(MaxImageReductionFactor, double);
00198   vtkGetMacro(MaxImageReductionFactor, double);
00199 
00205   virtual void SetImageReductionFactorForUpdateRate(double DesiredUpdateRate);
00206 
00208 
00211   vtkSetMacro(AutoImageReductionFactor, int);
00212   vtkGetMacro(AutoImageReductionFactor, int);
00213   vtkBooleanMacro(AutoImageReductionFactor, int);
00215 
00217 
00218   vtkGetMacro(RenderTime, double);
00219   vtkGetMacro(ImageProcessingTime, double);
00221 
00223 
00231   vtkGetMacro(SyncRenderWindowRenderers, int);
00232   vtkSetMacro(SyncRenderWindowRenderers, int);
00233   vtkBooleanMacro(SyncRenderWindowRenderers, int);
00234   virtual void AddRenderer(vtkRenderer *);
00235   virtual void RemoveRenderer(vtkRenderer *);
00236   virtual void RemoveAllRenderers();
00238 
00240 
00247   vtkSetMacro(WriteBackImages, int);
00248   vtkGetMacro(WriteBackImages, int);
00249   vtkBooleanMacro(WriteBackImages, int);
00251 
00253 
00256   vtkSetMacro(MagnifyImages, int);
00257   vtkGetMacro(MagnifyImages, int);
00258   vtkBooleanMacro(MagnifyImages, int);
00260 
00261 //BTX
00262   enum { NEAREST, LINEAR };
00263 //ETX
00264 
00266 
00269   virtual void SetMagnifyImageMethod(int method);
00270   vtkGetMacro(MagnifyImageMethod, int);
00271   void SetMagnifyImageMethodToNearest() {
00272     this->SetMagnifyImageMethod(NEAREST);
00273   }
00274   void SetMagnifyImageMethodToLinear() {
00275     this->SetMagnifyImageMethod(LINEAR);
00276   }
00278 
00280 
00281   virtual void MagnifyImage(vtkUnsignedCharArray *fullImage,
00282                             const int fullImageSize[2],
00283                             vtkUnsignedCharArray *reducedImage,
00284                             const int reducedImageSize[2],
00285                             const int fullImageViewport[4] = NULL,
00286                             const int reducedImageViewport[4] = NULL);
00287   static void MagnifyImageNearest(vtkUnsignedCharArray *fullImage,
00288                                   const int fullImageSize[2],
00289                                   vtkUnsignedCharArray *reducedImage,
00290                                   const int reducedImageSize[2],
00291                                   const int fullImageViewport[4] = NULL,
00292                                   const int reducedImageViewport[4] = NULL);
00293   static void MagnifyImageLinear(vtkUnsignedCharArray *fullImage,
00294                                  const int fullImageSize[2],
00295                                  vtkUnsignedCharArray *reducedImage,
00296                                  const int reducedImageSize[2],
00297                                  const int fullImageViewport[4] = NULL,
00298                                  const int reducedImageViewport[4] = NULL);
00300 
00302 
00307   virtual void GetPixelData(vtkUnsignedCharArray *data);
00308   virtual void GetPixelData(int x1, int y1, int x2, int y2,
00309           vtkUnsignedCharArray *data);
00311 
00313 
00318   virtual void GetReducedPixelData(vtkUnsignedCharArray *data);
00319   virtual void GetReducedPixelData(int x1, int y1, int x2, int y2,
00320            vtkUnsignedCharArray *data);
00322 
00324 
00325   vtkGetVector2Macro(FullImageSize, int);
00327 
00328 
00329   vtkGetVector2Macro(ReducedImageSize, int);
00331 
00334   void TileWindows(int xsize, int ysize, int nColumns);
00335 
00337 
00339   vtkSetMacro(UseRGBA, int);
00340   vtkGetMacro(UseRGBA, int);
00342 
00344 
00347   vtkSetMacro(ForceRenderWindowSize, int);
00348   vtkGetMacro(ForceRenderWindowSize, int);
00350 
00352 
00354   vtkSetVector2Macro(ForcedRenderWindowSize, int);
00355   vtkGetVector2Macro(ForcedRenderWindowSize, int);
00357 
00358 //BTX
00359   enum Tags {
00360     RENDER_RMI_TAG=34532,
00361     COMPUTE_VISIBLE_PROP_BOUNDS_RMI_TAG=54636,
00362     WIN_INFO_TAG=87834,
00363     REN_INFO_TAG=87836,
00364     LIGHT_INFO_TAG=87838,
00365     REN_ID_TAG=58794,
00366     BOUNDS_TAG=23543
00367   };
00368 
00369   virtual void CheckForAbortRender() {}
00370   virtual int CheckForAbortComposite() {return 0;}  
00371 //ETX
00372 
00373 // Disable warnings about qualifiers on return types.
00374 #if defined(_COMPILER_VERSION)
00375 # pragma set woff 3303
00376 #endif
00377 #if defined(__INTEL_COMPILER)
00378 # pragma warning (push)
00379 # pragma warning (disable:858)
00380 #endif
00381 
00382 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00383 # define StartServiceA StartService
00384 # define StartServiceW StartService
00385 #endif
00386 
00389   VTK_LEGACY(virtual void StartService());
00390 
00391 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00392 # undef StartServiceW
00393 # undef StartServiceA
00394   //BTX
00395   VTK_LEGACY(virtual void StartServiceA());
00396   VTK_LEGACY(virtual void StartServiceW());
00397   //ETX
00398 #endif
00399 
00400 // Reset disabled warning about qualifiers on return types.
00401 #if defined(__INTEL_COMPILER)
00402 # pragma warning (pop)
00403 #endif
00404 #if defined(_COMPILER_VERSION)
00405 # pragma reset woff 3303
00406 #endif
00407 
00409 
00413   vtkSetMacro(UseBackBuffer, int);
00414   vtkGetMacro(UseBackBuffer, int);
00415   vtkBooleanMacro(UseBackBuffer, int);
00417 
00419 
00423   vtkSetMacro(SynchronizeTileProperties, int);
00424   vtkGetMacro(SynchronizeTileProperties, int);
00425   vtkBooleanMacro(SynchronizeTileProperties, int);
00427 
00429 
00431   virtual void GenericStartRenderCallback();
00432   virtual void GenericEndRenderCallback();
00434 
00435 //BTX
00436 protected:
00437   vtkParallelRenderManager();
00438   ~vtkParallelRenderManager();
00439 
00440 
00442 
00443   void AddRenderWindowEventHandlers();
00444   void RemoveRenderWindowEventHandlers();
00446 
00447   vtkRenderWindow *RenderWindow;
00448   vtkMultiProcessController *Controller;
00449   vtkRendererCollection *Renderers;
00450 
00451   virtual vtkRendererCollection *GetRenderers();
00452 
00453   int ForceRenderWindowSize;
00454   int ForcedRenderWindowSize[2];
00455 
00462   int RootProcessId;
00463 
00464   int ObservingRenderWindow;
00465   int ObservingAbort;
00466 
00467   unsigned long StartRenderTag;
00468   unsigned long EndRenderTag;
00469   unsigned long ResetCameraTag;
00470   unsigned long ResetCameraClippingRangeTag;
00471   unsigned long AbortRenderCheckTag;
00472 
00473   double ImageReductionFactor;
00474   double MaxImageReductionFactor;
00475   int AutoImageReductionFactor;
00476 
00477   int WriteBackImages;
00478   int MagnifyImages;
00479   int MagnifyImageMethod;
00480 
00481   int UseRGBA;
00482   int SynchronizeTileProperties;
00483   int FullImageSize[2];
00484   int ReducedImageSize[2];
00485 
00486   vtkUnsignedCharArray *FullImage;
00487   vtkUnsignedCharArray *ReducedImage;
00488 
00489   int FullImageUpToDate;
00490   int ReducedImageUpToDate;
00491   int RenderWindowImageUpToDate;
00492 
00493   vtkDoubleArray *Viewports;
00494 
00495   int Lock;
00496   int ParallelRendering;
00497   int RenderEventPropagation;
00498   int UseCompositing;
00499   int SyncRenderWindowRenderers;
00500 
00501   vtkTimerLog *Timer;
00502 
00503   double RenderTime;
00504   double ImageProcessingTime;
00505 
00508   double AverageTimePerPixel;
00509 
00511 
00515   virtual void SendWindowInformation() {}
00516   virtual void ReceiveWindowInformation() {}
00517   virtual void SendRendererInformation(vtkRenderer *) {};
00518   virtual void ReceiveRendererInformation(vtkRenderer *) {};
00520 
00522 
00528   virtual void CollectWindowInformation(vtkMultiProcessStream&) {}
00529   virtual bool ProcessWindowInformation(vtkMultiProcessStream&) 
00530     { return true; }
00531   virtual void CollectRendererInformation(vtkRenderer*,
00532     vtkMultiProcessStream&) {}
00533   virtual bool ProcessRendererInformation(vtkRenderer*,
00534     vtkMultiProcessStream&) { return true; }
00536 
00538 
00540   virtual void PreRenderProcessing() = 0;
00541   virtual void PostRenderProcessing() = 0;
00543 
00546   virtual void SetRenderWindowSize();
00547 
00551   virtual void LocalComputeVisiblePropBounds(vtkRenderer *ren, double bounds[6]);
00552 
00554   virtual void MagnifyReducedImage();
00555 
00557   virtual void WriteFullImage();
00558 
00560   virtual void ReadReducedImage();
00561 
00564   virtual int LastRenderInFrontBuffer();
00565 
00567   virtual int ChooseBuffer();
00568   
00570 
00571   virtual void SetRenderWindowPixelData(vtkUnsignedCharArray *pixels,
00572           const int pixelDimensions[2]);
00574 
00579   virtual int ImageReduceRenderer(vtkRenderer *) { return 1; }
00580 
00581   struct RenderWindowInfo
00582   {
00583     int FullSize[2];
00584     int ReducedSize[2];
00585     int NumberOfRenderers;
00586     int UseCompositing;
00587     int TileScale[2];
00588     double ImageReductionFactor;
00589     double DesiredUpdateRate;
00590     double TileViewport[4];
00591 
00592     // Save/restore the struct to/from a stream.
00593     void Save(vtkMultiProcessStream& stream);
00594     bool Restore(vtkMultiProcessStream& stream);
00595   };
00596 
00597   struct RendererInfo
00598   {
00599     int Draw;
00600     int NumberOfLights;
00601     double Viewport[4];
00602     double CameraPosition[3];
00603     double CameraFocalPoint[3];
00604     double CameraViewUp[3];
00605     double WindowCenter[2];
00606     double CameraClippingRange[2];
00607     double CameraViewAngle;
00608     double Background[3];
00609     double Background2[3];
00610     bool GradientBackground;
00611     
00612     double ParallelScale;
00613 
00614     // Save/restore the struct to/from a stream.
00615     void Save(vtkMultiProcessStream& stream);
00616     bool Restore(vtkMultiProcessStream& stream);
00617   };
00618   
00619   struct LightInfo
00620   {
00621     double Position[3];
00622     double FocalPoint[3];
00623     double Type;
00624     // Save/restore the struct to/from a stream.
00625     void Save(vtkMultiProcessStream& stream);
00626     bool Restore(vtkMultiProcessStream& stream);
00627   };
00628 
00629   int AddedRMIs;
00630   unsigned long RenderRMIId;
00631   unsigned long BoundsRMIId;
00632   int UseBackBuffer;
00633 
00634   static bool DefaultRenderEventPropagation;
00635 
00636 private:
00637   vtkParallelRenderManager(const vtkParallelRenderManager &); //Not implemented
00638   void operator=(const vtkParallelRenderManager &);  //Not implemented
00639 //ETX
00640 };
00641 
00642 #endif //__vtkParalleRenderManager_h