Skip to content
Snippets Groups Projects
Commit b4a1dc51 authored by Louis Amore's avatar Louis Amore Committed by Mathieu Westphal (Kitware)
Browse files

Add vtkXMLDataObjectWriter

vtkXMLDataObjectWriter is a superclass for vtkXMLDataSetWriter and other
non-DataSet writers
parent aa36c0f3
No related branches found
No related tags found
1 merge request!3288Add XML writer and reader for vtkTable
......@@ -43,11 +43,11 @@ protected:
virtual vtkXMLWriter* CreatePieceWriter(int index) = 0;
virtual void WritePData(vtkIndent indent) VTK_OVERRIDE;
void WritePData(vtkIndent indent) VTK_OVERRIDE;
virtual int WritePieceInternal() VTK_OVERRIDE;
int WritePieceInternal() VTK_OVERRIDE;
virtual int WritePiece(int index) VTK_OVERRIDE;
int WritePiece(int index) VTK_OVERRIDE;
void WritePrimaryElementAttributes(ostream& os, vtkIndent indent) VTK_OVERRIDE;
......
......@@ -4,6 +4,7 @@ set(Module_SRCS
vtkXMLCompositeDataWriter.cxx
vtkXMLDataReader.cxx
vtkXMLDataSetWriter.cxx
vtkXMLDataObjectWriter.cxx
vtkXMLFileReadTester.cxx
vtkXMLGenericDataObjectReader.cxx
vtkXMLHierarchicalBoxDataFileConverter.cxx
......
......@@ -36,7 +36,7 @@
#include "vtkTable.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLDataSetWriter.h"
#include "vtkXMLDataObjectWriter.h"
#include <vtksys/SystemTools.hxx>
#include <map>
......@@ -68,7 +68,7 @@ public:
if (iter == this->TmpWriters.end())
{
vtkSmartPointer<vtkXMLWriter> writer;
writer.TakeReference(vtkXMLDataSetWriter::NewWriter(dataset_type));
writer.TakeReference(vtkXMLDataObjectWriter::NewWriter(dataset_type));
if (writer)
{
std::pair<int, vtkSmartPointer<vtkXMLWriter> > pair(dataset_type, writer);
......@@ -470,9 +470,9 @@ void vtkXMLCompositeDataWriter::CreateWriters(vtkCompositeDataSet* hdInput)
}
// Create a writer based on the type of this input. We just instantiate
// vtkXMLDataSetWriter. That internally creates the write type of writer
// vtkXMLDataObjectWriter. That internally creates the write type of writer
// based on the data type.
writer.TakeReference(vtkXMLDataSetWriter::NewWriter(this->Internal->DataTypes[i]));
writer.TakeReference(vtkXMLDataObjectWriter::NewWriter(this->Internal->DataTypes[i]));
if (writer)
{
// Copy settings to the writer.
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLDataObjectWriter.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 "vtkXMLDataObjectWriter.h"
#include "vtkAlgorithmOutput.h"
#include "vtkCallbackCommand.h"
#include "vtkDataSet.h"
#include "vtkHyperOctree.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkRectilinearGrid.h"
#include "vtkSmartPointer.h"
#include "vtkStructuredGrid.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXMLHyperOctreeWriter.h"
#include "vtkXMLImageDataWriter.h"
#include "vtkXMLPolyDataWriter.h"
#include "vtkXMLRectilinearGridWriter.h"
#include "vtkXMLStructuredGridWriter.h"
#include "vtkXMLTableWriter.h"
#include "vtkXMLUnstructuredGridWriter.h"
vtkStandardNewMacro(vtkXMLDataObjectWriter);
//----------------------------------------------------------------------------
vtkXMLDataObjectWriter::vtkXMLDataObjectWriter()
{
// Setup a callback for the internal writer to report progress.
this->InternalProgressObserver = vtkCallbackCommand::New();
this->InternalProgressObserver->SetCallback(&vtkXMLDataObjectWriter::ProgressCallbackFunction);
this->InternalProgressObserver->SetClientData(this);
}
//----------------------------------------------------------------------------
vtkXMLDataObjectWriter::~vtkXMLDataObjectWriter()
{
this->InternalProgressObserver->Delete();
}
//----------------------------------------------------------------------------
void vtkXMLDataObjectWriter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
vtkDataSet* vtkXMLDataObjectWriter::GetInput()
{
return static_cast<vtkDataSet*>(this->Superclass::GetInput());
}
//----------------------------------------------------------------------------
vtkXMLWriter* vtkXMLDataObjectWriter::NewWriter(int dataset_type)
{
// Create a writer based on the data set type.
switch (dataset_type)
{
case VTK_UNIFORM_GRID:
case VTK_IMAGE_DATA:
case VTK_STRUCTURED_POINTS:
return vtkXMLImageDataWriter::New();
case VTK_STRUCTURED_GRID:
return vtkXMLStructuredGridWriter::New();
case VTK_RECTILINEAR_GRID:
return vtkXMLRectilinearGridWriter::New();
case VTK_UNSTRUCTURED_GRID:
return vtkXMLUnstructuredGridWriter::New();
case VTK_POLY_DATA:
return vtkXMLPolyDataWriter::New();
case VTK_HYPER_OCTREE:
return vtkXMLHyperOctreeWriter::New();
case VTK_TABLE:
return vtkXMLTableWriter::New();
}
return nullptr;
}
//----------------------------------------------------------------------------
int vtkXMLDataObjectWriter::WriteInternal()
{
// Create a writer based on the data set type.
vtkXMLWriter* writer =
vtkXMLDataObjectWriter::NewWriter(this->GetInput()->GetDataObjectType());
if (writer)
{
writer->SetInputConnection(this->GetInputConnection(0, 0));
// Copy the settings to the writer.
writer->SetDebug(this->GetDebug());
writer->SetFileName(this->GetFileName());
writer->SetByteOrder(this->GetByteOrder());
writer->SetCompressor(this->GetCompressor());
writer->SetBlockSize(this->GetBlockSize());
writer->SetDataMode(this->GetDataMode());
writer->SetEncodeAppendedData(this->GetEncodeAppendedData());
writer->SetHeaderType(this->GetHeaderType());
writer->SetIdType(this->GetIdType());
writer->AddObserver(vtkCommand::ProgressEvent, this->InternalProgressObserver);
// Try to write.
int result = writer->Write();
// Cleanup.
writer->RemoveObserver(this->InternalProgressObserver);
writer->Delete();
return result;
}
// Make sure we got a valid writer for the data set.
vtkErrorMacro("Cannot write dataset type: "
<< this->GetInput()->GetDataObjectType() << " which is a "
<< this->GetInput()->GetClassName());
return 0;
}
//----------------------------------------------------------------------------
const char* vtkXMLDataObjectWriter::GetDataSetName()
{
return "DataSet";
}
//----------------------------------------------------------------------------
const char* vtkXMLDataObjectWriter::GetDefaultFileExtension()
{
return "vtk";
}
//----------------------------------------------------------------------------
void vtkXMLDataObjectWriter::ProgressCallbackFunction(vtkObject* caller,
unsigned long,
void* clientdata, void*)
{
vtkAlgorithm* w = vtkAlgorithm::SafeDownCast(caller);
if (w)
{
reinterpret_cast<vtkXMLDataObjectWriter*>(clientdata)->ProgressCallback(w);
}
}
//----------------------------------------------------------------------------
void vtkXMLDataObjectWriter::ProgressCallback(vtkAlgorithm* w)
{
float width = this->ProgressRange[1] - this->ProgressRange[0];
float internalProgress = w->GetProgress();
float progress = this->ProgressRange[0] + internalProgress*width;
this->UpdateProgressDiscrete(progress);
if (this->AbortExecute)
{
w->SetAbortExecute(1);
}
}
//----------------------------------------------------------------------------
int vtkXMLDataObjectWriter::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLDataObjectWriter.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 vtkXMLDataObjectWriter
* @brief Write any type of VTK XML file.
*
* vtkXMLDataObjectWriter is a wrapper around the VTK XML file format
* writers. Given an input vtkDataSet, the correct writer is
* automatically selected based on the type of input.
*
* @sa
* vtkXMLImageDataWriter vtkXMLStructuredGridWriter
* vtkXMLRectilinearGridWriter vtkXMLPolyDataWriter
* vtkXMLUnstructuredGridWriter
*/
#ifndef vtkXMLDataObjectWriter_h
#define vtkXMLDataObjectWriter_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkXMLWriter.h"
class vtkCallbackCommand;
class VTKIOXML_EXPORT vtkXMLDataObjectWriter : public vtkXMLWriter
{
public:
vtkTypeMacro(vtkXMLDataObjectWriter,vtkXMLWriter);
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
static vtkXMLDataObjectWriter* New();
/**
* Get/Set the writer's input.
*/
vtkDataSet* GetInput();
/**
* Creates a writer for the given dataset type. May return nullptr for
* unsupported/unrecognized dataset types. Returns a new instance. The caller
* is responsible of calling vtkObject::Delete() or vtkObject::UnRegister() on
* it when done.
*/
static vtkXMLWriter* NewWriter(int dataset_type);
protected:
vtkXMLDataObjectWriter();
~vtkXMLDataObjectWriter() VTK_OVERRIDE;
// see algorithm for more info
int FillInputPortInformation(int port, vtkInformation* info) VTK_OVERRIDE;
// Override writing method from superclass.
int WriteInternal() VTK_OVERRIDE;
// Dummies to satisfy pure virtuals from superclass.
const char* GetDataSetName() VTK_OVERRIDE;
const char* GetDefaultFileExtension() VTK_OVERRIDE;
// Callback registered with the InternalProgressObserver.
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* InternalProgressObserver;
private:
vtkXMLDataObjectWriter(const vtkXMLDataObjectWriter&) VTK_DELETE_FUNCTION;
void operator=(const vtkXMLDataObjectWriter&) VTK_DELETE_FUNCTION;
};
#endif
......@@ -31,7 +31,6 @@
#include "vtkXMLPolyDataWriter.h"
#include "vtkXMLRectilinearGridWriter.h"
#include "vtkXMLStructuredGridWriter.h"
#include "vtkXMLTableWriter.h"
#include "vtkXMLUnstructuredGridWriter.h"
vtkStandardNewMacro(vtkXMLDataSetWriter);
......@@ -39,135 +38,17 @@ vtkStandardNewMacro(vtkXMLDataSetWriter);
//----------------------------------------------------------------------------
vtkXMLDataSetWriter::vtkXMLDataSetWriter()
{
// Setup a callback for the internal writer to report progress.
this->InternalProgressObserver = vtkCallbackCommand::New();
this->InternalProgressObserver->SetCallback(&vtkXMLDataSetWriter::ProgressCallbackFunction);
this->InternalProgressObserver->SetClientData(this);
}
//----------------------------------------------------------------------------
vtkXMLDataSetWriter::~vtkXMLDataSetWriter()
{
this->InternalProgressObserver->Delete();
}
//----------------------------------------------------------------------------
void vtkXMLDataSetWriter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
vtkDataSet* vtkXMLDataSetWriter::GetInput()
{
return static_cast<vtkDataSet*>(this->Superclass::GetInput());
}
//----------------------------------------------------------------------------
vtkXMLWriter* vtkXMLDataSetWriter::NewWriter(int dataset_type)
{
// Create a writer based on the data set type.
switch (dataset_type)
{
case VTK_UNIFORM_GRID:
case VTK_IMAGE_DATA:
case VTK_STRUCTURED_POINTS:
return vtkXMLImageDataWriter::New();
case VTK_STRUCTURED_GRID:
return vtkXMLStructuredGridWriter::New();
case VTK_RECTILINEAR_GRID:
return vtkXMLRectilinearGridWriter::New();
case VTK_UNSTRUCTURED_GRID:
return vtkXMLUnstructuredGridWriter::New();
case VTK_POLY_DATA:
return vtkXMLPolyDataWriter::New();
case VTK_HYPER_OCTREE:
return vtkXMLHyperOctreeWriter::New();
case VTK_TABLE:
return vtkXMLTableWriter::New();
}
return nullptr;
}
//----------------------------------------------------------------------------
int vtkXMLDataSetWriter::WriteInternal()
{
// Create a writer based on the data set type.
vtkXMLWriter* writer =
vtkXMLDataSetWriter::NewWriter(this->GetInput()->GetDataObjectType());
if (writer)
{
writer->SetInputConnection(this->GetInputConnection(0, 0));
// Copy the settings to the writer.
writer->SetDebug(this->GetDebug());
writer->SetFileName(this->GetFileName());
writer->SetByteOrder(this->GetByteOrder());
writer->SetCompressor(this->GetCompressor());
writer->SetBlockSize(this->GetBlockSize());
writer->SetDataMode(this->GetDataMode());
writer->SetEncodeAppendedData(this->GetEncodeAppendedData());
writer->SetHeaderType(this->GetHeaderType());
writer->SetIdType(this->GetIdType());
writer->AddObserver(vtkCommand::ProgressEvent, this->InternalProgressObserver);
// Try to write.
int result = writer->Write();
// Cleanup.
writer->RemoveObserver(this->InternalProgressObserver);
writer->Delete();
return result;
}
// Make sure we got a valid writer for the data set.
vtkErrorMacro("Cannot write dataset type: "
<< this->GetInput()->GetDataObjectType() << " which is a "
<< this->GetInput()->GetClassName());
return 0;
}
//----------------------------------------------------------------------------
const char* vtkXMLDataSetWriter::GetDataSetName()
{
return "DataSet";
}
//----------------------------------------------------------------------------
const char* vtkXMLDataSetWriter::GetDefaultFileExtension()
{
return "vtk";
}
//----------------------------------------------------------------------------
void vtkXMLDataSetWriter::ProgressCallbackFunction(vtkObject* caller,
unsigned long,
void* clientdata, void*)
{
vtkAlgorithm* w = vtkAlgorithm::SafeDownCast(caller);
if (w)
{
reinterpret_cast<vtkXMLDataSetWriter*>(clientdata)->ProgressCallback(w);
}
}
//----------------------------------------------------------------------------
void vtkXMLDataSetWriter::ProgressCallback(vtkAlgorithm* w)
{
float width = this->ProgressRange[1] - this->ProgressRange[0];
float internalProgress = w->GetProgress();
float progress = this->ProgressRange[0] + internalProgress*width;
this->UpdateProgressDiscrete(progress);
if (this->AbortExecute)
{
w->SetAbortExecute(1);
}
}
//----------------------------------------------------------------------------
int vtkXMLDataSetWriter::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
return 1;
}
......@@ -30,30 +30,16 @@
#define vtkXMLDataSetWriter_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkXMLWriter.h"
#include "vtkXMLDataObjectWriter.h"
class vtkCallbackCommand;
class VTKIOXML_EXPORT vtkXMLDataSetWriter : public vtkXMLWriter
class VTKIOXML_EXPORT vtkXMLDataSetWriter : public vtkXMLDataObjectWriter
{
public:
vtkTypeMacro(vtkXMLDataSetWriter,vtkXMLWriter);
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
vtkTypeMacro(vtkXMLDataSetWriter,vtkXMLDataObjectWriter);
static vtkXMLDataSetWriter* New();
/**
* Get/Set the writer's input.
*/
vtkDataSet* GetInput();
/**
* Creates a writer for the given dataset type. May return nullptr for
* unsupported/unrecognized dataset types. Returns a new instance. The caller
* is responsible of calling vtkObject::Delete() or vtkObject::UnRegister() on
* it when done.
*/
static vtkXMLWriter* NewWriter(int dataset_type);
protected:
vtkXMLDataSetWriter();
~vtkXMLDataSetWriter() VTK_OVERRIDE;
......@@ -61,22 +47,6 @@ protected:
// see algorithm for more info
int FillInputPortInformation(int port, vtkInformation* info) VTK_OVERRIDE;
// Override writing method from superclass.
int WriteInternal() VTK_OVERRIDE;
// Dummies to satisfy pure virtuals from superclass.
const char* GetDataSetName() VTK_OVERRIDE;
const char* GetDefaultFileExtension() VTK_OVERRIDE;
// Callback registered with the InternalProgressObserver.
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* InternalProgressObserver;
private:
vtkXMLDataSetWriter(const vtkXMLDataSetWriter&) VTK_DELETE_FUNCTION;
void operator=(const vtkXMLDataSetWriter&) VTK_DELETE_FUNCTION;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment