File: vtkPResampleFilter.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 178; javascript: 165; objc: 153; tcl: 59
file content (182 lines) | stat: -rw-r--r-- 6,931 bytes parent folder | download | duplicates (5)
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
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkPResampleFilter.h"

#include "vtkCellData.h"
#include "vtkCommunicator.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkDataObject.h"
#include "vtkIdTypeArray.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMath.h"
#include "vtkMultiProcessController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPProbeFilter.h"
#include "vtkPointData.h"
#include "vtkStreamingDemandDrivenPipeline.h"

VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkPResampleFilter);

vtkCxxSetObjectMacro(vtkPResampleFilter, Controller, vtkMultiProcessController);

//------------------------------------------------------------------------------
vtkPResampleFilter::vtkPResampleFilter()
  : UseInputBounds(0)
{
  this->Controller = nullptr;
  this->SetController(vtkMultiProcessController::GetGlobalController());
  this->UseInputBoundsOn();
  this->CustomSamplingBounds[0] = this->CustomSamplingBounds[2] = this->CustomSamplingBounds[4] = 0;
  this->CustomSamplingBounds[1] = this->CustomSamplingBounds[3] = this->CustomSamplingBounds[5] = 1;
  this->SamplingDimension[0] = this->SamplingDimension[1] = this->SamplingDimension[2] = 10;

  vtkMath::UninitializeBounds(this->Bounds);
}

//------------------------------------------------------------------------------
vtkPResampleFilter::~vtkPResampleFilter()
{
  this->SetController(nullptr);
}

//------------------------------------------------------------------------------
double* vtkPResampleFilter::CalculateBounds(vtkDataSet* input)
{
  double localBounds[6];
  input->GetBounds(localBounds);

  if (!this->Controller)
  {
    memcpy(this->Bounds, localBounds, 6 * sizeof(double));
  }
  else
  {
    double localBoundsMin[3], globalBoundsMin[3];
    double localBoundsMax[3], globalBoundsMax[3];
    for (int i = 0; i < 3; i++)
    {
      // Change uninitialized bounds to something that will work
      // with collective MPI calls.
      if (localBounds[2 * i] > localBounds[2 * i + 1])
      {
        localBounds[2 * i] = VTK_DOUBLE_MAX;
        localBounds[2 * i + 1] = -VTK_DOUBLE_MAX;
      }
      localBoundsMin[i] = localBounds[2 * i];
      localBoundsMax[i] = localBounds[2 * i + 1];
    }
    this->Controller->AllReduce(localBoundsMin, globalBoundsMin, 3, vtkCommunicator::MIN_OP);
    this->Controller->AllReduce(localBoundsMax, globalBoundsMax, 3, vtkCommunicator::MAX_OP);
    for (int i = 0; i < 3; i++)
    {
      if (globalBoundsMin[i] <= globalBoundsMax[i])
      {
        this->Bounds[2 * i] = globalBoundsMin[i];
        this->Bounds[2 * i + 1] = globalBoundsMax[i];
      }
      else
      {
        this->Bounds[2 * i] = 0;
        this->Bounds[2 * i + 1] = 0;
      }
    }
  }

  cout << "Bounds: " << localBounds[0] << " " << localBounds[1] << " " << localBounds[2] << " "
       << localBounds[3] << " " << localBounds[4] << " " << localBounds[5] << " " << endl;
  return this->Bounds;
}

//------------------------------------------------------------------------------
int vtkPResampleFilter::RequestInformation(
  vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
{
  int wholeExtent[6] = { 0, this->SamplingDimension[0] - 1, 0, this->SamplingDimension[1] - 1, 0,
    this->SamplingDimension[2] - 1 };

  vtkInformation* outInfo = outputVector->GetInformationObject(0);
  outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wholeExtent, 6);

  return 1;
}

//------------------------------------------------------------------------------
int vtkPResampleFilter::RequestUpdateExtent(
  vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector*)
{
  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
  // This needs to be here because input and output extents are not
  // necessarily related. The output extent is controlled by the
  // resampled dataset whereas the input extent is controlled by
  // input data.
  inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
    inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()), 6);
  return 1;
}

//------------------------------------------------------------------------------
int vtkPResampleFilter::RequestData(vtkInformation* vtkNotUsed(request),
  vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
  // get the info objects
  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
  vtkInformation* outInfo = outputVector->GetInformationObject(0);

  // get the input and output
  vtkDataSet* input = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
  vtkDataSet* output = vtkDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));

  // Create Image Data for resampling
  vtkNew<vtkImageData> source;
  double* boundsToSample =
    (this->UseInputBounds == 1) ? this->CalculateBounds(input) : this->CustomSamplingBounds;
  source->SetOrigin(boundsToSample[0], boundsToSample[2], boundsToSample[4]);
  source->SetDimensions(this->SamplingDimension);
  source->SetSpacing(
    (boundsToSample[1] - boundsToSample[0]) / static_cast<double>(this->SamplingDimension[0] - 1),
    (boundsToSample[3] - boundsToSample[2]) / static_cast<double>(this->SamplingDimension[1] - 1),
    (boundsToSample[5] - boundsToSample[4]) / static_cast<double>(this->SamplingDimension[2] - 1));

  // Probe data
  vtkNew<vtkPProbeFilter> probeFilter;
  probeFilter->SetController(this->Controller);
  probeFilter->SetSourceData(input);
  probeFilter->SetInputData(source);
  probeFilter->Update();
  output->ShallowCopy(probeFilter->GetOutput());

  return 1;
}

//------------------------------------------------------------------------------
int vtkPResampleFilter::FillInputPortInformation(int port, vtkInformation* info)
{
  if (!this->Superclass::FillInputPortInformation(port, info))
  {
    return 0;
  }
  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
  return 1;
}

//------------------------------------------------------------------------------
void vtkPResampleFilter::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "Controller " << this->Controller << endl;
  os << indent << "UseInputBounds " << this->UseInputBounds << endl;
  if (this->UseInputBounds == 0)
  {
    os << indent << "CustomSamplingBounds [" << this->CustomSamplingBounds[0] << ", "
       << this->CustomSamplingBounds[1] << ", " << this->CustomSamplingBounds[2] << ", "
       << this->CustomSamplingBounds[3] << ", " << this->CustomSamplingBounds[4] << ", "
       << this->CustomSamplingBounds[5] << "]" << endl;
  }
  os << indent << "SamplingDimension " << this->SamplingDimension[0] << " x "
     << this->SamplingDimension[1] << " x " << this->SamplingDimension[2] << endl;
}
VTK_ABI_NAMESPACE_END