File: metaMesh.h

package info (click to toggle)
paraview 5.13.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 544,220 kB
  • sloc: cpp: 3,374,605; ansic: 1,332,409; python: 150,381; xml: 122,166; sql: 65,887; sh: 7,317; javascript: 5,262; yacc: 4,417; java: 3,977; perl: 2,363; lex: 1,929; f90: 1,397; makefile: 170; objc: 153; tcl: 59; pascal: 50; fortran: 29
file content (352 lines) | stat: -rw-r--r-- 7,299 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*============================================================================
  MetaIO
  Copyright 2000-2010 Insight Software Consortium

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#include "metaTypes.h"

#ifndef ITKMetaIO_METAMESH_H
#  define ITKMetaIO_METAMESH_H

#  include "metaUtils.h"
#  include "metaObject.h"

#  ifdef _MSC_VER
#    pragma warning(disable : 4251)
#  endif

#  include <list>


/*!    MetaMesh (.h and .cxx)
 *
 * Description:
 *    Reads and Writes MetaMeshFiles.
 *
 * \author Julien Jomier
 *
 * \date June, 2004
 *
 * Depends on:
 *    MetaUtils.h
 */

#  if (METAIO_USE_NAMESPACE)
namespace METAIO_NAMESPACE
{
#  endif

/** Typedef for the type of cells */
#  define MET_NUM_CELL_TYPES 9

enum MET_CellGeometry
{
  MET_VERTEX_CELL = 0,
  MET_LINE_CELL,
  MET_TRIANGLE_CELL,
  MET_QUADRILATERAL_CELL,
  MET_POLYGON_CELL,
  MET_TETRAHEDRON_CELL,
  MET_HEXAHEDRON_CELL,
  MET_QUADRATIC_EDGE_CELL,
  MET_QUADRATIC_TRIANGLE_CELL
};

const unsigned char MET_CellSize[MET_NUM_VALUE_TYPES] = { 1, 2, 3, 4, 5, 4, 8, 3, 6 };

const char MET_CellTypeName[MET_NUM_VALUE_TYPES][4] = { { 'V', 'R', 'T', '\0' }, { 'L', 'N', 'E', '\0' },
                                                        { 'T', 'R', 'I', '\0' }, { 'Q', 'A', 'D', '\0' },
                                                        { 'P', 'L', 'Y', '\0' }, { 'T', 'E', 'T', '\0' },
                                                        { 'H', 'E', 'X', '\0' }, { 'Q', 'E', 'D', '\0' },
                                                        { 'Q', 'T', 'R', '\0' } };


/** Define a mesh point */
class METAIO_EXPORT MeshPoint
{
public:
  explicit MeshPoint(int dim);
  ~MeshPoint();

  unsigned int m_Dim;
  float *      m_X;
  int          m_Id{};
};


/** Define a mesh cell
 *  a cell contains a list of Ids corresponding to the list
 *  of points */
class METAIO_EXPORT MeshCell
{
public:
  explicit MeshCell(int dim);
  ~MeshCell();

  int          m_Id;
  unsigned int m_Dim;
  int *        m_PointsId;
};

/** Define a mesh cell links
 *  a celllink contains a list of Ids corresponding to the list
 *  of links cells */
class METAIO_EXPORT MeshCellLink
{
public:
  MeshCellLink() { m_Id = 0; }
  ~MeshCellLink() = default;

  int            m_Id; // id of the cell link
  std::list<int> m_Links;
};

/** Define a mesh point data */
class METAIO_EXPORT MeshDataBase
{
public:
  MeshDataBase() { m_Id = -1; }
  virtual ~MeshDataBase() = default;

  virtual void
  Write(std::ofstream * stream) = 0;
  virtual unsigned int
  GetSize() = 0;
  virtual MET_ValueEnumType
      GetMetaType() = 0;
  int m_Id;

protected:
  std::ifstream * m_ReadStream{};
  std::ofstream * m_WriteStream{};
};

/** Mesh point data class for basic types (i.e int, float ... ) */
template <typename TElementType>
class METAIO_EXPORT MeshData : public MeshDataBase
{
public:
  MeshData() { m_Id = -1; }
  ~MeshData() override = default;

  MET_ValueEnumType
  GetMetaType() override
  {
    return MET_GetPixelType(typeid(TElementType));
  }

