1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkLSDynaPart.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 #ifndef vtkLSDynaPart_h
16 #define vtkLSDynaPart_h
17 
18 #include "vtkIOLSDynaModule.h" // For export macro
19 #include "vtkObject.h"
20 #include "LSDynaMetaData.h" //needed for lsdyna types
21 #include "vtkStdString.h" //needed for string
22 
23 class vtkUnstructuredGrid;
24 class vtkPoints;
25 
26 class VTKIOLSDYNA_EXPORT vtkLSDynaPart: public vtkObject
27 {
28 public:
29   static vtkLSDynaPart *New();
30 
31   vtkTypeMacro(vtkLSDynaPart,vtkObject);
32   virtual void PrintSelf(ostream &os, vtkIndent indent);
33 
34   //Description: Set the type of the part
35   void SetPartType(int type);
36 
37   //Description: Returns the type of the part
PartType()38   LSDynaMetaData::LSDYNA_TYPES PartType() const { return Type; }
39 
40   //Description: Returns if the type of the part is considered valid
41   bool hasValidType() const;
42 
GetUserMaterialId()43   vtkIdType GetUserMaterialId() const { return UserMaterialId; }
GetPartId()44   vtkIdType GetPartId() const { return PartId; }
45   bool HasCells() const;
46 
47   //Setup the part with some basic information about what it holds
48   void InitPart(vtkStdString name,
49                 const vtkIdType& partId,
50                 const vtkIdType& userMaterialId,
51                 const vtkIdType& numGlobalPoints,
52                 const int& sizeOfWord);
53 
54   //Reserves the needed space in memory for this part
55   //that way we never over allocate memory
56   void AllocateCellMemory(const vtkIdType& numCells, const vtkIdType& cellLen);
57 
58   //Add a cell to the part
59   void AddCell(const int& cellType, const vtkIdType& npts, vtkIdType conn[8]);
60 
61   //Description:
62   //Setups the part cell topology so that we can cache information
63   //between timesteps.
64   void BuildToplogy();
65 
66   //Description:
67   //Returns if the toplogy for this part has been constructed
IsTopologyBuilt()68   bool IsTopologyBuilt() const { return TopologyBuilt; }
69 
70   //Description:
71   //Constructs the grid for this part and returns it.
72   vtkUnstructuredGrid* GenerateGrid();
73 
74   //Description:
75   //allows the part to store dead cells
76   void EnableDeadCells(const int& deadCellsAsGhostArray);
77 
78   //Description:
79   //removes the dead cells array if it exists from the grid
80   void DisableDeadCells();
81 
82   //Description:
83   //We set cells as dead to make them not show up during rendering
84   void SetCellsDeadState(unsigned char *dead, const vtkIdType &size);
85 
86   //Description:
87   //allows the part to store user cell ids
88   void EnableCellUserIds();
89 
90   //Description:
91   //Set the user ids for the cells of this grid
92   void SetNextCellUserIds(const vtkIdType& value);
93 
94 
95   //Description:
96   //Called to init point filling for a property
97   //is also able to set the point position of the grid too as that
98   //is stored as a point property
99   void AddPointProperty(const char* name, const vtkIdType& numComps,
100     const bool& isIdTypeProperty, const bool &isProperty,
101     const bool& isGeometryPoints);
102 
103   //Description:
104   //Given a chunk of point property memory copy it to the correct
105   //property on the part
106   void ReadPointBasedProperty(float *data,
107                               const vtkIdType& numTuples,
108                               const vtkIdType& numComps,
109                               const vtkIdType& currentGlobalPointIndex);
110 
111   void ReadPointBasedProperty(double *data,
112                               const vtkIdType& numTuples,
113                               const vtkIdType& numComps,
114                               const vtkIdType& currentGlobalPointIndex);
115 
116   //Description:
117   //Adds a property to the part
118   void AddCellProperty(const char* name, const int& offset, const int& numComps);
119 
120   //Description:
121   //Given the raw data converts it to be the properties for this part
122   //The cell properties are woven together as a block for each cell
123   void ReadCellProperties(float *cellProperties, const vtkIdType& numCells,
124                           const vtkIdType &numPropertiesInCell);
125   void ReadCellProperties(double *cellsProperties, const vtkIdType& numCells,
126                           const vtkIdType &numPropertiesInCell);
127 
128   //Description:
129   //Get the id of the lowest global point this part needs
130   //Note: Presumes topology has been built already
131   vtkIdType GetMinGlobalPointId() const;
132 
133   //Description:
134   //Get the id of the largest global point this part needs
135   //Note: Presumes topology has been built already
136   vtkIdType GetMaxGlobalPointId() const;
137 
138 protected:
139   vtkLSDynaPart();
140   ~vtkLSDynaPart();
141 
142   vtkUnstructuredGrid* RemoveDeletedCells();
143 
144   void BuildUniquePoints();
145   void BuildCells();
146 
147   void GetPropertyData(const char* name, const vtkIdType &numComps,
148   const bool &isIdTypeArray, const bool& isProperty, const bool& isGeometry);
149 
150   template<typename T>
151   void AddPointInformation(T *buffer,T *pointData,
152                            const vtkIdType& numTuples,
153                            const vtkIdType& numComps,
154                            const vtkIdType& currentGlobalPointIndex);
155 
156   //basic info about the part
157   LSDynaMetaData::LSDYNA_TYPES Type;
158   vtkStdString Name;
159   vtkIdType UserMaterialId;
160   vtkIdType PartId;
161 
162   vtkIdType NumberOfCells;
163   vtkIdType NumberOfPoints;
164   vtkIdType NumberOfGlobalPoints;
165 
166   bool DeadCellsAsGhostArray;
167   bool HasDeadCells;
168 
169   bool TopologyBuilt;
170   bool DoubleBased;
171 
172   vtkUnstructuredGrid* Grid;
173   vtkUnstructuredGrid* ThresholdGrid;
174 
175   vtkPoints* Points;
176 
177   class InternalCells;
178   InternalCells *Cells;
179 
180   class InternalCellProperties;
181   InternalCellProperties *CellProperties;
182 
183   class InternalPointsUsed;
184   class DensePointsUsed;
185   class SparsePointsUsed;
186   InternalPointsUsed *GlobalPointsUsed;
187 
188   //used when reading properties
189   class InternalCurrentPointInfo;
190   InternalCurrentPointInfo *CurrentPointPropInfo;
191 
192 private:
193   vtkLSDynaPart( const vtkLSDynaPart& ); // Not implemented.
194   void operator = ( const vtkLSDynaPart& ); // Not implemented.
195 };
196 
197 #endif // VTKLSDYNAPART
198