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 
100 #ifndef __vtkMultiThreshold_h
101 #define __vtkMultiThreshold_h
102 
103 #include "vtkFiltersGeneralModule.h" // For export macro
105 #include "vtkMath.h" // for Inf() and NegInf()
106 
107 #include <vector> // for lists of threshold rules
108 #include <map> // for IntervalRules map
109 #include <set> // for UpdateDependents()
110 #include <string> // for holding array names in NormKey
111 
112 class vtkCell;
113 class vtkCellData;
114 class vtkDataArray;
115 class vtkGenericCell;
116 class vtkPointSet;
117 class vtkUnstructuredGrid;
118 
119 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
120 {
121 public:
123  static vtkMultiThreshold* New();
124  virtual void PrintSelf( ostream& os, vtkIndent indent );
125 
126  //BTX
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  //ETX
147 
149 
192  int AddIntervalSet( double xmin, double xmax, int omin, int omax,
193  int assoc, const char* arrayName, int component, int allScalars );
194  int AddIntervalSet( double xmin, double xmax, int omin, int omax,
195  int assoc, int attribType, int component, int allScalars );
197 
199 
205  int AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars );
206  int AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars );
207  int AddBandpassIntervalSet( double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars );
208  int AddNotchIntervalSet( double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars );
210 
213  int AddBooleanSet( int operation, int numInputs, int* inputs );
214 
217  int OutputSet( int setId );
218 
220  void Reset();
221 
222  //BTX
224  typedef double (*TupleNorm)( vtkDataArray* arr, vtkIdType tuple, int component );
225 
226  // NormKey must be able to use TupleNorm typedef:
227  class NormKey;
228 
229  // Interval must be able to use NormKey typedef:
230  class Interval;
231 
232  // Set needs to refer to boolean set pointers
233  class BooleanSet;
234 
236  class NormKey {
237  public:
238  int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or vtkDataObject::FIELD_ASSOCIATION_CELLS
239  int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS, NORMALS, TCOORDS, GLOBALIDS}
240  std::string Name; // Either empty or (when ArrayType == -1) an input array name
241  int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
242  int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points be in the interval?
243  int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
244  TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct component) of a tuple.
245 
247  void ComputeNorm( vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2] ) const;
248 
250  bool operator < ( const NormKey& other ) const {
251  if ( this->Association < other.Association )
252  return true;
253  else if ( this->Association > other.Association )
254  return false;
255 
256  if ( this->Component < other.Component )
257  return true;
258  else if ( this->Component > other.Component )
259  return false;
260 
261  if ( (! this->AllScalars) && other.AllScalars )
262  return true;
263  else if ( this->AllScalars && (! other.AllScalars) )
264  return false;
265 
266  if ( this->Type == -1 )
267  {
268  if ( other.Type == -1 )
269  return this->Name < other.Name;
270  return true;
271  }
272  else
273  {
274  return this->Type < other.Type;
275  }
276  }
277  };
278 
283  class Set {
284  public:
285  int Id;
286  int OutputId;
287 
289  Set() {
290  this->OutputId = -1;
291  }
293  virtual ~Set() { }
295  virtual void PrintNodeName( ostream& os );
297  virtual void PrintNode( ostream& os ) = 0;
299  virtual BooleanSet* GetBooleanSetPointer();
300  virtual Interval* GetIntervalPointer();
301  };
302 
304  class Interval : public Set {
305  public:
307  double EndpointValues[2];
309  int EndpointClosures[2];
312 
317  int Match( double cellNorm[2] );
318 
319  virtual ~Interval() { }
320  virtual void PrintNode( ostream& os );
321  virtual Interval* GetIntervalPointer();
322  };
323 
325  class BooleanSet : public Set {
326  public:
328  int Operator;
330  std::vector<int> Inputs;
331 
333  BooleanSet( int sId, int op, int* inBegin, int* inEnd ) : Inputs( inBegin, inEnd ) {
334  this->Id = sId;
335  this->Operator = op;
336  }
337  virtual ~BooleanSet() { }
338  virtual void PrintNode( ostream& os );
339  virtual BooleanSet* GetBooleanSetPointer();
340  };
341  //ETX
342 
343 protected:
344 
346  virtual ~vtkMultiThreshold();
347 
348  //BTX
350 
361  enum Ruling {
362  INCONCLUSIVE=-1,
363  INCLUDE=-2,
364  EXCLUDE=-3
365  };
366  //ETX
368 
371 
375  virtual int FillInputPortInformation( int port, vtkInformation* info );
376 
382 
385 
386  //BTX
388  typedef std::vector<Interval*> IntervalList;
390  typedef std::map<NormKey,IntervalList> RuleMap;
391 
392  typedef std::vector<int> TruthTreeValues;
393  typedef std::vector<TruthTreeValues> TruthTree;
394 
398 
402  std::vector<Set*> Sets;
403 
410 
412 
414  void UpdateDependents(
415  int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
416  vtkCellData* inCellData, vtkIdType cellId, vtkGenericCell* cell, std::vector<vtkUnstructuredGrid*>& outv );
418 
420  int AddIntervalSet( NormKey& nk, double xmin, double xmax, int omin, int omax );
421 
422  //ETX
423 
425  void PrintGraph( ostream& os );
426 
427  vtkMultiThreshold( const vtkMultiThreshold& ); // Not implemented.
428  void operator = ( const vtkMultiThreshold& ); // Not implemented.
429 };
430 
431 inline int vtkMultiThreshold::AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars )
432 {
433  return this->AddIntervalSet( vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
434 }
435 
436 inline int vtkMultiThreshold::AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars )
437 {
438  return this->AddIntervalSet( xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars );
439 }
440 
442  double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars )
443 {
444  return this->AddIntervalSet( xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
445 }
446 
448  double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars )
449 {
450  int band = this->AddIntervalSet( xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
451  if ( band < 0 )
452  {
453  return -1;
454  }
455  return this->AddBooleanSet( NAND, 1, &band );
456 }
457 
459 {
460  return 0;
461 }
462 
464 {
465  return 0;
466 }
467 
469 {
470  return this;
471 }
472 
474 {
475  return this;
476 }
477 
478 #endif // __vtkMultiThreshold_h