VTK  9.2.6
vtkMultiThreshold.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMultiThreshold.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*----------------------------------------------------------------------------
16  Copyright (c) Sandia Corporation
17  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
18 ----------------------------------------------------------------------------*/
19 
115 #ifndef vtkMultiThreshold_h
116 #define vtkMultiThreshold_h
117 
118 #include "vtkFiltersGeneralModule.h" // For export macro
119 #include "vtkMath.h" // for Inf() and NegInf()
121 
122 #include <map> // for IntervalRules map
123 #include <set> // for UpdateDependents()
124 #include <string> // for holding array names in NormKey
125 #include <vector> // for lists of threshold rules
126 
127 class vtkCell;
128 class vtkCellData;
129 class vtkDataArray;
130 class vtkGenericCell;
131 class vtkPointSet;
132 class vtkUnstructuredGrid;
133 
134 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
135 {
136 public:
139  void PrintSelf(ostream& os, vtkIndent indent) override;
140 
142  enum Closure
143  {
144  OPEN = 0,
145  CLOSED = 1
146  };
148  enum Norm
149  {
150  LINFINITY_NORM = -3,
151  L2_NORM = -2,
152  L1_NORM = -1
153  };
157  {
158  AND,
159  OR,
160  XOR,
161  WOR,
162  NAND
163  };
164 
166 
218  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, const char* arrayName,
219  int component, int allScalars);
220  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, int attribType,
221  int component, int allScalars);
223 
225 
232  int AddLowpassIntervalSet(
233  double xmax, int assoc, const char* arrayName, int component, int allScalars);
234  int AddHighpassIntervalSet(
235  double xmin, int assoc, const char* arrayName, int component, int allScalars);
236  int AddBandpassIntervalSet(
237  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars);
238  int AddNotchIntervalSet(
239  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars);
241 
245  int AddBooleanSet(int operation, int numInputs, int* inputs);
246 
250  int OutputSet(int setId);
251 
255  void Reset();
256 
259  typedef double (*TupleNorm)(vtkDataArray* arr, vtkIdType tuple, int component);
260 
261  // NormKey must be able to use TupleNorm typedef:
262  class NormKey;
263 
264  // Interval must be able to use NormKey typedef:
265  class Interval;
266 
267  // Set needs to refer to boolean set pointers
268  class BooleanSet;
269 
271  class NormKey
272  {
273  public:
274  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or
275  // vtkDataObject::FIELD_ASSOCIATION_CELLS
276  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS,
277  // NORMALS, TCOORDS, GLOBALIDS}
278  std::string Name; // Either empty or (when ArrayType == -1) an input array name
279  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
280  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points
281  // be in the interval?
282  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
283  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct
284  // component) of a tuple.
285 
289  vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2]) const;
290 
293  bool operator<(const NormKey& other) const
294  {
295  if (this->Association < other.Association)
296  return true;
297  else if (this->Association > other.Association)
298  return false;
299 
300  if (this->Component < other.Component)
301  return true;
302  else if (this->Component > other.Component)
303  return false;
304 
305  if ((!this->AllScalars) && other.AllScalars)
306  return true;
307  else if (this->AllScalars && (!other.AllScalars))
308  return false;
309 
310  if (this->Type == -1)
311  {
312  if (other.Type == -1)
313  return this->Name < other.Name;
314  return true;
315  }
316  else
317  {
318  return this->Type < other.Type;
319  }
320  }
321  };
322 
327  class Set
328  {
329  public:
330  int Id;
331  int OutputId;
333 
336  Set() { this->OutputId = -1; }
338  virtual ~Set() = default;
340  virtual void PrintNodeName(ostream& os);
342  virtual void PrintNode(ostream& os) = 0;
344  virtual BooleanSet* GetBooleanSetPointer();
345  virtual Interval* GetIntervalPointer();
346  };
347 
349  class Interval : public Set
350  {
351  public:
353  double EndpointValues[2];
355  int EndpointClosures[2];
358 
364  int Match(double cellNorm[2]);
365 
366  ~Interval() override = default;
367  void PrintNode(ostream& os) override;
368  Interval* GetIntervalPointer() override;
369  };
370 
372  class BooleanSet : public Set
373  {
374  public:
376  int Operator;
378  std::vector<int> Inputs;
379 
381  BooleanSet(int sId, int op, int* inBegin, int* inEnd)
382  : Inputs(inBegin, inEnd)
383  {
384  this->Id = sId;
385  this->Operator = op;
386  }
387  ~BooleanSet() override = default;
388  void PrintNode(ostream& os) override;
389  BooleanSet* GetBooleanSetPointer() override;
390  };
391 
392 protected:
394  ~vtkMultiThreshold() override;
395 
410  enum Ruling
411  {
412  INCONCLUSIVE = -1,
413  INCLUDE = -2,
414  EXCLUDE = -3
415  };
416 
421 
428 
435 
440 
442  typedef std::vector<Interval*> IntervalList;
444  typedef std::map<NormKey, IntervalList> RuleMap;
445 
446  typedef std::vector<int> TruthTreeValues;
447  typedef std::vector<TruthTreeValues> TruthTree;
448 
453 
459  std::vector<Set*> Sets;
460 
468 
472  void UpdateDependents(int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
473  vtkCellData* inCellData, vtkIdType inCell, vtkGenericCell* cell,
474  std::vector<vtkUnstructuredGrid*>& outv);
475 
479  int AddIntervalSet(NormKey& nk, double xmin, double xmax, int omin, int omax);
480 
484  void PrintGraph(ostream& os);
485 
487  void operator=(const vtkMultiThreshold&) = delete;
488 };
489 
491  double xmax, int assoc, const char* arrayName, int component, int allScalars)
492 {
493  return this->AddIntervalSet(
494  vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
495 }
496 
498  double xmin, int assoc, const char* arrayName, int component, int allScalars)
499 {
500  return this->AddIntervalSet(
501  xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars);
502 }
503 
505  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars)
506 {
507  return this->AddIntervalSet(xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
508 }
509 
511  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars)
512 {
513  int band =
514  this->AddIntervalSet(xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
515  if (band < 0)
516  {
517  return -1;
518  }
519  return this->AddBooleanSet(NAND, 1, &band);
520 }
521 
523 {
524  return nullptr;
525 }
526 
528 {
529  return nullptr;
530 }
531 
533 {
534  return this;
535 }
536 
538 {
539  return this;
540 }
541 
542 #endif // vtkMultiThreshold_h
represent and manipulate cell attribute data
Definition: vtkCellData.h:51
abstract class to specify cell behavior
Definition: vtkCell.h:70
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:65
provides thread-safe access to cells
a simple class to control print indentation
Definition: vtkIndent.h:49
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
static double NegInf()
Special IEEE-754 number used to represent negative infinity.
static double Inf()
Special IEEE-754 number used to represent positive infinity.
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
A subset of a mesh represented as a boolean set operation.
int Operator
The boolean operation that will be performed on the inputs to obtain the output.
BooleanSet(int sId, int op, int *inBegin, int *inEnd)
Construct a new set with the given ID, operator, and inputs.
void PrintNode(ostream &os) override
Print a graphviz node name for use in an edge statement.
std::vector< int > Inputs
A list of input sets. These may be IntervalSets or BooleanSets.
~BooleanSet() override=default
BooleanSet * GetBooleanSetPointer() override
Avoid dynamic_casts. Subclasses must override.
A subset of a mesh represented by a range of acceptable attribute values.
void PrintNode(ostream &os) override
Print a graphviz node name for use in an edge statement.
~Interval() override=default
int Match(double cellNorm[2])
Does the specified range fall inside the interval? For cell-centered attributes, only cellNorm[0] is ...
NormKey Norm
This contains information about the attribute over which the interval is defined.
Interval * GetIntervalPointer() override
A class with comparison operator used to index input array norms used in threshold rules.
void ComputeNorm(vtkIdType cellId, vtkCell *cell, vtkDataArray *array, double cellNorm[2]) const
Compute the norm of a cell by calling NormFunction for all its points or for its single cell-centered...
bool operator<(const NormKey &other) const
A partial ordering of NormKey objects is required for them to serve as keys in the vtkMultiThreshold:...
A base class for representing threshold sets.
int OutputId
A unique identifier for this set.
virtual Interval * GetIntervalPointer()
virtual void PrintNodeName(ostream &os)
Print a graphviz node label statement (with fancy node name and shape).
virtual void PrintNode(ostream &os)=0
Print a graphviz node name for use in an edge statement.
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
Set()
The index of the output mesh that will hold this set or -1 if the set is not output.
virtual ~Set()=default
Virtual destructor since we have virtual members.
Threshold cells within multiple intervals.
~vtkMultiThreshold() override
TruthTree DependentSets
A list of boolean sets whose values depend on the given set.
int NumberOfOutputs
The number of output datasets.
vtkMultiThreshold(const vtkMultiThreshold &)=delete
void operator=(const vtkMultiThreshold &)=delete
Ruling
When an interval is evaluated, its value is used to update a truth table.
Norm
Norms that can be used to threshold vector attributes.
std::map< NormKey, IntervalList > RuleMap
A map describing the IntervalSets that share a common attribute and norm.
std::vector< Set * > Sets
A list of rules keyed by their unique integer ID.
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
int NextArrayIndex
A variable used to store the next index to use when calling SetInputArrayToProcess.
RuleMap IntervalRules
A set of threshold rules sorted by the attribute+norm to which they are applied.
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.
static vtkMultiThreshold * New()
std::vector< int > TruthTreeValues
void Reset()
Remove all the intervals currently defined.
int AddLowpassIntervalSet(double xmax, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void PrintGraph(ostream &os)
Print out a graphviz-formatted text description of all the sets.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This function performs the actual thresholding.
int AddBooleanSet(int operation, int numInputs, int *inputs)
Create a new mesh subset using boolean operations on pre-existing sets.
int OutputSet(int setId)
Create an output mesh containing a boolean or interval subset of the input mesh.
void UpdateDependents(int id, std::set< int > &unresolvedOutputs, TruthTreeValues &setStates, vtkCellData *inCellData, vtkIdType inCell, vtkGenericCell *cell, std::vector< vtkUnstructuredGrid * > &outv)
Recursively update the setStates and unresolvedOutputs vectors based on this->DependentSets.
int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, int attribType, int component, int allScalars)
Add a mesh subset to be computed by thresholding an attribute of the input mesh.
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.
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.
SetOperation
Operations that can be performed on sets to generate another set.
@ WOR
Include elements that belong to an odd number of input sets (a kind of "winding XOR")
@ XOR
Include an element if it belongs to exactly one input set.
@ NAND
Only include elements that don't belong to any input set.
@ AND
Only include an element if it belongs to all the input sets.
@ OR
Include an element if it belongs to any input set.
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
Closure
Whether the endpoint value of an interval should be included or excluded.
@ CLOSED
Specify a closed interval.
int FillInputPortInformation(int port, vtkInformation *info) override
We accept any mesh that is descended from vtkPointSet.
std::vector< TruthTreeValues > TruthTree
int AddIntervalSet(NormKey &nk, double xmin, double xmax, int omin, int omax)
A utility method called by the public AddInterval members.
concrete class for storing a set of points
Definition: vtkPointSet.h:79
dataset represents arbitrary combinations of all possible cell types
@ component
Definition: vtkX3D.h:181
@ info
Definition: vtkX3D.h:382
@ port
Definition: vtkX3D.h:453
@ string
Definition: vtkX3D.h:496
int vtkIdType
Definition: vtkType.h:332