opensurgsim
Fem-inl.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 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_FEM_INL_H
17 #define SURGSIM_PHYSICS_FEM_INL_H
18 
19 #include "SurgSim/DataStructures/PlyReader.h"
20 #include "SurgSim/Framework/Log.h"
21 
23 
24 namespace SurgSim
25 {
26 namespace Physics
27 {
28 
29 template <class VertexData, class Element>
31 {
32 }
33 
34 template <class VertexData, class Element>
35 size_t Fem<VertexData, Element>::addElement(std::shared_ptr<Element> element)
36 {
37  m_elements.push_back(element);
38  return m_elements.size() - 1;
39 }
40 
41 template <class VertexData, class Element>
43 {
44  return m_elements.size();
45 }
46 
47 template <class VertexData, class Element>
48 const std::vector<std::shared_ptr<Element>>&
50 {
51  return m_elements;
52 }
53 
54 template <class VertexData, class Element>
55 std::vector<std::shared_ptr<Element>>& Fem<VertexData, Element>::getElements()
56 {
57  return m_elements;
58 }
59 
60 template <class VertexData, class Element>
61 std::shared_ptr<Element> Fem<VertexData, Element>::getElement(size_t id) const
62 {
63  return m_elements[id];
64 }
65 
66 template <class VertexData, class Element>
67 size_t Fem<VertexData, Element>::addBoundaryCondition(size_t boundaryCondition)
68 {
69  m_boundaryConditions.push_back(boundaryCondition);
70  return m_boundaryConditions.size() - 1;
71 }
72 
73 template <class VertexData, class Element>
74 const std::vector<size_t>& Fem<VertexData, Element>::getBoundaryConditions() const
75 {
76  return m_boundaryConditions;
77 }
78 
79 template <class VertexData, class Element>
81 {
82  return m_boundaryConditions;
83 }
84 
85 template <class VertexData, class Element>
87 {
88  return m_boundaryConditions[id];
89 }
90 template <class VertexData, class Element> template <class PlyType, class FemType>
91 bool Fem<VertexData, Element>::loadFemFile(const std::string& filename)
92 {
93  SurgSim::DataStructures::PlyReader reader(filename);
94  if (!reader.isValid())
95  {
97  << "'" << filename << "' is an invalid .ply file.";
98  return false;
99  }
100 
101  auto delegate = std::make_shared<PlyType>(
102  std::dynamic_pointer_cast<FemType>(this->shared_from_this()));
103  if (!reader.parseWithDelegate(delegate))
104  {
106  << "The input file '" << filename << "' does not have the property required by FEM element mesh.";
107  return false;
108  }
109 
110  return true;
111 }
112 
113 } // namespace Physics
114 } // namespace SurgSim
115 
116 #endif // SURGSIM_PHYSICS_FEM_INL_H
size_t getBoundaryCondition(size_t id) const
Retrieves a specific boundary condition.
Definition: Fem-inl.h:86
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
const std::vector< size_t > & getBoundaryConditions() const
Gets entire vector of boundary conditions.
Definition: Fem-inl.h:74
std::shared_ptr< Element > getElement(size_t id) const
Retrieve a specific element from the mesh.
Definition: Fem-inl.h:61
The convenience header that provides the entirety of the logging API.
size_t addElement(std::shared_ptr< Element > element)
Adds FEM element to mesh of Element template type.
Definition: Fem-inl.h:35
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ...
Definition: PlyReader.h:85
const std::vector< std::shared_ptr< Element > > & getElements() const
Gets entire FEM element vector.
Definition: Fem-inl.h:49
bool loadFemFile(const std::string &filename)
Shared loading method for all 3 dimensions.
Definition: Fem-inl.h:91
size_t addBoundaryCondition(size_t boundaryCondition)
Add boundary condition to mesh.
Definition: Fem-inl.h:67
Fem()
Default constructor.
Definition: Fem-inl.h:30
bool isValid() const
Query if this object is valid.
Definition: PlyReader.cpp:92
static std::shared_ptr< Logger > getDefaultLogger()
Get default logger.
Definition: Logger.h:116
size_t getNumElements() const
Gets number of FEM elements in the mesh.
Definition: Fem-inl.h:42
bool parseWithDelegate(std::shared_ptr< PlyReaderDelegate > delegate)
Sets a delegate for parsing and then parse the file.
Definition: PlyReader.cpp:336
#define SURGSIM_LOG_SEVERE(logger)
Logs a message to the specified logger at the SEVERE level.
Definition: LogMacros.h:106