Commit 514322ca authored by Pat Marion's avatar Pat Marion
Browse files

ENH: Move WriteImage code from vtkSMRenderViewProxy to vtkSMUtilities

so that it can be reused.
parent 727170a5
......@@ -94,7 +94,7 @@ inline bool SetIntVectorProperty(vtkSMProxy* proxy, const char* pname,
}
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkSMRenderViewProxy, "1.90");
vtkCxxRevisionMacro(vtkSMRenderViewProxy, "1.91");
vtkStandardNewMacro(vtkSMRenderViewProxy);
vtkInformationKeyMacro(vtkSMRenderViewProxy, LOD_RESOLUTION, Integer);
......@@ -1163,41 +1163,9 @@ int vtkSMRenderViewProxy::WriteImage(const char* filename,
return vtkErrorCode::UnknownError;
}
vtkImageData* shot = this->CaptureWindow(magnification);
// This is usually called on a serial client, but if it is called in
// a parallel job (for example, while coprocessing for a solver), then
// we really only want to write out an image on process 0.
int error_code;
vtkMultiProcessController *controller
= vtkMultiProcessController::GetGlobalController();
if (controller->GetLocalProcessId() == 0)
{
vtkObject* object = vtkInstantiator::CreateInstance(writerName);
if (!object)
{
vtkErrorMacro("Failed to create Writer " << writerName);
return vtkErrorCode::UnknownError;
}
vtkImageWriter* writer = vtkImageWriter::SafeDownCast(object);
if (!writer)
{
vtkErrorMacro("Object is not a vtkImageWriter: "<<object->GetClassName());
object->Delete();
return vtkErrorCode::UnknownError;
}
writer->SetInput(shot);
writer->SetFileName(filename);
writer->Write();
error_code = writer->GetErrorCode();
writer->Delete();
}
shot->Delete();
controller->Broadcast(&error_code, 1, 0);
return error_code;
vtkSmartPointer<vtkImageData> shot;
shot.TakeReference(this->CaptureWindow(magnification));
return vtkSMUtilities::SaveImageOnProcessZero(shot, filename, writerName);
}
//-----------------------------------------------------------------------------
......
......@@ -19,19 +19,20 @@
#include "vtkImageData.h"
#include "vtkInstantiator.h"
#include "vtkJPEGWriter.h"
#include "vtkMath.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkPNGWriter.h"
#include "vtkPNMWriter.h"
#include "vtkPoints.h"
#include "vtkTIFFWriter.h"
#include "vtkTransform.h"
#include "vtkMath.h"
#include <vtksys/SystemTools.hxx>
#include <vtkstd/string>
vtkStandardNewMacro(vtkSMUtilities);
vtkCxxRevisionMacro(vtkSMUtilities, "1.3");
vtkCxxRevisionMacro(vtkSMUtilities, "1.4");
//----------------------------------------------------------------------------
int vtkSMUtilities::SaveImage(vtkImageData* image, const char* filename,
......@@ -85,6 +86,56 @@ int vtkSMUtilities::SaveImage(vtkImageData* image, const char* filename,
return error_code;
}
//----------------------------------------------------------------------------
int vtkSMUtilities::
SaveImage(vtkImageData* image, const char* filename, const char* writerName)
{
if (!filename || !writerName)
{
return vtkErrorCode::UnknownError;
}
vtkObject* object = vtkInstantiator::CreateInstance(writerName);
if (!object)
{
vtkGenericWarningMacro("Failed to create Writer " << writerName);
return vtkErrorCode::UnknownError;
}
vtkImageWriter* writer = vtkImageWriter::SafeDownCast(object);
if (!writer)
{
vtkGenericWarningMacro("Object is not a vtkImageWriter: "
<< object->GetClassName());
object->Delete();
return vtkErrorCode::UnknownError;
}
writer->SetInput(image);
writer->SetFileName(filename);
writer->Write();
int error_code = writer->GetErrorCode();
writer->Delete();
return error_code;
}
//----------------------------------------------------------------------------
// This is usually called on a serial client, but if it is called in
// a parallel job (for example, while coprocessing for a solver), then
// we really only want to write out an image on process 0.
int vtkSMUtilities::SaveImageOnProcessZero(vtkImageData* image,
const char* filename, const char* writerName)
{
int error_code;
vtkMultiProcessController *controller =
vtkMultiProcessController::GetGlobalController();
if (controller->GetLocalProcessId() == 0)
{
error_code = SaveImage(image, filename, writerName);
}
controller->Broadcast(&error_code, 1, 0);
return error_code;
}
//----------------------------------------------------------------------------
vtkPoints* vtkSMUtilities::CreateOrbit(const double center[3],
......
......@@ -41,6 +41,18 @@ public:
static int SaveImage(vtkImageData* image, const char* filename)
{ return vtkSMUtilities::SaveImage(image, filename, -1); }
// Description:
// Save the image to a file using a vtkImageWriter subclass given by writerName.
// The file is created on the process on which this method is called.
static int SaveImage(vtkImageData* image, const char* filename,
const char* writerName);
// Description:
// Calls SaveImage(image, filename, writerName) only on process 0.
// Other processes will recieve the return code through a broadcast.
static int SaveImageOnProcessZero(vtkImageData* image,
const char* filename, const char* writerName);
// Description:
// Returns the points an orbit to revolve around the \c center at a distance
// of \c radius in the plane defined by the \c center and the \c normal. The
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment