File: vtkExtractSelectedArraysOverTime.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,992 kB
  • sloc: cpp: 2,336,570; 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: 185; javascript: 165; objc: 153; tcl: 59
file content (269 lines) | stat: -rw-r--r-- 9,399 bytes parent folder | download | duplicates (3)
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkExtractSelectedArraysOverTime.h"

#include "vtkDataSetAttributes.h"
#include "vtkExtractDataArraysOverTime.h"
#include "vtkExtractSelection.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include "vtkStreamingDemandDrivenPipeline.h"

#include <cassert>

VTK_ABI_NAMESPACE_BEGIN
//****************************************************************************
vtkStandardNewMacro(vtkExtractSelectedArraysOverTime);
//------------------------------------------------------------------------------
vtkExtractSelectedArraysOverTime::vtkExtractSelectedArraysOverTime()
  : NumberOfTimeSteps(0)
  , FieldType(vtkSelectionNode::CELL)
  , ContentType(-1)
  , ReportStatisticsOnly(false)
  , Error(vtkExtractSelectedArraysOverTime::NoError)
  , SelectionExtractor(nullptr)
  , IsExecuting(false)
{
  this->SetNumberOfInputPorts(2);
  this->ArraysExtractor = vtkSmartPointer<vtkExtractDataArraysOverTime>::New();
  this->SelectionExtractor = vtkSmartPointer<vtkExtractSelection>::New();
}

//------------------------------------------------------------------------------
vtkExtractSelectedArraysOverTime::~vtkExtractSelectedArraysOverTime()
{
  this->SetSelectionExtractor(nullptr);
}

//------------------------------------------------------------------------------
void vtkExtractSelectedArraysOverTime::SetSelectionExtractor(vtkExtractSelection* extractor)
{
  if (this->SelectionExtractor != extractor)
  {
    this->SelectionExtractor = extractor;
    this->Modified();
  }
}

//------------------------------------------------------------------------------
vtkExtractSelection* vtkExtractSelectedArraysOverTime::GetSelectionExtractor()
{
  return this->SelectionExtractor;
}

//------------------------------------------------------------------------------
void vtkExtractSelectedArraysOverTime::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "NumberOfTimeSteps: " << this->NumberOfTimeSteps << endl;
  os << indent << "SelectionExtractor: " << this->SelectionExtractor.Get() << endl;
  os << indent << "ReportStatisticsOnly: " << (this->ReportStatisticsOnly ? "ON" : "OFF") << endl;
}

//------------------------------------------------------------------------------
int vtkExtractSelectedArraysOverTime::FillInputPortInformation(int port, vtkInformation* info)
{
  if (port == 0)
  {
    // We can handle composite datasets.
    info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
  }
  else
  {
    info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkSelection");
    info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
  }
  return 1;
}

//------------------------------------------------------------------------------
int vtkExtractSelectedArraysOverTime::RequestInformation(
  vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
  assert(this->ArraysExtractor != nullptr);
  return this->ArraysExtractor->ProcessRequest(request, inputVector, outputVector);
}

//------------------------------------------------------------------------------
int vtkExtractSelectedArraysOverTime::RequestUpdateExtent(
  vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
  assert(this->ArraysExtractor != nullptr);
  return this->ArraysExtractor->ProcessRequest(request, inputVector, outputVector);
}

