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 ) VTK_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() VTK_OVERRIDE { }
322  void PrintNode( ostream& os ) VTK_OVERRIDE;
323  Interval* GetIntervalPointer() VTK_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() VTK_OVERRIDE { }
340  void PrintNode( ostream& os ) VTK_OVERRIDE;
341  BooleanSet* GetBooleanSetPointer() VTK_OVERRIDE;
342  };
343 
344 protected:
345 
347  ~vtkMultiThreshold() VTK_OVERRIDE;
348 
363  enum Ruling {
364  INCONCLUSIVE=-1,
365  INCLUDE=-2,
366  EXCLUDE=-3
367  };
368 
372  int RequestData( vtkInformation*, vtkInformationVector**, vtkInformationVector* ) VTK_OVERRIDE;
373 
379  int FillInputPortInformation( int port, vtkInformation* info ) VTK_OVERRIDE;
380 
386  int NextArrayIndex;
387 
391  int NumberOfOutputs;
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 
404  RuleMap IntervalRules;
405 
410  std::vector<Set*> Sets;
411 
418  TruthTree DependentSets;
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& ) VTK_DELETE_FUNCTION;
438  void operator = ( const vtkMultiThreshold& ) VTK_DELETE_FUNCTION;
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 0;
471 }
472 
474 {
475  return 0;
476 }
477 
479 {
480  return this;
481 }
482 
484 {
485  return this;
486 }
487 
488 #endif // vtkMultiThreshold_h
static double NegInf()
Special IEEE-754 number used to represent negative infinity.
A subset of a mesh represented by a range of acceptable attribute values.
virtual ~Set()
Virtual destructor since we have virtual members.
int Operator
The boolean operation that will be performed on the inputs to obtain the output.
A subset of a mesh represented as a boolean set operation.
std::vector< TruthTreeValues > TruthTree
Store vtkAlgorithm input/output information.
static double Inf()
Special IEEE-754 number used to represent positive infinity.
represent and manipulate cell attribute data
Definition: vtkCellData.h:32
int OutputId
A unique identifier for this set.
virtual Interval * GetIntervalPointer()
Set()
The index of the output mesh that will hold this set or -1 if the set is not output.
BooleanSet(int sId, int op, int *inBegin, int *inEnd)
Construct a new set with the given ID, operator, and inputs.
NormKey Norm
This contains information about the attribute over which the interval is defined. ...
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:39
Include elements that belong to an odd number of input sets (a kind of &quot;winding XOR&quot;) ...
int vtkIdType
Definition: vtkType.h:345
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.
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
provides thread-safe access to cells
Ruling
When an interval is evaluated, its value is used to update a truth table.
static vtkMultiBlockDataSetAlgorithm * New()
abstract class to specify cell behavior
Definition: vtkCell.h:56
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
These convenience members make it easy to insert closed intervals.
a simple class to control print indentation
Definition: vtkIndent.h:33
Closure
Whether the endpoint value of an interval should be included or excluded.
std::vector< int > Inputs
A list of input sets. These may be IntervalSets or BooleanSets.
dataset represents arbitrary combinations of all possible cell types
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
Interval * GetIntervalPointer() override
Include an element if it belongs to exactly one input set.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::map< NormKey, IntervalList > RuleMap
A map describing the IntervalSets that share a common attribute and norm.
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.
BooleanSet * GetBooleanSetPointer() override
Avoid dynamic_casts. Subclasses must override.
Only include an element if it belongs to all the input sets.
SetOperation
Operations that can be performed on sets to generate another set. Most of these operators take 2 or m...
Store zero or more vtkInformation instances.
A class with comparison operator used to index input array norms used in threshold rules...
Norm
Norms that can be used to threshold vector attributes.
Include an element if it belongs to any input set.
Threshold cells within multiple intervals.
A base class for representing threshold sets.
std::vector< int > TruthTreeValues