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