opensurgsim
TriangleMeshPlyReaderDelegate.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, 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_DATASTRUCTURES_TRIANGLEMESHPLYREADERDELEGATE_H
17 #define SURGSIM_DATASTRUCTURES_TRIANGLEMESHPLYREADERDELEGATE_H
18 
19 #include <array>
20 #include <memory>
21 
22 #include "SurgSim/DataStructures/EmptyData.h"
23 #include "SurgSim/DataStructures/PlyReader.h"
24 #include "SurgSim/DataStructures/PlyReaderDelegate.h"
25 
26 namespace SurgSim
27 {
28 namespace DataStructures
29 {
30 
32 template <class M>
34 {
35 public:
36 
37  typedef M MeshType;
38 
41 
44  explicit TriangleMeshPlyReaderDelegate(std::shared_ptr<MeshType> mesh);
45 
48  std::shared_ptr<MeshType> getMesh();
49 
53  bool registerDelegate(PlyReader* reader) override;
54 
58  bool fileIsAcceptable(const PlyReader& reader) override;
59 
64  void* beginVertices(const std::string& elementName, size_t vertexCount);
65 
68  virtual void processVertex(const std::string& elementName);
69 
72  void endVertices(const std::string& elementName);
73 
78  void* beginFaces(const std::string& elementName, size_t faceCount);
79 
82  void processFace(const std::string& elementName);
83 
86  void endFaces(const std::string& elementName);
87 
88  void* beginEdges(const std::string& elementName, size_t edgeCount);
89 
90  void processEdge(const std::string& elementName);
91 
92  void endEdges(const std::string& elementName);
93 
95  void endFile();
96 
97 protected:
98 
100  bool hasTextureCoordinates();
101 
104  struct VertexData
105  {
106  double x = std::numeric_limits<double>::signaling_NaN();
107  double y = std::numeric_limits<double>::signaling_NaN();
108  double z = std::numeric_limits<double>::signaling_NaN();
109  int64_t overrun1 = -1;
110  double s = std::numeric_limits<double>::signaling_NaN();
111  double t = std::numeric_limits<double>::signaling_NaN();
112  int64_t overrun2 = -1;
113  } m_vertexData;
114 
116  struct ListData
117  {
118  unsigned int count = 0;
119  unsigned int* indices = nullptr;
120  int64_t overrun = -1;
121  } m_listData;
122 
124  std::shared_ptr<MeshType> m_mesh;
125 
126  // Statically allocated index array to receive data for the faces
127  std::array<size_t, 3> m_face;
128  std::array<size_t, 2> m_edge = {};
129 
130 private:
132  bool m_hasTextureCoordinates;
133 
135  bool m_hasFaces;
136 
138  bool m_hasEdges;
139 };
140 
141 
142 };
143 };
144 
145 #include "SurgSim/DataStructures/TriangleMeshPlyReaderDelegate-inl.h"
146 
147 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
std::shared_ptr< MeshType > getMesh()
Gets the mesh.
Definition: TriangleMeshPlyReaderDelegate-inl.h:46
bool hasTextureCoordinates()
Definition: TriangleMeshPlyReaderDelegate-inl.h:189
virtual void processVertex(const std::string &elementName)
Callback function to process one vertex.
Definition: TriangleMeshPlyReaderDelegate-inl.h:141
void endFaces(const std::string &elementName)
Callback function to finalize processing of faces.
Definition: TriangleMeshPlyReaderDelegate-inl.h:175
Internal structure, the receiver for data from the "vertex" element Provide space for standard ply ve...
Definition: TriangleMeshPlyReaderDelegate.h:104
bool registerDelegate(PlyReader *reader) override
Registers the delegate with the reader, overridden from.
Definition: TriangleMeshPlyReaderDelegate-inl.h:52
Internal structure, the received for data from the "face" element.
Definition: TriangleMeshPlyReaderDelegate.h:116
void endVertices(const std::string &elementName)
Callback function to finalize processing of vertices.
Definition: TriangleMeshPlyReaderDelegate-inl.h:148
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ...
Definition: PlyReader.h:85
TriangleMeshPlyReaderDelegate()
Default constructor.
Definition: TriangleMeshPlyReaderDelegate-inl.h:24
void endFile()
Callback function to finalize processing of the mesh.
Definition: TriangleMeshPlyReaderDelegate-inl.h:183
Implementation of PlyReaderDelegate for simple triangle meshes.
Definition: TriangleMeshPlyReaderDelegate.h:33
int64_t overrun2
Used to check for buffer overruns.
Definition: TriangleMeshPlyReaderDelegate.h:112
void processFace(const std::string &elementName)
Callback function to process one face.
Definition: TriangleMeshPlyReaderDelegate-inl.h:165
std::shared_ptr< MeshType > m_mesh
The mesh that will be created.
Definition: TriangleMeshPlyReaderDelegate.h:124
void * beginVertices(const std::string &elementName, size_t vertexCount)
Callback function, begin the processing of vertices.
Definition: TriangleMeshPlyReaderDelegate-inl.h:131
bool fileIsAcceptable(const PlyReader &reader) override
Check whether this file is acceptable to the delegate, overridden from.
Definition: TriangleMeshPlyReaderDelegate-inl.h:111
int64_t overrun1
Used to check for buffer overruns.
Definition: TriangleMeshPlyReaderDelegate.h:109
PlyReaderDelegate abstract class.
Definition: PlyReaderDelegate.h:31
void * beginFaces(const std::string &elementName, size_t faceCount)
Callback function, begin the processing of faces.
Definition: TriangleMeshPlyReaderDelegate-inl.h:156