vtkXMLPDataSetWriter.cxx 4.83 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXMLPDataSetWriter.cxx

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8 9
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 13 14 15 16
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkXMLPDataSetWriter.h"

17
#include "vtkCallbackCommand.h"
18 19
#include "vtkDataSet.h"
#include "vtkImageData.h"
20
#include "vtkInformation.h"
21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkRectilinearGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXMLPImageDataWriter.h"
#include "vtkXMLPPolyDataWriter.h"
#include "vtkXMLPRectilinearGridWriter.h"
#include "vtkXMLPStructuredGridWriter.h"
#include "vtkXMLPUnstructuredGridWriter.h"

vtkStandardNewMacro(vtkXMLPDataSetWriter);

//----------------------------------------------------------------------------
35
vtkXMLPDataSetWriter::vtkXMLPDataSetWriter() = default;
36 37

//----------------------------------------------------------------------------
38
vtkXMLPDataSetWriter::~vtkXMLPDataSetWriter() = default;
39 40 41 42 43 44 45 46 47 48

//----------------------------------------------------------------------------
void vtkXMLPDataSetWriter::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

//----------------------------------------------------------------------------
vtkDataSet* vtkXMLPDataSetWriter::GetInput()
{
49
  return static_cast<vtkDataSet*>(this->Superclass::GetInput());
50 51 52
}

//----------------------------------------------------------------------------
53
int vtkXMLPDataSetWriter::WriteInternal()
54
{
55
  vtkAlgorithmOutput* input = this->GetInputConnection(0, 0);
56
  vtkXMLPDataWriter* writer = nullptr;
57

58
  // Create a writer based on the data set type.
59
  switch (this->GetInput()->GetDataObjectType())
60
  {
61
    case VTK_UNIFORM_GRID:
62 63
    case VTK_IMAGE_DATA:
    case VTK_STRUCTURED_POINTS:
64
    {
65
      vtkXMLPImageDataWriter* w = vtkXMLPImageDataWriter::New();
66
      w->SetInputConnection(input);
67
      writer = w;
68
    } break;
69
    case VTK_STRUCTURED_GRID:
70
    {
71
      vtkXMLPStructuredGridWriter* w = vtkXMLPStructuredGridWriter::New();
72
      w->SetInputConnection(input);
73
      writer = w;
74
    } break;
75
    case VTK_RECTILINEAR_GRID:
76
    {
77
      vtkXMLPRectilinearGridWriter* w = vtkXMLPRectilinearGridWriter::New();
78
      w->SetInputConnection(input);
79
      writer = w;
80
    } break;
81
    case VTK_UNSTRUCTURED_GRID:
82
    {
83
      vtkXMLPUnstructuredGridWriter* w = vtkXMLPUnstructuredGridWriter::New();
84
      w->SetInputConnection(input);
85
      writer = w;
86
    } break;
87
    case VTK_POLY_DATA:
88
    {
89
      vtkXMLPPolyDataWriter* w = vtkXMLPPolyDataWriter::New();
90
      w->SetInputConnection(input);
91
      writer = w;
92 93
    } break;
  }
94

95 96
  // Make sure we got a valid writer for the data set.
  if(!writer)
97
  {
98
    vtkErrorMacro("Cannot write dataset type: "
99
                  << this->GetInput()->GetDataObjectType());
100
    return 0;
101
  }
102

103 104 105 106 107 108 109 110
  // 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());
111 112
  writer->SetHeaderType(this->GetHeaderType());
  writer->SetIdType(this->GetIdType());
113 114 115 116
  writer->SetNumberOfPieces(this->GetNumberOfPieces());
  writer->SetGhostLevel(this->GetGhostLevel());
  writer->SetStartPiece(this->GetStartPiece());
  writer->SetEndPiece(this->GetEndPiece());
117
  writer->SetWriteSummaryFile(this->WriteSummaryFile);
118
  writer->AddObserver(vtkCommand::ProgressEvent, this->InternalProgressObserver);
119

120 121
  // Try to write.
  int result = writer->Write();
122

123
  // Cleanup.
124
  writer->RemoveObserver(this->InternalProgressObserver);
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
  writer->Delete();
  return result;
}

//----------------------------------------------------------------------------
const char* vtkXMLPDataSetWriter::GetDataSetName()
{
  return "DataSet";
}

//----------------------------------------------------------------------------
const char* vtkXMLPDataSetWriter::GetDefaultFileExtension()
{
  return "vtk";
}

//----------------------------------------------------------------------------
vtkXMLWriter* vtkXMLPDataSetWriter::CreatePieceWriter(int)
{
144
  return nullptr;
145
}
146 147 148 149 150 151 152
//----------------------------------------------------------------------------
int vtkXMLPDataSetWriter::FillInputPortInformation(
  int vtkNotUsed(port), vtkInformation* info)
{
  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
  return 1;
}