forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkXMLPStructuredGridReader.cxx
179 lines (149 loc) · 5.42 KB
/
vtkXMLPStructuredGridReader.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLPStructuredGridReader.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 "vtkXMLPStructuredGridReader.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkStructuredGrid.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLStructuredGridReader.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkStandardNewMacro(vtkXMLPStructuredGridReader);
//----------------------------------------------------------------------------
vtkXMLPStructuredGridReader::vtkXMLPStructuredGridReader()
{
}
//----------------------------------------------------------------------------
vtkXMLPStructuredGridReader::~vtkXMLPStructuredGridReader()
{
}
//----------------------------------------------------------------------------
void vtkXMLPStructuredGridReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
void vtkXMLPStructuredGridReader::SetupEmptyOutput()
{
this->GetCurrentOutput()->Initialize();
}
//----------------------------------------------------------------------------
vtkStructuredGrid* vtkXMLPStructuredGridReader::GetOutput(int idx)
{
return vtkStructuredGrid::SafeDownCast( this->GetOutputDataObject(idx) );
}
//----------------------------------------------------------------------------
vtkStructuredGrid* vtkXMLPStructuredGridReader::GetOutput()
{
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkStructuredGrid* vtkXMLPStructuredGridReader::GetPieceInput(int index)
{
vtkXMLStructuredGridReader* reader =
static_cast<vtkXMLStructuredGridReader*>(this->PieceReaders[index]);
return reader->GetOutput();
}
//----------------------------------------------------------------------------
const char* vtkXMLPStructuredGridReader::GetDataSetName()
{
return "PStructuredGrid";
}
//----------------------------------------------------------------------------
void vtkXMLPStructuredGridReader::SetOutputExtent(int* extent)
{
vtkStructuredGrid::SafeDownCast(this->GetCurrentOutput())->SetExtent(extent);
}
//----------------------------------------------------------------------------
void vtkXMLPStructuredGridReader::GetPieceInputExtent(int index, int* extent)
{
this->GetPieceInput(index)->GetExtent(extent);
}
//----------------------------------------------------------------------------
int
vtkXMLPStructuredGridReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
{
if(!this->Superclass::ReadPrimaryElement(ePrimary)) { return 0; }
// Find the PPoints element.
this->PPointsElement = 0;
int i;
int numNested = ePrimary->GetNumberOfNestedElements();
for(i=0;i < numNested; ++i)
{
vtkXMLDataElement* eNested = ePrimary->GetNestedElement(i);
if((strcmp(eNested->GetName(), "PPoints") == 0) &&
(eNested->GetNumberOfNestedElements() == 1))
{
this->PPointsElement = eNested;
}
}
if(!this->PPointsElement)
{
int extent[6];
this->GetCurrentOutputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent);
if((extent[0] <= extent[1]) && (extent[2] <= extent[3]) &&
(extent[4] <= extent[5]))
{
vtkErrorMacro("Could not find PPoints element with 1 array.");
return 0;
}
}
return 1;
}
//----------------------------------------------------------------------------
void vtkXMLPStructuredGridReader::SetupOutputData()
{
this->Superclass::SetupOutputData();
// Create the points array.
vtkPoints* points = vtkPoints::New();
if(this->PPointsElement)
{
// Non-zero volume.
vtkAbstractArray* aa = this->CreateArray(this->PPointsElement->GetNestedElement(0));
vtkDataArray* a = vtkDataArray::SafeDownCast(aa);
if(a)
{
a->SetNumberOfTuples(this->GetNumberOfPoints());
points->SetData(a);
a->Delete();
}
else
{
if (aa) { aa->Delete(); }
this->DataError = 1;
}
}
vtkStructuredGrid::SafeDownCast(this->GetCurrentOutput())->SetPoints(points);
points->Delete();
}
//----------------------------------------------------------------------------
int vtkXMLPStructuredGridReader::ReadPieceData()
{
if(!this->Superclass::ReadPieceData()) { return 0; }
// Copy the points.
vtkStructuredGrid* input = this->GetPieceInput(this->Piece);
vtkStructuredGrid* output = vtkStructuredGrid::SafeDownCast(
this->GetCurrentOutput());
this->CopyArrayForPoints(input->GetPoints()->GetData(),
output->GetPoints()->GetData());
return 1;
}
//----------------------------------------------------------------------------
vtkXMLDataReader* vtkXMLPStructuredGridReader::CreatePieceReader()
{
return vtkXMLStructuredGridReader::New();
}
int vtkXMLPStructuredGridReader::FillOutputPortInformation(int, vtkInformation *info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkStructuredGrid");
return 1;
}