Commit 76724337 authored by Louis Amore's avatar Louis Amore Committed by Mathieu Westphal

Add vtkXMLPTableWriter & vtkXMLPTableReader

parent 00989c11
......@@ -6,6 +6,7 @@ set(Module_SRCS
vtkXMLPRectilinearGridWriter.cxx
vtkXMLPStructuredDataWriter.cxx
vtkXMLPStructuredGridWriter.cxx
vtkXMLPTableWriter.cxx
vtkXMLPUnstructuredDataWriter.cxx
vtkXMLPUnstructuredGridWriter.cxx
vtkXMLPHierarchicalBoxDataWriter.cxx
......
......@@ -17,14 +17,18 @@ pf = vtk.vtkProgrammableFilter()
def execute():
info = pf.GetOutputInformation(0)
et = vtk.vtkExtentTranslator()
et.SetWholeExtent(info.Get(vtk.vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT()))
et.SetPiece(info.Get(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER()))
et.SetNumberOfPieces(info.Get(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_NUMBER_OF_PIECES()))
et.PieceToExtent()
if pf.GetInput().IsA("vtkDataSet"):
et.SetWholeExtent(info.Get(vtk.vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT()))
et.SetPiece(info.Get(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER()))
et.SetNumberOfPieces(info.Get(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_NUMBER_OF_PIECES()))
et.PieceToExtent()
output = pf.GetOutput()
input = pf.GetInput()
output.ShallowCopy(input)
output.Crop(et.GetExtent())
if pf.GetInput().IsA("vtkDataSet"):
output.Crop(et.GetExtent())
pf.SetExecuteMethod(execute)
......@@ -90,6 +94,26 @@ def GetSource(dataType):
pf.SetInputData(sg)
return pf
elif dataType == 'Table':
s.Update()
input = s.GetOutput()
table = vtk.vtkTable()
RTData = input.GetPointData().GetArray(0)
nbTuples = RTData.GetNumberOfTuples()
array = vtk.vtkFloatArray()
array.SetName("RTData")
array.SetNumberOfTuples(nbTuples)
for i in range(0, nbTuples):
array.SetTuple1(i, float(RTData.GetTuple1(i)))
table.AddColumn(array)
pf.SetInputData(table)
return pf
def TestDataType(dataType, reader, writer, ext, numTris, useSubdir=False):
s = GetSource(dataType)
......@@ -114,17 +138,27 @@ def TestDataType(dataType, reader, writer, ext, numTris, useSubdir=False):
reader.SetFileName(filename)
cf = vtk.vtkContourFilter()
cf.SetValue(0, 130)
cf.SetComputeNormals(0)
cf.SetComputeGradients(0)
cf.SetInputConnection(reader.GetOutputPort())
cf.UpdateInformation()
cf.GetOutputInformation(0).Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_NUMBER_OF_PIECES(), nranks)
cf.GetOutputInformation(0).Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER(), rank)
cf.Update()
ntris = cf.GetOutput().GetNumberOfCells()
ntris = 0
if dataType != "Table":
cf = vtk.vtkContourFilter()
cf.SetValue(0, 130)
cf.SetComputeNormals(0)
cf.SetComputeGradients(0)
cf.SetInputConnection(reader.GetOutputPort())
cf.UpdateInformation()
cf.GetOutputInformation(0).Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_NUMBER_OF_PIECES(), nranks)
cf.GetOutputInformation(0).Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER(), rank)
cf.Update()
ntris = cf.GetOutput().GetNumberOfCells()
else:
reader.UpdateInformation()
reader.GetOutputInformation(0).Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_NUMBER_OF_PIECES(), nranks)
reader.GetOutputInformation(0).Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER(), rank)
reader.Update()
ntris = reader.GetOutput().GetNumberOfRows()
da = vtk.vtkIntArray()
da.InsertNextValue(ntris)
......@@ -148,9 +182,11 @@ TestDataType('ImageData', vtk.vtkXMLPImageDataReader(), vtk.vtkXMLPImageDataWrit
TestDataType('RectilinearGrid', vtk.vtkXMLPRectilinearGridReader(), vtk.vtkXMLPRectilinearGridWriter(), 'vtr', 4924)
TestDataType('StructuredGrid', vtk.vtkXMLPStructuredGridReader(), vtk.vtkXMLPStructuredGridWriter(), 'vts', 4924)
TestDataType('UnstructuredGrid', vtk.vtkXMLPUnstructuredGridReader(), vtk.vtkXMLPUnstructuredGridWriter(), 'vtu', 11856)
TestDataType('Table', vtk.vtkXMLPTableReader(), vtk.vtkXMLPTableWriter(), 'vtt', 18522)
# Test writers with UseSubdirectory on
TestDataType('ImageData', vtk.vtkXMLPImageDataReader(), vtk.vtkXMLPImageDataWriter(), 'vti', 4924, useSubdir=True)
TestDataType('RectilinearGrid', vtk.vtkXMLPRectilinearGridReader(), vtk.vtkXMLPRectilinearGridWriter(), 'vtr', 4924, useSubdir=True)
TestDataType('StructuredGrid', vtk.vtkXMLPStructuredGridReader(), vtk.vtkXMLPStructuredGridWriter(), 'vts', 4924, useSubdir=True)
TestDataType('UnstructuredGrid', vtk.vtkXMLPUnstructuredGridReader(), vtk.vtkXMLPUnstructuredGridWriter(), 'vtu', 11856, useSubdir=True)
TestDataType('Table', vtk.vtkXMLPTableReader(), vtk.vtkXMLPTableWriter(), 'vtt', 18522, useSubdir=True)
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLPTableWriter.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.
=========================================================================*/
/**
* @class vtkXMLPTableWriter
* @brief Write PVTK XML UnstructuredGrid files.
*
* vtkXMLPTableWriter writes the PVTK XML Table
* file format. One table input can be written into a
* parallel file format with any number of pieces spread across files.
* The standard extension for this writer's file format is "pvtt".
* This writer uses vtkXMLTableWriter to write the
* individual piece files.
*
* @sa
* vtkXMLTableWriter
*/
#ifndef vtkXMLPTableWriter_h
#define vtkXMLPTableWriter_h
#include "vtkIOParallelXMLModule.h" // For export macro
#include "vtkXMLWriter.h"
class vtkCallbackCommand;
class vtkMultiProcessController;
class vtkTable;
class vtkXMLTableWriter;
class VTKIOPARALLELXML_EXPORT vtkXMLPTableWriter : public vtkXMLWriter
{
public:
static vtkXMLPTableWriter* New();
vtkTypeMacro(vtkXMLPTableWriter, vtkXMLWriter);
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
/**
* Get/Set the writer's input.
*/
vtkTable* GetInput();
/**
* Get the default file extension for files written by this writer.
*/
const char* GetDefaultFileExtension() VTK_OVERRIDE;
//@{
/**
* Get/Set the number of pieces that are being written in parallel.
*/
vtkSetMacro(NumberOfPieces, int);
vtkGetMacro(NumberOfPieces, int);
//@}
//@{
/**
* Get/Set the range of pieces assigned to this writer.
*/
vtkSetMacro(StartPiece, int);
vtkGetMacro(StartPiece, int);
vtkSetMacro(EndPiece, int);
vtkGetMacro(EndPiece, int);
//@}
//@{
/**
* Get/Set the ghost level used for this writer's piece.
*/
vtkSetMacro(GhostLevel, int);
vtkGetMacro(GhostLevel, int);
//@}
//@{
/**
* Get/Set whether to use a subdirectory to store the pieces
*/
vtkSetMacro(UseSubdirectory, bool);
vtkGetMacro(UseSubdirectory, bool);
//@}
//@{
/**
* Get/Set whether the writer should write the summary file that
* refers to all of the pieces' individual files.
* This is on by default. Note that only the first process writes
* the summary file.
*/
virtual void SetWriteSummaryFile(int flag);
vtkGetMacro(WriteSummaryFile, int);
vtkBooleanMacro(WriteSummaryFile, int);
//@}
//@{
/**
* Controller used to communicate data type of blocks.
* By default, the global controller is used. If you want another
* controller to be used, set it with this.
*/
virtual void SetController(vtkMultiProcessController*);
vtkGetObjectMacro(Controller, vtkMultiProcessController);
//@}
/**
* Overridden to handle passing the CONTINUE_EXECUTING() flags to the
* executive.
*/
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector) VTK_OVERRIDE;
protected:
vtkXMLPTableWriter();
~vtkXMLPTableWriter() VTK_OVERRIDE;
/**
* see algorithm for more info
*/
int FillInputPortInformation(int port, vtkInformation* info) VTK_OVERRIDE;
const char* GetDataSetName() VTK_OVERRIDE;
vtkXMLTableWriter* CreateTablePieceWriter();
vtkXMLWriter* CreatePieceWriter(int index);
void WritePData(vtkIndent indent);
/**
* Overridden to make appropriate piece request from upstream.
*/
virtual int RequestUpdateExtent(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector);
/**
* Override writing method from superclass.
*/
int WriteInternal() VTK_OVERRIDE;
/**
* Collect information between ranks before writing the summary file.
* This method is called on all ranks while summary file is only written on 1
* rank (rank 0).
*/
virtual void PrepareSummaryFile();
void WritePrimaryElementAttributes(ostream& os, vtkIndent indent) VTK_OVERRIDE;
int WriteData() VTK_OVERRIDE;
virtual void WritePPieceAttributes(int index);
char* CreatePieceFileName(int index, const char* path = nullptr);
void SplitFileName();
virtual int WritePiece(int index);
/**
* Callback registered with the InternalProgressObserver.
*/
static void ProgressCallbackFunction(vtkObject*, unsigned long, void*, void*);
/**
* Valid at end of WriteInternal to indicate if we're going to continue
* execution.
*/
vtkGetMacro(ContinuingExecution, bool);
void WritePRowData(vtkDataSetAttributes* ds, vtkIndent indent);
/**
* Progress callback from internal writer.
*/
/**
* The observer to report progress from the internal writer.
*/
vtkCallbackCommand* InternalProgressObserver;
vtkMultiProcessController* Controller;
virtual void ProgressCallback(vtkAlgorithm* w);
int StartPiece;
int EndPiece;
int NumberOfPieces;
int GhostLevel;
int WriteSummaryFile;
bool UseSubdirectory;
char* PathName;
char* FileNameBase;
char* FileNameExtension;
char* PieceFileNameExtension;
private:
vtkXMLPTableWriter(const vtkXMLPTableWriter&) VTK_DELETE_FUNCTION;
void operator=(const vtkXMLPTableWriter&) VTK_DELETE_FUNCTION;
/**
* Method used to delete all written files.
*/
void DeleteFiles();
/**
* Initializes PieceFileNameExtension.
*/
void SetupPieceFileNameExtension();
/**
* Indicates the piece currently being written.
*/
int CurrentPiece;
/**
* Set in WriteInternal() to request continued execution from the executive to
* write more pieces.
*/
bool ContinuingExecution;
/**
* Flags used to keep track of which pieces were written out.
*/
unsigned char* PieceWrittenFlags;
};
#endif
......@@ -25,6 +25,7 @@ set(Module_SRCS
vtkXMLPRectilinearGridReader.cxx
vtkXMLPStructuredDataReader.cxx
vtkXMLPStructuredGridReader.cxx
vtkXMLPTableReader.cxx
vtkXMLPUnstructuredDataReader.cxx
vtkXMLPUnstructuredGridReader.cxx
vtkXMLReader.cxx
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLPTableReader.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.
=========================================================================*/
/**
* @class vtkXMLPTableReader
* @brief Read PVTK XML Table files.
*
* vtkXMLPTableReader reads the PVTK XML Table
* file format. This reads the parallel format's summary file and
* then uses vtkXMLTableReader to read data from the
* individual Table piece files. Streaming is supported.
* The standard extension for this reader's file format is "pvtt".
*
* @sa
* vtkXMLTableReader
*/
#ifndef vtkXMLPTableReader_h
#define vtkXMLPTableReader_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkXMLReader.h"
//class vtkDataArray;
class vtkTable;
class vtkXMLTableReader;
class VTKIOXML_EXPORT vtkXMLPTableReader : public vtkXMLReader
{
public:
vtkTypeMacro(vtkXMLPTableReader,vtkXMLReader);
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
static vtkXMLPTableReader *New();
//@{
/**
* Get the reader's output.
*/
vtkTable *GetOutput();
vtkTable *GetOutput(int idx);
//@}
/**
* For the specified port, copy the information this reader sets up in
* SetupOutputInformation to outInfo
*/
void CopyOutputInformation(vtkInformation *outInfo, int port) VTK_OVERRIDE;
//@{
/**
* Get the number of pieces from the summary file being read.
*/
vtkGetMacro(NumberOfPieces, int);
//@}
//@{
/**
* Get the number of columns arrays available in the input.
*/
int GetNumberOfColumnArrays();
//@}
//@{
/**
* Get the name of the column with the given index in
* the input.
*/
const char* GetColumnArrayName(int index);
//@}
//@{
/**
* Get/Set whether the column array with the given name is to
* be read.
*/
int GetColumnArrayStatus(const char* name);
void SetColumnArrayStatus(const char* name, int status);
//@}
//@{
/**
* Get the data array selection tables used to configure which data
* arrays are loaded by the reader.
*/
vtkGetObjectMacro(ColumnSelection, vtkDataArraySelection);
//@}
protected:
vtkXMLPTableReader();
~vtkXMLPTableReader() VTK_OVERRIDE;
const char* GetDataSetName() VTK_OVERRIDE;
void GetOutputUpdateExtent(int& piece, int& numberOfPieces);
void SetupOutputTotals();
void SetupOutputData() VTK_OVERRIDE;
void SetupNextPiece();
int ReadPieceData();
vtkXMLTableReader *CreatePieceReader();
int FillOutputPortInformation(int, vtkInformation*) VTK_OVERRIDE;
int RequestInformation(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector) VTK_OVERRIDE;
vtkTable* GetOutputAsTable();
vtkTable* GetPieceInputAsTable(int piece);
vtkIdType GetNumberOfRows();
void SetupEmptyOutput() VTK_OVERRIDE;
/**
* Setup the output's information.
*/
void SetupOutputInformation(vtkInformation *outInfo) VTK_OVERRIDE;
/**
* Pipeline execute data driver. Called by vtkXMLReader.
*/
void ReadXMLData() VTK_OVERRIDE;
int ReadPrimaryElement(vtkXMLDataElement* ePrimary) VTK_OVERRIDE;
void SetupUpdateExtent(int piece, int numberOfPieces);
/**
* Get the number of rows in the given piece. Valid after
* UpdateInformation.
*/
virtual vtkIdType GetNumberOfRowsInPiece(int piece);
/**
* The update request.
*/
int UpdatePiece;
int UpdateNumberOfPieces;
/**
* The range of pieces from the file that will form the UpdatePiece.
*/
int StartPiece;
int EndPiece;
vtkIdType TotalNumberOfRows;
vtkIdType StartRow;
/**
* Pipeline execute information driver. Called by vtkXMLReader.
*/
int ReadXMLInformation() VTK_OVERRIDE;
virtual void SetupPieces(int numPieces);
virtual void DestroyPieces();
int ReadPiece(vtkXMLDataElement* ePiece, int index);
virtual int ReadPiece(vtkXMLDataElement* ePiece);
int ReadPieceData(int index);
int CanReadPiece(int index);
char* CreatePieceFileName(const char* fileName);
void SplitFileName();
/**
* Callback registered with the PieceProgressObserver.
*/
static void PieceProgressCallbackFunction(vtkObject*, unsigned long, void*,
void*);
virtual void PieceProgressCallback();
/**
* Pieces from the input summary file.
*/
int NumberOfPieces;
/**
* The piece currently being read.
*/
int Piece;
/**
* The path to the input file without the file name.
*/
char* PathName;
/**
* Information per-piece.
*/
vtkXMLDataElement** PieceElements;
vtkXMLTableReader** PieceReaders;
int* CanReadPieceFlag;
/**
* The PRowData element representations.
*/
vtkXMLDataElement* PRowElement;
/**
* The observer to report progress from reading serial data in each
* piece.
*/
vtkCallbackCommand* PieceProgressObserver;
/**
* Check whether the given array element is an enabled array.
*/
int ColumnIsEnabled(vtkXMLDataElement* elementRowData);
int GetNumberOfRowArrays();
const char* GetRowArrayName(int index);
vtkDataArraySelection* ColumnSelection;
private:
vtkXMLPTableReader(const vtkXMLPTableReader&) VTK_DELETE_FUNCTION;
void operator=(const vtkXMLPTableReader&) VTK_DELETE_FUNCTION;
};
#endif
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