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 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLGenericDataObjectReader.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 "vtkXMLGenericDataObjectReader.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkHyperOctree.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkNonOverlappingAMR.h"
#include "vtkObjectFactory.h"
#include "vtkOverlappingAMR.h"
#include "vtkPolyData.h"
#include "vtkRectilinearGrid.h"
#include "vtkSmartPointer.h"
#include "vtkStructuredGrid.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXMLFileReadTester.h"
#include "vtkXMLHyperOctreeReader.h"
#include "vtkXMLImageDataReader.h"
#include "vtkXMLMultiBlockDataReader.h"
#include "vtkXMLPImageDataReader.h"
#include "vtkXMLPolyDataReader.h"
#include "vtkXMLPPolyDataReader.h"
#include "vtkXMLPRectilinearGridReader.h"
#include "vtkXMLPStructuredGridReader.h"
#include "vtkXMLPUnstructuredGridReader.h"
#include "vtkXMLRectilinearGridReader.h"
#include "vtkXMLStructuredGridReader.h"
#include "vtkXMLUniformGridAMRReader.h"
#include "vtkXMLUnstructuredGridReader.h"
#include "vtkCommand.h"
#include <cassert>
vtkStandardNewMacro(vtkXMLGenericDataObjectReader);
// ---------------------------------------------------------------------------
vtkXMLGenericDataObjectReader::vtkXMLGenericDataObjectReader()
{
this->Reader=0;
}
// ---------------------------------------------------------------------------
vtkXMLGenericDataObjectReader::~vtkXMLGenericDataObjectReader()
{
if(this->Reader!=0)
{
this->Reader->Delete();
}
}
// ---------------------------------------------------------------------------
int vtkXMLGenericDataObjectReader::ReadOutputType(const char *name,
bool ¶llel)
{
parallel=false;
// Test if the file with the given name is a VTKFile with the given
// type.
vtkSmartPointer<vtkXMLFileReadTester> tester=
vtkSmartPointer<vtkXMLFileReadTester>::New();
tester->SetFileName(name);
if(tester->TestReadFile())
{
char *cfileDataType=tester->GetFileDataType();
if(cfileDataType!=0)
{
std::string fileDataType(cfileDataType);
if(fileDataType.compare("HierarchicalBoxDataSet")==0 ||
fileDataType.compare("vtkHierarchicalBoxDataSet") == 0)
{
return VTK_HIERARCHICAL_BOX_DATA_SET;
}
if (fileDataType.compare("vtkOverlappingAMR") == 0)
{
return VTK_OVERLAPPING_AMR;
}
if (fileDataType.compare("vtkNonOverlappingAMR") == 0)
{
return VTK_NON_OVERLAPPING_AMR;
}
if(fileDataType.compare("HyperOctree")==0)
{
return VTK_HYPER_OCTREE;
}
if(fileDataType.compare("ImageData")==0)
{
return VTK_IMAGE_DATA;
}
if(fileDataType.compare("PImageData")==0)
{
parallel=true;
return VTK_IMAGE_DATA;
}
if(fileDataType.compare("vtkMultiBlockDataSet")==0)
{
return VTK_MULTIBLOCK_DATA_SET;
}
if(fileDataType.compare("PolyData")==0)
{
return VTK_POLY_DATA;
}
if(fileDataType.compare("PPolyData")==0)
{
parallel=true;
return VTK_POLY_DATA;
}
if(fileDataType.compare("RectilinearGrid")==0)
{
return VTK_RECTILINEAR_GRID;
}
if(fileDataType.compare("PRectilinearGrid")==0)
{
parallel=true;
return VTK_RECTILINEAR_GRID;
}
if(fileDataType.compare("StructuredGrid")==0)
{
return VTK_STRUCTURED_GRID;
}
if(fileDataType.compare("PStructuredGrid")==0)
{
parallel=true;
return VTK_STRUCTURED_GRID;
}
if(fileDataType.compare("UnstructuredGrid")==0 ||
fileDataType.compare("UnstructuredGridBase")==0)
{
return VTK_UNSTRUCTURED_GRID;
}
if(fileDataType.compare("PUnstructuredGrid")==0 ||
fileDataType.compare("PUnstructuredGridBase")==0)
{
parallel=true;
return VTK_UNSTRUCTURED_GRID;
}
}
}
vtkErrorMacro(<<"could not load " << name);
return -1;
}
// ---------------------------------------------------------------------------
int vtkXMLGenericDataObjectReader::RequestDataObject(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
if(!this->Stream && !this->FileName)
{
vtkErrorMacro("File name not specified");
return 0;
}
if(this->Reader!=0)
{
this->Reader->Delete();
this->Reader=0;
}
vtkDataObject *output=0;
// Create reader.
bool parallel=false;
switch(this->ReadOutputType(this->FileName,parallel))
{
case VTK_HIERARCHICAL_BOX_DATA_SET:
this->Reader = vtkXMLUniformGridAMRReader::New();
output=vtkHierarchicalBoxDataSet::New();
break;
case VTK_OVERLAPPING_AMR:
this->Reader = vtkXMLUniformGridAMRReader::New();
output = vtkOverlappingAMR::New();
break;
case VTK_NON_OVERLAPPING_AMR:
this->Reader = vtkXMLUniformGridAMRReader::New();
output = vtkNonOverlappingAMR::New();
break;
case VTK_HYPER_OCTREE:
this->Reader=vtkXMLHyperOctreeReader::New();
output=vtkHyperOctree::New();
break;
case VTK_IMAGE_DATA:
if(parallel)
{
this->Reader=vtkXMLPImageDataReader::New();
}
else
{
this->Reader=vtkXMLImageDataReader::New();
}
output=vtkImageData::New();
break;
case VTK_MULTIBLOCK_DATA_SET:
this->Reader=vtkXMLMultiBlockDataReader::New();
output=vtkMultiBlockDataSet::New();
break;
case VTK_POLY_DATA:
if(parallel)
{
this->Reader=vtkXMLPPolyDataReader::New();
}
else
{
this->Reader=vtkXMLPolyDataReader::New();
}
output=vtkPolyData::New();
break;
case VTK_RECTILINEAR_GRID:
if(parallel)
{
this->Reader=vtkXMLPRectilinearGridReader::New();
}
else
{
this->Reader=vtkXMLRectilinearGridReader::New();
}
output=vtkRectilinearGrid::New();
break;
case VTK_STRUCTURED_GRID:
if(parallel)
{
this->Reader=vtkXMLPStructuredGridReader::New();
}
else
{
this->Reader=vtkXMLStructuredGridReader::New();
}
output=vtkStructuredGrid::New();
break;
case VTK_UNSTRUCTURED_GRID:
if(parallel)
{
this->Reader=vtkXMLPUnstructuredGridReader::New();
}
else
{
this->Reader=vtkXMLUnstructuredGridReader::New();
}
output=vtkUnstructuredGrid::New();
break;
default:
this->Reader=0;
}
if(this->Reader!=0)
{
this->Reader->SetFileName(this->GetFileName());
// this->Reader->SetStream(this->GetStream());
// Delegate the error observers
if (this->GetReaderErrorObserver())
{
this->Reader->AddObserver(vtkCommand::ErrorEvent, this->GetReaderErrorObserver());
}
if (this->GetParserErrorObserver())
{
this->Reader->SetParserErrorObserver(this->GetParserErrorObserver());
}
// Delegate call. RequestDataObject() would be more appropriate but it is
// protected.
int result=this->Reader->ProcessRequest(request,inputVector,outputVector);
if(result)
{
vtkInformation* outInfo = outputVector->GetInformationObject(0);
outInfo->Set(vtkDataObject::DATA_OBJECT(), output);
// outInfo->Set(vtkDataObject::DATA_OBJECT(),output);
if(output!=0)
{
output->Delete();
}
}
return result;
}
else
{
return 0;
}
}
// ----------------------------------------------------------------------------
int vtkXMLGenericDataObjectReader::RequestInformation(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// reader is created in RequestDataObject.
if(this->Reader!=0)
{
// RequestInformation() would be more appropriate but it is protected.
return this->Reader->ProcessRequest(request, inputVector, outputVector);
}
else
{
return 0;
}
}
// ----------------------------------------------------------------------------
int vtkXMLGenericDataObjectReader::RequestUpdateExtent(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// reader is created in RequestDataObject.
if(this->Reader!=0)
{
// RequestUpdateExtent() would be more appropriate but it is protected.
return this->Reader->ProcessRequest(request, inputVector, outputVector);
}
else
{
return 0;
}
}
// ----------------------------------------------------------------------------
int vtkXMLGenericDataObjectReader::RequestData(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// reader is created in RequestDataObject.
if(this->Reader!=0)
{
// RequestData() would be more appropriate but it is protected.
return this->Reader->ProcessRequest(request, inputVector, outputVector);
}
else
{
return 0;
}
}
// ----------------------------------------------------------------------------
void vtkXMLGenericDataObjectReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
// ----------------------------------------------------------------------------
vtkDataObject* vtkXMLGenericDataObjectReader::GetOutput()
{
return this->GetOutput(0);
}
// ----------------------------------------------------------------------------
vtkDataObject* vtkXMLGenericDataObjectReader::GetOutput(int idx)
{
return this->GetOutputDataObject(idx);
}
// ---------------------------------------------------------------------------
vtkHierarchicalBoxDataSet *
vtkXMLGenericDataObjectReader::GetHierarchicalBoxDataSetOutput()
{
return vtkHierarchicalBoxDataSet::SafeDownCast(this->GetOutput());
}
// ---------------------------------------------------------------------------
vtkHyperOctree *vtkXMLGenericDataObjectReader::GetHyperOctreeOutput()
{
return vtkHyperOctree::SafeDownCast(this->GetOutput());
}
// ---------------------------------------------------------------------------
vtkImageData *vtkXMLGenericDataObjectReader::GetImageDataOutput()
{
return vtkImageData::SafeDownCast(this->GetOutput());
}
// ---------------------------------------------------------------------------
vtkMultiBlockDataSet *
vtkXMLGenericDataObjectReader::GetMultiBlockDataSetOutput()
{
return vtkMultiBlockDataSet::SafeDownCast(this->GetOutput());
}
// ---------------------------------------------------------------------------
vtkPolyData *vtkXMLGenericDataObjectReader::GetPolyDataOutput()
{
return vtkPolyData::SafeDownCast(this->GetOutput());
}
// ---------------------------------------------------------------------------
vtkRectilinearGrid *vtkXMLGenericDataObjectReader::GetRectilinearGridOutput()
{
return vtkRectilinearGrid::SafeDownCast(this->GetOutput());
}
// ---------------------------------------------------------------------------
vtkStructuredGrid *vtkXMLGenericDataObjectReader::GetStructuredGridOutput()
{
return vtkStructuredGrid::SafeDownCast(this->GetOutput());
}
// ---------------------------------------------------------------------------
vtkUnstructuredGrid *vtkXMLGenericDataObjectReader::GetUnstructuredGridOutput()
{
return vtkUnstructuredGrid::SafeDownCast(this->GetOutput());
}
// ----------------------------------------------------------------------------
const char* vtkXMLGenericDataObjectReader::GetDataSetName()
{
assert("check: not_used" && 0); // should not be used.
return "DataObject"; // not used.
}
// ----------------------------------------------------------------------------
void vtkXMLGenericDataObjectReader::SetupEmptyOutput()
{
this->GetCurrentOutput()->Initialize();
}
// ----------------------------------------------------------------------------
int vtkXMLGenericDataObjectReader::FillOutputPortInformation(
int,
vtkInformation *info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkDataObject");
return 1;
}
// ----------------------------------------------------------------------------
vtkIdType vtkXMLGenericDataObjectReader::GetNumberOfPoints()
{
vtkIdType numPts = 0;
vtkDataSet* output = vtkDataSet::SafeDownCast(this->GetCurrentOutput());
if (output)
{
numPts = output->GetNumberOfPoints();
}
return numPts;
}
// ----------------------------------------------------------------------------
vtkIdType vtkXMLGenericDataObjectReader::GetNumberOfCells()
{
vtkIdType numCells = 0;
vtkDataSet* output = vtkDataSet::SafeDownCast(this->GetCurrentOutput());
if (output)
{
numCells = output->GetNumberOfCells();
}
return numCells;
}
|