Commit 1c383f1c authored by Chris Harris's avatar Chris Harris

Refactor vtkPNrrReader into parallel and non parallel version

The idea here is to have a base class vtkNrrdReader that can be
used without MPI and contains no #ifdefs. The subclass vtkPNrrdReader
is an MPI version. The object factory overrides are then used to
create the correct version depending on whether you link to the
parallel module. In order todo this the MPI code from vtkMPIImageReader
has to be pushed down into vtkPNrrdReader. vtkMPIImageReader has been
removed.

Change-Id: I4839c72711333ddbd8a79056391299a8c420ed21
parent ef1c817c
......@@ -32,6 +32,7 @@ set(Module_SRCS
vtkTIFFWriter.cxx
vtkVolume16Reader.cxx
vtkVolumeReader.cxx
vtkNrrdReader.cxx
)
if(WIN32)
......
This diff is collapsed.
// -*- c++ -*-
/*=========================================================================
Program: Visualization Toolkit
Module: vtkNrrdReader.h
Copyright (c) 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.
=========================================================================*/
/*----------------------------------------------------------------------------
Copyright (c) Sandia Corporation
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
// .NAME vtkNrrdReader - Read nrrd files file system
//
// .SECTION Description
//
// .SECTION Bugs
//
// There are several limitations on what type of nrrd files we can read. This
// reader only supports nrrd files in raw format. Other encodings like ascii
// and hex will result in errors. When reading in detached headers, this only
// supports reading one file that is detached.
//
#ifndef __vtkNrrdReader_h
#define __vtkNrrdReader_h
#include "vtkIOImageModule.h" // For export macro
#include "vtkImageReader.h"
class vtkCharArray;
class VTKIOIMAGE_EXPORT vtkNrrdReader : public vtkImageReader
{
public:
vtkTypeMacro(vtkNrrdReader, vtkImageReader);
static vtkNrrdReader *New();
virtual void PrintSelf(ostream &os, vtkIndent indent);
virtual int CanReadFile(const char *filename);
protected:
vtkNrrdReader();
~vtkNrrdReader();
virtual int RequestInformation(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
virtual int RequestData(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
int ReadHeaderInternal(vtkCharArray *headerBuffer);
virtual int ReadHeader();
virtual int ReadHeader(vtkCharArray *headerBuffer);
vtkStringArray *DataFiles;
private:
vtkNrrdReader(const vtkNrrdReader &); // Not implemented.
void operator=(const vtkNrrdReader &); // Not implemented.
};
#endif //__vtkNrrdReader_h
......@@ -2,8 +2,37 @@ find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
set(Module_SRCS
vtkMPIImageReader.cxx
vtkPNrrdReader.cxx
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx
)
vtk_module_library(vtkIOParallelMPI ${Module_SRCS})
set_source_files_properties(
${vtk-module}ObjectFactory
WRAP_EXCLUDE
)
# Now to generate our object factory.
set( vtk_module_overrides
NrrdReader
)
foreach(_class ${vtk_module_overrides})
set(_override vtkP${_class})
set(_vtk_override_includes "${_vtk_override_includes} #include \"${_override}.h\"")
set(_vtk_override_creates "${_vtk_override_creates}
VTK_CREATE_CREATE_FUNCTION(${_override})")
set(_vtk_override_do "${_vtk_override_do}
this->RegisterOverride(\"${_class}\",
\"${_override}\",
\"Override for ${vtk-module} module\", 1,
vtkObjectFactoryCreate${_override});")
endforeach()
# Now lets create the object factory classes
string(TOUPPER ${vtk-module} VTK-MODULE)
configure_file(${VTK_CMAKE_DIR}/vtkObjectFactory.h.in
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.h)
configure_file(${VTK_CMAKE_DIR}/vtkObjectFactory.cxx.in
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx)
vtk_module_library(vtkIOMPIImage ${Module_SRCS})
vtk_module(vtkIOParallelMPI
vtk_module(vtkIOMPIImage
IMPLEMENTS
vtkIOImage
GROUPS
MPI
DEPENDS
vtkParallelCore
vtkParallelMPI
vtkIOImage
)
This diff is collapsed.
// -*- c++ -*-
/*=========================================================================
Program: Visualization Toolkit
Module: vtkMPIImageReader.h
Copyright (c) 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.
=========================================================================*/
/*----------------------------------------------------------------------------
Copyright (c) Sandia Corporation
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/
// .NAME vtkMPIImageReader Superclass of parallel binary image file readers.
//
// .SECTION Description
//
// vtkMPIImageReader provides the mechanism to read a brick of bytes (or shorts,
// or ints, or floats, or doubles, ...) from a file or series of files. You can
// use it to read raw image data from files. You may also be able to subclass
// this to read simple file formats.
//
// What distinguishes this class from vtkImageReader and vtkImageReader2 is that
// it performs synchronized parallel I/O using the MPIIO layer. This can make a
// huge difference in file read times, especially when reading in parallel from
// a parallel file system.
//
// Despite the name of this class, vtkMPIImageReader will work even if MPI is
// not available. If MPI is not available or MPIIO is not available or the
// given Controller is not a vtkMPIController (or NULL), then this class will
// silently work exactly like its superclass. The point is that you can safely
// use this class in applications that may or may not be compiled with MPI (or
// may or may not actually be run with MPI).
//
// .SECTION See Also
// vtkMultiProcessController, vtkImageReader, vtkImageReader2
//
#ifndef __vtkMPIImageReader_h
#define __vtkMPIImageReader_h
#include "vtkIOParallelMPIModule.h" // For export macro
#include "vtkImageReader.h"
class vtkMPIOpaqueFileHandle;
class vtkMultiProcessController;
class VTKIOPARALLELMPI_EXPORT vtkMPIImageReader : public vtkImageReader
{
public:
vtkTypeMacro(vtkMPIImageReader, vtkImageReader);
static vtkMPIImageReader *New();
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Get/set the multi process controller to use for coordinated reads. By
// default, set to the global controller.
vtkGetObjectMacro(Controller, vtkMultiProcessController);
virtual void SetController(vtkMultiProcessController *);
protected:
vtkMPIImageReader();
~vtkMPIImageReader();
vtkMultiProcessController *Controller;
// Description:
// Returns the size, in bytes of the scalar data type (GetDataScalarType).
int GetDataScalarTypeSize();
// Description:
// Break up the controller based on the files each process reads. Each group
// comprises the processes that read the same files in the same order.
// this->GroupedController is set to the group for the current process.
virtual void PartitionController(const int extent[6]);
// Description:
// Get the header size of the given open file. This should be used in liu of
// the GetHeaderSize methods of the superclass.
virtual unsigned long GetHeaderSize(vtkMPIOpaqueFileHandle &file);
// Description:
// Set up a "view" on the open file that will allow you to read the 2D or 3D
// subarray from the file in one read. Once you call this method, the file
// will look as if it contains only the data the local process needs to read
// in.
virtual void SetupFileView(vtkMPIOpaqueFileHandle &file, const int extent[6]);
// Description:
// Given a slice of the data, open the appropriate file, read the data into
// given buffer, and close the file. For three dimensional data, always
// use "slice" 0. Make sure the GroupedController is properly created before
// calling this using the PartitionController method.
virtual void ReadSlice(int slice, const int extent[6], void *buffer);
// Description:
// Transform the data from the order read from a file to the order to place
// in the output data (as defined by the transform).
virtual void TransformData(vtkImageData *data);
// Description:
// A group of processes that are reading the same file (as determined by
// PartitionController.
void SetGroupedController(vtkMultiProcessController *);
vtkMultiProcessController *GroupedController;
virtual void ExecuteDataWithInformation(vtkDataObject *data,
vtkInformation *outInfo);
private:
vtkMPIImageReader(const vtkMPIImageReader &); // Not implemented
void operator=(const vtkMPIImageReader &); // Not implemented
};
#endif //__vtkMPIImageReader_h
This diff is collapsed.
......@@ -22,7 +22,7 @@
//
// .SECTION Description
//
// vtkPNrrdReader is a subclass of vtkMPIImageReader that will read Nrrd format
// vtkPNrrdReader is a subclass of vtkNrrdReader that will read Nrrd format
// header information of the image before reading the data. This means that the
// reader will automatically set information like file dimensions.
//
......@@ -37,36 +37,76 @@
#ifndef __vtkPNrrdReader_h
#define __vtkPNrrdReader_h
#include "vtkIOParallelMPIModule.h" // For export macro
#include "vtkMPIImageReader.h"
#include "vtkIOMPIImageModule.h" // For export macro
#include "vtkNrrdReader.h"
class vtkCharArray;
class vtkMultiProcessController;
class vtkMPIOpaqueFileHandle;
class VTKIOPARALLELMPI_EXPORT vtkPNrrdReader : public vtkMPIImageReader
class VTKIOMPIIMAGE_EXPORT vtkPNrrdReader : public vtkNrrdReader
{
public:
vtkTypeMacro(vtkPNrrdReader, vtkMPIImageReader);
vtkTypeMacro(vtkPNrrdReader, vtkNrrdReader);
static vtkPNrrdReader *New();
virtual void PrintSelf(ostream &os, vtkIndent indent);
virtual int CanReadFile(const char *filename);
// Description:
// Get/set the multi process controller to use for coordinated reads. By
// default, set to the global controller.
vtkGetObjectMacro(Controller, vtkMultiProcessController);
virtual void SetController(vtkMultiProcessController *);
protected:
vtkPNrrdReader();
~vtkPNrrdReader();
virtual int RequestInformation(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
virtual int RequestData(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
virtual int ReadHeader();
virtual int ReadHeader(vtkCharArray *headerBuffer);
vtkStringArray *DataFiles;
// Description:
// Returns the size, in bytes of the scalar data type (GetDataScalarType).
int GetDataScalarTypeSize();
// Description:
// Break up the controller based on the files each process reads. Each group
// comprises the processes that read the same files in the same order.
// this->GroupedController is set to the group for the current process.
virtual void PartitionController(const int extent[6]);
// Description:
// Get the header size of the given open file. This should be used in liu of
// the GetHeaderSize methods of the superclass.
virtual unsigned long GetHeaderSize(vtkMPIOpaqueFileHandle &file);
// Description:
// Set up a "view" on the open file that will allow you to read the 2D or 3D
// subarray from the file in one read. Once you call this method, the file
// will look as if it contains only the data the local process needs to read
// in.
virtual void SetupFileView(vtkMPIOpaqueFileHandle &file, const int extent[6]);
// Description:
// Given a slice of the data, open the appropriate file, read the data into
// given buffer, and close the file. For three dimensional data, always
// use "slice" 0. Make sure the GroupedController is properly created before
// calling this using the PartitionController method.
virtual void ReadSlice(int slice, const int extent[6], void *buffer);
// Description:
// Transform the data from the order read from a file to the order to place
// in the output data (as defined by the transform).
virtual void TransformData(vtkImageData *data);
// Description:
// A group of processes that are reading the same file (as determined by
// PartitionController.
void SetGroupedController(vtkMultiProcessController *);
vtkMultiProcessController *GroupedController;
virtual void ExecuteDataWithInformation(vtkDataObject *data,
vtkInformation *outInfo);
vtkMultiProcessController *Controller;
private:
vtkPNrrdReader(const vtkPNrrdReader &); // Not implemented.
......
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