Commit a7add686 authored by Ethan Stam's avatar Ethan Stam Committed by Kitware Robot

Merge topic 'wip-HTG-readers-and-writers'

170ca8b6 Remove ReadPiece for vtkXMLHyperTreeGridReader
c8c38811 Merge branch 'ethan.stam/vtk-wip-HTG-readers-and-writers' into wip-HTG-readers-and-writers
77b1c651 Fix compilation warings for vtkXMLPHyperTreeGridWriter
6541525f Fix compilation warings for vtkXMLPHyperTreeGridReader
48ab1936 Allow HTG trees to be written in any order
14a36f74 fix easy htg warning and error
fdd8120a StartPiece instead of Piece 0
0d6f60cf Get phtg orientation
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Sebastien Jourdain's avatarSebastien Jourdain <sebastien.jourdain@kitware.com>
Merge-request: !5271
parents 4dd64236 170ca8b6
......@@ -805,7 +805,8 @@ vtkHyperTreeGrid::NewNonOrientedMooreSuperCursorLight( vtkIdType index,
void vtkHyperTreeGrid::Initialize()
{
this->Superclass::Initialize();
// DataObject Initialize will not do PointData
this->PointData->Initialize();
// Delete existing trees
this->DeleteTrees();
}
......
......@@ -12,7 +12,8 @@ set(classes
vtkXMLPUnstructuredGridWriter
vtkXMLPHierarchicalBoxDataWriter
vtkXMLPMultiBlockDataWriter
vtkXMLPUniformGridAMRWriter)
vtkXMLPUniformGridAMRWriter
vtkXMLPHyperTreeGridWriter)
vtk_module_add_module(VTK::IOParallelXML
CLASSES ${classes})
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLPHyperTreeGridWriter.cxx
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.
=========================================================================*/
#include "vtkXMLPHyperTreeGridWriter.h"
#include "vtkCallbackCommand.h"
#include "vtkErrorCode.h"
#include "vtkHyperTreeGrid.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkXMLHyperTreeGridWriter.h"
#include <vtksys/SystemTools.hxx>
#include <cassert>
vtkStandardNewMacro(vtkXMLPHyperTreeGridWriter);
//----------------------------------------------------------------------------
vtkXMLPHyperTreeGridWriter::vtkXMLPHyperTreeGridWriter() = default;
//----------------------------------------------------------------------------
vtkXMLPHyperTreeGridWriter::~vtkXMLPHyperTreeGridWriter() = default;
//----------------------------------------------------------------------------
void vtkXMLPHyperTreeGridWriter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
vtkHyperTreeGrid* vtkXMLPHyperTreeGridWriter::GetInput()
{
return vtkHyperTreeGrid::SafeDownCast(this->Superclass::GetInput());
}
//----------------------------------------------------------------------------
const char* vtkXMLPHyperTreeGridWriter::GetDataSetName()
{
return "PHyperTreeGrid";
}
//----------------------------------------------------------------------------
const char* vtkXMLPHyperTreeGridWriter::GetDefaultFileExtension()
{
return "phtg";
}
//----------------------------------------------------------------------------
vtkXMLHyperTreeGridWriter* vtkXMLPHyperTreeGridWriter::CreateHyperTreeGridPieceWriter(int vtkNotUsed(index))
{
// Create the writer for the piece.
vtkXMLHyperTreeGridWriter* pWriter = vtkXMLHyperTreeGridWriter::New();
pWriter->SetInputConnection(this->GetInputConnection(0, 0));
return pWriter;
}
//----------------------------------------------------------------------------
vtkXMLWriter* vtkXMLPHyperTreeGridWriter::CreatePieceWriter(int index)
{
// Create the writer for the piece.
vtkXMLHyperTreeGridWriter* pWriter = this->CreateHyperTreeGridPieceWriter(index);
return pWriter;
}
//----------------------------------------------------------------------------
void vtkXMLPHyperTreeGridWriter::WritePData(vtkIndent vtkNotUsed(indent))
{
}
//----------------------------------------------------------------------------
int vtkXMLPHyperTreeGridWriter::WritePieceInternal()
{
int piece = this->GetCurrentPiece();
vtkHyperTreeGrid* inputHyperTreeGrid = this->GetInput();
if (inputHyperTreeGrid)
{
if (!this->WritePiece(piece))
{
vtkErrorMacro("Could not write the current piece.");
this->DeleteFiles();
return 0;
}
this->PieceWrittenFlags[piece] = static_cast<unsigned char>(0x1);
}
return 1;
}
//----------------------------------------------------------------------------
int vtkXMLPHyperTreeGridWriter::WritePiece(int index)
{
// Create the writer for the piece. Its configuration should match
// our own writer.
vtkXMLWriter* pWriter = this->CreatePieceWriter(index);
pWriter->AddObserver(vtkCommand::ProgressEvent, this->InternalProgressObserver);
char* fileName = this->CreatePieceFileName(index, this->PathName);
std::string path = vtksys::SystemTools::GetParentDirectory(fileName);
if (!path.empty() && !vtksys::SystemTools::PathExists(path))
{
vtksys::SystemTools::MakeDirectory(path);
}
pWriter->SetFileName(fileName);
delete[] fileName;
// Copy the writer settings.
pWriter->SetDebug(this->Debug);
pWriter->SetCompressor(this->Compressor);
pWriter->SetDataMode(this->DataMode);
pWriter->SetByteOrder(this->ByteOrder);
pWriter->SetEncodeAppendedData(this->EncodeAppendedData);
pWriter->SetHeaderType(this->HeaderType);
pWriter->SetBlockSize(this->BlockSize);
// Write the piece.
int result = pWriter->Write();
this->SetErrorCode(pWriter->GetErrorCode());
// Cleanup.
pWriter->RemoveObserver(this->InternalProgressObserver);
pWriter->Delete();
return result;
}
//----------------------------------------------------------------------------
void vtkXMLPHyperTreeGridWriter::SetupPieceFileNameExtension()
{
this->Superclass::SetupPieceFileNameExtension();
// Create a temporary piece writer and then initialize the extension.
vtkXMLWriter* writer = this->CreatePieceWriter(0);
const char* ext = writer->GetDefaultFileExtension();
this->PieceFileNameExtension = new char[strlen(ext) + 2];
this->PieceFileNameExtension[0] = '.';
strcpy(this->PieceFileNameExtension + 1, ext);
writer->Delete();
}
//----------------------------------------------------------------------------
int vtkXMLPHyperTreeGridWriter::FillInputPortInformation(int, vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkHyperTreeGrid");
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLPHyperTreeGridWriter.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 vtkXMLPHyperTreeGridWriter
* @brief Write PVTK XML HyperTreeGrid files.
*
* vtkXMLPHyperTreeGridWriter writes the PVTK XML HyperTreeGrid
* file format. One hypertree grid 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 "phtg".
* This writer uses vtkXMLHyperTreeGridWriter to write the
* individual piece files.
*
* @sa
* vtkXMLHyperTreeGridWriter
*/
#ifndef vtkXMLPHyperTreeGridWriter_h
#define vtkXMLPHyperTreeGridWriter_h
#include "vtkXMLPDataObjectWriter.h"
class vtkCallbackCommand;
class vtkMultiProcessController;
class vtkHyperTreeGrid;
class vtkXMLHyperTreeGridWriter;
class vtkXMLPDataObjectWriter;
class VTKIOPARALLELXML_EXPORT vtkXMLPHyperTreeGridWriter : public vtkXMLPDataObjectWriter
{
public:
static vtkXMLPHyperTreeGridWriter* New();
vtkTypeMacro(vtkXMLPHyperTreeGridWriter, vtkXMLPDataObjectWriter);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Get/Set the writer's input.
*/
vtkHyperTreeGrid* GetInput();
/**
* Get the default file extension for files written by this writer.
*/
const char* GetDefaultFileExtension() override;
protected:
vtkXMLPHyperTreeGridWriter();
~vtkXMLPHyperTreeGridWriter() override;
/**
* see algorithm for more info
*/
int FillInputPortInformation(int port, vtkInformation* info) override;
/**
* Return the type of data being actually written
*/
const char* GetDataSetName() override;
/**
* Create a writer for the piece at a given index
*/
vtkXMLWriter* CreatePieceWriter(int index);
/**
* Create a table writer for the actual piece. Used by
* CreatePieceWriter(int index)
*/
vtkXMLHyperTreeGridWriter* CreateHyperTreeGridPieceWriter(int index);
/**
* Write a piece of the dataset on disk. Called by WritePieceInternal()
*/
int WritePiece(int index) override;
/**
* Method called by the superclass::WriteInternal(). Write a piece using
* WritePiece(int index).
*/
int WritePieceInternal() override;
/**
* Write Data associated with the input dataset
*/
void WritePData(vtkIndent indent) override;
private:
vtkXMLPHyperTreeGridWriter(const vtkXMLPHyperTreeGridWriter&) = delete;
void operator=(const vtkXMLPHyperTreeGridWriter&) = delete;
/**
* Initializes PieceFileNameExtension.
*/
void SetupPieceFileNameExtension() override;
};
#endif
......@@ -20,6 +20,7 @@ set(classes
vtkXMLMultiGroupDataReader
vtkXMLPDataObjectReader
vtkXMLPDataReader
vtkXMLPHyperTreeGridReader
vtkXMLPImageDataReader
vtkXMLPPolyDataReader
vtkXMLPRectilinearGridReader
......
......@@ -35,6 +35,7 @@
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStructuredGrid.h"
#include "vtkTable.h"
#include "vtkHyperTreeGrid.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLDataObjectWriter.h"
......@@ -270,7 +271,8 @@ int vtkXMLCompositeDataWriter::WriteNonCompositeData(
vtkDataSet* curDS = vtkDataSet::SafeDownCast(dObj);
vtkTable* curTable = vtkTable::SafeDownCast(dObj);
if (!curDS && !curTable)
vtkHyperTreeGrid* curHTG = vtkHyperTreeGrid::SafeDownCast(dObj);
if (!curDS && !curTable && !curHTG)
{
if (dObj)
{
......@@ -477,7 +479,8 @@ void vtkXMLCompositeDataWriter::CreateWriters(vtkCompositeDataSet* hdInput)
vtkSmartPointer<vtkXMLWriter>& writer = this->Internal->Writers[i];
vtkDataSet* ds = vtkDataSet::SafeDownCast(iter->GetCurrentDataObject());
vtkTable* table = vtkTable::SafeDownCast(iter->GetCurrentDataObject());
if (ds == nullptr && table == nullptr)
vtkHyperTreeGrid* htg = vtkHyperTreeGrid::SafeDownCast(iter->GetCurrentDataObject());
if (ds == nullptr && table == nullptr && htg == nullptr)
{
writer = nullptr;
continue;
......
This diff is collapsed.
......@@ -19,6 +19,9 @@
* vtkXMLHyperTreeGridReader reads the VTK XML HyperTreeGrid file
* format. The standard extension for this reader's file format is "htg".
*
* NOTE: HyperTree exists as separate units with all data within htg
* But each htg file is considered one piece for the parallel reader
* Later may want to treat individual HyperTrees as separate pieces.
*/
#ifndef vtkXMLHyperTreeGridReader_h
......@@ -36,20 +39,20 @@ class vtkIdTypeArray;
class VTKIOXML_EXPORT vtkXMLHyperTreeGridReader : public vtkXMLReader
{
public:
vtkTypeMacro(vtkXMLHyperTreeGridReader,vtkXMLReader);
vtkTypeMacro(vtkXMLHyperTreeGridReader, vtkXMLReader);
void PrintSelf(ostream& os, vtkIndent indent) override;
static vtkXMLHyperTreeGridReader *New();
static vtkXMLHyperTreeGridReader* New();
//@{
/**
* Get the reader's output.
*/
vtkHyperTreeGrid *GetOutput();
vtkHyperTreeGrid *GetOutput(int idx);
vtkHyperTreeGrid* GetOutput();
vtkHyperTreeGrid* GetOutput(int idx);
//@}
//These defer to the HyperTreeGrid output.
vtkIdType GetNumberOfVertices();
// These defer to the HyperTreeGrid output.
vtkIdType GetNumberOfPoints();
vtkIdType GetNumberOfPieces();
......@@ -84,7 +87,7 @@ protected:
void SetupOutputData() override;
// Setup the output's information
void SetupOutputInformation(vtkInformation *outInfo) override;
void SetupOutputInformation(vtkInformation* outInfo) override;
// Setup the number of pieces
void SetupPieces(int numPieces);
......@@ -96,21 +99,20 @@ protected:
int FillOutputPortInformation(int, vtkInformation*) override;
// Read the coordinates describing the grid
void ReadGrid(vtkXMLDataElement *elem);
void ReadGrid(vtkXMLDataElement* elem);
// Recover the structure of the HyperTreeGrid, used by ReadXMLData.
void ReadTrees(vtkXMLDataElement *elem);
void ReadTrees(vtkXMLDataElement* elem);
// Used by ReadTopology to recursively build the tree
void SubdivideFromDescriptor(
vtkHyperTreeGridNonOrientedCursor* treeCursor,
unsigned int level,
int numChildren,
vtkBitArray* desc,
vtkIdTypeArray* posByLevel);
void SubdivideFromDescriptor(vtkHyperTreeGridNonOrientedCursor* treeCursor,
unsigned int level,
int numChildren,
vtkBitArray* desc,
vtkIdTypeArray* posByLevel);
// Number of vertices in HyperTreeGrid being read
vtkIdType NumberOfVertices;
vtkIdType NumberOfPoints;
vtkIdType NumberOfPieces;
int UpdatedPiece;
......
This diff is collapsed.
......@@ -18,42 +18,29 @@
*
* vtkXMLHyperTreeGridWriter writes the VTK XML HyperTreeGrid file
* format. The standard extension for this writer's file format is "htg".
*/
*/
#ifndef vtkXMLHyperTreeGridWriter_h
#define vtkXMLHyperTreeGridWriter_h
#include "vtkBitArray.h" // For ivar
#include "vtkIOXMLModule.h" // For export macro
#include "vtkXMLWriter.h"
#include <vector> // std::vector
class OffsetsManagerGroup;
class OffsetsManagerArray;
class vtkHyperTreeGrid;
class vtkHyperTreeGridNonOrientedCursor;
class VTKIOXML_EXPORT vtkXMLHyperTreeGridWriter : public vtkXMLWriter
{
public:
vtkTypeMacro(vtkXMLHyperTreeGridWriter,vtkXMLWriter);
vtkTypeMacro(vtkXMLHyperTreeGridWriter, vtkXMLWriter);
void PrintSelf(ostream& os, vtkIndent indent) override;
static vtkXMLHyperTreeGridWriter* New();
//@{
/**
* Get/Set the number of pieces used to stream the table through the
* pipeline while writing to the file.
*/
vtkSetMacro(NumberOfPieces, int);
vtkGetMacro(NumberOfPieces, int);
//@}
//@{
/**
* Get/Set the piece to write to the file. If this is
* negative or equal to the NumberOfPieces, all pieces will be written.
*/
vtkSetMacro(WritePiece, int);
vtkGetMacro(WritePiece, int);
//@}
/**
* Get/Set the writer's input.
*/
......@@ -80,7 +67,7 @@ protected:
int StartPrimaryElement(vtkIndent);
// ... dim, size, origin>
void WritePrimaryElementAttributes(ostream &, vtkIndent) override;
void WritePrimaryElementAttributes(ostream&, vtkIndent) override;
// Grid coordinates and mask
int WriteGrid(vtkIndent);
......@@ -91,15 +78,25 @@ protected:
// </HyperTreeGrid>
int FinishPrimaryElement(vtkIndent);
/**
* Number of pieces used for streaming.
*/
int NumberOfPieces;
// Descriptors for individual hypertrees
std::vector<vtkBitArray*> Descriptors;
/**
* Which piece to write, if not all.
*/
int WritePiece;
// Masks for individual hypertrees
std::vector<vtkBitArray*> Masks;
// Helper to simplify writing appended array data
void WriteAppendedArrayDataHelper(vtkAbstractArray* array, OffsetsManager& offsets);
void WritePointDataAppendedArrayDataHelper(vtkAbstractArray* array,
vtkIdType treeOffset,
vtkIdType treeCount,
OffsetsManager& offsets);
OffsetsManagerGroup* CoordsOMG;
OffsetsManagerGroup* DescriptorOMG;
OffsetsManagerGroup* MaskOMG;
OffsetsManagerGroup* PointDataOMG;
int NumberOfTrees;
private:
vtkXMLHyperTreeGridWriter(const vtkXMLHyperTreeGridWriter&) = delete;
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLPHyperTreeGridReader.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 vtkXMLPHyperTreeGridReader
* @brief Read PVTK XML HyperTreeGrid files.
*
* vtkXMLPHyperTreeGridReader reads the PVTK XML HyperTreeGrid file format.
* This reader uses vtkXMLHyperTreeGridReader to read data from the
* individual HyperTreeGrid piece files. Streaming is supported.
* The standard extension for this reader's file format is "phtg".
*
* @sa
* vtkXMLHyperTreeGridReader
*/
#ifndef vtkXMLPHyperTreeGridReader_h
#define vtkXMLPHyperTreeGridReader_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkXMLPDataObjectReader.h"
class vtkHyperTreeCursor;
class vtkHyperTreeGrid;
class vtkHyperTreeGridNonOrientedCursor;
class vtkXMLHyperTreeGridReader;
class VTKIOXML_EXPORT vtkXMLPHyperTreeGridReader : public vtkXMLPDataObjectReader
{
public:
vtkTypeMacro(vtkXMLPHyperTreeGridReader, vtkXMLPDataObjectReader);
void PrintSelf(ostream& os, vtkIndent indent) override;
static vtkXMLPHyperTreeGridReader* New();
//@{
/**
* Get the reader's output.
*/
vtkHyperTreeGrid* GetOutput();
vtkHyperTreeGrid* GetOutput(int idx);
//@}
/**
* For the specified port, copy the information this reader sets up in
* SetupOutputInformation to outInfo
*/
void CopyOutputInformation(vtkInformation* outInfo, int port) override;
protected:
vtkXMLPHyperTreeGridReader();
~vtkXMLPHyperTreeGridReader() override;
/**
* Return the type of the dataset being read
*/
const char* GetDataSetName() override;
/**
* Get the number of vertices available in the input.
*/
vtkIdType GetNumberOfPoints();
vtkIdType GetNumberOfPointsInPiece(int piece);
vtkHyperTreeGrid* GetOutputAsHyperTreeGrid();
vtkHyperTreeGrid* GetPieceInputAsHyperTreeGrid(int piece);
/**
* Get the current piece index and the total number of pieces in the dataset
* Here let's consider a piece to be one hypertreegrid file
*/
void GetOutputUpdateExtent(int& piece, int& numberOfPieces);
/**
* Initialize current output
*/
void SetupEmptyOutput() override;
/**
* Initialize current output data
*/
void SetupOutputData() override;
/**
* Setup the output's information.
*/
void SetupOutputInformation(vtkInformation* outInfo) override;
/**
* Initialize the number of vertices from all the pieces
*/
void SetupOutputTotals();
/**
* no-op
*/
void SetupNextPiece();
/**
* Setup the number of pieces to be read
*/
void SetupPieces(int numPieces) override;
/**
* Setup the extent for the parallel reader and the piece readers.
*/
void SetupUpdateExtent(int piece, int numberOfPieces);
/**
* Setup the readers and then read the input data
*/
void ReadXMLData() override;
/**
* Whether or not the current reader can read the current piece
*/
int CanReadPiece(int index) override;
/**
* Pipeline execute data driver. Called by vtkXMLReader.
*/
int ReadPrimaryElement(vtkXMLDataElement* ePrimary) override;
/**
* Delete all piece readers and related information
*/
void DestroyPieces() override;
using vtkXMLPDataObjectReader::ReadPiece;
/**
* Setup the current piece reader.
*/
int ReadPiece(vtkXMLDataElement* ePiece) override;
/**
* Actually read the current piece data
*/
int ReadPieceData(int index);
int ReadPieceData();
void RecursivelyProcessTree(
vtkHyperTreeGridNonOrientedCursor* inCursor, vtkHyperTreeGridNonOrientedCursor* outCursor);
/**
* Create a reader according to the data to read
*/
vtkXMLHyperTreeGridReader* CreatePieceReader();
int FillOutputPortInformation(int, vtkInformation*) override;
int RequestInformation(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
/**
* Callback registered with the PieceProgressObserver.
*/
void PieceProgressCallback() override;
/**
* The update request.
*/
int UpdatePiece;
int UpdateNumberOfPieces;
/**
* The range of pieces from the file that will form the UpdatePiece.
*/
int StartPiece;
int EndPiece;
vtkIdType TotalNumberOfPoints;
vtkIdType PieceStartIndex;
vtkXMLHyperTreeGridReader** PieceReaders;
private:
vtkXMLPHyperTreeGridReader(const vtkXMLPHyperTreeGridReader&) = delete;
void operator=(const vtkXMLPHyperTreeGridReader&) = delete;
};
#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