Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound 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 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00091 #ifndef __vtkRearrangeFields_h
00092 #define __vtkRearrangeFields_h
00093 
00094 #include "vtkDataSetToDataSetFilter.h"
00095 
00096 class vtkFieldData;
00097 
00098 class VTK_GRAPHICS_EXPORT vtkRearrangeFields : public vtkDataSetToDataSetFilter
00099 {
00100 public:
00101   vtkTypeMacro(vtkRearrangeFields,vtkDataSetToDataSetFilter);
00102   void PrintSelf(ostream& os, vtkIndent indent);
00103 
00105   static vtkRearrangeFields *New();
00106 
00107 //BTX
00108   enum OperationType
00109   {
00110     COPY=0,
00111     MOVE=1
00112   };
00113   enum FieldLocation
00114   {
00115     DATA_OBJECT=0,
00116     POINT_DATA=1,
00117     CELL_DATA=2
00118   };
00119 //ETX
00120 
00122 
00125   int AddOperation(int operationType, int attributeType, int fromFieldLoc,
00126                    int toFieldLoc);
00127   // Description:
00128   // Add an operation which copies a field (data array) from one field 
00129   // data to another. Returns an operation id which can later
00130   // be used to remove the operation.
00131   int AddOperation(int operationType, const char* name, int fromFieldLoc,
00132                    int toFieldLoc);
00133   // Description:
00134   // Helper method used by other language bindings. Allows the caller to
00135   // specify arguments as strings instead of enums.Returns an operation id 
00136   // which can later be used to remove the operation.
00137   int AddOperation(const char* operationType, const char* attributeType,
00138                    const char* fromFieldLoc,  const char* toFieldLoc);
00140 
00142 
00143   int RemoveOperation(int operationId);
00144   // Description:
00145   // Remove an operation with the given signature. See AddOperation
00146   // for details.
00147   int RemoveOperation(int operationType, int attributeType, int fromFieldLoc,
00148                       int toFieldLoc);
00149   // Description:
00150   // Remove an operation with the given signature. See AddOperation
00151   // for details.
00152   int RemoveOperation(int operationType, const char* name, int fromFieldLoc,
00153                       int toFieldLoc);
00154   // Description:
00155   // Remove an operation with the given signature. See AddOperation
00156   // for details.
00157   int RemoveOperation(const char* operationType, const char* attributeType,
00158                       const char* fromFieldLoc,  const char* toFieldLoc);
00160 
00162 
00163   void RemoveAllOperations() 
00164     { 
00165     this->Modified();
00166     this->LastId = 0; 
00167     this->DeleteAllOperations(); 
00168     }
00170   
00171 //BTX
00172   enum FieldType
00173   {
00174     NAME,
00175     ATTRIBUTE
00176   };
00177 
00178   struct Operation
00179   {
00180     int OperationType; // COPY or MOVE
00181     int FieldType;     // NAME or ATTRIBUTE
00182     char* FieldName;   
00183     int AttributeType;
00184     int FromFieldLoc; // fd, pd or do
00185     int ToFieldLoc;   // fd, pd or do
00186     int Id;            // assigned during creation
00187     Operation* Next;   // linked list
00188     Operation() { FieldName = 0; }
00189     ~Operation() { delete[] FieldName; }
00190   };
00191 //ETX
00192 
00193 protected:
00194 
00195   vtkRearrangeFields();
00196   virtual ~vtkRearrangeFields();
00197 
00198   void Execute();
00199 
00200 
00201   // Operations are stored as a linked list.
00202   Operation* Head;
00203   Operation* Tail;
00204   // This is incremented whenever a new operation is created.
00205   // It is not decremented when an operation is deleted.
00206   int LastId;
00207 
00208   // Methods to browse/modify the linked list.
00209   Operation* GetNextOperation(Operation* op)
00210     { return op->Next; }
00211   Operation* GetFirst()
00212     { return this->Head; }
00213   void AddOperation(Operation* op);
00214   void DeleteOperation(Operation* op, Operation* before);
00215   Operation* FindOperation(int id, Operation*& before);
00216   Operation* FindOperation(const char* name, Operation*& before);
00217   Operation* FindOperation(int operationType, const char* name, 
00218                            int fromFieldLoc, int toFieldLoc,
00219                            Operation*& before);
00220   Operation* FindOperation(int operationType, int attributeType, 
00221                            int fromFieldLoc, int toFieldLoc,
00222                            Operation*& before);
00223   // Used when finding/deleting an operation given a signature.
00224   int CompareOperationsByType(const Operation* op1, const Operation* op2);
00225   int CompareOperationsByName(const Operation* op1, const Operation* op2);
00226 
00227   void DeleteAllOperations();
00228   void ApplyOperation(Operation* op, vtkDataSet* input, vtkDataSet* output);
00229   // Given location (DATA_OBJECT, CELL_DATA, POINT_DATA) return the
00230   // pointer to the corresponding field data.
00231   vtkFieldData* GetFieldDataFromLocation(vtkDataSet* ds, int fieldLoc);
00232 
00233   // Used by AddOperation() and RemoveOperation() designed to be used 
00234   // from other language bindings.
00235   static char OperationTypeNames[2][5];
00236   static char FieldLocationNames[3][12];
00237   static char AttributeNames[vtkDataSetAttributes::NUM_ATTRIBUTES][10];
00238 
00239   void PrintAllOperations(ostream& os, vtkIndent indent)
00240     {
00241       Operation* cur = this->GetFirst();
00242       if (!cur) { return; }
00243       Operation* before;
00244       do
00245         {
00246         before = cur;
00247         cur = cur->Next;
00248         os << endl;
00249         this->PrintOperation(before, os, indent);
00250         } 
00251       while (cur);
00252     }
00253 
00254   void PrintOperation(Operation* op, ostream& os, vtkIndent indent)
00255     {
00256       os << indent << "Id: " << op->Id << endl;
00257       os << indent << "Type: " << op->OperationType << endl;
00258       os << indent << "Field type: " << op->FieldType << endl;
00259       if ( op->FieldName)
00260         {
00261         os << indent << "Field name: " << op->FieldName << endl;
00262         }
00263       else
00264         {
00265         os << indent << "Field name: (none)" << endl;
00266         }
00267       os << indent << "Attribute type: " << op->AttributeType << endl;
00268       os << indent << "Source field location: " << op->FromFieldLoc << endl;
00269       os << indent << "Target field location: " << op->ToFieldLoc << endl;
00270       os << indent << "Next operation: " << op->Next << endl;
00271       os << endl;
00272     }
00273 private:
00274   vtkRearrangeFields(const vtkRearrangeFields&);  // Not implemented.
00275   void operator=(const vtkRearrangeFields&);  // Not implemented.
00276 };
00277 
00278 #endif
00279 
00280 

Generated on Thu Mar 28 14:19:22 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001