vtkXMLImageDataReader.cxx 3.9 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXMLImageDataReader.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 "vtkXMLImageDataReader.h"
16 17 18

#include "vtkDataArray.h"
#include "vtkImageData.h"
19
#include "vtkObjectFactory.h"
20
#include "vtkPointData.h"
21
#include "vtkXMLDataElement.h"
22 23
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
24
#include "vtkInformationVector.h"
25 26 27 28

vtkStandardNewMacro(vtkXMLImageDataReader);

//----------------------------------------------------------------------------
29
vtkXMLImageDataReader::vtkXMLImageDataReader() = default;
30 31

//----------------------------------------------------------------------------
32
vtkXMLImageDataReader::~vtkXMLImageDataReader() = default;
33 34 35 36 37 38 39 40 41 42

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

//----------------------------------------------------------------------------
vtkImageData* vtkXMLImageDataReader::GetOutput()
{
43
  return this->GetOutput(0);
44 45
}

46 47 48
//----------------------------------------------------------------------------
vtkImageData* vtkXMLImageDataReader::GetOutput(int idx)
{
49
  return vtkImageData::SafeDownCast(this->GetOutputDataObject(idx));
50 51 52
}


53 54 55 56 57 58 59 60 61
//----------------------------------------------------------------------------
const char* vtkXMLImageDataReader::GetDataSetName()
{
  return "ImageData";
}

//----------------------------------------------------------------------------
void vtkXMLImageDataReader::SetOutputExtent(int* extent)
{
62
  vtkImageData::SafeDownCast(this->GetCurrentOutput())->SetExtent(extent);
63 64 65 66 67
}

//----------------------------------------------------------------------------
int vtkXMLImageDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
{
68
  if (!this->Superclass::ReadPrimaryElement(ePrimary))
69
  {
70
    return 0;
71
  }
72

73
  // Get the image's origin.
74
  if (ePrimary->GetVectorAttribute("Origin", 3, this->Origin) != 3)
75
  {
76 77 78
    this->Origin[0] = 0;
    this->Origin[1] = 0;
    this->Origin[2] = 0;
79
  }
80

81
  // Get the image's spacing.
82
  if (ePrimary->GetVectorAttribute("Spacing", 3, this->Spacing) != 3)
83
  {
84 85 86
    this->Spacing[0] = 1;
    this->Spacing[1] = 1;
    this->Spacing[2] = 1;
87
  }
88

89 90 91 92
  return 1;
}

//----------------------------------------------------------------------------
93 94
// Note that any changes (add or removing information) made to this method
// should be replicated in CopyOutputInformation
95
void vtkXMLImageDataReader::SetupOutputInformation(vtkInformation *outInfo)
96
{
97 98 99 100
  this->Superclass::SetupOutputInformation(outInfo);

  outInfo->Set(vtkDataObject::ORIGIN(), this->Origin, 3);
  outInfo->Set(vtkDataObject::SPACING(), this->Spacing, 3);
101
}
102 103


104 105
//----------------------------------------------------------------------------
void vtkXMLImageDataReader::CopyOutputInformation(vtkInformation *outInfo, int port)
106
{
107
  this->Superclass::CopyOutputInformation(outInfo, port);
108
  vtkInformation *localInfo =
109 110
    this->GetExecutive()->GetOutputInformation(port);
  if (localInfo->Has(vtkDataObject::ORIGIN()))
111
  {
112
    outInfo->CopyEntry(localInfo, vtkDataObject::ORIGIN());
113
  }
114
  if (localInfo->Has(vtkDataObject::SPACING()))
115
  {
116
    outInfo->CopyEntry(localInfo, vtkDataObject::SPACING());
117
  }
118
}
119 120


121 122 123 124 125 126
//----------------------------------------------------------------------------
int vtkXMLImageDataReader::FillOutputPortInformation(int, vtkInformation* info)
{
  info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkImageData");
  return 1;
}