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