VTK
dox/Filters/General/vtkMultiThreshold.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkMultiThreshold.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 /*----------------------------------------------------------------------------
00016  Copyright (c) Sandia Corporation
00017  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
00018 ----------------------------------------------------------------------------*/
00019 
00100 #ifndef __vtkMultiThreshold_h
00101 #define __vtkMultiThreshold_h
00102 
00103 #include "vtkFiltersGeneralModule.h" // For export macro
00104 #include "vtkMultiBlockDataSetAlgorithm.h"
00105 #include "vtkMath.h" // for Inf() and NegInf()
00106 
00107 #include <vector> // for lists of threshold rules
00108 #include <map> // for IntervalRules map
00109 #include <set> // for UpdateDependents()
00110 #include <string> // for holding array names in NormKey
00111 
00112 class vtkCell;
00113 class vtkCellData;
00114 class vtkDataArray;
00115 class vtkGenericCell;
00116 class vtkPointSet;
00117 class vtkUnstructuredGrid;
00118 
00119 class VTKFILTERSGENERAL_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm
00120 {
00121 public:
00122   vtkTypeMacro(vtkMultiThreshold,vtkMultiBlockDataSetAlgorithm);
00123   static vtkMultiThreshold* New();
00124   virtual void PrintSelf( ostream& os, vtkIndent indent );
00125 
00126   //BTX
00128   enum Closure {
00129     OPEN=0,   
00130     CLOSED=1  
00131   };
00133   enum Norm {
00134     LINFINITY_NORM=-3, 
00135     L2_NORM=-2,        
00136     L1_NORM=-1         
00137   };
00139   enum SetOperation {
00140     AND, 
00141     OR, 
00142     XOR, 
00143     WOR, 
00144     NAND 
00145   };
00146   //ETX
00147 
00149 
00192   int AddIntervalSet( double xmin, double xmax, int omin, int omax,
00193     int assoc, const char* arrayName, int component, int allScalars );
00194   int AddIntervalSet( double xmin, double xmax, int omin, int omax,
00195     int assoc, int attribType, int component, int allScalars );
00197 
00199 
00205   int AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars );
00206   int AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars );
00207   int AddBandpassIntervalSet( double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars );
00208   int AddNotchIntervalSet( double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars );
00210 
00213   int AddBooleanSet( int operation, int numInputs, int* inputs );
00214 
00217   int OutputSet( int setId );
00218 
00220   void Reset();
00221 
00222   //BTX
00224   typedef double (*TupleNorm)( vtkDataArray* arr, vtkIdType tuple, int component );
00225 
00226   // NormKey must be able to use TupleNorm typedef:
00227   class NormKey;
00228 
00229   // Interval must be able to use NormKey typedef:
00230   class Interval;
00231 
00232   // Set needs to refer to boolean set pointers
00233   class BooleanSet;
00234 
00236   class NormKey {
00237   public:
00238     int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or vtkDataObject::FIELD_ASSOCIATION_CELLS
00239     int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS, NORMALS, TCOORDS, GLOBALIDS}
00240     std::string Name; // Either empty or (when ArrayType == -1) an input array name
00241     int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number
00242     int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points be in the interval?
00243     int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess()
00244     TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct component) of a tuple.
00245 
00247     void ComputeNorm( vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2] ) const;
00248 
00250     bool operator < ( const NormKey& other ) const {
00251       if ( this->Association < other.Association )
00252         return true;
00253       else if ( this->Association > other.Association )
00254         return false;
00255 
00256       if ( this->Component < other.Component )
00257         return true;
00258       else if ( this->Component > other.Component )
00259         return false;
00260 
00261       if ( (! this->AllScalars) && other.AllScalars )
00262         return true;
00263       else if ( this->AllScalars && (! other.AllScalars) )
00264         return false;
00265 
00266       if ( this->Type == -1 )
00267         {
00268         if ( other.Type == -1 )
00269           return this->Name < other.Name;
00270         return true;
00271         }
00272       else
00273         {
00274         return this->Type < other.Type;
00275         }
00276     }
00277   };
00278 
00283   class Set {
00284   public:
00285     int Id; 
00286     int OutputId; 
00287 
00289     Set() {
00290       this->OutputId = -1;
00291     }
00293     virtual ~Set() { }
00295     virtual void PrintNodeName( ostream& os );
00297     virtual void PrintNode( ostream& os ) = 0;
00299     virtual BooleanSet* GetBooleanSetPointer();
00300     virtual Interval* GetIntervalPointer();
00301   };
00302 
00304   class Interval : public Set {
00305   public:
00307     double EndpointValues[2];
00309     int EndpointClosures[2];
00311     NormKey Norm;
00312 
00317     int Match( double cellNorm[2] );
00318 
00319     virtual ~Interval() { }
00320     virtual void PrintNode( ostream& os );
00321     virtual Interval* GetIntervalPointer();
00322   };
00323 
00325   class BooleanSet : public Set {
00326   public:
00328     int Operator;
00330     std::vector<int> Inputs;
00331 
00333     BooleanSet( int sId, int op, int* inBegin, int* inEnd ) : Inputs( inBegin, inEnd ) {
00334       this->Id = sId;
00335       this->Operator = op;
00336     }
00337     virtual ~BooleanSet() { }
00338     virtual void PrintNode( ostream& os );
00339     virtual BooleanSet* GetBooleanSetPointer();
00340   };
00341   //ETX
00342 
00343 protected:
00344 
00345   vtkMultiThreshold();
00346   virtual ~vtkMultiThreshold();
00347 
00348   //BTX
00350 
00361   enum Ruling {
00362     INCONCLUSIVE=-1,
00363     INCLUDE=-2,
00364     EXCLUDE=-3
00365   };
00366   //ETX
00368 
00370   virtual int RequestData( vtkInformation*, vtkInformationVector**, vtkInformationVector* );
00371 
00375   virtual int FillInputPortInformation( int port, vtkInformation* info );
00376 
00381   int NextArrayIndex;
00382 
00384   int NumberOfOutputs;
00385 
00386   //BTX
00388   typedef std::vector<Interval*> IntervalList;
00390   typedef std::map<NormKey,IntervalList> RuleMap;
00391 
00392   typedef std::vector<int> TruthTreeValues;
00393   typedef std::vector<TruthTreeValues> TruthTree;
00394 
00397   RuleMap IntervalRules;
00398 
00402   std::vector<Set*> Sets;
00403 
00409   TruthTree DependentSets;
00410 
00412 
00414   void UpdateDependents(
00415     int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates,
00416     vtkCellData* inCellData, vtkIdType cellId, vtkGenericCell* cell, std::vector<vtkUnstructuredGrid*>& outv );
00418 
00420   int AddIntervalSet( NormKey& nk, double xmin, double xmax, int omin, int omax );
00421 
00422   //ETX
00423 
00425   void PrintGraph( ostream& os );
00426 
00427   vtkMultiThreshold( const vtkMultiThreshold& ); // Not implemented.
00428   void operator = ( const vtkMultiThreshold& ); // Not implemented.
00429 };
00430 
00431 inline int vtkMultiThreshold::AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars )
00432 {
00433   return this->AddIntervalSet( vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
00434 }
00435 
00436 inline int vtkMultiThreshold::AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars )
00437 {
00438   return this->AddIntervalSet( xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars );
00439 }
00440 
00441 inline int vtkMultiThreshold::AddBandpassIntervalSet(
00442   double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars )
00443 {
00444   return this->AddIntervalSet( xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
00445 }
00446 
00447 inline int vtkMultiThreshold::AddNotchIntervalSet(
00448   double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars )
00449 {
00450   int band = this->AddIntervalSet( xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars );
00451   if ( band < 0 )
00452     {
00453     return -1;
00454     }
00455   return this->AddBooleanSet( NAND, 1, &band );
00456 }
00457 
00458 inline vtkMultiThreshold::Interval* vtkMultiThreshold::Set::GetIntervalPointer()
00459 {
00460   return 0;
00461 }
00462 
00463 inline vtkMultiThreshold::BooleanSet* vtkMultiThreshold::Set::GetBooleanSetPointer()
00464 {
00465   return 0;
00466 }
00467 
00468 inline vtkMultiThreshold::Interval* vtkMultiThreshold::Interval::GetIntervalPointer()
00469 {
00470   return this;
00471 }
00472 
00473 inline vtkMultiThreshold::BooleanSet* vtkMultiThreshold::BooleanSet::GetBooleanSetPointer()
00474 {
00475   return this;
00476 }
00477 
00478 #endif // __vtkMultiThreshold_h