opensurgsim
FemPlyReaderDelegate.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2014-2015, 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_FEMPLYREADERDELEGATE_H
17 #define SURGSIM_PHYSICS_FEMPLYREADERDELEGATE_H
18 
19 #include <array>
20 #include <memory>
21 
22 #include "SurgSim/DataStructures/PlyReaderDelegate.h"
23 #include "SurgSim/Physics/Fem.h"
24 
25 namespace SurgSim
26 {
27 namespace Physics
28 {
29 
34 {
35 public:
38 
39 protected:
40  // \return Name of the element (1/2/3D), which this delegate processes.
41  virtual std::string getElementName() const = 0;
42 
44  bool fileIsAcceptable(const SurgSim::DataStructures::PlyReader& reader) override;
45 
47  virtual void endParseFile() = 0;
48 
53  virtual void* beginVertices(const std::string& elementName, size_t vertexCount);
54 
57  virtual void processVertex(const std::string& elementName) = 0;
58 
61  virtual void endVertices(const std::string& elementName);
62 
67  void* beginFemElements(const std::string& elementName, size_t elementCount);
68 
71  virtual void processFemElement(const std::string& elementName) = 0;
72 
75  void endFemElements(const std::string& elementName);
76 
81  void* beginMaterials(const std::string& elementName, size_t materialCount);
82 
85  void endMaterials(const std::string& elementName);
86 
91  void* beginBoundaryConditions(const std::string& elementName, size_t boundaryConditionCount);
92 
95  virtual void processBoundaryCondition(const std::string& elementName) = 0;
96 
97 protected:
99  struct Vertex6DData
100  {
101  double x = std::numeric_limits<double>::signaling_NaN();
102  double y = std::numeric_limits<double>::signaling_NaN();
103  double z = std::numeric_limits<double>::signaling_NaN();
104  int64_t overrun1 = -1;
105  double thetaX = std::numeric_limits<double>::signaling_NaN();
106  double thetaY = std::numeric_limits<double>::signaling_NaN();
107  double thetaZ = std::numeric_limits<double>::signaling_NaN();
108  int64_t overrun2 = -1;
109  } m_vertexData;
110 
113 
116 
119  {
120  double massDensity = std::numeric_limits<double>::signaling_NaN();
121  double poissonRatio = std::numeric_limits<double>::signaling_NaN();
122  double youngModulus = std::numeric_limits<double>::signaling_NaN();
123  int64_t overrun = -1;
124  } m_materialData;
125 
126  bool m_hasMaterial;
127  bool m_hasPerElementMaterial;
128 
130  struct ElementData
131  {
132  unsigned int type = 0; // “LinearBeam”, “CorotationalTetrahedron”…
133  int64_t overrun1 = -1;
134 
135  unsigned int* indices = nullptr;
136  unsigned int vertexCount = 0;
137  int64_t overrun2 = -1;
138  double massDensity = std::numeric_limits<double>::signaling_NaN();
139  double poissonRatio = std::numeric_limits<double>::signaling_NaN();
140  double youngModulus = std::numeric_limits<double>::signaling_NaN();
141  } m_elementData;
142  bool m_hasRotationDOF;
143 };
144 
145 } // namespace Physics
146 } // namespace SurgSim
147 
148 #endif // SURGSIM_PHYSICS_FEMPLYREADERDELEGATE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Internal data to receive the "material" data.
Definition: FemPlyReaderDelegate.h:118
Internal data to receive the fem element.
Definition: FemPlyReaderDelegate.h:130
void * beginMaterials(const std::string &elementName, size_t materialCount)
Callback function, begin the processing of materials.
Definition: FemPlyReaderDelegate.cpp:175
Common part of implementation of PlyReaderDelegate for FemRepresentations.
Definition: FemPlyReaderDelegate.h:33
FemPlyReaderDelegate()
Constructor.
Definition: FemPlyReaderDelegate.cpp:27
virtual void endVertices(const std::string &elementName)
Callback function to finalize processing of vertices.
Definition: FemPlyReaderDelegate.cpp:153
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ...
Definition: PlyReader.h:85
unsigned int m_boundaryConditionData
Internal data to receive the "boundary_condition" element.
Definition: FemPlyReaderDelegate.h:115
Vertex data containing 6 dofs (3 translational and 3 rotational)
Definition: FemPlyReaderDelegate.h:99
void * beginFemElements(const std::string &elementName, size_t elementCount)
Callback function, begin the processing of FemElements.
Definition: FemPlyReaderDelegate.cpp:160
virtual void processBoundaryCondition(const std::string &elementName)=0
Callback function to process one boundary condition.
virtual void * beginVertices(const std::string &elementName, size_t vertexCount)
Callback function, begin the processing of vertices.
Definition: FemPlyReaderDelegate.cpp:147
void * beginBoundaryConditions(const std::string &elementName, size_t boundaryConditionCount)
Callback function, begin the processing of boundary conditions.
Definition: FemPlyReaderDelegate.cpp:188
virtual void processFemElement(const std::string &elementName)=0
Callback function to process one FemElement.
void endFemElements(const std::string &elementName)
Callback function to finalize processing of FemElements.
Definition: FemPlyReaderDelegate.cpp:167
bool registerDelegate(SurgSim::DataStructures::PlyReader *reader) override
Registers the delegate with the reader.
Definition: FemPlyReaderDelegate.cpp:31
void endMaterials(const std::string &elementName)
Callback function, end the processing of materials.
Definition: FemPlyReaderDelegate.cpp:181
int64_t overrun2
Used to check for buffer overruns.
Definition: FemPlyReaderDelegate.h:108
virtual void processVertex(const std::string &elementName)=0
Callback function to process one vertex.
virtual void endParseFile()=0
Callback for end of PlyReader::parseFile.
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: FemPlyReaderDelegate.cpp:113
bool m_hasBoundaryConditions
Flag indicating if the associated file has boundary conditions.
Definition: FemPlyReaderDelegate.h:112
int64_t overrun1
Used to check for buffer overruns.
Definition: FemPlyReaderDelegate.h:104
PlyReaderDelegate abstract class.
Definition: PlyReaderDelegate.h:31