VTK
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 
104 #ifndef vtkMultiThreshold_h
105 #define vtkMultiThreshold_h
106 
107 #include "vtkFiltersGeneralModule.h" // For export macro
109 #include "vtkMath.h" // for Inf() and NegInf()
110 
111 #include <vector> // for lists of threshold rules
112 #include <map> // for IntervalRules map
113 #include <set> // for UpdateDependents()
114 #include <string> // for holding array names in NormKey
115 
116 class vtkCell;
117 class vtkCellData;
118 class vtkDataArray;
119 class vtkGenericCell;
120 class vtkPointSet;
121 class vtkUnstructuredGrid;
122 
123 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
124 {
125 public:
127  static vtkMultiThreshold* New();
128  void PrintSelf( ostream& os, vtkIndent indent ) override;
129 
131  enum Closure {
132  OPEN=0,
133  CLOSED=1
134  };
136  enum Norm {
137  LINFINITY_NORM=-3,
138  L2_NORM=-2,
139  L1_NORM=-1
140  };
143  AND,
144  OR,
145  XOR,
146  WOR,
147  NAND
148  };
149 
151 
193  int AddIntervalSet( double xmin, double xmax, int omin, int omax,
194  int assoc, const char* arrayName, int component, int allScalars );
195  int AddIntervalSet( double xmin, double xmax, int omin, int omax,
196  int assoc, int attribType, int component, int allScalars );
198 
200 
207  int AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars );
208  int AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars );
209  int AddBandpassIntervalSet( double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars );
210  int AddNotchIntervalSet( double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars );
212 
216  int AddBooleanSet( int operation, int numInputs, int* inputs );
217 
221  int OutputSet( int setId );
222 
226  void Reset();
227 
229  typedef double (*TupleNorm)( vtkDataArray* arr, vtkIdType tuple, int component );
230 
231  // NormKey must be able to use TupleNorm typedef:
232  class NormKey;
233 
234  // Interval must be able to use NormKey typedef:
235  class Interval;
236 
237  // Set needs to refer to boolean set pointers
238  class BooleanSet;
239 
241  class NormKey {
242  public:
243  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or vtkDataObject::FIELD_ASSOCIATION_CELLS
244  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS, NORMALS, TCOORDS, GLOBALIDS}
245  std::string Name; // Either empty or (when ArrayType == -1) an input array name
246  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
247  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points be in the interval?
248  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
249  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct component) of a tuple.
250 
252  void ComputeNorm( vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2] ) const;
253 
255  bool operator < ( const NormKey& other ) const {
256  if ( this->Association < other.Association )
257  return true;
258  else if ( this->Association > other.Association )
259  return false;
260 
261  if ( this->Component < other.Component )
262  return true;
263  else if ( this->Component > other.Component )
264  return false;
265 
266  if ( (! this->AllScalars) && other.AllScalars )
267  return true;
268  else if ( this->AllScalars && (! other.AllScalars) )
269  return false;
270 
271  if ( this->Type == -1 )
272  {
273  if ( other.Type == -1 )
274  return this->Name < other.Name;
275  return true;
276  }
277  else
278  {
279  return this->Type < other.Type;
280  }
281  }
282  };
283 
288  class Set {
289  public:
290  int Id;
291  int OutputId;
292 
294  Set() {
295  this->OutputId = -1;
296  }
298  virtual ~Set() { }
300  virtual void PrintNodeName( ostream& os );
302  virtual void PrintNode( ostream& os ) = 0;
304  virtual BooleanSet* GetBooleanSetPointer();
305  virtual Interval* GetIntervalPointer();
306  };
307 
309  class Interval : public Set {
310  public:
312  double EndpointValues[2];
314  int EndpointClosures[2];
317 
322  int Match( double cellNorm[2] );
323 
324  ~Interval() override { }
325  void PrintNode( ostream& os ) override;
326  Interval* GetIntervalPointer() override;
327  };
328 
330  class BooleanSet : public Set {
331  public:
333  int Operator;
335  std::vector<int> Inputs;
336 
338  BooleanSet( int sId, int op, int* inBegin, int* inEnd ) : Inputs( inBegin, inEnd ) {
339  this->Id = sId;
340  this->Operator = op;
341  }
342  ~BooleanSet() override { }
343  void PrintNode( ostream& os ) override;
344  BooleanSet* GetBooleanSetPointer() override;
345  };
346 
347 protected:
348 
350  ~vtkMultiThreshold() override;
351 
366  enum Ruling {
367  INCONCLUSIVE=-1,
368  INCLUDE=-2,
369  EXCLUDE=-3
370  };
371 
376 
382  int FillInputPortInformation( int port, vtkInformation* info ) override;
383 
390 
395 
397  typedef std::vector<Interval*> IntervalList;
399  typedef std::map<NormKey,IntervalList> RuleMap;
400 
401  typedef std::vector<int> TruthTreeValues;
402  typedef std::vector<TruthTreeValues> TruthTree;
403 
408 
413  std::vector<Set*> Sets;
414 
422 
426  void UpdateDependents(
427  int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
428  vtkCellData* inCellData, vtkIdType cellId, vtkGenericCell* cell, std::vector<vtkUnstructuredGrid*>& outv );
429 
433  int AddIntervalSet( NormKey& nk, double xmin, double xmax, int omin, int omax );
434 
438  void PrintGraph( ostream& os );
439 
440  vtkMultiThreshold( const vtkMultiThreshold& ) = delete;
441  void operator = ( const vtkMultiThreshold& ) = delete;
442 };
443 
444 inline int vtkMultiThreshold::AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars )
445 {
446  return this->AddIntervalSet( vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
447 }
448 
449 inline int vtkMultiThreshold::AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars )
450 {
451  return this->AddIntervalSet( xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars );
452 }
453 
455  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars )
456 {
457  return this->AddIntervalSet( xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
458 }
459 
461  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars )
462 {
463  int band = this->AddIntervalSet( xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
464  if ( band < 0 )
465  {
466  return -1;
467  }
468  return this->AddBooleanSet( NAND, 1, &band );
469 }
470 
472 {
473  return nullptr;
474 }
475 
477 {
478  return nullptr;
479 }
480 
482 {
483  return this;
484 }
485 
487 {
488  return this;
489 }
490 
491 #endif // vtkMultiThreshold_h
vtkMultiThreshold::NormKey::Component
int Component
Definition: vtkMultiThreshold.h:246
double
double
Definition: vtkVectorOperators.h:166
vtkMultiThreshold::Sets
std::vector< Set * > Sets
A list of rules keyed by their unique integer ID.
Definition: vtkMultiThreshold.h:413
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:421
vtkX3D::component
Definition: vtkX3D.h:175
vtkMultiThreshold::Interval::~Interval
~Interval() override
Definition: vtkMultiThreshold.h:324
vtkMath.h
vtkMultiThreshold::Interval
A subset of a mesh represented by a range of acceptable attribute values.
Definition: vtkMultiThreshold.h:309
vtkMultiThreshold::WOR
Include elements that belong to an odd number of input sets (a kind of "winding XOR")
Definition: vtkMultiThreshold.h:146
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:41
vtkMultiThreshold::TruthTree
std::vector< TruthTreeValues > TruthTree
Definition: vtkMultiThreshold.h:402
vtkMultiThreshold::NormKey::NormFunction
TupleNorm NormFunction
Definition: vtkMultiThreshold.h:249
vtkMultiThreshold::NAND
Only include elements that don't belong to any input set.
Definition: vtkMultiThreshold.h:147
vtkMultiThreshold::Ruling
Ruling
When an interval is evaluated, its value is used to update a truth table.
Definition: vtkMultiThreshold.h:366
vtkMultiThreshold::BooleanSet::~BooleanSet
~BooleanSet() override
Definition: vtkMultiThreshold.h:342
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:454
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:338
vtkMultiThreshold::AddHighpassIntervalSet
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:449
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
operator<
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkMultiThreshold::Interval::Norm
NormKey Norm
This contains information about the attribute over which the interval is defined.
Definition: vtkMultiThreshold.h:316
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:444
vtkMultiBlockDataSetAlgorithm::RequestData
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
Definition: vtkMultiBlockDataSetAlgorithm.h:91
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:333
vtkX3D::port
Definition: vtkX3D.h:447
vtkMultiThreshold::IntervalList
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
Definition: vtkMultiThreshold.h:397
vtkMultiThreshold::Interval::GetIntervalPointer
Interval * GetIntervalPointer() override
Definition: vtkMultiThreshold.h:481
vtkMultiThreshold::NormKey::Name
std::string Name
Definition: vtkMultiThreshold.h:245
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:486
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:59
vtkCellData
represent and manipulate cell attribute data
Definition: vtkCellData.h:38
vtkMultiThreshold::RuleMap
std::map< NormKey, IntervalList > RuleMap
A map describing the IntervalSets that share a common attribute and norm.
Definition: vtkMultiThreshold.h:399
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkMultiThreshold::Closure
Closure
Whether the endpoint value of an interval should be included or excluded.
Definition: vtkMultiThreshold.h:131
vtkMultiThreshold::NumberOfOutputs
int NumberOfOutputs
The number of output datasets.
Definition: vtkMultiThreshold.h:394
vtkMultiThreshold::Set::GetBooleanSetPointer
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
Definition: vtkMultiThreshold.h:476
vtkMultiThreshold::NormKey::Association
int Association
Definition: vtkMultiThreshold.h:243
vtkMultiThreshold::IntervalRules
RuleMap IntervalRules
A set of threshold rules sorted by the attribute+norm to which they are applied.
Definition: vtkMultiThreshold.h:407
vtkMultiThreshold::BooleanSet
A subset of a mesh represented as a boolean set operation.
Definition: vtkMultiThreshold.h:330
vtkMultiThreshold::OR
Include an element if it belongs to any input set.
Definition: vtkMultiThreshold.h:144
vtkMultiBlockDataSetAlgorithm.h
vtkMultiThreshold::AND
Only include an element if it belongs to all the input sets.
Definition: vtkMultiThreshold.h:143
vtkMultiThreshold::Set::OutputId
int OutputId
A unique identifier for this set.
Definition: vtkMultiThreshold.h:291
vtkMultiThreshold::NormKey::InputArrayIndex
int InputArrayIndex
Definition: vtkMultiThreshold.h:248
vtkMultiThreshold::Set::~Set
virtual ~Set()
Virtual destructor since we have virtual members.
Definition: vtkMultiThreshold.h:298
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:294
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:86
vtkMultiThreshold::Norm
Norm
Norms that can be used to threshold vector attributes.
Definition: vtkMultiThreshold.h:136
vtkX3D::info
Definition: vtkX3D.h:376
vtkX3D::string
Definition: vtkX3D.h:490
vtkMultiThreshold::Set::GetIntervalPointer
virtual Interval * GetIntervalPointer()
Definition: vtkMultiThreshold.h:471
vtkMultiThreshold::XOR
Include an element if it belongs to exactly one input set.
Definition: vtkMultiThreshold.h:145
vtkMultiThreshold
Threshold cells within multiple intervals.
Definition: vtkMultiThreshold.h:123
vtkPointSet
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:42
vtkMultiThreshold::NormKey::Type
int Type
Definition: vtkMultiThreshold.h:244
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:39
vtkMultiThreshold::BooleanSet::Inputs
std::vector< int > Inputs
A list of input sets. These may be IntervalSets or BooleanSets.
Definition: vtkMultiThreshold.h:335
vtkMultiThreshold::TruthTreeValues
std::vector< int > TruthTreeValues
Definition: vtkMultiThreshold.h:401
vtkMultiThreshold::Set
A base class for representing threshold sets.
Definition: vtkMultiThreshold.h:288
vtkUnstructuredGrid
dataset represents arbitrary combinations of all possible cell types
Definition: vtkUnstructuredGrid.h:87
vtkMultiThreshold::AddNotchIntervalSet
int AddNotchIntervalSet(double xlo, double xhi, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:460
vtkMultiThreshold::NormKey::AllScalars
int AllScalars
Definition: vtkMultiThreshold.h:247
vtkMultiThreshold::SetOperation
SetOperation
Operations that can be performed on sets to generate another set. Most of these operators take 2 or m...
Definition: vtkMultiThreshold.h:142
vtkMultiThreshold::NormKey
A class with comparison operator used to index input array norms used in threshold rules.
Definition: vtkMultiThreshold.h:241
vtkMultiThreshold::NextArrayIndex
int NextArrayIndex
A variable used to store the next index to use when calling SetInputArrayToProcess.
Definition: vtkMultiThreshold.h:389
vtkMultiThreshold::Set::Id
int Id
Definition: vtkMultiThreshold.h:290
vtkMultiBlockDataSetAlgorithm
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
Definition: vtkMultiBlockDataSetAlgorithm.h:35