VTK
dox/Filters/Core/vtkRearrangeFields.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkRearrangeFields.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 =========================================================================*/
00063 #ifndef __vtkRearrangeFields_h
00064 #define __vtkRearrangeFields_h
00065 
00066 #include "vtkFiltersCoreModule.h" // For export macro
00067 #include "vtkDataSetAlgorithm.h"
00068 
00069 #include "vtkDataSetAttributes.h" // Needed for NUM_ATTRIBUTES
00070 
00071 class vtkFieldData;
00072 
00073 class VTKFILTERSCORE_EXPORT vtkRearrangeFields : public vtkDataSetAlgorithm
00074 {
00075 public:
00076   vtkTypeMacro(vtkRearrangeFields,vtkDataSetAlgorithm);
00077   void PrintSelf(ostream& os, vtkIndent indent);
00078 
00080   static vtkRearrangeFields *New();
00081 
00082 //BTX
00083   enum OperationType
00084   {
00085     COPY=0,
00086     MOVE=1
00087   };
00088   enum FieldLocation
00089   {
00090     DATA_OBJECT=0,
00091     POINT_DATA=1,
00092     CELL_DATA=2
00093   };
00094 //ETX
00095 
00097 
00100   int AddOperation(int operationType, int attributeType, int fromFieldLoc,
00101                    int toFieldLoc);
00103 
00104 
00107   int AddOperation(int operationType, const char* name, int fromFieldLoc,
00108                    int toFieldLoc);
00110 
00111 
00114   int AddOperation(const char* operationType, const char* attributeType,
00115                    const char* fromFieldLoc,  const char* toFieldLoc);
00117 
00119   int RemoveOperation(int operationId);
00121 
00123   int RemoveOperation(int operationType, int attributeType, int fromFieldLoc,
00124                       int toFieldLoc);
00126 
00127 
00129   int RemoveOperation(int operationType, const char* name, int fromFieldLoc,
00130                       int toFieldLoc);
00132 
00133 
00135   int RemoveOperation(const char* operationType, const char* attributeType,
00136                       const char* fromFieldLoc,  const char* toFieldLoc);
00138 
00140 
00141   void RemoveAllOperations()
00142     {
00143     this->Modified();
00144     this->LastId = 0;
00145     this->DeleteAllOperations();
00146     }
00148 
00149 //BTX
00150   enum FieldType
00151   {
00152     NAME,
00153     ATTRIBUTE
00154   };
00155 
00156   struct Operation
00157   {
00158     int OperationType; // COPY or MOVE
00159     int FieldType;     // NAME or ATTRIBUTE
00160     char* FieldName;
00161     int AttributeType;
00162     int FromFieldLoc; // fd, pd or do
00163     int ToFieldLoc;   // fd, pd or do
00164     int Id;            // assigned during creation
00165     Operation* Next;   // linked list
00166     Operation() { FieldName = 0; }
00167     ~Operation() { delete[] FieldName; }
00168   };
00169 //ETX
00170 
00171 protected:
00172 
00173   vtkRearrangeFields();
00174   virtual ~vtkRearrangeFields();
00175 
00176   int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
00177 
00178 
00179   // Operations are stored as a linked list.
00180   Operation* Head;
00181   Operation* Tail;
00182   // This is incremented whenever a new operation is created.
00183   // It is not decremented when an operation is deleted.
00184   int LastId;
00185 
00186   // Methods to browse/modify the linked list.
00187   Operation* GetNextOperation(Operation* op)
00188     { return op->Next; }
00189   Operation* GetFirst()
00190     { return this->Head; }
00191   void AddOperation(Operation* op);
00192   void DeleteOperation(Operation* op, Operation* before);
00193   Operation* FindOperation(int id, Operation*& before);
00194   Operation* FindOperation(const char* name, Operation*& before);
00195   Operation* FindOperation(int operationType, const char* name,
00196                            int fromFieldLoc, int toFieldLoc,
00197                            Operation*& before);
00198   Operation* FindOperation(int operationType, int attributeType,
00199                            int fromFieldLoc, int toFieldLoc,
00200                            Operation*& before);
00201   // Used when finding/deleting an operation given a signature.
00202   int CompareOperationsByType(const Operation* op1, const Operation* op2);
00203   int CompareOperationsByName(const Operation* op1, const Operation* op2);
00204 
00205   void DeleteAllOperations();
00206   void ApplyOperation(Operation* op, vtkDataSet* input, vtkDataSet* output);
00207   // Given location (DATA_OBJECT, CELL_DATA, POINT_DATA) return the
00208   // pointer to the corresponding field data.
00209   vtkFieldData* GetFieldDataFromLocation(vtkDataSet* ds, int fieldLoc);
00210 
00211   // Used by AddOperation() and RemoveOperation() designed to be used
00212   // from other language bindings.
00213   static char OperationTypeNames[2][5];
00214   static char FieldLocationNames[3][12];
00215   static char AttributeNames[vtkDataSetAttributes::NUM_ATTRIBUTES][10];
00216 
00217   void PrintAllOperations(ostream& os, vtkIndent indent);
00218   void PrintOperation(Operation* op, ostream& os, vtkIndent indent);
00219 private:
00220   vtkRearrangeFields(const vtkRearrangeFields&);  // Not implemented.
00221   void operator=(const vtkRearrangeFields&);  // Not implemented.
00222 };
00223 
00224 #endif
00225 
00226