GemaMesh
The GeMA Mesh Plugin
gmpGemaCell.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4 ** All rights reserved.
5 **
6 ** This file is part of the "GeMA" software. It's use should respect
7 ** the terms in the license agreement that can be found together
8 ** with this source code.
9 ** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11 ** A PARTICULAR PURPOSE.
12 **
13 ************************************************************************/
14 
24 #ifndef _GEMA_PLUGIN_GEMA_CELL_H_
25 #define _GEMA_PLUGIN_GEMA_CELL_H_
26 
27 #include "gmpCellBase.h"
28 #include "uibhmTopology.h"
29 
37 template <class Base, class Proxy, class CellMeshData, GmCellType T, int N, int VN> class GmpGemaCell
38  : public GmpCellBaseWithId<Base, Proxy, CellMeshData, T, N, VN>
39 {
40 public:
43  : GmpCellBaseWithId<Base, Proxy, CellMeshData, T, N, VN>(id, meshId)
44  {
45  Q_UNUSED(mesh); // Needed by the surface mesh plugin
47  }
48 
49  // See comments on the base class
50  virtual int nodeIndex(int localIndex) const
51  {
52  assert(localIndex >= 0 && localIndex < N);
53  return meshData()->cellNodesPtr(_nodeOffset)[localIndex];
54  }
55 
56  // See comments on the base class.
57  virtual void nodes(int* nodeList, bool ghost) const
58  {
59  Q_UNUSED(ghost); assert(!ghost); // This class does not supports ghost nodes. This is handled by GmpGemaGhostCell
60  memcpy(nodeList, meshData()->cellNodesPtr(_nodeOffset), N*sizeof(int));
61  }
62 
63  // See comments on the base class
64  virtual bool setNodes(const int* nodeList)
65  {
66  assert(nodeList);
67 
68 #if 0 // Checked when first reading the mesh. Also tested at the API on the Lua binding.
69  int nnodes = mesh()->numNodes();
70  for(int i = 0; i<N; i++)
71  {
72  int node = nodeList[i];
73  if(node < 0 || node >= nnodes)
74  return false;
75  }
76 #endif
77  // If the mesh has a topology structure and the cell has already been added to that structure,
78  // we can't update the set of node cells.
79  UibhmTopologyBase* topo = meshData()->_topology;
80  if(topo && topo->cellIsIndexed(cellId()))
81  return false;
82 
83  // Update!
84  memcpy(meshData()->cellNodesPtr(_nodeOffset), nodeList, N*sizeof(int));
85  return true;
86  }
87 
89  int offset() const { return _nodeOffset; }
90 
91  void setOffset(int offset) { _nodeOffset = offset; }
92 
93 protected:
95 };
96 
98 template <class Base, class Proxy, class CellMeshData, GmCellType T, int N, int VN> class GmpGemaGhostCell
99  : public GmpGhostCellBase<GmpGemaCell, Base, Proxy, CellMeshData, T, N, VN>
100 {
101 public:
103 #ifdef Q_OS_WIN
104  GmpGemaGhostCell(GmCellMesh* mesh, int meshId, int id, int offset) : GmpGhostCellBase(mesh, meshId, id, offset) {}
105 #else
106  GmpGemaGhostCell(GmCellMesh* mesh, int meshId, int id, int offset) : GmpGhostCellBase<GmpGemaCell, Base, Proxy, CellMeshData, T, N, VN>(mesh, meshId, id, offset) {}
107 #endif
108 };
109 
110 
111 static_assert(sizeof(GmpGemaCell <GmCell, GmLuaCell, GmpGemaCellMeshData<GmSingleVector>, GM_BAR2, 2, 2>) == 16, "Unexpected cell size");
112 static_assert(sizeof(GmpGemaGhostCell<GmCell, GmLuaCell, GmpGemaCellMeshData<GmSingleVector>, GM_BAR2, 2, 2>) == 32, "Unexpected cell size");;
113 
114 
115 #endif
GmpGhostCellBase(GmCellMesh *mesh, int meshId, int id, int offset)
Constructs a cell given its id and associated mesh id.
Definition: gmpCellBase.h:244
int _nodeOffset
Index in the mesh data for the first node for this cell.
Definition: gmpGemaCell.h:94
Declaration of the UibhmTopology familiy of classes.
GmpGemaGhostCell(GmCellMesh *mesh, int meshId, int id, int offset)
Constructs a cell given its id.
Definition: gmpGemaCell.h:106
Basic implementation for a "Gema cell", adding the information about the offset of its nodes in the g...
Definition: gmpGemaCell.h:37
CellMeshData * meshData() const
Returns the mesh data object associated with this cell's mesh.
Definition: gmpCellBase.h:154
Declaration of the GmpCellBase class.
Basic implementation for a GmpGemaGhostCell cell, based on the GmpGhostCellBase class.
Definition: gmpGemaCell.h:98
Auxiliar structure used to share data between GmpGemaCellMesh and GmpMeshLoader.
Definition: gmpGemaCellMeshData.h:36
Template class used to add ghost node support to template class CellBase.
Definition: gmpCellBase.h:240
int offset() const
Returns the offset in the global mesh cell nodes vector for this cell.
Definition: gmpGemaCell.h:89
Interface for accessing the "exported" functions of a UibhmTopology class instance,...
Definition: uibhmTopology.h:83
virtual int numNodes() const=0
Adds cell id and active information to a GmpCellBase class.
Definition: gmpCellBase.h:184