  void
  Write(std::ofstream * stream) override
  {
    // char* id = new char[sizeof(int)];
    // The file is written as LSB by default
    int mid = m_Id;
    MET_SwapByteIfSystemMSB(&mid, MET_INT);
    // MET_DoubleToValue((double)m_Id,MET_INT,id,0);
    stream->write((char *)&mid, sizeof(int));
    // delete [] id;
    // char* data = new char[sizeof(m_Data)];
    // double mdata = m_Data;
    // MET_DoubleToValue((double)m_Data,GetMetaType(),data,0);
    TElementType data = m_Data;
    MET_SwapByteIfSystemMSB(&data, GetMetaType());
    stream->write((char *)&data, sizeof(data));
  }

  unsigned int
  GetSize() override
  {
    unsigned int size = sizeof(int);
    size += sizeof(m_Data);
    return size;
  }

  TElementType m_Data;
};


class METAIO_EXPORT MetaMesh : public MetaObject
{

  // PUBLIC
public:
  typedef std::list<MeshPoint *>    PointListType;
  typedef std::list<MeshCell *>     CellListType;
  typedef std::list<MeshCellLink *> CellLinkListType;
  typedef std::list<MeshDataBase *> PointDataListType;
  typedef std::list<MeshDataBase *> CellDataListType;

  // Constructors & Destructor
  MetaMesh();

  explicit MetaMesh(const char * _headerName);

  explicit MetaMesh(const MetaMesh * _mesh);

  explicit MetaMesh(unsigned int dim);

  ~MetaMesh() override;

  void
  PrintInfo() const override;

  void
  CopyInfo(const MetaObject * _object) override;

  //    NPoints(...)
  //       Required Field
  //       Number of points which compose the mesh
  int
  NPoints() const;

  //    NCells(...)
  //       Required Field
  //       Number of cells which compose the mesh
  int
  NCells() const;

  //    NCellLinks(...)
  //       Required Field
  //       Number of cellLinks which compose the mesh
  int
  NCellLinks() const;

#if 0 //These are not yet implemented
  //    NCellTypes(...)
  //       Required Field
  //       Number of cells which compose the mesh
  void
  NCellTypes(int ncelltypes);
  int
  NCellTypes(void) const;
#endif

  /** Clear the metaMesh */
  void
  Clear() override;

  PointListType &
  GetPoints()
  {
    return m_PointList;
  }
  const PointListType &
  GetPoints() const
  {
    return m_PointList;
  }

  CellListType &
  GetCells(MET_CellGeometry geom)
  {
    return *(m_CellListArray[geom]);
  }
  const CellListType &
  GetCells(MET_CellGeometry geom) const
  {
    return *(m_CellListArray[geom]);
  }

  CellLinkListType &
  GetCellLinks()
  {
    return m_CellLinks;
  }
  const CellLinkListType &
  GetCellLinks() const
  {
    return m_CellLinks;
  }

  PointDataListType &
  GetPointData()
  {
    return m_PointData;
  }
  const PointDataListType &
  GetPointData() const
  {
    return m_PointData;
  }

  CellDataListType &
  GetCellData()
  {
    return m_CellData;
  }
  const CellDataListType &
  GetCellData() const
  {
    return m_CellData;
  }

  MET_ValueEnumType
  PointDataType() const
  {
    return m_PointDataType;
  }
  void
  PointDataType(MET_ValueEnumType _elementType)
  {
    m_PointDataType = _elementType;
  }

  MET_ValueEnumType
  CellDataType() const
  {
    return m_CellDataType;
  }
  void
  CellDataType(MET_ValueEnumType _elementType)
  {
    m_CellDataType = _elementType;
  }

  // PROTECTED
protected:
  bool m_ElementByteOrderMSB{};

  void
  M_SetupReadFields() override;

  void
  M_SetupWriteFields() override;

  bool
  M_Read() override;

  bool
  M_Write() override;

  int  m_NPoints;
  int  m_NCells{};
  int  m_NCellLinks{};
  int  m_NPointData{};
  int  m_NCellData{};
  char m_PointDim[255]{}; // "PointDim = "       "x y z r"

  PointListType m_PointList;

  // We store the Cell lists in a vector
  CellListType *    m_CellListArray[MET_NUM_CELL_TYPES]{};
  CellLinkListType  m_CellLinks;
  PointDataListType m_PointData;
  CellDataListType  m_CellData;

  MET_ValueEnumType m_PointType;
  MET_ValueEnumType m_PointDataType;
  MET_ValueEnumType m_CellDataType;
};

#  if (METAIO_USE_NAMESPACE)
};
#  endif


#endif