iMSTK
Interactive Medical Simulation Toolkit
imstkPointSet.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 #pragma once
8 
9 #include "imstkGeometry.h"
10 #include "imstkTypes.h"
11 
12 #include <unordered_map>
13 
14 namespace imstk
15 {
16 class AbstractDataArray;
17 template<typename T, int N> class VecDataArray;
18 
25 class PointSet : public Geometry
26 {
27 public:
28  PointSet();
29  ~PointSet() override = default;
30 
31  IMSTK_TYPE_NAME(PointSet)
32 
33 
34  void initialize(std::shared_ptr<VecDataArray<double, 3>> positions);
37 
41  virtual void clear();
42 
46  virtual void print() const override;
47 
51  virtual void computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner, const double paddingPercent = 0.0) override;
52 
53 // Accessors
57  void setInitialVertexPositions(std::shared_ptr<VecDataArray<double, 3>> vertices);
58 
62  std::shared_ptr<VecDataArray<double, 3>> getInitialVertexPositions() const { return m_initialVertexPositions; }
63 
67  Vec3d& getInitialVertexPosition(const size_t vertNum);
68 
72  void setVertexPositions(std::shared_ptr<VecDataArray<double, 3>> positions);
73 
77  std::shared_ptr<VecDataArray<double, 3>> getVertexPositions(DataType type = DataType::PostTransform) const;
78 
82  void setVertexPosition(const size_t vertNum, const Vec3d& pos);
83 
87  const Vec3d& getVertexPosition(const size_t vertNum, DataType type = DataType::PostTransform) const;
88  Vec3d& getVertexPosition(const size_t vertNum, DataType type = DataType::PostTransform);
90 
94  int getNumVertices() const;
95 
96 // Attributes
100  void setVertexAttribute(const std::string& arrayName, std::shared_ptr<AbstractDataArray> arr);
101 
105  std::shared_ptr<AbstractDataArray> getVertexAttribute(const std::string& arrayName) const;
106 
110  bool hasVertexAttribute(const std::string& arrayName) const;
111 
115  void setVertexAttributes(std::unordered_map<std::string, std::shared_ptr<AbstractDataArray>> attributes) { m_vertexAttributes = attributes; }
116 
120  const std::unordered_map<std::string, std::shared_ptr<AbstractDataArray>>& getVertexAttributes() const { return m_vertexAttributes; }
121 
125  void setVertexScalars(const std::string& arrayName, std::shared_ptr<AbstractDataArray> scalars);
126  void setVertexScalars(const std::string& arrayName);
127  std::string getActiveVertexScalars() const { return m_activeVertexScalars; }
128  std::shared_ptr<AbstractDataArray> getVertexScalars() const;
130 
134  void setVertexNormals(const std::string& arrayName, std::shared_ptr<VecDataArray<double, 3>> normals);
135  void setVertexNormals(const std::string& arrayName);
136  std::string getActiveVertexNormals() const { return m_activeVertexNormals; }
137  std::shared_ptr<VecDataArray<double, 3>> getVertexNormals() const;
139 
143  void setVertexTangents(const std::string& arrayName, std::shared_ptr<VecDataArray<float, 3>> tangents);
144  void setVertexTangents(const std::string& arrayName);
145  std::string getActiveVertexTangents() const { return m_activeVertexTangents; }
146  std::shared_ptr<VecDataArray<float, 3>> getVertexTangents() const;
148 
152  void setVertexTCoords(const std::string& arrayName, std::shared_ptr<VecDataArray<float, 2>> tcoords);
153  void setVertexTCoords(const std::string& arrayName);
154  std::string getActiveVertexTCoords() const { return m_activeVertexTCoords; }
155  std::shared_ptr<VecDataArray<float, 2>> getVertexTCoords() const;
157 
161  void updatePostTransformData() const override;
162 
167  std::unique_ptr<PointSet> clone()
168  {
169  return std::unique_ptr<PointSet>(cloneImplementation());
170  }
171 
172 protected:
176  void applyTransform(const Mat4d& m) override;
177 
182  void setActiveVertexAttribute(std::string& activeAttributeName, const std::string attributeName,
183  const int expectedNumComponents, const ScalarTypeId expectedScalarType);
184 
185  std::shared_ptr<VecDataArray<double, 3>> m_initialVertexPositions;
186  std::shared_ptr<VecDataArray<double, 3>> m_vertexPositions;
187 
188  std::unordered_map<std::string, std::shared_ptr<AbstractDataArray>> m_vertexAttributes;
189  std::string m_activeVertexNormals = "";
190  std::string m_activeVertexScalars = "";
191  std::string m_activeVertexTangents = "";
192  std::string m_activeVertexTCoords = "";
193 
194  Vec3d m_lowerCorner;
195  Vec3d m_upperCorner;
196 
197 private:
198  PointSet* cloneImplementation() const;
199 };
200 } // namespace imstk
void initialize(std::shared_ptr< VecDataArray< double, 3 >> positions)
Initializes the data structure given vertex positions.
void setVertexNormals(const std::string &arrayName, std::shared_ptr< VecDataArray< double, 3 >> normals)
Get/Set the active normals.
Base class for all geometries represented by discrete points and elements The pointsets follow a pipe...
Definition: imstkPointSet.h:25
void setVertexTangents(const std::string &arrayName, std::shared_ptr< VecDataArray< float, 3 >> tangents)
Get/Set the active tangents.
std::unique_ptr< PointSet > clone()
Polymorphic clone, hides the declaration in superclass return own type.
std::shared_ptr< AbstractDataArray > getVertexAttribute(const std::string &arrayName) const
Get a specific data array. If the array name cannot be found, nullptr is returned.
void applyTransform(const Mat4d &m) override
Applies transformation m directly the initial and post transform data.
void setVertexAttributes(std::unordered_map< std::string, std::shared_ptr< AbstractDataArray >> attributes)
Set the vertex attributes map.
virtual void print() const override
Print the mesh info.
bool hasVertexAttribute(const std::string &arrayName) const
Check if a specific data array exists.
const std::unordered_map< std::string, std::shared_ptr< AbstractDataArray > > & getVertexAttributes() const
Get the vertex attributes map.
void setVertexTCoords(const std::string &arrayName, std::shared_ptr< VecDataArray< float, 2 >> tcoords)
Get/Set the active tcoords.
Compound Geometry.
virtual void computeBoundingBox(Vec3d &lowerCorner, Vec3d &upperCorner, const double paddingPercent=0.0) override
Compute the bounding box for the entire mesh.
void setVertexAttribute(const std::string &arrayName, std::shared_ptr< AbstractDataArray > arr)
Set a data array holding some per vertex data.
void updatePostTransformData() const override
Applies the geometries member transform to produce currPositions.
Base class for any geometrical representation.
Definition: imstkGeometry.h:22
void setVertexScalars(const std::string &arrayName, std::shared_ptr< AbstractDataArray > scalars)
Get/Set the active scalars.
void setActiveVertexAttribute(std::string &activeAttributeName, const std::string attributeName, const int expectedNumComponents, const ScalarTypeId expectedScalarType)
Sets the active vertex attribute name as long as the # components is satisfied. Throws message and ca...
const Vec3d & getVertexPosition(const size_t vertNum, DataType type=DataType::PostTransform) const
Returns the position of a vertex given its index.
void setVertexPosition(const size_t vertNum, const Vec3d &pos)
Set the current position of a vertex given its index to certain position (this is not a thread-safe m...
void setInitialVertexPositions(std::shared_ptr< VecDataArray< double, 3 >> vertices)
Sets initial positions from an array.
std::shared_ptr< VecDataArray< double, 3 > > getVertexPositions(DataType type=DataType::PostTransform) const
Returns the vector of current positions of the mesh vertices.
virtual void clear()
Clears all the mesh data.
void setVertexPositions(std::shared_ptr< VecDataArray< double, 3 >> positions)
Sets current vertex positions of the mesh.
Vec3d & getInitialVertexPosition(const size_t vertNum)
Returns the initial position of a vertex given its index.
int getNumVertices() const
Returns the number of total vertices in the mesh.
std::shared_ptr< VecDataArray< double, 3 > > getInitialVertexPositions() const
Returns the vector of initial positions of the mesh vertices.
Definition: imstkPointSet.h:62
DataType
Enumeration for the data to retrieve PreTransform for data where transform matrix is not applied Po...
Definition: imstkGeometry.h:41