VTK  9.0.20200925
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 
103 #ifndef vtkMultiThreshold_h
104 #define vtkMultiThreshold_h
105 
106 #include "vtkFiltersGeneralModule.h" // For export macro
107 #include "vtkMath.h" // for Inf() and NegInf()
109 
110 #include <map> // for IntervalRules map
111 #include <set> // for UpdateDependents()
112 #include <string> // for holding array names in NormKey
113 #include <vector> // for lists of threshold rules
114 
115 class vtkCell;
116 class vtkCellData;
117 class vtkDataArray;
118 class vtkGenericCell;
119 class vtkPointSet;
120 class vtkUnstructuredGrid;
121 
122 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
123 {
124 public:
126  static vtkMultiThreshold* New();
127  void PrintSelf(ostream& os, vtkIndent indent) override;
128 
130  enum Closure
131  {
132  OPEN = 0,
133  CLOSED = 1
134  };
136  enum Norm
137  {
138  LINFINITY_NORM = -3,
139  L2_NORM = -2,
140  L1_NORM = -1
141  };
145  {
146  AND,
147  OR,
148  XOR,
149  WOR,
150  NAND
151  };
152 
154 
206  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, const char* arrayName,
207  int component, int allScalars);
208  int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, int attribType,
209  int component, int allScalars);
211 
213 
220  int AddLowpassIntervalSet(
221  double xmax, int assoc, const char* arrayName, int component, int allScalars);
222  int AddHighpassIntervalSet(
223  double xmin, int assoc, const char* arrayName, int component, int allScalars);
224  int AddBandpassIntervalSet(
225  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars);
226  int AddNotchIntervalSet(
227  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars);
229 
233  int AddBooleanSet(int operation, int numInputs, int* inputs);
234 
238  int OutputSet(int setId);
239 
243  void Reset();
244 
247  typedef double (*TupleNorm)(vtkDataArray* arr, vtkIdType tuple, int component);
248 
249  // NormKey must be able to use TupleNorm typedef:
250  class NormKey;
251 
252  // Interval must be able to use NormKey typedef:
253  class Interval;
254 
255  // Set needs to refer to boolean set pointers
256  class BooleanSet;
257 
259  class NormKey
260  {
261  public:
262  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or
263  // vtkDataObject::FIELD_ASSOCIATION_CELLS
264  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS,
265  // NORMALS, TCOORDS, GLOBALIDS}
266  std::string Name; // Either empty or (when ArrayType == -1) an input array name
267  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
268  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points
269  // be in the interval?
270  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
271  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct
272  // component) of a tuple.
273 
276  void ComputeNorm(
277  vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2]) const;
278 
281  bool operator<(const NormKey& other) const
282  {
283  if (this->Association < other.Association)
284  return true;
285  else if (this->Association > other.Association)
286  return false;
287 
288  if (this->Component < other.Component)
289  return true;
290  else if (this->Component > other.Component)
291  return false;
292 
293  if ((!this->AllScalars) && other.AllScalars)
294  return true;
295  else if (this->AllScalars && (!other.AllScalars))
296  return false;
297 
298  if (this->Type == -1)
299  {
300  if (other.Type == -1)
301  return this->Name < other.Name;
302  return true;
303  }
304  else
305  {
306  return this->Type < other.Type;
307  }
308  }
309  };
310 
315  class Set
316  {
317  public:
318  int Id;
319  int OutputId;
320 
324  Set() { this->OutputId = -1; }
326  virtual ~Set() = default;
328  virtual void PrintNodeName(ostream& os);
330  virtual void PrintNode(ostream& os) = 0;
332  virtual BooleanSet* GetBooleanSetPointer();
333  virtual Interval* GetIntervalPointer();
334  };
335 
337  class Interval : public Set
338  {
339  public:
341  double EndpointValues[2];
343  int EndpointClosures[2];
346 
352  int Match(double cellNorm[2]);
353 
354  ~Interval() override = default;
355  void PrintNode(ostream& os) override;
356  Interval* GetIntervalPointer() override;
357  };
358 
360  class BooleanSet : public Set
361  {
362  public:
364  int Operator;
366  std::vector<int> Inputs;
367 
369  BooleanSet(int sId, int op, int* inBegin, int* inEnd)
370  : Inputs(inBegin, inEnd)
371  {
372  this->Id = sId;
373  this->Operator = op;
374  }
375  ~BooleanSet() override = default;
376  void PrintNode(ostream& os) override;
377  BooleanSet* GetBooleanSetPointer() override;
378  };
379 
380 protected:
382  ~vtkMultiThreshold() override;
383 
398  enum Ruling
399  {
400  INCONCLUSIVE = -1,
401  INCLUDE = -2,
402  EXCLUDE = -3
403  };
404 
409 
415  int FillInputPortInformation(int port, vtkInformation* info) override;
416 
423 
428 
430  typedef std::vector<Interval*> IntervalList;
432  typedef std::map<NormKey, IntervalList> RuleMap;
433 
434  typedef std::vector<int> TruthTreeValues;
435  typedef std::vector<TruthTreeValues> TruthTree;
436 
441 
447  std::vector<Set*> Sets;
448 
456 
460  void UpdateDependents(int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
461  vtkCellData* inCellData, vtkIdType inCell, vtkGenericCell* cell,
462  std::vector<vtkUnstructuredGrid*>& outv);
463 
467  int AddIntervalSet(NormKey& nk, double xmin, double xmax, int omin, int omax);
468 
472  void PrintGraph(ostream& os);
473 
474  vtkMultiThreshold(const vtkMultiThreshold&) = delete;
475  void operator=(const vtkMultiThreshold&) = delete;
476 };
477 
479  double xmax, int assoc, const char* arrayName, int component, int allScalars)
480 {
481  return this->AddIntervalSet(
482  vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
483 }
484 
486  double xmin, int assoc, const char* arrayName, int component, int allScalars)
487 {
488  return this->AddIntervalSet(
489  xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars);
490 }
491 
493  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars)
494 {
495  return this->AddIntervalSet(xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
496 }
497 
499  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars)
500 {
501  int band =
502  this->AddIntervalSet(xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars);
503  if (band < 0)
504  {
505  return -1;
506  }
507  return this->AddBooleanSet(NAND, 1, &band);
508 }
509 
511 {
512  return nullptr;
513 }
514 
516 {
517  return nullptr;
518 }
519 
521 {
522  return this;
523 }
524 
526 {
527  return this;
528 }
529 
530 #endif // vtkMultiThreshold_h
vtkMultiThreshold::NormKey::Component
int Component
Definition: vtkMultiThreshold.h:267
vtkMultiThreshold::Sets
std::vector< Set * > Sets
A list of rules keyed by their unique integer ID.
Definition: vtkMultiThreshold.h:447
vtkMultiThreshold::AddBooleanSet
int AddBooleanSet(int operation, int numInputs, int *inputs)
Create a new mesh subset using boolean operations on pre-existing sets.
vtkMultiThreshold::DependentSets
TruthTree DependentSets
A list of boolean sets whose values depend on the given set.
Definition: vtkMultiThreshold.h:455
vtkX3D::component
Definition: vtkX3D.h:181
vtkMath.h
vtkMultiThreshold::Interval
A subset of a mesh represented by a range of acceptable attribute values.
Definition: vtkMultiThreshold.h:337
vtkMultiThreshold::WOR
Include elements that belong to an odd number of input sets (a kind of "winding XOR")
Definition: vtkMultiThreshold.h:149
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:35
vtkMultiThreshold::TruthTree
std::vector< TruthTreeValues > TruthTree
Definition: vtkMultiThreshold.h:435
vtkMultiThreshold::NormKey::NormFunction
TupleNorm NormFunction
Definition: vtkMultiThreshold.h:271
vtkMultiThreshold::NAND
Only include elements that don't belong to any input set.
Definition: vtkMultiThreshold.h:150
vtkMultiThreshold::Ruling
Ruling
When an interval is evaluated, its value is used to update a truth table.
Definition: vtkMultiThreshold.h:398
vtkMultiBlockDataSetAlgorithm::New
static vtkMultiBlockDataSetAlgorithm * New()
vtkMultiThreshold::AddBandpassIntervalSet
int AddBandpassIntervalSet(double xmin, double xmax, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:492
vtkMultiThreshold::BooleanSet::BooleanSet
BooleanSet(int sId, int op, int *inBegin, int *inEnd)
Construct a new set with the given ID, operator, and inputs.
Definition: vtkMultiThreshold.h:369
vtkMultiThreshold::AddHighpassIntervalSet
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:485
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkMultiThreshold::Interval::Norm
NormKey Norm
This contains information about the attribute over which the interval is defined.
Definition: vtkMultiThreshold.h:345
vtkMath::Inf
static double Inf()
Special IEEE-754 number used to represent positive infinity.
vtkMultiThreshold::AddLowpassIntervalSet
int AddLowpassIntervalSet(double xmax, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
Definition: vtkMultiThreshold.h:478
vtkMultiBlockDataSetAlgorithm::RequestData
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
Definition: vtkMultiBlockDataSetAlgorithm.h:89
vtkMultiThreshold::RuleMap
std::map< NormKey, IntervalList > RuleMap
A map describing the IntervalSets that share a common attribute and norm.
Definition: vtkMultiThreshold.h:432
vtkMath::NegInf
static double NegInf()
Special IEEE-754 number used to represent negative infinity.
vtkMultiThreshold::BooleanSet::Operator
int Operator
The boolean operation that will be performed on the inputs to obtain the output.
Definition: vtkMultiThreshold.h:364
vtkX3D::port
Definition: vtkX3D.h:453
vtkMultiThreshold::IntervalList
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
Definition: vtkMultiThreshold.h:430
vtkMultiThreshold::Interval::GetIntervalPointer
Interval * GetIntervalPointer() override
Definition: vtkMultiThreshold.h:520
vtkMultiThreshold::NormKey::Name
std::string Name
Definition: vtkMultiThreshold.h:266
vtkMultiThreshold::AddIntervalSet
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.
vtkMultiThreshold::BooleanSet::GetBooleanSetPointer
BooleanSet * GetBooleanSetPointer() override
Avoid dynamic_casts. Subclasses must override.
Definition: vtkMultiThreshold.h:525
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:57
vtkCellData
represent and manipulate cell attribute data
Definition: vtkCellData.h:32
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkMultiThreshold::Closure
Closure
Whether the endpoint value of an interval should be included or excluded.
Definition: vtkMultiThreshold.h:130
vtkMultiThreshold::NumberOfOutputs
int NumberOfOutputs
The number of output datasets.
Definition: vtkMultiThreshold.h:427
vtkMultiThreshold::Set::GetBooleanSetPointer
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
Definition: vtkMultiThreshold.h:515
vtkMultiThreshold::NormKey::Association
int Association
Definition: vtkMultiThreshold.h:262
vtkMultiThreshold::NormKey::operator<
bool operator<(const NormKey &other) const
A partial ordering of NormKey objects is required for them to serve as keys in the vtkMultiThreshold:...
Definition: vtkMultiThreshold.h:281
vtkMultiThreshold::IntervalRules
RuleMap IntervalRules
A set of threshold rules sorted by the attribute+norm to which they are applied.
Definition: vtkMultiThreshold.h:440
vtkMultiThreshold::BooleanSet
A subset of a mesh represented as a boolean set operation.
Definition: vtkMultiThreshold.h:360
vtkMultiThreshold::OR
Include an element if it belongs to any input set.
Definition: vtkMultiThreshold.h:147
vtkMultiBlockDataSetAlgorithm.h
vtkMultiThreshold::AND
Only include an element if it belongs to all the input sets.
Definition: vtkMultiThreshold.h:146
vtkMultiThreshold::Set::OutputId
int OutputId
A unique identifier for this set.
Definition: vtkMultiThreshold.h:319
vtkMultiThreshold::NormKey::InputArrayIndex
int InputArrayIndex
Definition: vtkMultiThreshold.h:270
vtkMultiThreshold::Set::Set
Set()
The index of the output mesh that will hold this set or -1 if the set is not output.
Definition: vtkMultiThreshold.h:324
vtkMultiBlockDataSetAlgorithm::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkMultiThreshold::CLOSED
Specify a closed interval.
Definition: vtkMultiThreshold.h:133
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:73
vtkMultiThreshold::Norm
Norm
Norms that can be used to threshold vector attributes.
Definition: vtkMultiThreshold.h:136
vtkX3D::info
Definition: vtkX3D.h:382
vtkX3D::string
Definition: vtkX3D.h:496
vtkMultiThreshold::Set::GetIntervalPointer
virtual Interval * GetIntervalPointer()
Definition: vtkMultiThreshold.h:510
vtkMultiThreshold::XOR
Include an element if it belongs to exactly one input set.
Definition: vtkMultiThreshold.h:148
vtkMultiThreshold
Threshold cells within multiple intervals.
Definition: vtkMultiThreshold.h:122
vtkPointSet
concrete class for storing a set of points
Definition: vtkPointSet.h:66
vtkMultiThreshold::NormKey::Type
int Type
Definition: vtkMultiThreshold.h:264
vtkMultiBlockDataSetAlgorithm::FillInputPortInformation
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
vtkGenericCell
provides thread-safe access to cells
Definition: vtkGenericCell.h:36
vtkMultiThreshold::BooleanSet::Inputs
std::vector< int > Inputs
A list of input sets. These may be IntervalSets or BooleanSets.
Definition: vtkMultiThreshold.h:366
vtkMultiThreshold::TruthTreeValues
std::vector< int > TruthTreeValues
Definition: vtkMultiThreshold.h:434
vtkMultiThreshold::Set
A base class for representing threshold sets.
Definition: vtkMultiThreshold.h:315
vtkUnstructuredGrid
dataset represents arbitrary combinations of all possible cell types
Definition: vtkUnstructuredGrid.h:93
vtkMultiThreshold::AddNotchIntervalSet
int AddNotchIntervalSet(double xlo, double xhi, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:498
vtkMultiThreshold::NormKey::AllScalars
int AllScalars
Definition: vtkMultiThreshold.h:268
vtkMultiThreshold::SetOperation
SetOperation
Operations that can be performed on sets to generate another set.
Definition: vtkMultiThreshold.h:144
vtkMultiThreshold::NormKey
A class with comparison operator used to index input array norms used in threshold rules.
Definition: vtkMultiThreshold.h:259
vtkMultiThreshold::NextArrayIndex
int NextArrayIndex
A variable used to store the next index to use when calling SetInputArrayToProcess.
Definition: vtkMultiThreshold.h:422
vtkMultiThreshold::Set::Id
int Id
Definition: vtkMultiThreshold.h:318
vtkMultiBlockDataSetAlgorithm
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
Definition: vtkMultiBlockDataSetAlgorithm.h:32