1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkXMLPImageDataReader.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkXMLPImageDataReader.h"
16
17 #include "vtkDataArray.h"
18 #include "vtkImageData.h"
19 #include "vtkObjectFactory.h"
20 #include "vtkPointData.h"
21 #include "vtkXMLDataElement.h"
22 #include "vtkXMLImageDataReader.h"
23 #include "vtkInformation.h"
24 #include "vtkStreamingDemandDrivenPipeline.h"
25
26 vtkStandardNewMacro(vtkXMLPImageDataReader);
27
28 //----------------------------------------------------------------------------
vtkXMLPImageDataReader()29 vtkXMLPImageDataReader::vtkXMLPImageDataReader()
30 {
31 }
32
33 //----------------------------------------------------------------------------
~vtkXMLPImageDataReader()34 vtkXMLPImageDataReader::~vtkXMLPImageDataReader()
35 {
36 }
37
38 //----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)39 void vtkXMLPImageDataReader::PrintSelf(ostream& os, vtkIndent indent)
40 {
41 this->Superclass::PrintSelf(os, indent);
42 }
43
44 //----------------------------------------------------------------------------
GetOutput()45 vtkImageData* vtkXMLPImageDataReader::GetOutput()
46 {
47 return this->GetOutput(0);
48 }
49
50 //----------------------------------------------------------------------------
GetOutput(int idx)51 vtkImageData* vtkXMLPImageDataReader::GetOutput(int idx)
52 {
53 return vtkImageData::SafeDownCast( this->GetOutputDataObject(idx) );
54 }
55
56 //----------------------------------------------------------------------------
GetPieceInput(int index)57 vtkImageData* vtkXMLPImageDataReader::GetPieceInput(int index)
58 {
59 vtkXMLImageDataReader* reader =
60 static_cast<vtkXMLImageDataReader*>(this->PieceReaders[index]);
61 return reader->GetOutput();
62 }
63
64 //----------------------------------------------------------------------------
GetDataSetName()65 const char* vtkXMLPImageDataReader::GetDataSetName()
66 {
67 return "PImageData";
68 }
69
70 //----------------------------------------------------------------------------
SetupEmptyOutput()71 void vtkXMLPImageDataReader::SetupEmptyOutput()
72 {
73 this->GetCurrentOutput()->Initialize();
74 }
75
76 //----------------------------------------------------------------------------
SetOutputExtent(int * extent)77 void vtkXMLPImageDataReader::SetOutputExtent(int* extent)
78 {
79 vtkImageData::SafeDownCast(this->GetCurrentOutput())->SetExtent(extent);
80 }
81
82 //----------------------------------------------------------------------------
GetPieceInputExtent(int index,int * extent)83 void vtkXMLPImageDataReader::GetPieceInputExtent(int index, int* extent)
84 {
85 this->GetPieceInput(index)->GetExtent(extent);
86 }
87
88 //----------------------------------------------------------------------------
ReadPrimaryElement(vtkXMLDataElement * ePrimary)89 int vtkXMLPImageDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
90 {
91 if (!this->Superclass::ReadPrimaryElement(ePrimary))
92 {
93 return 0;
94 }
95
96 // Get the image's origin.
97 if (ePrimary->GetVectorAttribute("Origin", 3, this->Origin) != 3)
98 {
99 this->Origin[0] = 0;
100 this->Origin[1] = 0;
101 this->Origin[2] = 0;
102 }
103
104 // Get the image's spacing.
105 if (ePrimary->GetVectorAttribute("Spacing", 3, this->Spacing) != 3)
106 {
107 this->Spacing[0] = 1;
108 this->Spacing[1] = 1;
109 this->Spacing[2] = 1;
110 }
111
112 return 1;
113 }
114
115 //----------------------------------------------------------------------------
116 // Note that any changes (add or removing information) made to this method
117 // should be replicated in CopyOutputInformation
SetupOutputInformation(vtkInformation * outInfo)118 void vtkXMLPImageDataReader::SetupOutputInformation(vtkInformation *outInfo)
119 {
120 this->Superclass::SetupOutputInformation(outInfo);
121
122 outInfo->Set(vtkDataObject::ORIGIN(), this->Origin, 3);
123 outInfo->Set(vtkDataObject::SPACING(), this->Spacing, 3);
124 }
125
126 //----------------------------------------------------------------------------
CopyOutputInformation(vtkInformation * outInfo,int port)127 void vtkXMLPImageDataReader::CopyOutputInformation(
128 vtkInformation *outInfo, int port)
129 {
130 this->Superclass::CopyOutputInformation(outInfo, port);
131
132 vtkInformation *localInfo =
133 this->GetExecutive()->GetOutputInformation(port);
134 if (localInfo->Has(vtkDataObject::ORIGIN()))
135 {
136 outInfo->CopyEntry(localInfo, vtkDataObject::ORIGIN());
137 }
138 if (localInfo->Has(vtkDataObject::SPACING()))
139 {
140 outInfo->CopyEntry(localInfo, vtkDataObject::SPACING());
141 }
142 }
143
144 //----------------------------------------------------------------------------
CreatePieceReader()145 vtkXMLDataReader* vtkXMLPImageDataReader::CreatePieceReader()
146 {
147 return vtkXMLImageDataReader::New();
148 }
149
150 //----------------------------------------------------------------------------
FillOutputPortInformation(int,vtkInformation * info)151 int vtkXMLPImageDataReader::FillOutputPortInformation(int, vtkInformation* info)
152 {
153 info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkImageData");
154 return 1;
155 }
156