1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkCPExodusIIElementBlock.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 =========================================================================*/
15 // .NAME vtkCPExodusIIElementBlock - Uses an Exodus II element block as a
16 //  vtkMappedUnstructuredGrid's implementation.
17 //
18 // .SECTION Description
19 // This class allows raw data arrays returned by the Exodus II library to be
20 // used directly in VTK without repacking the data into the vtkUnstructuredGrid
21 // memory layout. Use the vtkCPExodusIIInSituReader to read an Exodus II file's
22 // data into this structure.
23 
24 #ifndef vtkCPExodusIIElementBlock_h
25 #define vtkCPExodusIIElementBlock_h
26 
27 #include "vtkObject.h"
28 #include "vtkIOExodusModule.h" // For export macro
29 
30 #include "vtkMappedUnstructuredGrid.h" // For mapped unstructured grid wrapper
31 
32 #include <string> // For std::string
33 
34 class vtkGenericCell;
35 
36 class VTKIOEXODUS_EXPORT vtkCPExodusIIElementBlockImpl : public vtkObject
37 {
38 public:
39   static vtkCPExodusIIElementBlockImpl *New();
40   virtual void PrintSelf(ostream &os, vtkIndent indent);
41   vtkTypeMacro(vtkCPExodusIIElementBlockImpl, vtkObject)
42 
43   // Description:
44   // Set the Exodus element block data. 'elements' is the array returned from
45   // ex_get_elem_conn. 'type', 'numElements', and 'nodesPerElement' are obtained
46   // from ex_get_elem_block. Returns true or false depending on whether or not
47   // the element type can be translated into a VTK cell type. This object takes
48   // ownership of the elements array unless this function returns false.
49   bool SetExodusConnectivityArray(int *elements, const std::string &type,
50                                   int numElements, int nodesPerElement);
51 
52   // API for vtkMappedUnstructuredGrid's implementation.
53   vtkIdType GetNumberOfCells();
54   int GetCellType(vtkIdType cellId);
55   void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
56   void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
57   int GetMaxCellSize();
58   void GetIdsOfCellsOfType(int type, vtkIdTypeArray *array);
59   int IsHomogeneous();
60 
61   // This container is read only -- these methods do nothing but print a
62   // warning.
63   void Allocate(vtkIdType numCells, int extSize = 1000);
64   vtkIdType InsertNextCell(int type, vtkIdList *ptIds);
65   vtkIdType InsertNextCell(int type, vtkIdType npts, vtkIdType *ptIds);
66   vtkIdType InsertNextCell(int type, vtkIdType npts, vtkIdType *ptIds,
67                            vtkIdType nfaces, vtkIdType *faces);
68   void ReplaceCell(vtkIdType cellId, int npts, vtkIdType *pts);
69 
70 protected:
71   vtkCPExodusIIElementBlockImpl();
72   ~vtkCPExodusIIElementBlockImpl();
73 
74 private:
75   vtkCPExodusIIElementBlockImpl(const vtkCPExodusIIElementBlockImpl &); // Not implemented.
76   void operator=(const vtkCPExodusIIElementBlockImpl &);   // Not implemented.
77 
78   // Convert between Exodus node ids and VTK point ids.
NodeToPoint(const int & id)79   static vtkIdType NodeToPoint(const int &id)
80   {
81     return static_cast<vtkIdType>(id - 1);
82   }
PointToNode(const vtkIdType & id)83   static int PointToNode(const vtkIdType &id)
84   {
85     return static_cast<int>(id + 1);
86   }
87 
88   // Convenience methods to get pointers into the element array.
GetElementStart(vtkIdType cellId)89   int* GetElementStart(vtkIdType cellId) const
90   {
91     return this->Elements + (cellId * this->CellSize);
92   }
GetElementEnd(vtkIdType cellId)93   int* GetElementEnd(vtkIdType cellId) const
94   {
95     return this->Elements + (cellId * this->CellSize) + this->CellSize;
96   }
GetStart()97   int* GetStart() const { return this->Elements; }
GetEnd()98   int* GetEnd() const
99   {
100     return this->Elements + (this->NumberOfCells * this->CellSize);
101   }
102 
103   int *Elements;
104   int CellType;
105   int CellSize;
106   vtkIdType NumberOfCells;
107 };
108 
109 vtkMakeExportedMappedUnstructuredGrid(vtkCPExodusIIElementBlock,
110                                       vtkCPExodusIIElementBlockImpl,
111                                       VTKIOEXODUS_EXPORT)
112 
113 #endif //vtkCPExodusIIElementBlock_h
114