VTK
|
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 "vtkMultiBlockDataSetAlgorithm.h" 00104 #include "vtkMath.h" // for Inf() and NegInf() 00105 00106 #include <vector> // for lists of threshold rules 00107 #include <map> // for IntervalRules map 00108 #include <set> // for UpdateDependents() 00109 #include <string> // for holding array names in NormKey 00110 00111 class vtkCell; 00112 class vtkCellData; 00113 class vtkDataArray; 00114 class vtkGenericCell; 00115 class vtkPointSet; 00116 class vtkUnstructuredGrid; 00117 00118 class VTK_GRAPHICS_EXPORT vtkMultiThreshold : public vtkMultiBlockDataSetAlgorithm 00119 { 00120 public: 00121 vtkTypeMacro(vtkMultiThreshold,vtkMultiBlockDataSetAlgorithm); 00122 static vtkMultiThreshold* New(); 00123 virtual void PrintSelf( ostream& os, vtkIndent indent ); 00124 00125 //BTX 00127 enum Closure { 00128 OPEN=0, 00129 CLOSED=1 00130 }; 00132 enum Norm { 00133 LINFINITY_NORM=-3, 00134 L2_NORM=-2, 00135 L1_NORM=-1 00136 }; 00138 enum SetOperation { 00139 AND, 00140 OR, 00141 XOR, 00142 WOR, 00143 NAND 00144 }; 00145 //ETX 00146 00148 00191 int AddIntervalSet( double xmin, double xmax, int omin, int omax, 00192 int assoc, const char* arrayName, int component, int allScalars ); 00193 int AddIntervalSet( double xmin, double xmax, int omin, int omax, 00194 int assoc, int attribType, int component, int allScalars ); 00196 00198 00204 int AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars ); 00205 int AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars ); 00206 int AddBandpassIntervalSet( double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars ); 00207 int AddNotchIntervalSet( double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars ); 00209 00212 int AddBooleanSet( int operation, int numInputs, int* inputs ); 00213 00216 int OutputSet( int setId ); 00217 00219 void Reset(); 00220 00221 //BTX 00223 typedef double (*TupleNorm)( vtkDataArray* arr, vtkIdType tuple, int component ); 00224 00225 // NormKey must be able to use TupleNorm typedef: 00226 class NormKey; 00227 00228 // Interval must be able to use NormKey typedef: 00229 class Interval; 00230 00231 // Set needs to refer to boolean set pointers 00232 class BooleanSet; 00233 00235 class NormKey { 00236 public: 00237 int Association; // vtkDataObject::FIELD_ASSOCIATION_POINTS or vtkDataObject::FIELD_ASSOCIATION_CELLS 00238 int Type; // -1 => use Name, otherwise: vtkDataSetAttributes::{SCALARS, VECTORS, TENSORS, NORMALS, TCOORDS, GLOBALIDS} 00239 std::string Name; // Either empty or (when ArrayType == -1) an input array name 00240 int Component; // LINFINITY_NORM, L1_NORM, L2_NORM or an integer component number 00241 int AllScalars; // For Association == vtkDataObject::FIELD_ASSOCIATION_POINTS, must all points be in the interval? 00242 int InputArrayIndex; // The number passed to vtkAlgorithm::SetInputArrayToProcess() 00243 TupleNorm NormFunction; // A function pointer to compute the norm (or fetcht the correct component) of a tuple. 00244 00246 void ComputeNorm( vtkIdType cellId, vtkCell* cell, vtkDataArray* array, double cellNorm[2] ) const; 00247 00249 bool operator < ( const NormKey& other ) const { 00250 if ( this->Association < other.Association ) 00251 return true; 00252 else if ( this->Association > other.Association ) 00253 return false; 00254 00255 if ( this->Component < other.Component ) 00256 return true; 00257 else if ( this->Component > other.Component ) 00258 return false; 00259 00260 if ( (! this->AllScalars) && other.AllScalars ) 00261 return true; 00262 else if ( this->AllScalars && (! other.AllScalars) ) 00263 return false; 00264 00265 if ( this->Type == -1 ) 00266 { 00267 if ( other.Type == -1 ) 00268 return this->Name < other.Name; 00269 return true; 00270 } 00271 else 00272 { 00273 return this->Type < other.Type; 00274 } 00275 } 00276 }; 00277 00282 class Set { 00283 public: 00284 int Id; 00285 int OutputId; 00286 00288 Set() { 00289 this->OutputId = -1; 00290 } 00292 virtual ~Set() { } 00294 virtual void PrintNodeName( ostream& os ); 00296 virtual void PrintNode( ostream& os ) = 0; 00298 virtual BooleanSet* GetBooleanSetPointer(); 00299 virtual Interval* GetIntervalPointer(); 00300 }; 00301 00303 class Interval : public Set { 00304 public: 00306 double EndpointValues[2]; 00308 int EndpointClosures[2]; 00310 NormKey Norm; 00311 00316 int Match( double cellNorm[2] ); 00317 00318 virtual ~Interval() { } 00319 virtual void PrintNode( ostream& os ); 00320 virtual Interval* GetIntervalPointer(); 00321 }; 00322 00324 class BooleanSet : public Set { 00325 public: 00327 int Operator; 00329 std::vector<int> Inputs; 00330 00332 BooleanSet( int sId, int op, int* inBegin, int* inEnd ) : Inputs( inBegin, inEnd ) { 00333 this->Id = sId; 00334 this->Operator = op; 00335 } 00336 virtual ~BooleanSet() { } 00337 virtual void PrintNode( ostream& os ); 00338 virtual BooleanSet* GetBooleanSetPointer(); 00339 }; 00340 //ETX 00341 00342 protected: 00343 00344 vtkMultiThreshold(); 00345 virtual ~vtkMultiThreshold(); 00346 00347 //BTX 00349 00360 enum Ruling { 00361 INCONCLUSIVE=-1, 00362 INCLUDE=-2, 00363 EXCLUDE=-3 00364 }; 00365 //ETX 00367 00369 virtual int RequestData( vtkInformation*, vtkInformationVector**, vtkInformationVector* ); 00370 00374 virtual int FillInputPortInformation( int port, vtkInformation* info ); 00375 00380 int NextArrayIndex; 00381 00383 int NumberOfOutputs; 00384 00385 //BTX 00387 typedef std::vector<Interval*> IntervalList; 00389 typedef std::map<NormKey,IntervalList> RuleMap; 00390 00391 typedef std::vector<int> TruthTreeValues; 00392 typedef std::vector<TruthTreeValues> TruthTree; 00393 00396 RuleMap IntervalRules; 00397 00401 std::vector<Set*> Sets; 00402 00408 TruthTree DependentSets; 00409 00411 00413 void UpdateDependents( 00414 int id, std::set<int>& unresolvedOutputs, TruthTreeValues& setStates, 00415 vtkCellData* inCellData, vtkIdType cellId, vtkGenericCell* cell, std::vector<vtkUnstructuredGrid*>& outv ); 00417 00419 int AddIntervalSet( NormKey& nk, double xmin, double xmax, int omin, int omax ); 00420 00421 //ETX 00422 00424 void PrintGraph( ostream& os ); 00425 00426 vtkMultiThreshold( const vtkMultiThreshold& ); // Not implemented. 00427 void operator = ( const vtkMultiThreshold& ); // Not implemented. 00428 }; 00429 00430 inline int vtkMultiThreshold::AddLowpassIntervalSet( double xmax, int assoc, const char* arrayName, int component, int allScalars ) 00431 { 00432 return this->AddIntervalSet( vtkMath::NegInf(), xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars ); 00433 } 00434 00435 inline int vtkMultiThreshold::AddHighpassIntervalSet( double xmin, int assoc, const char* arrayName, int component, int allScalars ) 00436 { 00437 return this->AddIntervalSet( xmin, vtkMath::Inf(), CLOSED, CLOSED, assoc, arrayName, component, allScalars ); 00438 } 00439 00440 inline int vtkMultiThreshold::AddBandpassIntervalSet( 00441 double xmin, double xmax, int assoc, const char* arrayName, int component, int allScalars ) 00442 { 00443 return this->AddIntervalSet( xmin, xmax, CLOSED, CLOSED, assoc, arrayName, component, allScalars ); 00444 } 00445 00446 inline int vtkMultiThreshold::AddNotchIntervalSet( 00447 double xlo, double xhi, int assoc, const char* arrayName, int component, int allScalars ) 00448 { 00449 int band = this->AddIntervalSet( xlo, xhi, CLOSED, CLOSED, assoc, arrayName, component, allScalars ); 00450 if ( band < 0 ) 00451 { 00452 return -1; 00453 } 00454 return this->AddBooleanSet( NAND, 1, &band ); 00455 } 00456 00457 inline vtkMultiThreshold::Interval* vtkMultiThreshold::Set::GetIntervalPointer() 00458 { 00459 return 0; 00460 } 00461 00462 inline vtkMultiThreshold::BooleanSet* vtkMultiThreshold::Set::GetBooleanSetPointer() 00463 { 00464 return 0; 00465 } 00466 00467 inline vtkMultiThreshold::Interval* vtkMultiThreshold::Interval::GetIntervalPointer() 00468 { 00469 return this; 00470 } 00471 00472 inline vtkMultiThreshold::BooleanSet* vtkMultiThreshold::BooleanSet::GetBooleanSetPointer() 00473 { 00474 return this; 00475 } 00476 00477 #endif // __vtkMultiThreshold_h