opensurgsim
MassSpringPlyReaderDelegate.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2020, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_PHYSICS_MASSSPRINGPLYREADERDELEGATE_H
17 #define SURGSIM_PHYSICS_MASSSPRINGPLYREADERDELEGATE_H
18 
19 #include <array>
20 #include <limits>
21 #include <memory>
22 #include <string>
23 
24 #include "SurgSim/DataStructures/PlyReaderDelegate.h"
25 
26 namespace SurgSim
27 {
28 namespace Physics
29 {
30 class MassSpringModel;
31 
70 {
71 public:
74 
76  explicit MassSpringPlyReaderDelegate(std::shared_ptr<MassSpringModel> mesh);
77 
78 protected:
80  bool fileIsAcceptable(const SurgSim::DataStructures::PlyReader& reader) override;
81 
83  virtual void endParseFile();
84 
89  virtual void* beginVertices(const std::string& elementName, size_t vertexCount);
90 
93  virtual void processVertex(const std::string& elementName);
94 
97  virtual void endVertices(const std::string& elementName);
98 
103  void* beginElements(const std::string& elementName, size_t elementCount);
104 
107  virtual void processElement(const std::string& elementName);
108 
111  void endElements(const std::string& elementName);
112 
117  void* beginSprings(const std::string& elementName, size_t elementCount);
118 
121  virtual void processSpring(const std::string& elementName);
122 
125  void endSprings(const std::string& elementName);
126 
131  void* beginBoundaryConditions(const std::string& elementName, size_t boundaryConditionCount);
132 
135  virtual void processBoundaryCondition(const std::string& elementName);
136 
141  void* beginRadius(const std::string& elementName, size_t radiusCount);
142 
145  void endRadius(const std::string& elementName);
146 
151  void* beginThickness(const std::string& elementName, size_t thicknessCount);
152 
155  void endThickness(const std::string& elementName);
156 
157 protected:
159  struct MassData
160  {
161  double x = std::numeric_limits<double>::signaling_NaN();
162  double y = std::numeric_limits<double>::signaling_NaN();
163  double z = std::numeric_limits<double>::signaling_NaN();
164  double mass = std::numeric_limits<double>::signaling_NaN();
165  int64_t overrun1 = -1;
166  } m_massData;
167 
170 
172  unsigned int m_boundaryConditionData = 0;
173 
175  bool m_has1dElement = false;
176 
178  bool m_has2dElement = false;
179 
181  bool m_has3dElement = false;
182 
184  struct ElementData
185  {
186  int64_t overrun1 = -1;
187  unsigned int* indices = nullptr;
188  unsigned int nodeCount = 0;
189  int64_t overrun2 = -1;
190  } m_elementData;
191 
193  struct SpringData
194  {
195  int64_t overrun1 = -1;
196  unsigned int* indices = nullptr;
197  unsigned int nodeCount = 0;
198  int64_t overrun2 = -1;
199  double stiffness = std::numeric_limits<double>::signaling_NaN();
200  double damping = std::numeric_limits<double>::signaling_NaN();
201  } m_springData;
202 
204  bool m_hasRadius = false;
206  double m_radius = std::numeric_limits<double>::signaling_NaN();
207 
209  bool m_hasThickness = false;
211  double m_thickness = std::numeric_limits<double>::signaling_NaN();
212 
214  std::shared_ptr<MassSpringModel> m_mesh;
215 };
216 
217 } // namespace Physics
218 } // namespace SurgSim
219 
220 #endif // SURGSIM_PHYSICS_MASSSPRINGPLYREADERDELEGATE_H
Internal data to receive the spring (stretching and bending) data.
Definition: MassSpringPlyReaderDelegate.h:193
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
virtual void processSpring(const std::string &elementName)
Callback function to process one Spring.
Definition: MassSpringPlyReaderDelegate.cpp:232
virtual void processElement(const std::string &elementName)
Callback function to process one Element.
Definition: MassSpringPlyReaderDelegate.cpp:205
virtual void processBoundaryCondition(const std::string &elementName)
Callback function to process one boundary condition.
Definition: MassSpringPlyReaderDelegate.cpp:259
int64_t overrun1
Used to check for buffer overruns.
Definition: MassSpringPlyReaderDelegate.h:165
void * beginBoundaryConditions(const std::string &elementName, size_t boundaryConditionCount)
Callback function, begin the processing of boundary conditions.
Definition: MassSpringPlyReaderDelegate.cpp:253
Mass data containing 3 translational dofs and mass.
Definition: MassSpringPlyReaderDelegate.h:159
bool fileIsAcceptable(const SurgSim::DataStructures::PlyReader &reader) override
Check whether the file in the reader can be used with this delegate, this gives the delegate a chance...
Definition: MassSpringPlyReaderDelegate.cpp:142
Internal data to receive the element (nodeId) data.
Definition: MassSpringPlyReaderDelegate.h:184
void * beginThickness(const std::string &elementName, size_t thicknessCount)
Callback function, begin the processing of thickness.
Definition: MassSpringPlyReaderDelegate.cpp:275
virtual void endParseFile()
Callback for end of PlyReader::parseFile.
Definition: MassSpringPlyReaderDelegate.cpp:286
double m_thickness
Thickness information, if any.
Definition: MassSpringPlyReaderDelegate.h:211
unsigned int m_boundaryConditionData
Internal data to receive the "boundary_condition" element.
Definition: MassSpringPlyReaderDelegate.h:172
void * beginRadius(const std::string &elementName, size_t radiusCount)
Callback function, begin the processing of radius.
Definition: MassSpringPlyReaderDelegate.cpp:264
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ...
Definition: PlyReader.h:85
virtual void processVertex(const std::string &elementName)
Callback function to process one vertex.
Definition: MassSpringPlyReaderDelegate.cpp:182
void endRadius(const std::string &elementName)
Callback function, end the processing of radius.
Definition: MassSpringPlyReaderDelegate.cpp:269
bool m_has3dElement
Flag indicating if the associated file has 3d elements.
Definition: MassSpringPlyReaderDelegate.h:181
bool m_hasRadius
Flag indicating if the associated file has a radius.
Definition: MassSpringPlyReaderDelegate.h:204
bool m_has1dElement
Flag indicating if the associated file has 1d elements.
Definition: MassSpringPlyReaderDelegate.h:175
virtual void * beginVertices(const std::string &elementName, size_t vertexCount)
Callback function, begin the processing of vertices.
Definition: MassSpringPlyReaderDelegate.cpp:176
bool m_has2dElement
Flag indicating if the associated file has 2d elements.
Definition: MassSpringPlyReaderDelegate.h:178
double m_radius
Radius information, if any.
Definition: MassSpringPlyReaderDelegate.h:206
void * beginElements(const std::string &elementName, size_t elementCount)
Callback function, begin the processing of Elements.
Definition: MassSpringPlyReaderDelegate.cpp:198
bool m_hasBoundaryConditions
Flag indicating if the associated file has boundary conditions.
Definition: MassSpringPlyReaderDelegate.h:169
MassSpringPlyReaderDelegate()
Default constructor.
Definition: MassSpringPlyReaderDelegate.cpp:30
virtual void endVertices(const std::string &elementName)
Callback function to finalize processing of vertices.
Definition: MassSpringPlyReaderDelegate.cpp:191
Common part of implementation of PlyReaderDelegate for MassSpringRepresentations. ...
Definition: MassSpringPlyReaderDelegate.h:69
void endElements(const std::string &elementName)
Callback function to finalize processing of Elements.
Definition: MassSpringPlyReaderDelegate.cpp:217
void * beginSprings(const std::string &elementName, size_t elementCount)
Callback function, begin the processing of Springs.
Definition: MassSpringPlyReaderDelegate.cpp:225
bool m_hasThickness
Flag indicating if the associated file has a thickness.
Definition: MassSpringPlyReaderDelegate.h:209
void endSprings(const std::string &elementName)
Callback function to finalize processing of Springs.
Definition: MassSpringPlyReaderDelegate.cpp:245
std::shared_ptr< MassSpringModel > m_mesh
MassSpringModel to contain the ply file information.
Definition: MassSpringPlyReaderDelegate.h:214
void endThickness(const std::string &elementName)
Callback function, end the processing of thickness.
Definition: MassSpringPlyReaderDelegate.cpp:280
bool registerDelegate(SurgSim::DataStructures::PlyReader *reader) override
Registers the delegate with the reader.
Definition: MassSpringPlyReaderDelegate.cpp:41
PlyReaderDelegate abstract class.
Definition: PlyReaderDelegate.h:31