VTK  9.5.2
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
91
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
104VTK_ABI_NAMESPACE_BEGIN
105class vtkCell;
106class vtkCellData;
107class vtkDataArray;
108class vtkGenericCell;
109class vtkPointSet;
111
112class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
113{
114public:
117 void PrintSelf(ostream& os, vtkIndent indent) override;
118
121 {
122 OPEN = 0,
124 };
125
126 enum Norm
127 {
129 L2_NORM = -2,
131 };
132
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
211 double xmax, int assoc, const char* arrayName, int component, int allScalars);
213 double xmin, int assoc, const char* arrayName, int component, int allScalars);
215 double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars);
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
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
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;
311
314 Set() { this->OutputId = -1; }
316 virtual ~Set() = default;
318 virtual void PrintNodeName(ostream& os);
320 virtual void PrintNode(ostream& os) = 0;
323 virtual Interval* GetIntervalPointer();
324 };
325
327 class Interval : public Set
328 {
329 public:
331 double EndpointValues[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:
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;
368 };
369
370protected:
373
389 {
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
431
437 std::vector<Set*> Sets;
438
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
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
504
509
514
519
520VTK_ABI_NAMESPACE_END
521#endif // vtkMultiThreshold_h
represent and manipulate cell attribute data
Definition vtkCellData.h:32
abstract class to specify cell behavior
Definition vtkCell.h:51
provides thread-safe access to cells
a simple class to control print indentation
Definition vtkIndent.h:29
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.
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 EndpointClosures[2]
Are the endpoint values themselves included in the set (CLOSED) or not (OPEN)?
int Match(double cellNorm[2])
Does the specified range fall inside the interval?
NormKey Norm
This contains information about the attribute over which the interval is defined.
Interval * GetIntervalPointer() override
double EndpointValues[2]
The values defining the interval. These must be in ascending order.
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:...
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.
~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
static vtkMultiThreshold * New()
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.
@ L2_NORM
Use the norm for the specified array threshold.
@ L1_NORM
Use the norm for the specified array threshold.
@ LINFINITY_NORM
Use the norm for the specified array threshold.
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.
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.
double(* TupleNorm)(vtkDataArray *arr, vtkIdType tuple, int component)
A pointer to a function that returns a norm (or a single component) of a tuple with 1 or more compone...
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.
@ OPEN
Specify an open interval.
@ 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:59
dataset represents arbitrary combinations of all possible cell types
#define vtkDataArray
int vtkIdType
Definition vtkType.h:332