Newer
Older
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
#include "vtkNew.h"
#include <string>
#include <vtkCell.h>
#include <vtkIdList.h>
#include <vtkMultiProcessController.h>
#include <vtkPoints.h>
#include <vtkUnstructuredGrid.h>
#include <vtkTestUtilities.h>
#include <vtkXMLUnstructuredGridReader.h>
#include <vtkXMLPUnstructuredGridWriter.h>
#include <vtkXMLPUnstructuredGridReader.h>
bool CompareGrids(vtkUnstructuredGrid *s, vtkUnstructuredGrid *t)
{
if (s->GetNumberOfCells() != t->GetNumberOfCells())
{
return false;
}
for(vtkIdType i = 0; i < s->GetNumberOfCells(); ++i)
{
if (s->GetCellType(i) != t->GetCellType(i))
{
return false;
}
vtkNew<vtkIdList> sIds, tIds;
if (s->GetCellType(i) == VTK_POLYHEDRON)
{
s->GetFaceStream(i, sIds.GetPointer());
t->GetFaceStream(i, tIds.GetPointer());
}
else
{
s->GetCellPoints(i, sIds.GetPointer());
t->GetCellPoints(i, tIds.GetPointer());
}
if (sIds->GetNumberOfIds() != tIds->GetNumberOfIds())
{
return false;
}
for(vtkIdType j = 0; i < sIds->GetNumberOfIds(); ++j)
{
vtkIdType sId = sIds->GetId(j);
vtkIdType tId = tIds->GetId(j);
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
if(sId != tId) return false;
}
}
return true;
}
int TestParallelUnstructuredGridIO(int argc, char* argv[])
{
vtkNew<vtkPoints> points;
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(1, 0, 0);
points->InsertNextPoint(1, 1, 0);
points->InsertNextPoint(0, 1, 0);
points->InsertNextPoint(0, 0, 1);
points->InsertNextPoint(1, 0, 1);
points->InsertNextPoint(1, 1, 1);
points->InsertNextPoint(0, 1, 1);
points->InsertNextPoint(.5, .5, 2);
points->InsertNextPoint(.5, .5, -1);
vtkNew<vtkUnstructuredGrid> ug;
ug->SetPoints(points);
ug->Allocate(3); // allocate for 3 cells
vtkNew<vtkIdList> ids;
// add a hexahedron of the first 8 points (i.e. a cube)
ids->InsertNextId(0);
ids->InsertNextId(1);
ids->InsertNextId(2);
ids->InsertNextId(3);
ids->InsertNextId(4);
ids->InsertNextId(5);
ids->InsertNextId(6);
ids->InsertNextId(7);
ug->InsertNextCell(VTK_HEXAHEDRON, ids.GetPointer());
ids->Reset();
// add a polyhedron comprise of the top hexahedron face
// and four triangles to the 9th point
ids->InsertNextId(4);
ids->InsertNextId(5);
ids->InsertNextId(6);
ids->InsertNextId(7);
ids->InsertNextId(8);
vtkNew<vtkIdList> faces;
// top face of four points
faces->InsertNextId(4);
faces->InsertNextId(4);
faces->InsertNextId(5);
faces->InsertNextId(6);
faces->InsertNextId(7);
// four triangle side faces, each of three points
faces->InsertNextId(3);
faces->InsertNextId(4);
faces->InsertNextId(5);
faces->InsertNextId(8);
faces->InsertNextId(3);
faces->InsertNextId(5);
faces->InsertNextId(6);
faces->InsertNextId(8);
faces->InsertNextId(3);
faces->InsertNextId(6);
faces->InsertNextId(7);
faces->InsertNextId(8);
faces->InsertNextId(3);
faces->InsertNextId(7);
faces->InsertNextId(4);
faces->InsertNextId(8);
// insert the polyhedron cell
ug->InsertNextCell(VTK_POLYHEDRON, 5, ids.GetPointer()->GetPointer(0), 5, faces.GetPointer()->GetPointer(0));
// put another pyramid on the bottom towards the 10th point
faces->Reset();
ids->Reset();
// the list of points that the pyramid references
ids->InsertNextId(0);
ids->InsertNextId(1);
ids->InsertNextId(2);
ids->InsertNextId(3);
ids->InsertNextId(9);
// bottom face of four points
faces->InsertNextId(4);
faces->InsertNextId(0);
faces->InsertNextId(1);
faces->InsertNextId(2);
faces->InsertNextId(3);
// four side faces, each of three points
faces->InsertNextId(3);
faces->InsertNextId(0);
faces->InsertNextId(1);
faces->InsertNextId(9);
faces->InsertNextId(3);
faces->InsertNextId(1);
faces->InsertNextId(2);
faces->InsertNextId(9);
faces->InsertNextId(3);
faces->InsertNextId(2);
faces->InsertNextId(3);
faces->InsertNextId(9);
faces->InsertNextId(3);
faces->InsertNextId(3);
faces->InsertNextId(0);
faces->InsertNextId(9);
// insert the cell. We now have two pyramids with a cube in between
ug->InsertNextCell(VTK_POLYHEDRON, 5, ids.GetPointer()->GetPointer(0), 5, faces.GetPointer()->GetPointer(0));
vtkMultiProcessController* ctrl = vtkMultiProcessController::GetGlobalController();
vtkNew<vtkXMLPUnstructuredGridWriter> w;
w->SetController(ctrl);
w->SetInputData(ug);
w->SetUseSubdirectory(true);
char* tempDir = vtkTestUtilities::GetArgOrEnvOrDefault("-T", argc, argv,
"VTK_TEMP_DIR",
"Testing/Temporary");
std::string dir(tempDir);
std::string fn = dir + "/ug.pvtu";
w->SetFileName(fn.c_str());
w->SetDataModeToAscii();
w->Update();
ifstream f(fn.c_str());
if (!f.good())
{
std::cerr << "File " << fn << " does not exist." << std::endl;
return EXIT_FAILURE;
}
vtkNew<vtkXMLUnstructuredGridReader> r;
std::string piece = dir + "/ug/ug_0.vtu";
r->SetFileName(piece.c_str());
r->Update();
// first try reading the piece with a non-parallel reader
vtkUnstructuredGrid* read = r->GetOutput();
if (!CompareGrids(ug.GetPointer(), read)) return EXIT_FAILURE;
// now read the .pvtu file with the paralle reader
vtkNew<vtkXMLPUnstructuredGridReader> pr;
pr->SetFileName(fn.c_str());
// this will give a SIGSEGV on vtkXMLPUnstructuredGridReader::ReadPieceData()
pr->Update();
read = pr->GetOutput();
if (!CompareGrids(ug.GetPointer(), read)) return EXIT_FAILURE;
return EXIT_SUCCESS;
}