forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkThresholdGraph.cxx
170 lines (141 loc) · 4.65 KB
/
vtkThresholdGraph.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
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
#include "vtkThresholdGraph.h"
#include "vtkDoubleArray.h"
#include "vtkExtractSelectedGraph.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
vtkStandardNewMacro(vtkThresholdGraph);
//-----------------------------------------------------------------------------
vtkThresholdGraph::vtkThresholdGraph() : vtkGraphAlgorithm(),
LowerThreshold(0.0),
UpperThreshold(0.0)
{
}
//-----------------------------------------------------------------------------
vtkThresholdGraph::~vtkThresholdGraph()
{
// Do nothing.
}
//-----------------------------------------------------------------------------
void vtkThresholdGraph::PrintSelf(ostream &os, vtkIndent indent)
{
// Base class print.
vtkGraphAlgorithm::PrintSelf(os, indent);
os << indent << "LowerThreshold: " << this->LowerThreshold << endl;
os << indent << "UpperThreshold: " << this->UpperThreshold << endl;
}
//-----------------------------------------------------------------------------
int vtkThresholdGraph::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{
if(!inputVector[0])
{
vtkErrorMacro("Error: nullptr or invalid input vtkInformationVector.");
return 1;
}
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
if(!inInfo)
{
vtkErrorMacro("Error: nullptr or invalid input vtkInformation.");
return 1;
}
vtkDataObject* inDataObj = inInfo->Get(vtkDataObject::DATA_OBJECT());
if(!inDataObj)
{
vtkErrorMacro("Error: nullptr or invalid input data object.");
return 1;
}
if(!outputVector)
{
vtkErrorMacro("Error: nullptr or invalid output vtkInformationVector.");
return 1;
}
vtkInformation* outInfo = outputVector->GetInformationObject(0);
if(!outInfo)
{
vtkErrorMacro("Error: nullptr of invalid output vtkInformation.")
}
vtkDataObject* outDataObj = outInfo->Get(vtkDataObject::DATA_OBJECT());
if(!outDataObj)
{
vtkErrorMacro("Error: nullptr or invalid output data object.");
return 1;
}
vtkSmartPointer<vtkExtractSelectedGraph> extractThreshold (
vtkSmartPointer<vtkExtractSelectedGraph>::New());
vtkSmartPointer<vtkSelection> threshold (vtkSmartPointer<vtkSelection>::New());
vtkSmartPointer<vtkSelectionNode> thresholdNode (
vtkSmartPointer<vtkSelectionNode>::New());
vtkSmartPointer<vtkDoubleArray> thresholdArr (
vtkSmartPointer<vtkDoubleArray>::New());
vtkInformationVector* inArrayVec =
this->GetInformation()->Get(INPUT_ARRAYS_TO_PROCESS());
if (!inArrayVec)
{
vtkErrorMacro("Problem finding array to process");
return 1;
}
vtkInformation* inArrayInfo = inArrayVec->GetInformationObject(0);
if (!inArrayInfo)
{
vtkErrorMacro("Problem getting name of array to process.");
return 1;
}
if ( ! inArrayInfo->Has(vtkDataObject::FIELD_NAME()))
{
vtkErrorMacro("Missing field name.");
return 1;
}
const char* arrayNameToProcess =
inArrayInfo->Get(vtkDataObject::FIELD_NAME());
if(!arrayNameToProcess)
{
vtkErrorMacro("Unable to find valid array.");
return 1;
}
int fieldAssociation(-1);
if(!inArrayInfo->Has(vtkDataObject::FIELD_ASSOCIATION()))
{
vtkErrorMacro("Unable to query field association for the scalar.");
return 1;
}
fieldAssociation = inArrayInfo->Get(vtkDataObject::FIELD_ASSOCIATION());
thresholdArr->SetName(arrayNameToProcess);
thresholdArr->InsertNextValue(this->LowerThreshold);
thresholdArr->InsertNextValue(this->UpperThreshold);
thresholdNode->SetSelectionList(thresholdArr);
thresholdNode->SetContentType(vtkSelectionNode::THRESHOLDS);
if(fieldAssociation == vtkDataObject::FIELD_ASSOCIATION_EDGES)
{
thresholdNode->SetFieldType(vtkSelectionNode::EDGE);
}
else if(fieldAssociation == vtkDataObject::FIELD_ASSOCIATION_VERTICES)
{
thresholdNode->SetFieldType(vtkSelectionNode::VERTEX);
}
else
{
vtkErrorMacro("Array selected should be associated with vertex or " <<
"edge data.");
return 1;
}
threshold->AddNode(thresholdNode);
vtkSmartPointer<vtkDataObject> inputClone;
inputClone.TakeReference(inDataObj->NewInstance());
inputClone->ShallowCopy(inDataObj);
extractThreshold->SetInputData(0, inputClone);
extractThreshold->SetInputData(1, threshold);
extractThreshold->Update();
vtkDataObject* output = extractThreshold->GetOutputDataObject(0);
if(!output)
{
vtkErrorMacro("nullptr or invalid output.");
return 1;
}
outDataObj->ShallowCopy(output);
return 1;
}