Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Graphics/vtkRearrangeFields.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkRearrangeFields.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00078 #ifndef __vtkRearrangeFields_h
00079 #define __vtkRearrangeFields_h
00080 
00081 #include "vtkDataSetToDataSetFilter.h"
00082 
00083 #include "vtkDataSetAttributes.h" // Needed for NUM_ATTRIBUTES
00084 
00085 class vtkFieldData;
00086 
00087 class VTK_GRAPHICS_EXPORT vtkRearrangeFields : public vtkDataSetToDataSetFilter
00088 {
00089 public:
00090   vtkTypeRevisionMacro(vtkRearrangeFields,vtkDataSetToDataSetFilter);
00091   void PrintSelf(ostream& os, vtkIndent indent);
00092 
00094   static vtkRearrangeFields *New();
00095 
00096 //BTX
00097   enum OperationType
00098   {
00099     COPY=0,
00100     MOVE=1
00101   };
00102   enum FieldLocation
00103   {
00104     DATA_OBJECT=0,
00105     POINT_DATA=1,
00106     CELL_DATA=2
00107   };
00108 //ETX
00109 
00111 
00114   int AddOperation(int operationType, int attributeType, int fromFieldLoc,
00115                    int toFieldLoc);
00116   // Description:
00117   // Add an operation which copies a field (data array) from one field 
00118   // data to another. Returns an operation id which can later
00119   // be used to remove the operation.
00120   int AddOperation(int operationType, const char* name, int fromFieldLoc,
00121                    int toFieldLoc);
00122   // Description:
00123   // Helper method used by other language bindings. Allows the caller to
00124   // specify arguments as strings instead of enums.Returns an operation id 
00125   // which can later be used to remove the operation.
00126   int AddOperation(const char* operationType, const char* attributeType,
00127                    const char* fromFieldLoc,  const char* toFieldLoc);
00129 
00131 
00132   int RemoveOperation(int operationId);
00133   // Description:
00134   // Remove an operation with the given signature. See AddOperation
00135   // for details.
00136   int RemoveOperation(int operationType, int attributeType, int fromFieldLoc,
00137                       int toFieldLoc);
00138   // Description:
00139   // Remove an operation with the given signature. See AddOperation
00140   // for details.
00141   int RemoveOperation(int operationType, const char* name, int fromFieldLoc,
00142                       int toFieldLoc);
00143   // Description:
00144   // Remove an operation with the given signature. See AddOperation
00145   // for details.
00146   int RemoveOperation(const char* operationType, const char* attributeType,
00147                       const char* fromFieldLoc,  const char* toFieldLoc);
00149 
00151 
00152   void RemoveAllOperations() 
00153     { 
00154     this->Modified();
00155     this->LastId = 0; 
00156     this->DeleteAllOperations(); 
00157     }
00159   
00160 //BTX
00161   enum FieldType
00162   {
00163     NAME,
00164     ATTRIBUTE
00165   };
00166 
00167   struct Operation
00168   {
00169     int OperationType; // COPY or MOVE
00170     int FieldType;     // NAME or ATTRIBUTE
00171     char* FieldName;   
00172     int AttributeType;
00173     int FromFieldLoc; // fd, pd or do
00174     int ToFieldLoc;   // fd, pd or do
00175     int Id;            // assigned during creation
00176     Operation* Next;   // linked list
00177     Operation() { FieldName = 0; }
00178     ~Operation() { delete[] FieldName; }
00179   };
00180 //ETX
00181 
00182 protected:
00183 
00184   vtkRearrangeFields();
00185   virtual ~vtkRearrangeFields();
00186 
00187   void Execute();
00188 
00189 
00190   // Operations are stored as a linked list.
00191   Operation* Head;
00192   Operation* Tail;
00193   // This is incremented whenever a new operation is created.
00194   // It is not decremented when an operation is deleted.
00195   int LastId;
00196 
00197   // Methods to browse/modify the linked list.
00198   Operation* GetNextOperation(Operation* op)
00199     { return op->Next; }
00200   Operation* GetFirst()
00201     { return this->Head; }
00202   void AddOperation(Operation* op);
00203   void DeleteOperation(Operation* op, Operation* before);
00204   Operation* FindOperation(int id, Operation*& before);
00205   Operation* FindOperation(const char* name, Operation*& before);
00206   Operation* FindOperation(int operationType, const char* name, 
00207                            int fromFieldLoc, int toFieldLoc,
00208                            Operation*& before);
00209   Operation* FindOperation(int operationType, int attributeType, 
00210                            int fromFieldLoc, int toFieldLoc,
00211                            Operation*& before);
00212   // Used when finding/deleting an operation given a signature.
00213   int CompareOperationsByType(const Operation* op1, const Operation* op2);
00214   int CompareOperationsByName(const Operation* op1, const Operation* op2);
00215 
00216   void DeleteAllOperations();
00217   void ApplyOperation(Operation* op, vtkDataSet* input, vtkDataSet* output);
00218   // Given location (DATA_OBJECT, CELL_DATA, POINT_DATA) return the
00219   // pointer to the corresponding field data.
00220   vtkFieldData* GetFieldDataFromLocation(vtkDataSet* ds, int fieldLoc);
00221 
00222   // Used by AddOperation() and RemoveOperation() designed to be used 
00223   // from other language bindings.
00224   static char OperationTypeNames[2][5];
00225   static char FieldLocationNames[3][12];
00226   static char AttributeNames[vtkDataSetAttributes::NUM_ATTRIBUTES][10];
00227 
00228   void PrintAllOperations(ostream& os, vtkIndent indent);
00229   void PrintOperation(Operation* op, ostream& os, vtkIndent indent);
00230 private:
00231   vtkRearrangeFields(const vtkRearrangeFields&);  // Not implemented.
00232   void operator=(const vtkRearrangeFields&);  // Not implemented.
00233 };
00234 
00235 #endif
00236 
00237