VTK  9.7.1
vtkMultiThreshold.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 
92 #ifndef vtkMultiThreshold_h
93 #define vtkMultiThreshold_h
94 
95 #include "vtkFiltersGeneralModule.h" // For export macro
96 #include "vtkMath.h" // for Inf() and NegInf()
98 
99 #include <map> // for IntervalRules map
100 #include <set> // for UpdateDependents()
101 #include <string> // for holding array names in NormKey
102 #include <vector> // for lists of threshold rules
103 
104 VTK_ABI_NAMESPACE_BEGIN
105 class vtkCell;
106 class vtkCellData;
107 class vtkDataArray;
108 class vtkGenericCell;
109 class vtkPointSet;
110 class vtkUnstructuredGrid;
111 
112 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
113 {
114 public:
116  static vtkMultiThreshold* New();
117  void PrintSelf(ostream& os, vtkIndent indent) override;
118 
120  enum Closure
121  {
122  OPEN = 0,
123  CLOSED = 1
124  };
126  enum Norm
127  {
128  LINFINITY_NORM = -3,
129  L2_NORM = -2,
130  L1_NORM = -1
131  };
135  {
136  AND,
137  OR,
138  XOR,
139  WOR,
140  NAND
141  };
142 
144 
196  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, const char* arrayName,
197  int component, int allScalars);
198  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, int attribType,
199  int component, int allScalars);
201 
203 
210  int AddLowpassIntervalSet(
211  double xmax, int assoc, const char* arrayName, int component, int allScalars);
212  int AddHighpassIntervalSet(
213  double xmin, int assoc, const char* arrayName, int component, int allScalars);
214  int AddBandpassIntervalSet(
215  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars);
216  int AddNotchIntervalSet(
217  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars);
219 
223  int AddBooleanSet(int operation, int numInputs, int* inputs);
224 
228  int OutputSet(int setId);
229 
233  void Reset();
234 
237  typedef double (*TupleNorm)(vtkDataArray* arr, vtkIdType tuple, int component);
238 
239  // NormKey must be able to use TupleNorm typedef:
240  class NormKey;
241 
242  // Interval must be able to use NormKey typedef:
243  class Interval;
244 
245  // Set needs to refer to boolean set pointers
246  class BooleanSet;
247 
249  class NormKey
250  {
251  public:
252  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or
253  // vtkDataObject::FIELD_ASSOCIATION_CELLS
254  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS,
255  // NORMALS, TCOORDS, GLOBALIDS}
256  std::string Name; // Either empty or (when ArrayType == -1) an input array name
257  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
258  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points
259  // be in the interval?
260  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
261  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct
262  // component) of a tuple.
263 
266  void ComputeNorm(
267  vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2]) const;
268 
271  bool operator<(const NormKey& other) const
272  {
273  if (this->Association < other.Association)
274  return true;
275  else if (this->Association > other.Association)
276  return false;
277 
278  if (this->Component < other.Component)
279  return true;
280  else if (this->Component > other.Component)
281  return false;
282 
283  if ((!this->AllScalars) && other.AllScalars)
284  return true;
285  else if (this->AllScalars && (!other.AllScalars))
286  return false;
287 
288  if (this->Type == -1)
289  {
290  if (other.Type == -1)
291  return this->Name < other.Name;
292  return true;
293  }
294  else
295  {
296  return this->Type < other.Type;
297  }
298  }
299  };
300 
305  class Set
306  {
307  public:
308  int Id;
309  int OutputId;
310 
314  Set() { this->OutputId = -1; }
316  virtual ~Set() = default;
318  virtual void PrintNodeName(ostream& os);
320  virtual void PrintNode(ostream& os) = 0;
322  virtual BooleanSet* GetBooleanSetPointer();
323  virtual Interval* GetIntervalPointer();
324  };
325 
327  class Interval : public Set
328  {
329  public:
331  double EndpointValues[2];
333  int EndpointClosures[2];
336 
342  int Match(double cellNorm[2]);
343 
344  ~Interval() override = default;
345  void PrintNode(ostream& os) override;
346  Interval* GetIntervalPointer() override;
347  };
348 
350  class BooleanSet : public Set
351  {
352  public:
354  int Operator;
356  std::vector<int> Inputs;
357 
359  BooleanSet(int sId, int op, int* inBegin, int* inEnd)
360  : Inputs(inBegin, inEnd)
361  {
362  this->Id = sId;
363  this->Operator = op;
364  }
365  ~BooleanSet() override = default;
366  void PrintNode(ostream& os) override;
367  BooleanSet* GetBooleanSetPointer() override;
368  };
369 
370 protected:
372  ~vtkMultiThreshold() override;
373 
388  enum Ruling
389  {
390  INCONCLUSIVE = -1,
391  INCLUDE = -2,
392  EXCLUDE = -3
393  };
394 
399 
405  int FillInputPortInformation(int port, vtkInformation* info) override;
406 
413 
418 
420  typedef std::vector<Interval*> IntervalList;
422  typedef std::map<NormKey, IntervalList> RuleMap;
423 
424  typedef std::vector<int> TruthTreeValues;
425  typedef std::vector<TruthTreeValues> TruthTree;
426 
430  RuleMap IntervalRules;
431 
437  std::vector<Set*> Sets;
438 
445  TruthTree DependentSets;
446 
450  void UpdateDependents(int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
451  vtkCellData* inCellData, vtkIdType inCell, vtkGenericCell* cell,
452  std::vector<vtkUnstructuredGrid*>& outv);
453 
457  int AddIntervalSet(NormKey& nk, double xmin, double xmax, int omin, int omax);
458 
462  void PrintGraph(ostream& os);
463 
464  vtkMultiThreshold(const vtkMultiThreshold&) = delete;
465  void operator=(const vtkMultiThreshold&) = delete;
466 };
467 
469  double xmax, int assoc, const char* arrayName, int component, int allScalars)
470 {
471  return this->AddIntervalSet(
472  vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
473 }
474 
476  double xmin, int assoc, const char* arrayName, int component, int allScalars)
477 {
478  return this->AddIntervalSet(
479  xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars);
480 }
481 
483  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars)
484 {
485  return this->AddIntervalSet(xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
486 }
487 
489  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars)
490 {
491  int band =
492  this->AddIntervalSet(xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
493  if (band < 0)
494  {
495  return -1;
496  }
497  return this->AddBooleanSet(NAND, 1, &band);
498 }
499 
501 {
502  return nullptr;
503 }
504 
506 {
507  return nullptr;
508 }
509 
511 {
512  return this;
513 }
514 
516 {
517  return this;
518 }
519 
520 VTK_ABI_NAMESPACE_END
521 #endif // vtkMultiThreshold_h
std::vector< Set * > Sets
A list of rules keyed by their unique integer ID.
int NextArrayIndex
A variable used to store the next index to use when calling SetInputArrayToProcess.
static double NegInf()
Special IEEE-754 number used to represent negative infinity.
Only include elements that don't belong to any input set.
A subset of a mesh represented by a range of acceptable attribute values.
bool operator<(const NormKey &other) const
A partial ordering of NormKey objects is required for them to serve as keys in the vtkMultiThreshold:...
int Operator
The boolean operation that will be performed on the inputs to obtain the output.
A subset of a mesh represented as a boolean set operation.
std::vector< TruthTreeValues > TruthTree
int AddBooleanSet(int operation, int numInputs, int *inputs)
Create a new mesh subset using boolean operations on pre-existing sets.
Store vtkAlgorithm input/output information.
TruthTree DependentSets
A list of boolean sets whose values depend on the given set.
static double Inf()
Special IEEE-754 number used to represent positive infinity.
represent and manipulate cell attribute data
Definition: vtkCellData.h:31
int OutputId
A unique identifier for this set.
virtual Interval * GetIntervalPointer()
Set()
The index of the output mesh that will hold this set or -1 if the set is not output.
BooleanSet(int sId, int op, int *inBegin, int *inEnd)
Construct a new set with the given ID, operator, and inputs.
std::map< NormKey, IntervalList > RuleMap
A map describing the IntervalSets that share a common attribute and norm.
NormKey Norm
This contains information about the attribute over which the interval is defined. ...
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
concrete class for storing a set of points
Definition: vtkPointSet.h:58
Include elements that belong to an odd number of input sets (a kind of "winding XOR") ...
int vtkIdType
Definition: vtkType.h:363
int AddBandpassIntervalSet(double xmin, double xmax, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, const char *arrayName, int component, int allScalars)
Add a mesh subset to be computed by thresholding an attribute of the input mesh.
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
provides thread-safe access to cells
Ruling
When an interval is evaluated, its value is used to update a truth table.
static vtkMultiBlockDataSetAlgorithm * New()
int AddLowpassIntervalSet(double xmax, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
abstract class to specify cell behavior
Definition: vtkCell.h:50
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
a simple class to control print indentation
Definition: vtkIndent.h:28
Closure
Whether the endpoint value of an interval should be included or excluded.
std::vector< int > Inputs
A list of input sets. These may be IntervalSets or BooleanSets.
dataset represents arbitrary combinations of all possible cell types
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
Interval * GetIntervalPointer() override
Include an element if it belongs to exactly one input set.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
Specify a closed interval.
int NumberOfOutputs
The number of output datasets.
int AddNotchIntervalSet(double xlo, double xhi, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
BooleanSet * GetBooleanSetPointer() override
Avoid dynamic_casts. Subclasses must override.
RuleMap IntervalRules
A set of threshold rules sorted by the attribute+norm to which they are applied.
Only include an element if it belongs to all the input sets.
SetOperation
Operations that can be performed on sets to generate another set.
Store zero or more vtkInformation instances.
A class with comparison operator used to index input array norms used in threshold rules...
Norm
Norms that can be used to threshold vector attributes.
Include an element if it belongs to any input set.
Threshold cells within multiple intervals.
A base class for representing threshold sets.
std::vector< int > TruthTreeValues