Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class 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 =========================================================================*/
00067 #ifndef __vtkRearrangeFields_h
00068 #define __vtkRearrangeFields_h
00069 
00070 #include "vtkDataSetToDataSetFilter.h"
00071 
00072 #include "vtkDataSetAttributes.h" // Needed for NUM_ATTRIBUTES
00073 
00074 class vtkFieldData;
00075 
00076 class VTK_GRAPHICS_EXPORT vtkRearrangeFields : public vtkDataSetToDataSetFilter
00077 {
00078 public:
00079   vtkTypeRevisionMacro(vtkRearrangeFields,vtkDataSetToDataSetFilter);
00080   void PrintSelf(ostream& os, vtkIndent indent);
00081 
00083   static vtkRearrangeFields *New();
00084 
00085 //BTX
00086   enum OperationType
00087   {
00088     COPY=0,
00089     MOVE=1
00090   };
00091   enum FieldLocation
00092   {
00093     DATA_OBJECT=0,
00094     POINT_DATA=1,
00095     CELL_DATA=2
00096   };
00097 //ETX
00098 
00100 
00103   int AddOperation(int operationType, int attributeType, int fromFieldLoc,
00104                    int toFieldLoc);
00105   // Description:
00106   // Add an operation which copies a field (data array) from one field 
00107   // data to another. Returns an operation id which can later
00108   // be used to remove the operation.
00109   int AddOperation(int operationType, const char* name, int fromFieldLoc,
00110                    int toFieldLoc);
00111   // Description:
00112   // Helper method used by other language bindings. Allows the caller to
00113   // specify arguments as strings instead of enums.Returns an operation id 
00114   // which can later be used to remove the operation.
00115   int AddOperation(const char* operationType, const char* attributeType,
00116                    const char* fromFieldLoc,  const char* toFieldLoc);
00118 
00120 
00121   int RemoveOperation(int operationId);
00122   // Description:
00123   // Remove an operation with the given signature. See AddOperation
00124   // for details.
00125   int RemoveOperation(int operationType, int attributeType, int fromFieldLoc,
00126                       int toFieldLoc);
00127   // Description:
00128   // Remove an operation with the given signature. See AddOperation
00129   // for details.
00130   int RemoveOperation(int operationType, const char* name, int fromFieldLoc,
00131                       int toFieldLoc);
00132   // Description:
00133   // Remove an operation with the given signature. See AddOperation
00134   // for details.
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   void Execute();
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