Commit 0162b9f0 authored by Amy Squillacote's avatar Amy Squillacote

adding new parallel rendering classes

parent 6fb90b32
......@@ -16,7 +16,7 @@ rtDebugLeaks PromptUserOff
set myProcId 0
set numProcs 1
vtkCompositeManager compManager
vtkCompositeRenderManager compManager
if { [compManager GetController] != "" } {
catch [ set myProcId [[compManager GetController] GetLocalProcessId] ]
catch [ set numProcs [[compManager GetController] GetNumberOfProcesses] ]
......
......@@ -22,6 +22,7 @@ vtkCollectPolyData.cxx
vtkCommunicator.cxx
vtkCompositeManager.cxx
vtkCompositer.cxx
vtkCompositeRenderManager.cxx
vtkCompressCompositer.cxx
vtkCutMaterial.cxx
vtkDistributedStreamTracer.cxx
......@@ -32,6 +33,7 @@ vtkInputPort.cxx
vtkMemoryLimitImageDataStreamer.cxx
vtkMultiProcessController.cxx
vtkOutputPort.cxx
vtkParallelRenderManager.cxx
vtkPassThroughFilter.cxx
vtkPCellDataToPointData.cxx
vtkPDataSetReader.cxx
......@@ -59,6 +61,7 @@ vtkTreeCompositer.cxx
)
SET_SOURCE_FILES_PROPERTIES(
vtkParallelRenderManager
vtkPStreamTracer
ABSTRACT
)
......
......@@ -23,7 +23,7 @@
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCompositeManager.h"
#include "vtkCompositeRenderManager.h"
#include "vtkDebugLeaks.h"
#include "vtkParallelFactory.h"
#include "vtkRegressionTestImage.h"
......@@ -137,7 +137,7 @@ void proc1( vtkMultiProcessController *controller, void *arg )
iren->SetRenderWindow(renWin);
// The only thing we have to do to get parallel execution.
vtkCompositeManager* treeComp = vtkCompositeManager::New();
vtkCompositeRenderManager* treeComp = vtkCompositeRenderManager::New();
treeComp->SetController(controller);
treeComp->SetRenderWindow(renWin);
......
......@@ -17,7 +17,7 @@
=========================================================================*/
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCompositeManager.h"
#include "vtkCompositeRenderManager.h"
#include "vtkDebugLeaks.h"
#include "vtkDistributedStreamTracer.h"
#include "vtkLineSource.h"
......@@ -170,8 +170,9 @@ void MyMain( vtkMultiProcessController *controller, void *arg )
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkCompositeManager* compManager = vtkCompositeManager::New();
vtkCompositeRenderManager* compManager = vtkCompositeRenderManager::New();
compManager->SetRenderWindow(renWin);
compManager->SetController(controller);
compManager->InitializePieces();
if (myId)
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCompositeRenderManager.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCompositeRenderManager.h"
#include "vtkCompositer.h"
#include "vtkCompressCompositer.h"
#include "vtkFloatArray.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkRendererCollection.h"
#include "vtkRenderWindow.h"
#include "vtkTimerLog.h"
#include "vtkUnsignedCharArray.h"
vtkCxxRevisionMacro(vtkCompositeRenderManager, "1.1");
vtkStandardNewMacro(vtkCompositeRenderManager);
vtkCxxSetObjectMacro(vtkCompositeRenderManager, Compositer, vtkCompositer);
vtkCompositeRenderManager::vtkCompositeRenderManager()
{
this->Compositer = vtkCompressCompositer::New();
this->Compositer->Register(this);
this->Compositer->Delete();
this->DepthData = vtkFloatArray::New();
this->TmpPixelData = vtkUnsignedCharArray::New();
this->TmpDepthData = vtkFloatArray::New();
this->DepthData->SetNumberOfComponents(1);
this->TmpPixelData->SetNumberOfComponents(4);
this->TmpDepthData->SetNumberOfComponents(1);
}
vtkCompositeRenderManager::~vtkCompositeRenderManager()
{
this->SetCompositer(NULL);
this->DepthData->Delete();
this->TmpPixelData->Delete();
this->TmpDepthData->Delete();
}
void vtkCompositeRenderManager::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "ImageProcessingTime: " << this->ImageProcessingTime << endl;
os << indent << "Compositer: " << endl;
this->Compositer->PrintSelf(os, indent.GetNextIndent());
}
void vtkCompositeRenderManager::PreRenderProcessing()
{
// Turn swap buffers off before the render so the end render method has a
// chance to add the back buffer.
this->RenderWindow->SwapBuffersOff();
}
void vtkCompositeRenderManager::PostRenderProcessing()
{
if (this->Controller->GetNumberOfProcesses() > 1)
{
// Read in data.
this->ReadReducedImage();
this->Timer->StartTimer();
this->RenderWindow->GetZbufferData(0, 0, this->ReducedImageSize[0]-1,
this->ReducedImageSize[1]-1,
this->DepthData);
// Set up temporary buffers.
this->TmpPixelData->SetNumberOfComponents
(this->ReducedImage->GetNumberOfComponents());
this->TmpPixelData->SetNumberOfTuples
(this->ReducedImage->GetNumberOfTuples());
this->TmpDepthData->SetNumberOfComponents
(this->DepthData->GetNumberOfComponents());
this->TmpDepthData->SetNumberOfTuples(this->DepthData->GetNumberOfTuples());
// Do composite
this->Compositer->SetController(this->Controller);
this->Compositer->CompositeBuffer(this->ReducedImage, this->DepthData,
this->TmpPixelData, this->TmpDepthData);
this->Timer->StopTimer();
this->ImageProcessingTime = this->Timer->GetElapsedTime();
}
this->WriteFullImage();
// Swap buffers here
this->RenderWindow->SwapBuffersOn();
this->RenderWindow->Frame();
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCompositeRenderManager.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkCompositeRenderManager - An object to control sort-last parallel rendering.
//
// .SECTION Description:
// vtkCompositeRenderManager is a subclass of vtkParallelRenderManager that
// uses compositing to do parallel rendering. This class is intended to
// replace vtkCompositeManager.
//
#ifndef __vtkCompositeRenderManager_h
#define __vtkCompositeRenderManager_h
#include "vtkParallelRenderManager.h"
class vtkCompositer;
class VTK_PARALLEL_EXPORT vtkCompositeRenderManager : public vtkParallelRenderManager
{
public:
vtkTypeRevisionMacro(vtkCompositeRenderManager, vtkParallelRenderManager);
static vtkCompositeRenderManager *New();
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Set/Get the composite algorithm.
void SetCompositer(vtkCompositer *c);
vtkGetObjectMacro(Compositer, vtkCompositer);
// Description:
// Get rendering metrics.
vtkGetMacro(ImageProcessingTime, double);
protected:
vtkCompositeRenderManager();
~vtkCompositeRenderManager();
vtkCompositer *Compositer;
virtual void PreRenderProcessing();
virtual void PostRenderProcessing();
vtkFloatArray *DepthData;
vtkUnsignedCharArray *TmpPixelData;
vtkFloatArray *TmpDepthData;
private:
vtkCompositeRenderManager(const vtkCompositeRenderManager &);//Not implemented
void operator=(const vtkCompositeRenderManager &); //Not implemented
};
#endif //__vtkCompositeRenderManager_h
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkParallelRenderManager.h
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkParallelRenderManager - An object to control parallel rendering.
//
// .SECTION Description:
// vtkParallelRenderManager operates in multiple processes. It provides
// proper renderers and render windows for performing the parallel
// rendering correctly. It can also attach itself to render windows and
// propagate rendering events and camera views.
//
// This class is based on the vtkCompositeManager class, except that it can
// handle any type of parallel rendering.
//
// .SECTION Note:
// Many parallel rendering schemes do not correctly handle transparency.
// Unless otherwise documented, assume a sub class does not.
//
// .SECTION ToDo:
// Synchronization/barrier primitives.
//
// Query ranges of scalar values of objects in addition to the boundry in
// three-space
//
#ifndef __vtkParallelRenderManager_h
#define __vtkParallelRenderManager_h
#include "vtkObject.h"
class vtkRenderWindow;
class vtkRenderer;
class vtkUnsignedCharArray;
class vtkFloatArray;
class vtkTimerLog;
class vtkMultiProcessController;
class VTK_PARALLEL_EXPORT vtkParallelRenderManager : public vtkObject
{
public:
vtkTypeRevisionMacro(vtkParallelRenderManager, vtkObject);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Builds a vtkRenderWindow compatible with this render manager. The
// user program is responsible for registering the render window with the
// SetRenderWindow method and calling Delete. It is not advisable to use
// a parallel render manager with a render window that was not built with
// this method.
virtual vtkRenderWindow *MakeRenderWindow();
// Description:
// Builds a vtkRenderer compatible with this render manager. (Should we
// also register it?) The user program is responsible for calling
// Delete. It is not advisable to use a parallel render manager with a
// renderer that was not built with this method.
virtual vtkRenderer *MakeRenderer();
// Description:
// Set/Get the RenderWindow to use for compositing.
// We add a start and end observer to the window.
vtkGetObjectMacro(RenderWindow, vtkRenderWindow);
virtual void SetRenderWindow(vtkRenderWindow *renWin);
// Description:
// Set/Get the vtkMultiProcessController which will handle communications
// for the parallel rendering.
vtkGetObjectMacro(Controller, vtkMultiProcessController);
virtual void SetController(vtkMultiProcessController *controller);
// Description:
// This method sets the piece and number of pieces for each
// actor with a polydata mapper.
virtual void InitializePieces();
// Description:
// Make all rendering windows not viewable set as off screen rendering.
// To make all renderwindows on screen rendering again, call
// OffScreenRenderingOff on all the render windows. This class assumes
// the window on root node is the only one viewable. Subclasses should
// change this as necessary.
virtual void InitializeOffScreen();
// Description:
// Initializes the RMIs and then, if on root node, starts the interactor
// on the attached render window. Otherwise, starts processing RMIs.
// When the interactor returns, it breaks the RMI listening on all other
// processors.
virtual void StartInteractor();
// Description:
// If on node other than root, starts serving RMI requests for parallel
// renders.
virtual void StartService();
// Description:
// If on root node, stops the RMI processing on all service nodes.
virtual void StopServices();
// Description:
// Callbacks that initialize and finish rendering and other tasks.
virtual void StartRender();
virtual void EndRender();
virtual void SatelliteStartRender();
virtual void SatelliteEndRender();
virtual void RenderRMI();
virtual void ResetCamera(vtkRenderer *ren);
virtual void ResetCameraClippingRange(vtkRenderer *ren);
virtual void ComputeVisiblePropBoundsRMI();
virtual void InitializeRMIs();
// Description:
// Resets the camera of each renderer contained in the RenderWindow.
// Should only be called in the "root" process, and all remote processes
// must be processing RMIs for this method to complete.
virtual void ResetAllCameras();
// Description:
// Calculates the bounds by gathering information from all processes.
virtual void ComputeVisiblePropBounds(vtkRenderer *ren, float bounds[6]);
// Description:
// Turns on/off parallel rendering. When on (the default) the object
// responds to render events of the attached window, propagates the
// render event to other processors, and otherwise enables the parallel
// rendering process.
vtkSetMacro(ParallelRendering, int);
vtkGetMacro(ParallelRendering, int);
vtkBooleanMacro(ParallelRendering, int);
// Description:
// Turns on/off render event propagation. When on (the default) and
// ParallelRendering is on, process 0 will send an RMI call to all remote
// processes to perform a synchronized render. When off, render must be
// manually called on each process.
vtkSetMacro(RenderEventPropagation, int);
vtkGetMacro(RenderEventPropagation, int);
vtkBooleanMacro(RenderEventPropagation, int);
// Description:
// This is used for tiled display rendering. When data has been
// duplicated on all processes, then we do not need to compositing.
// Cameras and renders are still propagated though.
vtkSetMacro(UseCompositing, int);
vtkGetMacro(UseCompositing, int);
vtkBooleanMacro(UseCompositing, int);
// Description:
// Set/Get the reduction factor (for sort-last based parallel renderers).
// The size of rendered image is divided by the reduction factor and then
// is blown up to the size of the current vtkRenderWindow. Setting
// higher reduction factors enables shorter image transfer times (which
// is often the bottleneck) but will greatly reduce image quality. A
// reduction factor of 2 or greater should only be used for intermediate
// images in interactive applications. A reduction factor of 1 (or less)
// will result in no change in image quality. A parallel render manager
// may ignore the image reduction factor if it will result in little or
// no performance enhancements (eg. it does not do image space
// manipulations).
virtual void SetImageReductionFactor(int factor);
vtkGetMacro(ImageReductionFactor, int);
vtkSetMacro(MaxImageReductionFactor, int);
vtkGetMacro(MaxImageReductionFactor, int);
// Description:
// Sets the ReductionFactor based on the given desired update rate and
// the rendering metrics taken from the last time UpdateServerInfo was
// called. Note that if AutoReductionFactor is on, this function is called
// with the desired update rate of the render window automatically.
virtual void SetImageReductionFactorForUpdateRate(float DesiredUpdateRate);
// Description:
// If on, the ReductionFactor is automatically adjusted to best meet the
// the DesiredUpdateRate in the current RenderWindow based on metrics
// from the last render.
vtkSetMacro(AutoImageReductionFactor, int);
vtkGetMacro(AutoImageReductionFactor, int);
vtkBooleanMacro(AutoImageReductionFactor, int);
// Description:
// Get rendering metrics.
vtkGetMacro(RenderTime, double);
vtkGetMacro(ImageProcessingTime, double);
// Description:
// If on (the default), the result of any image space manipulations are
// written back to the render window frame buffer. If off, the image
// stored in the frame buffer may not be correct. Either way, the
// correct frame buffer images may be read with
// vtkParallelRenderManager::GetPixelData. Turning WriteBackImages off
// may result in a speedup if the render window is not visible to the user
// and images are read back for further processing or transit.
vtkSetMacro(WriteBackImages, int);
vtkGetMacro(WriteBackImages, int);
vtkBooleanMacro(WriteBackImages, int);
// Description:
// If on (the default), when the ImageReductionFactor is greater than 1
// and WriteBackImages is on, the image will be magnified to fill the
// entire render window.
vtkSetMacro(MagnifyImages, int);
vtkGetMacro(MagnifyImages, int);
vtkBooleanMacro(MagnifyImages, int);
//BTX
enum { NEAREST, LINEAR };
//ETX
// Description:
// Sets the method used to magnify images. Nearest simply replicates
// each pixel enough times to fill the image. Linear performs linear
// interpolation between the pixels.
virtual void SetMagnifyImageMethod(int method);
vtkGetMacro(MagnifyImageMethod, int);
void SetMagnifyImageMethodToNearest() {
this->SetMagnifyImageMethod(NEAREST);
}
void SetMagnifyImageMethodToLinear() {
this->SetMagnifyImageMethod(LINEAR);
}
// Description:
// The most appropriate way to retrieve full size image data after a
// render. Will work regardless of whether WriteBackImages or
// MagnifyImage is on or off. The data returned may be a shallow copy of
// an internal array. Therefore, the data may be invalid after the next
// render or if the ParallelRenderManager is destroyed.
virtual void GetPixelData(vtkUnsignedCharArray *data);
virtual void GetPixelData(int x1, int y1, int x2, int y2,
vtkUnsignedCharArray *data);
// Description:
// The most appropriate way to retrieve reduced size image data after a
// render. Will work regardless of whether WriteBackImages or
// MagnifyImage is on or off. The data returned may be a shallow copy of
// an internal array. Therefore, the data may be invalid after the next
// render or if the ParallelRenderManager is destroyed.
virtual void GetReducedPixelData(vtkUnsignedCharArray *data);
virtual void GetReducedPixelData(int x1, int y1, int x2, int y2,
vtkUnsignedCharArray *data);
// Description:
// Returns the full image size calculated at the last render.
vtkGetVector2Macro(FullImageSize, int);
// Description:
// Returns the reduced image size calculated at the last render.
vtkGetVector2Macro(ReducedImageSize, int);
//BTX
enum Tags {
RENDER_RMI_TAG=34532,
COMPUTE_VISIBLE_PROP_BOUNDS_RMI_TAG=54636,
WIN_INFO_INT_TAG=87834,
WIN_INFO_FLOAT_TAG=87835,
REN_INFO_INT_TAG=87836,
REN_INFO_FLOAT_TAG=87837,
LIGHT_INFO_FLOAT_TAG=87838,
REN_ID_TAG=58794,
BOUNDS_TAG=23543
};
virtual void CheckForAbortRender() {}
//ETX
protected:
vtkParallelRenderManager();
~vtkParallelRenderManager();
vtkRenderWindow *RenderWindow;
vtkMultiProcessController *Controller;
// Description:
// The "root" node's process id. This is the node which is listening for
// and propagating new render events from the RenderWindow. All
// processes on the controller must have the same value. This value must
// be set before SetRenderWindow method is called. In the constructor or
// the SetController methods are good places. By default this is set to
// 0.
int RootProcessId;
bool ObservingRenderWindow;
bool ObservingRenderer;
unsigned long StartRenderTag;
unsigned long EndRenderTag;
unsigned long ResetCameraTag;
unsigned long ResetCameraClippingRangeTag;
unsigned long AbortRenderCheckTag;
int ImageReductionFactor;
int MaxImageReductionFactor;
int AutoImageReductionFactor;
int WriteBackImages;
int MagnifyImages;
int MagnifyImageMethod;
int FullImageSize[2];
int ReducedImageSize[2];
vtkUnsignedCharArray *FullImage;
vtkUnsignedCharArray *ReducedImage;
bool FullImageUpToDate;
bool ReducedImageUpToDate;
bool RenderWindowImageUpToDate;
vtkFloatArray *Viewports;
int Lock;
int ParallelRendering;
int RenderEventPropagation;
int UseCompositing;
vtkTimerLog *Timer;
double RenderTime;
double ImageProcessingTime;
// Description:
// Used by SetImageReductionFactorForUpdateRate to smooth transitions
// transitions between image reduction factors.
double AverageTimePerPixel;
// Description:
// Used to synchronize rendering information per frame.
virtual void SendWindowInformation() {}
virtual void ReceiveWindowInformation() {}
virtual void SendRendererInformation(vtkRenderer *) {};
virtual void ReceiveRendererInformation(vtkRenderer *) {};
// Description:
// Here is a good place to handle processing of data before and after
// render.
virtual void PreRenderProcessing() = 0;
virtual void PostRenderProcessing() = 0;
// Description:
// Called in satellites to set the render window size to the current
// FullImageSize and ReducedImageSize (or vice versa)
virtual void SetRenderWindowSize();
// Description:
// Called by ComputeVisiblePropBoundsRMI to get the bounds of a local
// renderer. Override this method if the true bounds are different than
// those reported by the renderer.
virtual void LocalComputeVisiblePropBounds(vtkRenderer *ren, float bounds[6]);
// Description:
// When called, fills FullImage.
virtual void MagnifyReducedImage();
// Description:
// Write the full image back to the RenderWindow.