vtkXMLStructuredGridWriter.cxx 6.17 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXMLStructuredGridWriter.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
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkXMLStructuredGridWriter.h"
16 17

#include "vtkCellData.h"
18
#include "vtkErrorCode.h"
19
#include "vtkExtentTranslator.h"
20
#include "vtkInformation.h"
21
#include "vtkObjectFactory.h"
22
#include "vtkPointData.h"
23
#include "vtkStructuredGrid.h"
24
#include "vtkOffsetsManagerArray.h"
25

26
vtkCxxRevisionMacro(vtkXMLStructuredGridWriter, "1.10");
27 28 29 30 31
vtkStandardNewMacro(vtkXMLStructuredGridWriter);

//----------------------------------------------------------------------------
vtkXMLStructuredGridWriter::vtkXMLStructuredGridWriter()
{
32
  this->PointsOM = new OffsetsManagerGroup;
33 34 35 36 37
}

//----------------------------------------------------------------------------
vtkXMLStructuredGridWriter::~vtkXMLStructuredGridWriter()
{
38
  delete this->PointsOM;
39 40 41 42 43 44 45 46 47 48 49
}

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

//----------------------------------------------------------------------------
vtkStructuredGrid* vtkXMLStructuredGridWriter::GetInput()
{
50
  return static_cast<vtkStructuredGrid*>(this->Superclass::GetInput());
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
}

//----------------------------------------------------------------------------
void vtkXMLStructuredGridWriter::GetInputExtent(int* extent)
{
  this->GetInput()->GetExtent(extent);
}

//----------------------------------------------------------------------------
const char* vtkXMLStructuredGridWriter::GetDataSetName()
{
  return "StructuredGrid";
}

//----------------------------------------------------------------------------
const char* vtkXMLStructuredGridWriter::GetDefaultFileExtension()
{
  return "vts";
}

//----------------------------------------------------------------------------
72
void vtkXMLStructuredGridWriter::AllocatePositionArrays()
73
{
74
  this->Superclass::AllocatePositionArrays();
75
  this->PointsOM->Allocate(this->NumberOfPieces,this->NumberOfTimeSteps);
76 77 78 79 80 81
}

//----------------------------------------------------------------------------
void vtkXMLStructuredGridWriter::DeletePositionArrays()
{
  this->Superclass::DeletePositionArrays();
82 83 84 85 86 87 88
}

//----------------------------------------------------------------------------
void vtkXMLStructuredGridWriter::WriteAppendedPiece(int index,
                                                    vtkIndent indent)
{
  this->Superclass::WriteAppendedPiece(index, indent);
89 90 91 92
  if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
    {
    return;
    }
93 94
  this->WritePointsAppended(this->GetInput()->GetPoints(), indent, 
    &this->PointsOM->GetPiece(index));
95 96 97 98 99
}

//----------------------------------------------------------------------------
void vtkXMLStructuredGridWriter::WriteAppendedPieceData(int index)
{
100 101 102 103 104 105 106 107 108 109 110
  // Split progress range by the approximate fractions of data written
  // by each step in this method.
  float progressRange[2] = {0,0};
  this->GetProgressRange(progressRange);
  float fractions[3];
  this->CalculateSuperclassFraction(fractions);
  
  // Set the range of progress for the superclass.
  this->SetProgressRange(progressRange, 0, fractions);
  
  // Let the superclass write its data.
111
  this->Superclass::WriteAppendedPieceData(index);
112 113 114 115
  if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
    {
    return;
    }
116 117 118 119 120
  
  // Set the range of progress for the points array.
  this->SetProgressRange(progressRange, 1, fractions);
  
  // Write the points array.
121 122 123
  this->WritePointsAppendedData(this->GetInput()->GetPoints(), 
                                this->CurrentTimeIndex,
                                &this->PointsOM->GetPiece(index));
124 125 126
}

//----------------------------------------------------------------------------
127
void vtkXMLStructuredGridWriter::WriteInlinePiece(vtkIndent indent)
128
{
129 130 131 132 133 134 135 136 137 138 139
  // Split progress range by the approximate fractions of data written
  // by each step in this method.
  float progressRange[2] = {0,0};
  this->GetProgressRange(progressRange);
  float fractions[3];
  this->CalculateSuperclassFraction(fractions);
  
  // Set the range of progress for the superclass.
  this->SetProgressRange(progressRange, 0, fractions);
  
  // Let the superclass write its data.
140
  this->Superclass::WriteInlinePiece(indent);
141 142 143 144
  if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
    {
    return;
    }
145 146 147 148 149
  
  // Set the range of progress for the points array.
  this->SetProgressRange(progressRange, 1, fractions);
  
  // Write the points array.
150 151
  this->WritePointsInline(this->GetInput()->GetPoints(), indent);
}
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

//----------------------------------------------------------------------------
void vtkXMLStructuredGridWriter::CalculateSuperclassFraction(float* fractions)
{
  int extent[6];
  this->ExtentTranslator->GetExtent(extent);
  int dims[3] = {extent[1]-extent[0],
                 extent[3]-extent[2],
                 extent[5]-extent[4]};
  
  // The amount of data written by the superclass comes from the
  // point/cell data arrays.
  vtkIdType superclassPieceSize = 
    (this->GetInput()->GetPointData()->GetNumberOfArrays()*dims[0]*dims[1]*dims[2]+
     this->GetInput()->GetCellData()->GetNumberOfArrays()*(dims[0]-1)*(dims[1]-1)*(dims[2]-1));
  
  // The total data written includes the points array.
  vtkIdType totalPieceSize =
    superclassPieceSize + (dims[0] * dims[1] * dims[2]);
  if(totalPieceSize == 0)
    {
    totalPieceSize = 1;
    }
  fractions[0] = 0;
  fractions[1] = fractions[0] + float(superclassPieceSize)/totalPieceSize;
  fractions[2] = 1;
}
179

180
//----------------------------------------------------------------------------
181
int vtkXMLStructuredGridWriter::FillInputPortInformation(
182
  int , vtkInformation* info)
183 184 185 186
{
  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkStructuredGrid");
  return 1;
}