//------------------------------------------------------------------------------
int vtkExtractSelectedArraysOverTime::RequestData(
  vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
  if (this->ArraysExtractor->GetNumberOfTimeSteps() <= 0)
  {
    vtkErrorMacro("No time steps in input data!");
    return 0;
  }

  // get the output data object
  vtkInformation* outInfo = outputVector->GetInformationObject(0);

  // is this the first request
  if (!this->IsExecuting)
  {
    vtkSelection* selection = vtkSelection::GetData(inputVector[1], 0);
    if (!selection)
    {
      return 1;
    }

    if (!this->DetermineSelectionType(selection))
    {
      return 0;
    }

    bool reportStats = this->ReportStatisticsOnly;
    switch (this->ContentType)
    {
      // for the following types were the number of elements selected may
      // change over time, we can only track summaries.
      case vtkSelectionNode::QUERY:
        reportStats = true;
        break;
      default:
        break;
    }

    this->ArraysExtractor->SetReportStatisticsOnly(reportStats);
    const int association = vtkSelectionNode::ConvertSelectionFieldToAttributeType(this->FieldType);
    this->ArraysExtractor->SetFieldAssociation(association);
    switch (association)
    {
      case vtkDataObject::POINT:
        this->ArraysExtractor->SetInputArrayToProcess(0, 0, 0, association, "vtkOriginalPointIds");
        break;
      case vtkDataObject::CELL:
        this->ArraysExtractor->SetInputArrayToProcess(0, 0, 0, association, "vtkOriginalCellIds");
        break;
      case vtkDataObject::ROW:
        this->ArraysExtractor->SetInputArrayToProcess(0, 0, 0, association, "vtkOriginalRowIds");
        break;
      default:
        this->ArraysExtractor->SetInputArrayToProcess(
          0, 0, 0, association, vtkDataSetAttributes::GLOBALIDS);
        break;
    }
    this->IsExecuting = true;
  }

  auto extractedData = this->Extract(inputVector, outInfo);

  vtkSmartPointer<vtkDataObject> oldData = vtkDataObject::GetData(inputVector[0], 0);
  inputVector[0]->GetInformationObject(0)->Set(vtkDataObject::DATA_OBJECT(), extractedData);
  const int status = this->ArraysExtractor->ProcessRequest(request, inputVector, outputVector);
  inputVector[0]->GetInformationObject(0)->Set(vtkDataObject::DATA_OBJECT(), oldData);

  if (!status)
  {
    this->IsExecuting = false;
    return 0;
  }

  if (this->IsExecuting &&
    (!request->Has(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING()) ||
      request->Get(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING()) == 0))
  {
    this->PostExecute(request, inputVector, outputVector);
    this->IsExecuting = false;
  }

  return 1;
}

//------------------------------------------------------------------------------
void vtkExtractSelectedArraysOverTime::PostExecute(
  vtkInformation*, vtkInformationVector**, vtkInformationVector*)
{
  // nothing to do.
}

//------------------------------------------------------------------------------
vtkSmartPointer<vtkDataObject> vtkExtractSelectedArraysOverTime::Extract(
  vtkInformationVector** inputVector, vtkInformation* outInfo)
{
  vtkDataObject* input = vtkDataObject::GetData(inputVector[0], 0);
  vtkSelection* selInput = vtkSelection::GetData(inputVector[1], 0);
  vtkSmartPointer<vtkExtractSelection> filter = this->SelectionExtractor;
  if (filter == nullptr)
  {
    return input;
  }
  filter->SetPreserveTopology(false);
  filter->SetInputData(0, input);
  filter->SetInputData(1, selInput);

  vtkDebugMacro(<< "Preparing subfilter to extract from dataset");
  // pass all required information to the helper filter
  int piece = 0;
  int npieces = 1;
  int* uExtent = nullptr;
  if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()))
  {
    piece = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
    npieces = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
  }

  if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT()))
  {
    uExtent = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT());
  }
  filter->UpdatePiece(piece, npieces, 0, uExtent);

  vtkSmartPointer<vtkDataObject> extractedData;
  extractedData.TakeReference(filter->GetOutputDataObject(0)->NewInstance());
  extractedData->ShallowCopy(filter->GetOutputDataObject(0));

  double dtime = input->GetInformation()->Get(vtkDataObject::DATA_TIME_STEP());
  extractedData->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(), dtime);
  return extractedData;
}

//------------------------------------------------------------------------------
int vtkExtractSelectedArraysOverTime::DetermineSelectionType(vtkSelection* sel)
{
  int contentType = -1;
  int fieldType = -1;
  unsigned int numNodes = sel->GetNumberOfNodes();
  for (unsigned int cc = 0; cc < numNodes; cc++)
  {
    vtkSelectionNode* node = sel->GetNode(cc);
    if (node)
    {
      int nodeFieldType = node->GetFieldType();
      int nodeContentType = node->GetContentType();
      if ((fieldType != -1 && fieldType != nodeFieldType) ||
        (contentType != -1 && contentType != nodeContentType))
      {
        vtkErrorMacro("All vtkSelectionNode instances within a vtkSelection"
                      " must have the same ContentType and FieldType.");
        return 0;
      }
      fieldType = nodeFieldType;
      contentType = nodeContentType;
    }
  }
  this->ContentType = contentType;
  this->FieldType = fieldType;
  switch (this->ContentType)
  {
    case vtkSelectionNode::BLOCKS:
      // if selection blocks, assume we're extract cells.
      this->FieldType = vtkSelectionNode::CELL;
      break;
    default:
      break;
  }
  return 1;
}
VTK_ABI_NAMESPACE_END