iMSTK
Interactive Medical Simulation Toolkit
imstkAbstractCellMesh.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkPointSet.h"
8 #include "imstkVecDataArray.h"
9 
10 #include <unordered_set>
11 
12 #pragma once
13 
14 namespace imstk
15 {
21 class AbstractCellMesh : public PointSet
22 {
23 public:
24  ~AbstractCellMesh() override = default;
25 
29  bool isMesh() const override { return true; }
30 
31  void clear() override;
32 
36  void print() const override;
37 
38  virtual int getNumCells() const = 0;
39 
43  virtual void computeVertexToCellMap() { }
44 
48  virtual void computeVertexNeighbors() { }
49 
54  virtual std::shared_ptr<AbstractDataArray> getAbstractCells() const = 0;
55 
59  virtual int getCellVertexCount() const = 0;
60 
64  const std::vector<std::unordered_set<int>>& getVertexToCellMap() const { return m_vertexToCells; }
65 
69  const std::vector<int> getCellsForVertex(const int vertexId);
70 
73  const std::vector<std::unordered_set<int>>& getVertexNeighbors() const { return m_vertexToNeighborVertex; }
74 
75  // Attributes
79  const std::unordered_map<std::string, std::shared_ptr<AbstractDataArray>>& getCellAttributes() const { return m_cellAttributes; }
80 
81  void setCellAttribute(const std::string& arrayName, std::shared_ptr<AbstractDataArray> arr)
82  {
83  m_cellAttributes[arrayName] = arr;
84  }
85 
86  std::shared_ptr<AbstractDataArray> getCellAttribute(const std::string& name) const
87  {
88  auto it = m_cellAttributes.find(name);
89  if (it == m_cellAttributes.end())
90  {
91  LOG(FATAL) << "No attribute with name " << name << " found in " << getTypeName();
92  return nullptr;
93  }
94  return it->second;
95  }
96 
100  bool hasCellAttribute(const std::string& arrayName) const
101  {
102  return (m_cellAttributes.find(arrayName) != m_cellAttributes.end());
103  }
104 
108  void setCellAttributes(std::unordered_map<std::string, std::shared_ptr<AbstractDataArray>> attributes) { m_cellAttributes = attributes; }
109 
113  void setCellScalars(const std::string& arrayName, std::shared_ptr<AbstractDataArray> scalars);
114  void setCellScalars(const std::string& arrayName);
115  std::string getActiveCellScalars() const { return m_activeCellScalars; }
116  std::shared_ptr<AbstractDataArray> getCellScalars() const;
118 
122  void setCellNormals(const std::string& arrayName, std::shared_ptr<VecDataArray<double, 3>> normals);
123  void setCellNormals(const std::string& arrayName);
124  std::string getActiveCellNormals() const { return m_activeCellNormals; }
125  std::shared_ptr<VecDataArray<double, 3>> getCellNormals() const;
127 
131  void setCellTangents(const std::string& arrayName, std::shared_ptr<VecDataArray<double, 3>> tangents);
132  void setCellTangents(const std::string& arrayName);
133  std::string getActiveCellTangents() const { return m_activeCellTangents; }
134  std::shared_ptr<VecDataArray<double, 3>> getCellTangents() const;
136 
137 protected:
138  void setCellActiveAttribute(std::string& activeAttributeName, std::string attributeName,
139  const int expectedNumComponents, const ScalarTypeId expectedScalarType);
140 
141  std::vector<std::unordered_set<int>> m_vertexToCells;
142  std::vector<std::unordered_set<int>> m_vertexToNeighborVertex;
143 
145  std::unordered_map<std::string, std::shared_ptr<AbstractDataArray>> m_cellAttributes;
146 
147  std::string m_activeCellNormals = "";
148  std::string m_activeCellTangents = "";
149  std::string m_activeCellScalars = "";
150 };
151 } // namespace imstk
Base class for all geometries represented by discrete points and elements The pointsets follow a pipe...
Definition: imstkPointSet.h:25
void setCellNormals(const std::string &arrayName, std::shared_ptr< VecDataArray< double, 3 >> normals)
Get/Set the active normals.
virtual const std::string getTypeName() const =0
Returns the string representing the type name of the geometry.
void print() const override
Print the surface mesh.
std::vector< std::unordered_set< int > > m_vertexToNeighborVertex
Map of vertices to neighbor vertices.
void clear() override
Clears all the mesh data.
Compound Geometry.
const std::vector< int > getCellsForVertex(const int vertexId)
Returns cells that contain the vertex, will calculate vertex cells if necessary.
virtual void computeVertexToCellMap()
Computes neighboring cells for all vertices.
const std::unordered_map< std::string, std::shared_ptr< AbstractDataArray > > & getCellAttributes() const
Get the cell attributes map.
std::vector< std::unordered_set< int > > m_vertexToCells
Map of vertices to neighbor cells.
void setCellTangents(const std::string &arrayName, std::shared_ptr< VecDataArray< double, 3 >> tangents)
Get/Set the active tangents.
bool isMesh() const override
Returns true if the geometry is a mesh, else returns false.
void setCellAttributes(std::unordered_map< std::string, std::shared_ptr< AbstractDataArray >> attributes)
Set the cell attributes map.
virtual int getCellVertexCount() const =0
Number of verticies associated with the cell type.
bool hasCellAttribute(const std::string &arrayName) const
Check if a specific data array exists.
virtual std::shared_ptr< AbstractDataArray > getAbstractCells() const =0
Get cells as abstract array. Overridden by derived classes to return cells as point indices...
virtual void computeVertexNeighbors()
Computes neighboring vertices for all vertices.
const std::vector< std::unordered_set< int > > & getVertexToCellMap() const
Returns map of vertices to cells that contain the vertex (reverse linkage)
void setCellScalars(const std::string &arrayName, std::shared_ptr< AbstractDataArray > scalars)
Get/Set the active scalars.
const std::vector< std::unordered_set< int > > & getVertexNeighbors() const
Returns map of vertices to neighboring vertices.
Provides non templated base for cell based meshes.