Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkRearrangeFields.h

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