forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkmExtractVOI.cxx
112 lines (90 loc) · 3.49 KB
/
vtkmExtractVOI.cxx
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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExtractVOI.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 "vtkmExtractVOI.h"
#include "vtkCellData.h"
#include "vtkExtractStructuredGridHelper.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointData.h"
#include "vtkmlib/ArrayConverters.h"
#include "vtkmlib/ImageDataConverter.h"
#include "vtkmlib/Storage.h"
#include "vtkmCellSetExplicit.h"
#include "vtkmCellSetSingleType.h"
#include "vtkmFilterPolicy.h"
#include "vtkm/filter/ExtractStructured.h"
namespace {
struct InputFilterPolicy : public vtkmInputFilterPolicy
{
using StructuredCellSetList =
vtkm::ListTagBase<vtkm::cont::CellSetStructured<1>,
vtkm::cont::CellSetStructured<2>,
vtkm::cont::CellSetStructured<3>>;
};
}
vtkStandardNewMacro(vtkmExtractVOI)
//------------------------------------------------------------------------------
void vtkmExtractVOI::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
vtkmExtractVOI::vtkmExtractVOI() = default;
vtkmExtractVOI::~vtkmExtractVOI() = default;
//------------------------------------------------------------------------------
int vtkmExtractVOI::RequestData(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkImageData* input =
vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkImageData* output =
vtkImageData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
try
{
// convert the input dataset to a vtkm::cont::DataSet
auto in = tovtkm::Convert(input, tovtkm::FieldsFlag::PointsAndCells);
// transform VOI
int inExtents[6], voi[6];
input->GetExtent(inExtents);
for (int i = 0; i < 6; i += 2)
{
voi[i] = this->VOI[i] - inExtents[i];
voi[i + 1] = this->VOI[i + 1] - inExtents[i] + 1;
}
// apply the filter
vtkm::filter::PolicyBase<InputFilterPolicy> policy;
vtkm::filter::ExtractStructured filter;
filter.SetVOI(voi[0], voi[1], voi[2], voi[3], voi[4], voi[5]);
filter.SetSampleRate(this->SampleRate[0], this->SampleRate[1], this->SampleRate[2]);
filter.SetIncludeBoundary( (this->IncludeBoundary != 0 ) );
auto result = filter.Execute(in, policy);
// convert back to vtkImageData
int outExtents[6];
this->Internal->GetOutputWholeExtent(outExtents);
if (!fromvtkm::Convert(result, outExtents, output, input))
{
vtkErrorMacro(<< "Unable to convert VTKm DataSet back to VTK");
return 0;
}
}
catch (const vtkm::cont::Error& e)
{
vtkErrorMacro(<< "VTK-m error: " << e.GetMessage()
<< "Falling back to vtkExtractVOI");
return this->Superclass::RequestData(request, inputVector, outputVector);
}
return 1;
}