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 
101 #ifndef vtkMultiThreshold_h
102 #define vtkMultiThreshold_h
103 
104 #include "vtkFiltersGeneralModule.h" // For export macro
106 #include "vtkMath.h" // for Inf() and NegInf()
107 
108 #include <vector> // for lists of threshold rules
109 #include <map> // for IntervalRules map
110 #include <set> // for UpdateDependents()
111 #include <string> // for holding array names in NormKey
112 
113 class vtkCell;
114 class vtkCellData;
115 class vtkDataArray;
116 class vtkGenericCell;
117 class vtkPointSet;
118 class vtkUnstructuredGrid;
119 
120 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
121 {
122 public:
124  static vtkMultiThreshold* New();
125  void PrintSelf( ostream& os, vtkIndent indent ) override;
126 
128  enum Closure {
129  OPEN=0,
130  CLOSED=1
131  };
133  enum Norm {
134  LINFINITY_NORM=-3,
135  L2_NORM=-2,
136  L1_NORM=-1
137  };
140  AND,
141  OR,
142  XOR,
143  WOR,
144  NAND
145  };
146 
148 
190  int AddIntervalSet( double xmin, double xmax, int omin, int omax,
191  int assoc, const char* arrayName, int component, int allScalars );
192  int AddIntervalSet( double xmin, double xmax, int omin, int omax,
193  int assoc, int attribType, int component, int allScalars );
195 
197 
204  int AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars );
205  int AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars );
206  int AddBandpassIntervalSet( double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars );
207  int AddNotchIntervalSet( double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars );
209 
213  int AddBooleanSet( int operation, int numInputs, int* inputs );
214 
218  int OutputSet( int setId );
219 
223  void Reset();
224 
226  typedef double (*TupleNorm)( vtkDataArray* arr, vtkIdType tuple, int component );
227 
228  // NormKey must be able to use TupleNorm typedef:
229  class NormKey;
230 
231  // Interval must be able to use NormKey typedef:
232  class Interval;
233 
234  // Set needs to refer to boolean set pointers
235  class BooleanSet;
236 
238  class NormKey {
239  public:
240  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or vtkDataObject::FIELD_ASSOCIATION_CELLS
241  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS, NORMALS, TCOORDS, GLOBALIDS}
242  std::string Name; // Either empty or (when ArrayType == -1) an input array name
243  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
244  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points be in the interval?
245  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
246  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct component) of a tuple.
247 
249  void ComputeNorm( vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2] ) const;
250 
252  bool operator < ( const NormKey& other ) const {
253  if ( this->Association < other.Association )
254  return true;
255  else if ( this->Association > other.Association )
256  return false;
257 
258  if ( this->Component < other.Component )
259  return true;
260  else if ( this->Component > other.Component )
261  return false;
262 
263  if ( (! this->AllScalars) && other.AllScalars )
264  return true;
265  else if ( this->AllScalars && (! other.AllScalars) )
266  return false;
267 
268  if ( this->Type == -1 )
269  {
270  if ( other.Type == -1 )
271  return this->Name < other.Name;
272  return true;
273  }
274  else
275  {
276  return this->Type < other.Type;
277  }
278  }
279  };
280 
285  class Set {
286  public:
287  int Id;
288  int OutputId;
289 
291  Set() {
292  this->OutputId = -1;
293  }
295  virtual ~Set() { }
297  virtual void PrintNodeName( ostream& os );
299  virtual void PrintNode( ostream& os ) = 0;
301  virtual BooleanSet* GetBooleanSetPointer();
302  virtual Interval* GetIntervalPointer();
303  };
304 
306  class Interval : public Set {
307  public:
309  double EndpointValues[2];
311  int EndpointClosures[2];
314 
319  int Match( double cellNorm[2] );
320 
321  ~Interval() override { }
322  void PrintNode( ostream& os ) override;
323  Interval* GetIntervalPointer() override;
324  };
325 
327  class BooleanSet : public Set {
328  public:
330  int Operator;
332  std::vector<int> Inputs;
333 
335  BooleanSet( int sId, int op, int* inBegin, int* inEnd ) : Inputs( inBegin, inEnd ) {
336  this->Id = sId;
337  this->Operator = op;
338  }
339  ~BooleanSet() override { }
340  void PrintNode( ostream& os ) override;
341  BooleanSet* GetBooleanSetPointer() override;
342  };
343 
344 protected:
345 
347  ~vtkMultiThreshold() override;
348 
363  enum Ruling {
364  INCONCLUSIVE=-1,
365  INCLUDE=-2,
366  EXCLUDE=-3
367  };
368 
373 
379  int FillInputPortInformation( int port, vtkInformation* info ) override;
380 
387 
392 
394  typedef std::vector<Interval*> IntervalList;
396  typedef std::map<NormKey,IntervalList> RuleMap;
397 
398  typedef std::vector<int> TruthTreeValues;
399  typedef std::vector<TruthTreeValues> TruthTree;
400 
405 
410  std::vector<Set*> Sets;
411 
419 
423  void UpdateDependents(
424  int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
425  vtkCellData* inCellData, vtkIdType cellId, vtkGenericCell* cell, std::vector<vtkUnstructuredGrid*>& outv );
426 
430  int AddIntervalSet( NormKey& nk, double xmin, double xmax, int omin, int omax );
431 
435  void PrintGraph( ostream& os );
436 
437  vtkMultiThreshold( const vtkMultiThreshold& ) = delete;
438  void operator = ( const vtkMultiThreshold& ) = delete;
439 };
440 
441 inline int vtkMultiThreshold::AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars )
442 {
443  return this->AddIntervalSet( vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
444 }
445 
446 inline int vtkMultiThreshold::AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars )
447 {
448  return this->AddIntervalSet( xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars );
449 }
450 
452  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars )
453 {
454  return this->AddIntervalSet( xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
455 }
456 
458  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars )
459 {
460  int band = this->AddIntervalSet( xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
461  if ( band < 0 )
462  {
463  return -1;
464  }
465  return this->AddBooleanSet( NAND, 1, &band );
466 }
467 
469 {
470  return nullptr;
471 }
472 
474 {
475  return nullptr;
476 }
477 
479 {
480  return this;
481 }
482 
484 {
485  return this;
486 }
487 
488 #endif // vtkMultiThreshold_h
vtkMultiThreshold::NormKey::Component
int Component
Definition: vtkMultiThreshold.h:243
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:410
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:418
vtkX3D::component
Definition: vtkX3D.h:175
vtkMultiThreshold::Interval::~Interval
~Interval() override
Definition: vtkMultiThreshold.h:321
vtkMath.h
vtkMultiThreshold::Interval
A subset of a mesh represented by a range of acceptable attribute values.
Definition: vtkMultiThreshold.h:306
vtkMultiThreshold::WOR
Include elements that belong to an odd number of input sets (a kind of "winding XOR")
Definition: vtkMultiThreshold.h:143
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:35
vtkMultiThreshold::TruthTree
std::vector< TruthTreeValues > TruthTree
Definition: vtkMultiThreshold.h:399
vtkMultiThreshold::NormKey::NormFunction
TupleNorm NormFunction
Definition: vtkMultiThreshold.h:246
vtkMultiThreshold::NAND
Only include elements that don't belong to any input set.
Definition: vtkMultiThreshold.h:144
vtkMultiThreshold::Ruling
Ruling
When an interval is evaluated, its value is used to update a truth table.
Definition: vtkMultiThreshold.h:363
vtkMultiThreshold::BooleanSet::~BooleanSet
~BooleanSet() override
Definition: vtkMultiThreshold.h:339
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:451
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:335
vtkMultiThreshold::AddHighpassIntervalSet
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:446
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
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:313
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:441
vtkMultiBlockDataSetAlgorithm::RequestData
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
Definition: vtkMultiBlockDataSetAlgorithm.h:88
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:330
vtkX3D::port
Definition: vtkX3D.h:447
vtkMultiThreshold::IntervalList
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
Definition: vtkMultiThreshold.h:394
vtkMultiThreshold::Interval::GetIntervalPointer
Interval * GetIntervalPointer() override
Definition: vtkMultiThreshold.h:478
vtkMultiThreshold::NormKey::Name
std::string Name
Definition: vtkMultiThreshold.h:242
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:483
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:56
vtkCellData
represent and manipulate cell attribute data
Definition: vtkCellData.h:32
vtkMultiThreshold::RuleMap
std::map< NormKey, IntervalList > RuleMap
A map describing the IntervalSets that share a common attribute and norm.
Definition: vtkMultiThreshold.h:396
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:128
vtkMultiThreshold::NumberOfOutputs
int NumberOfOutputs
The number of output datasets.
Definition: vtkMultiThreshold.h:391
vtkMultiThreshold::Set::GetBooleanSetPointer
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
Definition: vtkMultiThreshold.h:473
vtkMultiThreshold::NormKey::Association
int Association
Definition: vtkMultiThreshold.h:240
vtkMultiThreshold::IntervalRules
RuleMap IntervalRules
A set of threshold rules sorted by the attribute+norm to which they are applied.
Definition: vtkMultiThreshold.h:404
vtkMultiThreshold::BooleanSet
A subset of a mesh represented as a boolean set operation.
Definition: vtkMultiThreshold.h:327
vtkMultiThreshold::OR
Include an element if it belongs to any input set.
Definition: vtkMultiThreshold.h:141
vtkMultiBlockDataSetAlgorithm.h
vtkMultiThreshold::AND
Only include an element if it belongs to all the input sets.
Definition: vtkMultiThreshold.h:140
vtkMultiThreshold::Set::OutputId
int OutputId
A unique identifier for this set.
Definition: vtkMultiThreshold.h:288
vtkMultiThreshold::NormKey::InputArrayIndex
int InputArrayIndex
Definition: vtkMultiThreshold.h:245
vtkMultiThreshold::Set::~Set
virtual ~Set()
Virtual destructor since we have virtual members.
Definition: vtkMultiThreshold.h:295
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:291
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:130
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:80
vtkMultiThreshold::Norm
Norm
Norms that can be used to threshold vector attributes.
Definition: vtkMultiThreshold.h:133
vtkX3D::info
Definition: vtkX3D.h:376
vtkX3D::string
Definition: vtkX3D.h:490
vtkMultiThreshold::Set::GetIntervalPointer
virtual Interval * GetIntervalPointer()
Definition: vtkMultiThreshold.h:468
vtkMultiThreshold::XOR
Include an element if it belongs to exactly one input set.
Definition: vtkMultiThreshold.h:142
vtkMultiThreshold
Threshold cells within multiple intervals.
Definition: vtkMultiThreshold.h:120
vtkPointSet
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:39
vtkMultiThreshold::NormKey::Type
int Type
Definition: vtkMultiThreshold.h:241
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:332
vtkMultiThreshold::TruthTreeValues
std::vector< int > TruthTreeValues
Definition: vtkMultiThreshold.h:398
vtkMultiThreshold::Set
A base class for representing threshold sets.
Definition: vtkMultiThreshold.h:285
vtkUnstructuredGrid
dataset represents arbitrary combinations of all possible cell types
Definition: vtkUnstructuredGrid.h:81
vtkMultiThreshold::AddNotchIntervalSet
int AddNotchIntervalSet(double xlo, double xhi, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:457
vtkMultiThreshold::NormKey::AllScalars
int AllScalars
Definition: vtkMultiThreshold.h:244
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:139
vtkMultiThreshold::NormKey
A class with comparison operator used to index input array norms used in threshold rules.
Definition: vtkMultiThreshold.h:238
vtkMultiThreshold::NextArrayIndex
int NextArrayIndex
A variable used to store the next index to use when calling SetInputArrayToProcess.
Definition: vtkMultiThreshold.h:386
vtkMultiThreshold::Set::Id
int Id
Definition: vtkMultiThreshold.h:287
vtkMultiBlockDataSetAlgorithm
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
Definition: vtkMultiBlockDataSetAlgorithm.h:32