VTK
vtkRearrangeFields.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkRearrangeFields.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
63 #ifndef __vtkRearrangeFields_h
64 #define __vtkRearrangeFields_h
65 
66 #include "vtkDataSetAlgorithm.h"
67 
68 #include "vtkDataSetAttributes.h" // Needed for NUM_ATTRIBUTES
69 
70 class vtkFieldData;
71 
73 {
74 public:
76  void PrintSelf(ostream& os, vtkIndent indent);
77 
79  static vtkRearrangeFields *New();
80 
81 //BTX
83  {
84  COPY=0,
85  MOVE=1
86  };
88  {
89  DATA_OBJECT=0,
90  POINT_DATA=1,
91  CELL_DATA=2
92  };
93 //ETX
94 
96 
99  int AddOperation(int operationType, int attributeType, int fromFieldLoc,
100  int toFieldLoc);
101  // Description:
102  // Add an operation which copies a field (data array) from one field
103  // data to another. Returns an operation id which can later
104  // be used to remove the operation.
105  int AddOperation(int operationType, const char* name, int fromFieldLoc,
106  int toFieldLoc);
107  // Description:
108  // Helper method used by other language bindings. Allows the caller to
109  // specify arguments as strings instead of enums.Returns an operation id
110  // which can later be used to remove the operation.
111  int AddOperation(const char* operationType, const char* attributeType,
112  const char* fromFieldLoc, const char* toFieldLoc);
114 
116 
117  int RemoveOperation(int operationId);
118  // Description:
119  // Remove an operation with the given signature. See AddOperation
120  // for details.
121  int RemoveOperation(int operationType, int attributeType, int fromFieldLoc,
122  int toFieldLoc);
123  // Description:
124  // Remove an operation with the given signature. See AddOperation
125  // for details.
126  int RemoveOperation(int operationType, const char* name, int fromFieldLoc,
127  int toFieldLoc);
128  // Description:
129  // Remove an operation with the given signature. See AddOperation
130  // for details.
131  int RemoveOperation(const char* operationType, const char* attributeType,
132  const char* fromFieldLoc, const char* toFieldLoc);
134 
136 
138  {
139  this->Modified();
140  this->LastId = 0;
141  this->DeleteAllOperations();
142  }
144 
145 //BTX
147  {
149  ATTRIBUTE
150  };
151 
152  struct Operation
153  {
154  int OperationType; // COPY or MOVE
155  int FieldType; // NAME or ATTRIBUTE
156  char* FieldName;
158  int FromFieldLoc; // fd, pd or do
159  int ToFieldLoc; // fd, pd or do
160  int Id; // assigned during creation
161  Operation* Next; // linked list
162  Operation() { FieldName = 0; }
163  ~Operation() { delete[] FieldName; }
164  };
165 //ETX
166 
167 protected:
168 
170  virtual ~vtkRearrangeFields();
171 
173 
174 
175  // Operations are stored as a linked list.
178  // This is incremented whenever a new operation is created.
179  // It is not decremented when an operation is deleted.
180  int LastId;
181 
182  // Methods to browse/modify the linked list.
184  { return op->Next; }
186  { return this->Head; }
187  void AddOperation(Operation* op);
188  void DeleteOperation(Operation* op, Operation* before);
189  Operation* FindOperation(int id, Operation*& before);
190  Operation* FindOperation(const char* name, Operation*& before);
191  Operation* FindOperation(int operationType, const char* name,
192  int fromFieldLoc, int toFieldLoc,
193  Operation*& before);
194  Operation* FindOperation(int operationType, int attributeType,
195  int fromFieldLoc, int toFieldLoc,
196  Operation*& before);
197  // Used when finding/deleting an operation given a signature.
198  int CompareOperationsByType(const Operation* op1, const Operation* op2);
199  int CompareOperationsByName(const Operation* op1, const Operation* op2);
200 
201  void DeleteAllOperations();
202  void ApplyOperation(Operation* op, vtkDataSet* input, vtkDataSet* output);
203  // Given location (DATA_OBJECT, CELL_DATA, POINT_DATA) return the
204  // pointer to the corresponding field data.
205  vtkFieldData* GetFieldDataFromLocation(vtkDataSet* ds, int fieldLoc);
206 
207  // Used by AddOperation() and RemoveOperation() designed to be used
208  // from other language bindings.
209  static char OperationTypeNames[2][5];
210  static char FieldLocationNames[3][12];
211  static char AttributeNames[vtkDataSetAttributes::NUM_ATTRIBUTES][10];
212 
213  void PrintAllOperations(ostream& os, vtkIndent indent);
214  void PrintOperation(Operation* op, ostream& os, vtkIndent indent);
215 private:
216  vtkRearrangeFields(const vtkRearrangeFields&); // Not implemented.
217  void operator=(const vtkRearrangeFields&); // Not implemented.
218 };
219 
220 #endif
221 
222