forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkGenericDataObjectReader.cxx
448 lines (403 loc) · 12.6 KB
/
vtkGenericDataObjectReader.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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGenericDataObjectReader.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 "vtkGenericDataObjectReader.h"
#include "vtkDirectedGraph.h"
#include "vtkGraph.h"
#include "vtkGraphReader.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkPolyDataReader.h"
#include "vtkRectilinearGrid.h"
#include "vtkRectilinearGridReader.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredGridReader.h"
#include "vtkStructuredPoints.h"
#include "vtkStructuredPointsReader.h"
#include "vtkTable.h"
#include "vtkTableReader.h"
#include "vtkTree.h"
#include "vtkTreeReader.h"
#include "vtkUndirectedGraph.h"
#include "vtkUnstructuredGrid.h"
#include "vtkUnstructuredGridReader.h"
vtkStandardNewMacro(vtkGenericDataObjectReader);
template<typename ReaderT, typename DataT>
void ReadData(const char* DataClass, vtkDataReader* Owner, vtkTimeStamp& MTime, vtkDataObject* Output)
{
ReaderT* const reader = ReaderT::New();
reader->SetFileName(Owner->GetFileName());
reader->SetInputArray(Owner->GetInputArray());
reader->SetInputString(Owner->GetInputString(),
Owner->GetInputStringLength());
reader->SetReadFromInputString(Owner->GetReadFromInputString());
reader->SetScalarsName(Owner->GetScalarsName());
reader->SetVectorsName(Owner->GetVectorsName());
reader->SetNormalsName(Owner->GetNormalsName());
reader->SetTensorsName(Owner->GetTensorsName());
reader->SetTCoordsName(Owner->GetTCoordsName());
reader->SetLookupTableName(Owner->GetLookupTableName());
reader->SetFieldDataName(Owner->GetFieldDataName());
reader->SetReadAllScalars(Owner->GetReadAllScalars());
reader->SetReadAllVectors(Owner->GetReadAllVectors());
reader->SetReadAllNormals(Owner->GetReadAllNormals());
reader->SetReadAllTensors(Owner->GetReadAllTensors());
reader->SetReadAllColorScalars(Owner->GetReadAllColorScalars());
reader->SetReadAllTCoords(Owner->GetReadAllTCoords());
reader->SetReadAllFields(Owner->GetReadAllFields());
reader->Update();
// Can we use the old output?
if(!(Output && strcmp(Output->GetClassName(), DataClass) == 0))
{
// Hack to make sure that the object is not modified
// with SetNthOutput. Otherwise, extra executions occur.
const vtkTimeStamp mtime = MTime;
Output = DataT::New();
Owner->GetExecutive()->SetOutputData(0, Output);
Output->Delete();
MTime = mtime;
}
Output->ShallowCopy(reader->GetOutput());
Output->GetPipelineInformation()->CopyEntry(
reader->GetOutput()->GetPipelineInformation(),
vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT());
reader->Delete();
}
vtkGenericDataObjectReader::vtkGenericDataObjectReader()
{
}
vtkGenericDataObjectReader::~vtkGenericDataObjectReader()
{
}
int vtkGenericDataObjectReader::RequestDataObject(
vtkInformation* /*information*/,
vtkInformationVector** /*inputVector*/,
vtkInformationVector* outputVector)
{
if(this->GetFileName() == NULL &&
(this->GetReadFromInputString() == 0 ||
(this->GetInputArray() == NULL && this->GetInputString() == NULL)))
{
vtkWarningMacro(<< "FileName must be set");
return 0;
}
int outputType = this->ReadOutputType();
vtkInformation* const info = outputVector->GetInformationObject(0);
vtkDataObject* output = info->Get(vtkDataObject::DATA_OBJECT());
if(output && (output->GetDataObjectType() == outputType))
{
return 1;
}
if(!output || output->GetDataObjectType() != outputType)
{
switch (outputType)
{
case VTK_DIRECTED_GRAPH:
output = vtkDirectedGraph::New();
break;
case VTK_UNDIRECTED_GRAPH:
output = vtkUndirectedGraph::New();
break;
case VTK_IMAGE_DATA:
output = vtkImageData::New();
break;
case VTK_POLY_DATA:
output = vtkPolyData::New();
break;
case VTK_RECTILINEAR_GRID:
output = vtkRectilinearGrid::New();
break;
case VTK_STRUCTURED_GRID:
output = vtkStructuredGrid::New();
break;
case VTK_STRUCTURED_POINTS:
output = vtkStructuredPoints::New();
break;
case VTK_TABLE:
output = vtkTable::New();
break;
case VTK_TREE:
output = vtkTree::New();
break;
case VTK_UNSTRUCTURED_GRID:
output = vtkUnstructuredGrid::New();
break;
default:
return 0;
}
output->SetPipelineInformation(info);
output->Delete();
}
return 1;
}
int vtkGenericDataObjectReader::RequestInformation(
vtkInformation* /*information*/,
vtkInformationVector** /*inputVector*/,
vtkInformationVector* outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
if(this->GetFileName() == NULL &&
(this->GetReadFromInputString() == 0 ||
(this->GetInputArray() == NULL && this->GetInputString() == NULL)))
{
vtkWarningMacro(<< "FileName must be set");
return 0;
}
vtkDataReader *reader = 0;
int retVal;
switch (this->ReadOutputType())
{
case VTK_UNDIRECTED_GRAPH:
case VTK_DIRECTED_GRAPH:
reader = vtkGraphReader::New();
break;
case VTK_IMAGE_DATA:
reader = vtkStructuredPointsReader::New();
break;
case VTK_POLY_DATA:
reader = vtkPolyDataReader::New();
break;
case VTK_RECTILINEAR_GRID:
reader = vtkRectilinearGridReader::New();
break;
case VTK_STRUCTURED_GRID:
reader = vtkStructuredGridReader::New();
break;
case VTK_STRUCTURED_POINTS:
reader = vtkStructuredPointsReader::New();
break;
case VTK_TABLE:
reader = vtkTableReader::New();
break;
case VTK_TREE:
reader = vtkTreeReader::New();
break;
case VTK_UNSTRUCTURED_GRID:
reader = vtkUnstructuredGridReader::New();
break;
default:
reader = NULL;
}
if(reader)
{
reader->SetFileName(this->GetFileName());
reader->SetReadFromInputString(this->GetReadFromInputString());
reader->SetInputArray(this->GetInputArray());
reader->SetInputString(this->GetInputString());
retVal = reader->ReadMetaData(outInfo);
reader->Delete();
return retVal;
}
return 1;
}
int vtkGenericDataObjectReader::RequestData(
vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkDataObject *output = outInfo->Get(vtkDataObject::DATA_OBJECT());
vtkDebugMacro(<<"Reading vtk dataset...");
switch (this->ReadOutputType())
{
case VTK_DIRECTED_GRAPH:
{
ReadData<vtkGraphReader, vtkDirectedGraph>("vtkDirectedGraph", this, this->MTime, output);
return 1;
}
case VTK_UNDIRECTED_GRAPH:
{
ReadData<vtkGraphReader, vtkUndirectedGraph>("vtkUndirectedGraph", this, this->MTime, output);
return 1;
}
case VTK_IMAGE_DATA:
{
ReadData<vtkStructuredPointsReader, vtkImageData>("vtkImageData", this, this->MTime, output);
return 1;
}
case VTK_POLY_DATA:
{
ReadData<vtkPolyDataReader, vtkPolyData>("vtkPolyData", this, this->MTime, output);
return 1;
}
case VTK_RECTILINEAR_GRID:
{
ReadData<vtkRectilinearGridReader, vtkRectilinearGrid>("vtkRectilinearGrid", this, this->MTime, output);
return 1;
}
case VTK_STRUCTURED_GRID:
{
ReadData<vtkStructuredGridReader, vtkStructuredGrid>("vtkStructuredGrid", this, this->MTime, output);
return 1;
}
case VTK_STRUCTURED_POINTS:
{
ReadData<vtkStructuredPointsReader, vtkStructuredPoints>("vtkStructuredPoints", this, this->MTime, output);
return 1;
}
case VTK_TABLE:
{
ReadData<vtkTableReader, vtkTable>("vtkTable", this, this->MTime, output);
return 1;
}
case VTK_TREE:
{
ReadData<vtkTreeReader, vtkTree>("vtkTree", this, this->MTime, output);
return 1;
}
case VTK_UNSTRUCTURED_GRID:
{
ReadData<vtkUnstructuredGridReader, vtkUnstructuredGrid>("vtkUnstructuredGrid", this, this->MTime, output);
return 1;
}
default:
vtkErrorMacro("Could not read file " << this->FileName);
}
return 0;
}
int vtkGenericDataObjectReader::ReadOutputType()
{
char line[256];
vtkDebugMacro(<<"Reading vtk data object...");
if(!this->OpenVTKFile() || !this->ReadHeader())
{
return -1;
}
// Determine dataset type
//
if(!this->ReadString(line))
{
vtkDebugMacro(<< "Premature EOF reading dataset keyword");
return -1;
}
if(!strncmp(this->LowerCase(line),"dataset",static_cast<unsigned long>(7)))
{
// See iftype is recognized.
//
if(!this->ReadString(line))
{
vtkDebugMacro(<< "Premature EOF reading type");
this->CloseVTKFile ();
return -1;
}
this->CloseVTKFile();
if(!strncmp(this->LowerCase(line), "directed_graph", 5))
{
return VTK_DIRECTED_GRAPH;
}
if(!strncmp(this->LowerCase(line), "undirected_graph", 5))
{
return VTK_UNDIRECTED_GRAPH;
}
if(!strncmp(this->LowerCase(line), "polydata",8))
{
return VTK_POLY_DATA;
}
if(!strncmp(this->LowerCase(line), "rectilinear_grid",16))
{
return VTK_RECTILINEAR_GRID;
}
if(!strncmp(this->LowerCase(line), "structured_grid",15))
{
return VTK_STRUCTURED_GRID;
}
if(!strncmp(this->LowerCase(line), "structured_points",17))
{
return VTK_STRUCTURED_POINTS;
}
if(!strncmp(this->LowerCase(line), "table", 5))
{
return VTK_TABLE;
}
if(!strncmp(this->LowerCase(line), "tree", 4))
{
return VTK_TREE;
}
if(!strncmp(this->LowerCase(line), "unstructured_grid",17))
{
return VTK_UNSTRUCTURED_GRID;
}
vtkDebugMacro(<< "Cannot read dataset type: " << line);
return -1;
}
else if(!strncmp(this->LowerCase(line),"field",static_cast<unsigned long>(5)))
{
vtkDebugMacro(<<"This object can only read data objects, not fields");
}
else
{
vtkDebugMacro(<<"Expecting DATASET keyword, got " << line << " instead");
}
return -1;
}
vtkGraph *vtkGenericDataObjectReader::GetGraphOutput()
{
return vtkGraph::SafeDownCast(this->GetOutput());
}
vtkPolyData *vtkGenericDataObjectReader::GetPolyDataOutput()
{
return vtkPolyData::SafeDownCast(this->GetOutput());
}
vtkRectilinearGrid *vtkGenericDataObjectReader::GetRectilinearGridOutput()
{
return vtkRectilinearGrid::SafeDownCast(this->GetOutput());
}
vtkStructuredGrid *vtkGenericDataObjectReader::GetStructuredGridOutput()
{
return vtkStructuredGrid::SafeDownCast(this->GetOutput());
}
vtkStructuredPoints *vtkGenericDataObjectReader::GetStructuredPointsOutput()
{
return vtkStructuredPoints::SafeDownCast(this->GetOutput());
}
vtkTable *vtkGenericDataObjectReader::GetTableOutput()
{
return vtkTable::SafeDownCast(this->GetOutput());
}
vtkTree *vtkGenericDataObjectReader::GetTreeOutput()
{
return vtkTree::SafeDownCast(this->GetOutput());
}
vtkUnstructuredGrid *vtkGenericDataObjectReader::GetUnstructuredGridOutput()
{
return vtkUnstructuredGrid::SafeDownCast(this->GetOutput());
}
void vtkGenericDataObjectReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
vtkDataObject *vtkGenericDataObjectReader::GetOutput()
{
return this->GetOutputDataObject(0);
}
vtkDataObject *vtkGenericDataObjectReader::GetOutput(int idx)
{
return this->GetOutputDataObject(idx);
}
int vtkGenericDataObjectReader::FillOutputPortInformation(int, vtkInformation *info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataObject");
return 1;
}
int vtkGenericDataObjectReader::ProcessRequest(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
// generate the data
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT()))
{
return this->RequestDataObject(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}