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 
103 #ifndef vtkMultiThreshold_h
104 #define vtkMultiThreshold_h
105 
106 #include "vtkFiltersGeneralModule.h" // For export macro
108 #include "vtkMath.h" // for Inf() and NegInf()
109 
110 #include <vector> // for lists of threshold rules
111 #include <map> // for IntervalRules map
112 #include <set> // for UpdateDependents()
113 #include <string> // for holding array names in NormKey
114 
115 class vtkCell;
116 class vtkCellData;
117 class vtkDataArray;
118 class vtkGenericCell;
119 class vtkPointSet;
120 class vtkUnstructuredGrid;
121 
123 {
124 public:
127  virtual void PrintSelf( ostream& os, vtkIndent indent );
128 
129  //BTX
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  //ETX
150 
152 
195  int AddIntervalSet( double xmin, double xmax, int omin, int omax,
196  int assoc, const char* arrayName, int component, int allScalars );
197  int AddIntervalSet( double xmin, double xmax, int omin, int omax,
198  int assoc, int attribType, int component, int allScalars );
200 
202 
208  int AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars );
209  int AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars );
210  int AddBandpassIntervalSet( double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars );
211  int AddNotchIntervalSet( double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars );
213 
216  int AddBooleanSet( int operation, int numInputs, int* inputs );
217 
220  int OutputSet( int setId );
221 
223  void Reset();
224 
225  //BTX
227  typedef double (*TupleNorm)( vtkDataArray* arr, vtkIdType tuple, int component );
228 
229  // NormKey must be able to use TupleNorm typedef:
230  class NormKey;
231 
232  // Interval must be able to use NormKey typedef:
233  class Interval;
234 
235  // Set needs to refer to boolean set pointers
236  class BooleanSet;
237 
239  class NormKey {
240  public:
241  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or vtkDataObject::FIELD_ASSOCIATION_CELLS
242  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS, NORMALS, TCOORDS, GLOBALIDS}
243  std::string Name; // Either empty or (when ArrayType == -1) an input array name
244  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
245  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points be in the interval?
246  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
247  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct component) of a tuple.
248 
250  void ComputeNorm( vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2] ) const;
251 
253  bool operator < ( const NormKey& other ) const {
254  if ( this->Association < other.Association )
255  return true;
256  else if ( this->Association > other.Association )
257  return false;
258 
259  if ( this->Component < other.Component )
260  return true;
261  else if ( this->Component > other.Component )
262  return false;
263 
264  if ( (! this->AllScalars) && other.AllScalars )
265  return true;
266  else if ( this->AllScalars && (! other.AllScalars) )
267  return false;
268 
269  if ( this->Type == -1 )
270  {
271  if ( other.Type == -1 )
272  return this->Name < other.Name;
273  return true;
274  }
275  else
276  {
277  return this->Type < other.Type;
278  }
279  }
280  };
281 
286  class Set {
287  public:
288  int Id;
289  int OutputId;
290 
292  Set() {
293  this->OutputId = -1;
294  }
296  virtual ~Set() { }
298  virtual void PrintNodeName( ostream& os );
300  virtual void PrintNode( ostream& os ) = 0;
302  virtual BooleanSet* GetBooleanSetPointer();
303  virtual Interval* GetIntervalPointer();
304  };
305 
307  class Interval : public Set {
308  public:
310  double EndpointValues[2];
312  int EndpointClosures[2];
315 
320  int Match( double cellNorm[2] );
321 
322  virtual ~Interval() { }
323  virtual void PrintNode( ostream& os );
324  virtual Interval* GetIntervalPointer();
325  };
326 
328  class BooleanSet : public Set {
329  public:
331  int Operator;
333  std::vector<int> Inputs;
334 
336  BooleanSet( int sId, int op, int* inBegin, int* inEnd ) : Inputs( inBegin, inEnd ) {
337  this->Id = sId;
338  this->Operator = op;
339  }
340  virtual ~BooleanSet() { }
341  virtual void PrintNode( ostream& os );
342  virtual BooleanSet* GetBooleanSetPointer();
343  };
344  //ETX
345 
346 protected:
347 
350 
351  //BTX
353 
364  enum Ruling {
365  INCONCLUSIVE=-1,
366  INCLUDE=-2,
367  EXCLUDE=-3
368  };
369  //ETX
371 
374 
379 
385 
388 
389  //BTX
391  typedef std::vector<Interval*> IntervalList;
393  typedef std::map<NormKey,IntervalList> RuleMap;
394 
395  typedef std::vector<int> TruthTreeValues;
396  typedef std::vector<TruthTreeValues> TruthTree;
397 
401 
405  std::vector<Set*> Sets;
406 
413 
415 
418  int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
419  vtkCellData* inCellData, vtkIdType cellId, vtkGenericCell* cell, std::vector<vtkUnstructuredGrid*>& outv );
421 
423  int AddIntervalSet( NormKey& nk, double xmin, double xmax, int omin, int omax );
424 
425  //ETX
426 
428  void PrintGraph( ostream& os );
429 
430  vtkMultiThreshold( const vtkMultiThreshold& ); // Not implemented.
431  void operator = ( const vtkMultiThreshold& ); // Not implemented.
432 };
433 
434 inline int vtkMultiThreshold::AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars )
435 {
436  return this->AddIntervalSet( vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
437 }
438 
439 inline int vtkMultiThreshold::AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars )
440 {
441  return this->AddIntervalSet( xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars );
442 }
443 
445  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars )
446 {
447  return this->AddIntervalSet( xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
448 }
449 
451  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars )
452 {
453  int band = this->AddIntervalSet( xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
454  if ( band < 0 )
455  {
456  return -1;
457  }
458  return this->AddBooleanSet( NAND, 1, &band );
459 }
460 
462 {
463  return 0;
464 }
465 
467 {
468  return 0;
469 }
470 
472 {
473  return this;
474 }
475 
477 {
478  return this;
479 }
480 
481 #endif // vtkMultiThreshold_h
vtkMultiThreshold::NormKey::Component
int Component
Definition: vtkMultiThreshold.h:244
double
double
Definition: vtkVectorOperators.h:166
vtkMultiThreshold::vtkMultiThreshold
vtkMultiThreshold()
vtkMultiThreshold::Sets
std::vector< Set * > Sets
Definition: vtkMultiThreshold.h:405
vtkMultiThreshold::AddBooleanSet
int AddBooleanSet(int operation, int numInputs, int *inputs)
vtkMultiThreshold::DependentSets
TruthTree DependentSets
Definition: vtkMultiThreshold.h:412
vtkX3D::component
@ component
Definition: vtkX3D.h:175
vtkMultiThreshold::FillInputPortInformation
virtual int FillInputPortInformation(int port, vtkInformation *info)
vtkMath.h
vtkMultiThreshold::Interval
A subset of a mesh represented by a range of acceptable attribute values.
Definition: vtkMultiThreshold.h:307
vtkMultiThreshold::AddIntervalSet
int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, int attribType, int component, int allScalars)
vtkMultiThreshold::WOR
@ 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:275
vtkMultiThreshold::Set::PrintNodeName
virtual void PrintNodeName(ostream &os)
Print a graphviz node label statement (with fancy node name and shape).
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:41
vtkMultiThreshold::TruthTree
std::vector< TruthTreeValues > TruthTree
Definition: vtkMultiThreshold.h:396
vtkMultiThreshold::NormKey::NormFunction
TupleNorm NormFunction
Definition: vtkMultiThreshold.h:247
vtkMultiThreshold::NAND
@ NAND
Only include elements that don't belong to any input set.
Definition: vtkMultiThreshold.h:147
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkMultiThreshold::Ruling
Ruling
Definition: vtkMultiThreshold.h:364
vtkMultiThreshold::AddBandpassIntervalSet
int AddBandpassIntervalSet(double xmin, double xmax, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:444
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:336
vtkMultiThreshold::vtkMultiThreshold
vtkMultiThreshold(const vtkMultiThreshold &)
vtkMultiThreshold::AddHighpassIntervalSet
int AddHighpassIntervalSet(double xmin, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:439
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
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:314
vtkMultiThreshold::New
static vtkMultiThreshold * New()
vtkMath::Inf
static double Inf()
vtkMultiThreshold::AddLowpassIntervalSet
int AddLowpassIntervalSet(double xmax, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:434
vtkMath::NegInf
static double NegInf()
vtkMultiThreshold::BooleanSet::Operator
int Operator
The boolean operation that will be performed on the inputs to obtain the output.
Definition: vtkMultiThreshold.h:331
vtkMultiThreshold::AddIntervalSet
int AddIntervalSet(NormKey &nk, double xmin, double xmax, int omin, int omax)
vtkX3D::port
@ port
Definition: vtkX3D.h:447
vtkMultiThreshold::IntervalList
std::vector< Interval * > IntervalList
A list of pointers to IntervalSets.
Definition: vtkMultiThreshold.h:391
vtkMultiThreshold::NormKey::Name
std::string Name
Definition: vtkMultiThreshold.h:243
vtkMultiThreshold::~vtkMultiThreshold
virtual ~vtkMultiThreshold()
vtkMultiThreshold::AddIntervalSet
int AddIntervalSet(double xmin, double xmax, int omin, int omax, int assoc, const char *arrayName, int component, int allScalars)
vtkFiltersGeneralModule.h
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:62
vtkMultiThreshold::BooleanSet::GetBooleanSetPointer
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
Definition: vtkMultiThreshold.h:476
vtkMultiThreshold::Interval::GetIntervalPointer
virtual Interval * GetIntervalPointer()
Definition: vtkMultiThreshold.h:471
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:393
vtkMultiThreshold::Interval::~Interval
virtual ~Interval()
Definition: vtkMultiThreshold.h:322
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
Definition: vtkMultiThreshold.h:387
vtkMultiThreshold::Set::GetBooleanSetPointer
virtual BooleanSet * GetBooleanSetPointer()
Avoid dynamic_casts. Subclasses must override.
Definition: vtkMultiThreshold.h:466
vtkMultiThreshold::NormKey::Association
int Association
Definition: vtkMultiThreshold.h:241
vtkMultiThreshold::IntervalRules
RuleMap IntervalRules
Definition: vtkMultiThreshold.h:400
vtkMultiThreshold::BooleanSet
A subset of a mesh represented as a boolean set operation.
Definition: vtkMultiThreshold.h:328
VTKFILTERSGENERAL_EXPORT
#define VTKFILTERSGENERAL_EXPORT
Definition: vtkFiltersGeneralModule.h:15
vtkMultiThreshold::OR
@ OR
Include an element if it belongs to any input set.
Definition: vtkMultiThreshold.h:144
vtkMultiBlockDataSetAlgorithm.h
vtkMultiThreshold::Interval::PrintNode
virtual void PrintNode(ostream &os)
Print a graphviz node name for use in an edge statement.
vtkMultiThreshold::BooleanSet::~BooleanSet
virtual ~BooleanSet()
Definition: vtkMultiThreshold.h:340
vtkMultiThreshold::NormKey::ComputeNorm
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...
vtkMultiThreshold::AND
@ 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:289
vtkMultiThreshold::RequestData
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
vtkMultiThreshold::NormKey::InputArrayIndex
int InputArrayIndex
Definition: vtkMultiThreshold.h:246
vtkMultiThreshold::Set::~Set
virtual ~Set()
Virtual destructor since we have virtual members.
Definition: vtkMultiThreshold.h:296
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:292
vtkMultiThreshold::CLOSED
@ 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
@ info
Definition: vtkX3D.h:376
vtkMultiThreshold::Set::GetIntervalPointer
virtual Interval * GetIntervalPointer()
Definition: vtkMultiThreshold.h:461
vtkMultiThreshold::XOR
@ 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
vtkMultiThreshold::BooleanSet::PrintNode
virtual void PrintNode(ostream &os)
Print a graphviz node name for use in an edge statement.
vtkPointSet
abstract class for specifying dataset behavior
Definition: vtkPointSet.h:45
vtkMultiThreshold::PrintGraph
void PrintGraph(ostream &os)
vtkMultiThreshold::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkMultiThreshold::Reset
void Reset()
vtkMultiThreshold::NormKey::Type
int Type
Definition: vtkMultiThreshold.h:242
vtkGenericCell
provides thread-safe access to cells
Definition: vtkGenericCell.h:42
vtkMultiThreshold::BooleanSet::Inputs
std::vector< int > Inputs
A list of input sets. These may be IntervalSets or BooleanSets.
Definition: vtkMultiThreshold.h:333
vtkMultiThreshold::TruthTreeValues
std::vector< int > TruthTreeValues
Definition: vtkMultiThreshold.h:395
vtkMultiThreshold::Set
A base class for representing threshold sets.
Definition: vtkMultiThreshold.h:286
vtkUnstructuredGrid
dataset represents arbitrary combinations of all possible cell types
Definition: vtkUnstructuredGrid.h:82
vtkMultiThreshold::AddNotchIntervalSet
int AddNotchIntervalSet(double xlo, double xhi, int assoc, const char *arrayName, int component, int allScalars)
Definition: vtkMultiThreshold.h:450
vtkMultiThreshold::Set::PrintNode
virtual void PrintNode(ostream &os)=0
Print a graphviz node name for use in an edge statement.
vtkMultiThreshold::Interval::Match
int Match(double cellNorm[2])
Does the specified range fall inside the interval? For cell-centered attributes, only cellNorm[0] is ...
vtkMultiThreshold::NormKey::AllScalars
int AllScalars
Definition: vtkMultiThreshold.h:245
vtkgl::string
GLsizei const GLchar ** string
Definition: vtkgl.h:12011
vtkMultiThreshold::OutputSet
int OutputSet(int setId)
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:239
vtkMultiThreshold::UpdateDependents
void UpdateDependents(int id, std::set< int > &unresolvedOutputs, TruthTreeValues &setStates, vtkCellData *inCellData, vtkIdType cellId, vtkGenericCell *cell, std::vector< vtkUnstructuredGrid * > &outv)
vtkMultiThreshold::NextArrayIndex
int NextArrayIndex
Definition: vtkMultiThreshold.h:384
vtkMultiThreshold::Set::Id
int Id
Definition: vtkMultiThreshold.h:288
vtkMultiBlockDataSetAlgorithm
Superclass for algorithms that produce only vtkMultiBlockDataSet as output.
Definition: vtkMultiBlockDataSetAlgorithm.h:32