MCPcopy Create free account
hub / github.com/Kitware/VTK / RequestData

Method RequestData

Filters/Parallel/vtkAlignImageDataSetFilter.cxx:114–188  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

112
113//------------------------------------------------------------------------------
114int vtkAlignImageDataSetFilter::RequestData(
115 vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
116{
117 auto outputCD = vtkCompositeDataSet::GetData(outputVector, 0);
118 outputCD->ShallowCopy(vtkDataObject::GetData(inputVector[0], 0));
119 auto images = vtkCompositeDataSet::GetDataSets<vtkImageData>(outputCD);
120
121 auto controller = this->GetController()
122 ? vtk::MakeSmartPointer(this->GetController())
123 : vtk::TakeSmartPointer<vtkMultiProcessController>(vtkDummyController::New());
124
125 int countLocal = static_cast<int>(images.size());
126 int countGlobal = countLocal;
127 controller->AllReduce(&countLocal, &countGlobal, 1, vtkCommunicator::SUM_OP);
128 if (countGlobal == 0)
129 {
130 // no images present. nothing to do.
131 return 1;
132 }
133
134 // the origin that all output image datas will have
135 vtkVector3d globalOrigin(VTK_DOUBLE_MAX);
136 if (!::ComputeGlobalOrigin(globalOrigin, images, controller, this->MinimumExtent))
137 {
138 vtkErrorMacro("Failed to compute global origin.");
139 return 0;
140 }
141
142 int illalignedOrigins = 0;
143 // adjust image extents
144 for (auto* image : images)
145 {
146 if (image->GetNumberOfPoints() == 0)
147 {
148 continue;
149 }
150
151 const vtkVector3d imgOrigin(image->GetOrigin());
152 const vtkVector3d imgSpacing(image->GetSpacing());
153
154 // we know the relationship is:
155 // inputOrigin+inputExtent[any]*spacing=globalOrigin+outputExtent[any]*spacing
156 // remember that spacing is the same for input and output imagedatas
157 int outputExtent[6], inputExtent[6], dims[3];
158 image->GetExtent(inputExtent);
159 image->GetDimensions(dims);
160 for (int cc = 0; cc < 3; ++cc)
161 {
162 outputExtent[2 * cc] = static_cast<int>(
163 (imgOrigin[cc] + inputExtent[2 * cc] * imgSpacing[cc]) - globalOrigin[cc] / imgSpacing[cc]);
164 // we compute the max extent based on the imagedata extent to reduce
165 // the chance of round-off error that may change the number of
166 // points and cells in the imagedata
167 outputExtent[2 * cc + 1] = outputExtent[2 * cc] + dims[cc] - 1;
168 }
169
170 const vtkVector3d pt0(image->GetPoint(0));
171 image->SetOrigin(globalOrigin.GetData());

Callers

nothing calls this directly

Calls 15

ComputeGlobalOriginFunction · 0.85
NormMethod · 0.80
GetDataFunction · 0.50
NewFunction · 0.50
ShallowCopyMethod · 0.45
GetControllerMethod · 0.45
sizeMethod · 0.45
AllReduceMethod · 0.45
GetNumberOfPointsMethod · 0.45
GetOriginMethod · 0.45
GetSpacingMethod · 0.45
GetExtentMethod · 0.45

Tested by

no test coverage detected