Commit 07792158 authored by Berk Geveci's avatar Berk Geveci

ENH: Added hierarchical dataset reader and writer

parent 5eb3bf5b
......@@ -3,7 +3,7 @@ SET(UKIT COMMON)
SET(KIT_TCL_LIBS ${VTK_TCL_LIBRARIES})
SET(KIT_PYTHON_LIBS)
SET(KIT_JAVA_LIBS)
SET(KIT_LIBS)
SET(KIT_LIBS vtksys)
IF(WIN32)
IF (NOT VTK_USE_X)
......
......@@ -94,6 +94,9 @@ vtkXMLDataParser.cxx
vtkXMLDataReader.cxx
vtkXMLDataSetWriter.cxx
vtkXMLFileReadTester.cxx
vtkXMLHierarchicalBoxDataReader.cxx
vtkXMLHierarchicalDataReader.cxx
vtkXMLHierarchicalDataWriter.cxx
vtkXMLImageDataReader.cxx
vtkXMLImageDataWriter.cxx
vtkXMLPDataReader.cxx
......
/*=========================================================================
Program: ParaView
Module: vtkXMLHierarchicalBoxDataReader.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkXMLHierarchicalBoxDataReader.h"
#include "vtkAMRBox.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkDataSet.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkUniformGrid.h"
#include "vtkXMLDataElement.h"
vtkCxxRevisionMacro(vtkXMLHierarchicalBoxDataReader, "1.1");
vtkStandardNewMacro(vtkXMLHierarchicalBoxDataReader);
//----------------------------------------------------------------------------
vtkXMLHierarchicalBoxDataReader::vtkXMLHierarchicalBoxDataReader()
{
}
//----------------------------------------------------------------------------
vtkXMLHierarchicalBoxDataReader::~vtkXMLHierarchicalBoxDataReader()
{
}
//----------------------------------------------------------------------------
void vtkXMLHierarchicalBoxDataReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
const char* vtkXMLHierarchicalBoxDataReader::GetDataSetName()
{
return "vtkHierarchicalBoxDataSet";
}
//----------------------------------------------------------------------------
int vtkXMLHierarchicalBoxDataReader::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataObject");
info->Set(vtkCompositeDataPipeline::COMPOSITE_DATA_TYPE_NAME(),
"vtkHierarchicalBoxDataSet");
return 1;
}
//----------------------------------------------------------------------------
void vtkXMLHierarchicalBoxDataReader::ReadXMLData()
{
this->Superclass::ReadXMLData();
vtkExecutive* exec = this->GetExecutive();
vtkInformation* info = exec->GetOutputInformation(0);
vtkDataObject* doOutput =
info->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET());
vtkHierarchicalBoxDataSet* hb =
vtkHierarchicalBoxDataSet::SafeDownCast(doOutput);
if (!hb)
{
return;
}
hb->GenerateVisibilityArrays();
}
//----------------------------------------------------------------------------
void vtkXMLHierarchicalBoxDataReader::HandleBlock(vtkXMLDataElement* ds,
int level, int dsId,
vtkHierarchicalDataSet* output,
vtkDataSet* data)
{
vtkUniformGrid* ugrid = vtkUniformGrid::SafeDownCast(data);
if (!ugrid)
{
vtkErrorMacro("HierarchicalBoxDataSet can only contain uniform grids."
<< " The file contains: " << data->GetClassName()
<< "dataset. Ignoring block.");
}
int box[6];
if (ds->GetVectorAttribute("amr_box", 6, box))
{
vtkHierarchicalBoxDataSet* hbds =
vtkHierarchicalBoxDataSet::SafeDownCast(output);
vtkAMRBox abox;
abox.LoCorner[0] = box[0];
abox.HiCorner[0] = box[1];
abox.LoCorner[1] = box[3];
abox.HiCorner[1] = box[4];
abox.LoCorner[2] = box[5];
abox.HiCorner[2] = box[6];
hbds->SetDataSet(level, dsId, abox, ugrid);
}
else
{
output->SetDataSet(level, dsId, data);
}
}
/*=========================================================================
Program: ParaView
Module: vtkXMLHierarchicalBoxDataReader.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 vtkXMLHierarchicalBoxDataReader - Reader for hierarchical datasets
// .SECTION Description
// vtkXMLHierarchicalBoxDataReader reads the VTK XML hierarchical box data
// file (uniform grid amr) format. XML hierarchical data files are
// meta-files that point to a list of serial VTK XML files. Reading in
// parallel is not yet supported.
// .SECTION See Also
// vtkXMLHierarchicalDataReader
#ifndef __vtkXMLHierarchicalBoxDataReader_h
#define __vtkXMLHierarchicalBoxDataReader_h
#include "vtkXMLHierarchicalDataReader.h"
class VTK_IO_EXPORT vtkXMLHierarchicalBoxDataReader : public vtkXMLHierarchicalDataReader
{
public:
static vtkXMLHierarchicalBoxDataReader* New();
vtkTypeRevisionMacro(vtkXMLHierarchicalBoxDataReader,vtkXMLHierarchicalDataReader);
void PrintSelf(ostream& os, vtkIndent indent);
protected:
vtkXMLHierarchicalBoxDataReader();
~vtkXMLHierarchicalBoxDataReader();
// Get the name of the data set being read.
virtual const char* GetDataSetName();
virtual void ReadXMLData();
virtual int FillOutputPortInformation(int, vtkInformation* info);
virtual void HandleBlock(
vtkXMLDataElement* ds, int level, int dsId,
vtkHierarchicalDataSet* output, vtkDataSet* data);
private:
vtkXMLHierarchicalBoxDataReader(const vtkXMLHierarchicalBoxDataReader&); // Not implemented.
void operator=(const vtkXMLHierarchicalBoxDataReader&); // Not implemented.
};
#endif
/*=========================================================================
Program: ParaView
Module: vtkXMLHierarchicalDataReader.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkXMLHierarchicalDataReader.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkDataSet.h"
#include "vtkHierarchicalDataSet.h"
#include "vtkInformation.h"
#include "vtkInstantiator.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtkXMLDataElement.h"
#include <vtkstd/map>
#include <vtkstd/string>
#include <vtkstd/vector>
vtkCxxRevisionMacro(vtkXMLHierarchicalDataReader, "1.1");
vtkStandardNewMacro(vtkXMLHierarchicalDataReader);
struct vtkXMLHierarchicalDataReaderEntry
{
const char* extension;
const char* name;
};
struct vtkXMLHierarchicalDataReaderInternals
{
vtkstd::vector<vtkXMLDataElement*> DataSets;
typedef vtkstd::map<vtkstd::string, vtkSmartPointer<vtkXMLReader> > ReadersType;
ReadersType Readers;
static const vtkXMLHierarchicalDataReaderEntry ReaderList[];
};
//----------------------------------------------------------------------------
vtkXMLHierarchicalDataReader::vtkXMLHierarchicalDataReader()
{
this->Internal = new vtkXMLHierarchicalDataReaderInternals;
}
//----------------------------------------------------------------------------
vtkXMLHierarchicalDataReader::~vtkXMLHierarchicalDataReader()
{
delete this->Internal;
}
//----------------------------------------------------------------------------
void vtkXMLHierarchicalDataReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
const char* vtkXMLHierarchicalDataReader::GetDataSetName()
{
return "vtkHierarchicalDataSet";
}
//----------------------------------------------------------------------------
void vtkXMLHierarchicalDataReader::SetupEmptyOutput()
{
vtkExecutive* exec = this->GetExecutive();
vtkInformation* info = exec->GetOutputInformation(0);
vtkDataObject* doOutput =
info->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET());
vtkHierarchicalDataSet* hb =
vtkHierarchicalDataSet::SafeDownCast(doOutput);
if (!hb)
{
return;
}
hb->Initialize();
}
//----------------------------------------------------------------------------
int vtkXMLHierarchicalDataReader::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataObject");
info->Set(vtkCompositeDataPipeline::COMPOSITE_DATA_TYPE_NAME(),
"vtkHierarchicalDataSet");
return 1;
}
//----------------------------------------------------------------------------
vtkExecutive* vtkXMLHierarchicalDataReader::CreateDefaultExecutive()
{
return vtkCompositeDataPipeline::New();
}
//----------------------------------------------------------------------------
vtkHierarchicalDataSet* vtkXMLHierarchicalDataReader::GetOutput()
{
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkHierarchicalDataSet* vtkXMLHierarchicalDataReader::GetOutput(int port)
{
vtkDataObject* output =
vtkCompositeDataPipeline::SafeDownCast(this->GetExecutive())->
GetCompositeOutputData(port);
return vtkHierarchicalDataSet::SafeDownCast(output);
}
//----------------------------------------------------------------------------
int vtkXMLHierarchicalDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
{
if(!this->Superclass::ReadPrimaryElement(ePrimary)) { return 0; }
int numNested = ePrimary->GetNumberOfNestedElements();
int i;
this->Internal->DataSets.clear();
for(i=0; i < numNested; ++i)
{
vtkXMLDataElement* eNested = ePrimary->GetNestedElement(i);
if(strcmp(eNested->GetName(), "DataSet") == 0)
{
this->Internal->DataSets.push_back(eNested);
}
}
return 1;
}
//----------------------------------------------------------------------------
vtkXMLReader* vtkXMLHierarchicalDataReader::GetReaderOfType(const char* type)
{
vtkXMLHierarchicalDataReaderInternals::ReadersType::iterator iter =
this->Internal->Readers.find(type);
if (iter != this->Internal->Readers.end())
{
return iter->second.GetPointer();
}
// Use the instantiator to create the reader.
vtkObject* o = vtkInstantiator::CreateInstance(type);
vtkXMLReader* reader = vtkXMLReader::SafeDownCast(o);
if (reader)
{
this->Internal->Readers[type] = reader;
reader->Delete();
}
return reader;
}
//----------------------------------------------------------------------------
void vtkXMLHierarchicalDataReader::ReadXMLData()
{
vtkExecutive* exec = this->GetExecutive();
vtkInformation* info = exec->GetOutputInformation(0);
vtkDataObject* doOutput =
info->Get(vtkCompositeDataSet::COMPOSITE_DATA_SET());
vtkHierarchicalDataSet* hb =
vtkHierarchicalDataSet::SafeDownCast(doOutput);
if (!hb)
{
return;
}
// Find the path to this file in case the internal files are
// specified as relative paths.
vtkstd::string filePath = this->FileName;
vtkstd::string::size_type pos = filePath.find_last_of("/\\");
if(pos != filePath.npos)
{
filePath = filePath.substr(0, pos);
}
else
{
filePath = "";
}
vtkstd::vector<vtkXMLDataElement*>::iterator d;
for(d=this->Internal->DataSets.begin();
d != this->Internal->DataSets.end(); ++d)
{
vtkXMLDataElement* ds = *d;
int level = 0;
int dsId = 0;
if (!ds->GetScalarAttribute("block", dsId))
{
continue;
}
int levelRead;
if (ds->GetScalarAttribute("level", levelRead))
{
level = levelRead;
}
// Construct the name of the internal file.
vtkstd::string fileName;
const char* file = ds->GetAttribute("file");
if(!(file[0] == '/' || file[1] == ':'))
{
fileName = filePath;
if(fileName.length())
{
fileName += "/";
}
}
fileName += file;
// Get the file extension.
vtkstd::string ext;
vtkstd::string::size_type pos = fileName.rfind('.');
if(pos != fileName.npos)
{
ext = fileName.substr(pos+1);
}
// Search for the reader matching this extension.
const char* rname = 0;
for(const vtkXMLHierarchicalDataReaderEntry* r = this->Internal->ReaderList;
!rname && r->extension; ++r)
{
if(ext == r->extension)
{
rname = r->name;
}
}
vtkXMLReader* reader = this->GetReaderOfType(rname);
reader->SetFileName(fileName.c_str());
reader->Update();
vtkDataSet* output = reader->GetOutputAsDataSet();
if (!output)
{
continue;
}
vtkDataSet* outputCopy = output->NewInstance();
outputCopy->ShallowCopy(output);
this->HandleBlock(ds, level, dsId, hb, outputCopy);
output->Initialize();
outputCopy->Delete();
}
}
//----------------------------------------------------------------------------
void vtkXMLHierarchicalDataReader::HandleBlock(vtkXMLDataElement*,
int level, int dsId,
vtkHierarchicalDataSet* output,
vtkDataSet* data)
{
output->SetDataSet(level, dsId, data);
}
//----------------------------------------------------------------------------
const vtkXMLHierarchicalDataReaderEntry
vtkXMLHierarchicalDataReaderInternals::ReaderList[] =
{
{"vtp", "vtkXMLPolyDataReader"},
{"vtu", "vtkXMLUnstructuredGridReader"},
{"vti", "vtkXMLImageDataReader"},
{"vtr", "vtkXMLRectilinearGridReader"},
{"vts", "vtkXMLStructuredGridReader"},
{0, 0}
};
/*=========================================================================
Program: ParaView
Module: vtkXMLHierarchicalDataReader.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 vtkXMLHierarchicalDataReader - Reader for hierarchical datasets
// .SECTION Description
// vtkXMLHierarchicalDataReader reads the VTK XML hierarchical data file
// (multi-block and amr) format. XML hierarchical data files are meta-files
// that point to a list of serial VTK XML files. Reading in parallel is not
// yet supported.
#ifndef __vtkXMLHierarchicalDataReader_h
#define __vtkXMLHierarchicalDataReader_h
#include "vtkXMLReader.h"
class vtkHierarchicalDataSet;
//BTX
struct vtkXMLHierarchicalDataReaderInternals;
//ETX
class VTK_IO_EXPORT vtkXMLHierarchicalDataReader : public vtkXMLReader
{
public:
static vtkXMLHierarchicalDataReader* New();
vtkTypeRevisionMacro(vtkXMLHierarchicalDataReader,vtkXMLReader);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get the output data object for a port on this algorithm.
vtkHierarchicalDataSet* GetOutput();
vtkHierarchicalDataSet* GetOutput(int);
protected:
vtkXMLHierarchicalDataReader();
~vtkXMLHierarchicalDataReader();
// Get the name of the data set being read.
virtual const char* GetDataSetName();
virtual void ReadXMLData();
virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
// Setup the output with no data available. Used in error cases.
virtual void SetupEmptyOutput();
virtual int FillOutputPortInformation(int, vtkInformation* info);
// Create a default executive.
virtual vtkExecutive* CreateDefaultExecutive();
vtkXMLReader* GetReaderOfType(const char* type);
virtual void HandleBlock(
vtkXMLDataElement* ds, int level, int dsId,
vtkHierarchicalDataSet* output, vtkDataSet* data);
private:
vtkXMLHierarchicalDataReader(const vtkXMLHierarchicalDataReader&); // Not implemented.
void operator=(const vtkXMLHierarchicalDataReader&); // Not implemented.
vtkXMLHierarchicalDataReaderInternals* Internal;
};
#endif
This diff is collapsed.
/*=========================================================================
Program: ParaView
Module: vtkXMLHierarchicalDataWriter.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 vtkXMLHierarchicalDataWriter - Writer for hierarchical datasets
// .SECTION Description
// vtkXMLHierarchicalDataWriter writes (serially) the VTK XML hierarchical
// and hierarchical box files. XML hierarchical data files are meta-files
// that point to a list of serial VTK XML files.
// .SECTION See Also
// vtkXMLPHierarchicalDataWriter
#ifndef __vtkXMLHierarchicalDataWriter_h
#define __vtkXMLHierarchicalDataWriter_h
#include "vtkXMLWriter.h"
class vtkCallbackCommand;
class vtkHierarchicalDataSet;
class vtkXMLHierarchicalDataWriterInternals;
class VTK_IO_EXPORT vtkXMLHierarchicalDataWriter : public vtkXMLWriter
{
public:
static vtkXMLHierarchicalDataWriter* New();
vtkTypeRevisionMacro(vtkXMLHierarchicalDataWriter,vtkXMLWriter);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get the default file extension for files written by this writer.
virtual const char* GetDefaultFileExtension();
// Description:
// Get/Set the piece number to write. The same piece number is used
// for all inputs.
vtkGetMacro(Piece, int);
vtkSetMacro(Piece, int);
// Description:
// Get/Set the number of pieces into which the inputs are split.
vtkGetMacro(NumberOfPieces, int);
vtkSetMacro(NumberOfPieces, int);
// Description:
// Get/Set the number of ghost levels to be written.
vtkGetMacro(GhostLevel, int);
vtkSetMacro(GhostLevel, int);
// Description:
// Get/Set whether this instance will write the meta-file.
vtkGetMacro(WriteMetaFile, int);
virtual void SetWriteMetaFile(int flag);
// See the vtkAlgorithm for a desciption of what these do
int ProcessRequest(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
protected:
vtkXMLHierarchicalDataWriter();
~vtkXMLHierarchicalDataWriter();
// see algorithm for more info
virtual int FillInputPortInformation(int port, vtkInformation* info);
int RequestData(
vtkInformation* , vtkInformationVector** , vtkInformationVector*);
int RequestUpdateExtent(
vtkInformation* , vtkInformationVector** , vtkInformationVector*);
virtual int WriteData();
virtual const char* GetDataSetName();
// Create a default executive.
virtual vtkExecutive* CreateDefaultExecutive();
vtkInformation* InputInformation;
virtual void FillDataTypes(vtkHierarchicalDataSet*);
unsigned int GetNumberOfDataTypes();
int* GetDataTypesPointer();
// Methods to create the set of writers matching the set of inputs.
void CreateWriters(vtkHierarchicalDataSet*);
vtkXMLWriter* GetWriter(int index);
// Methods to help construct internal file names.
void SplitFileName();
const char* GetFilePrefix();
const char* GetFilePath();
// Methods to construct the list of entries for the collection file.
void AppendEntry(const char* entry);
void DeleteAllEntries();
// Write the collection file if it is requested.
int WriteMetaFileIfRequested();
// Make a directory.
void MakeDirectory(const char* name);
// Remove a directory.
void RemoveADirectory(const char* name);
// Internal implementation details.
vtkXMLHierarchicalDataWriterInternals* Internal;
// The piece number to write.
int Piece;
// The number of pieces into which the inputs are split.
int NumberOfPieces;
// The number of ghost levels to write for unstructured data.
int GhostLevel;
// Whether to write the collection file on this node.
int WriteMetaFile;
int WriteMetaFileInitialized;
// Callback registered with the ProgressObserver.
static void ProgressCallbackFunction(vtkObject*, unsigned long, void*,
void*);
// Progress callback from internal writer.
virtual void ProgressCallback(vtkAlgorithm* w);
// The observer to report progress from the internal writer.
vtkCallbackCommand* ProgressObserver;
// Garbage collection support.
virtual void ReportReferences(vtkGarbageCollector*);
private:
vtkXMLHierarchicalDataWriter(const vtkXMLHierarchicalDataWriter&); // Not implemented.
void operator=(const vtkXMLHierarchicalDataWriter&); // Not implemented.
};
#endif
......@@ -93,6 +93,7 @@ vtkSubGroup.cxx
vtkTransmitPolyDataPiece.cxx
vtkTransmitUnstructuredGridPiece.cxx
vtkTreeCompositer.cxx
vtkXMLPHierarchicalDataWriter.cxx
)
IF(VTK_HAS_EXODUS)
......
......@@ -214,10 +214,15 @@ public:
{
MAX_PROCESSES = 8192,
ANY_SOURCE = -1,
INVALID_SOURCE = -2,
RMI_TAG = 315167,
RMI_ARG_TAG = 315168,
BREAK_RMI_TAG = 239954
INVALID_SOURCE = -2
};
enum Tags
{
RMI_TAG = 1,
RMI_ARG_TAG = 2,
BREAK_RMI_TAG = 3,
XML_WRITER_DATA_INFO = 4
};
//ETX
......