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 ) VTK_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() VTK_OVERRIDE { }
325  void PrintNode( ostream& os ) VTK_OVERRIDE;
326  Interval* GetIntervalPointer() VTK_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() VTK_OVERRIDE { }
343  void PrintNode( ostream& os ) VTK_OVERRIDE;
344  BooleanSet* GetBooleanSetPointer() VTK_OVERRIDE;
345  };
346 
347 protected:
348 
350  ~vtkMultiThreshold() VTK_OVERRIDE;
351 
366  enum Ruling {
367  INCONCLUSIVE=-1,
368  INCLUDE=-2,
369  EXCLUDE=-3
370  };
371 
375  int RequestData( vtkInformation*, vtkInformationVector**, vtkInformationVector* ) VTK_OVERRIDE;
376 
382  int FillInputPortInformation( int port, vtkInformation* info ) VTK_OVERRIDE;
383 
389  int NextArrayIndex;
390 
394  int NumberOfOutputs;
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 
407  RuleMap IntervalRules;
408 
413  std::vector<Set*> Sets;
414 
421  TruthTree DependentSets;
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& ) VTK_DELETE_FUNCTION;
441  void operator = ( const vtkMultiThreshold& ) VTK_DELETE_FUNCTION;
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 0;
474 }
475 
477 {
478  return 0;
479 }
480 
482 {
483  return this;
484 }
485 
487 {
488  return this;
489 }
490 
491 #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:38
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:42
Include elements that belong to an odd number of input sets (a kind of "winding XOR") ...
int vtkIdType
Definition: vtkType.h:287
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:59
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:39
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:54
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