TriangleMeshPlyReaderDelegate.h
Go to the documentation of this file.
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 
26 
27 namespace SurgSim
28 {
29 namespace DataStructures
30 {
31 
33 template <class M>
35 {
36 public:
37 
38  typedef M MeshType;
39 
42 
45  explicit TriangleMeshPlyReaderDelegate(std::shared_ptr<MeshType> mesh);
46 
49  std::shared_ptr<MeshType> getMesh();
50 
54  virtual bool registerDelegate(PlyReader* reader) override;
55 
59  virtual bool fileIsAcceptable(const PlyReader& reader) override;
60 
65  void* beginVertices(const std::string& elementName, size_t vertexCount);
66 
69  virtual void processVertex(const std::string& elementName);
70 
73  void endVertices(const std::string& elementName);
74 
79  void* beginFaces(const std::string& elementName, size_t faceCount);
80 
83  void processFace(const std::string& elementName);
84 
87  void endFaces(const std::string& elementName);
88 
90  void endFile();
91 
92 protected:
93 
95  bool hasTextureCoordinates();
96 
99  struct VertexData
100  {
101  double x;
102  double y;
103  double z;
104  int64_t overrun1;
105  double s;
106  double t;
107  int64_t overrun2;
108  } m_vertexData;
109 
111  struct FaceData
112  {
113  unsigned int edgeCount;
114  unsigned int* indices;
115  int64_t overrun;
116  } m_faceData;
117 
119  std::shared_ptr<MeshType> m_mesh;
120 
121  // Statically allocated index array to receive data for the faces
122  std::array<size_t, 3> m_indices;
123 
124 private:
127 
128 };
129 
130 }
131 }
132 
134 
135 #endif
Definition: DriveElementFromInputBehavior.cpp:27
std::shared_ptr< MeshType > getMesh()
Gets the mesh.
Definition: TriangleMeshPlyReaderDelegate-inl.h:35
M MeshType
Definition: TriangleMeshPlyReaderDelegate.h:38
bool hasTextureCoordinates()
Definition: TriangleMeshPlyReaderDelegate-inl.h:153
virtual void processVertex(const std::string &elementName)
Callback function to process one vertex.
Definition: TriangleMeshPlyReaderDelegate-inl.h:105
void endFaces(const std::string &elementName)
Callback function to finalize processing of faces.
Definition: TriangleMeshPlyReaderDelegate-inl.h:139
Internal structure, the receiver for data from the "vertex" element Provide space for standard ply ve...
Definition: TriangleMeshPlyReaderDelegate.h:99
virtual bool registerDelegate(PlyReader *reader) override
Registers the delegate with the reader, overridden from.
Definition: TriangleMeshPlyReaderDelegate-inl.h:41
double x
Definition: TriangleMeshPlyReaderDelegate.h:101
double z
Definition: TriangleMeshPlyReaderDelegate.h:103
std::array< size_t, 3 > m_indices
Definition: TriangleMeshPlyReaderDelegate.h:122
int64_t overrun
Used to check for buffer overruns.
Definition: TriangleMeshPlyReaderDelegate.h:115
bool m_hasTextureCoordinates
Set to true if s/t coordinates are found in the .ply file.
Definition: TriangleMeshPlyReaderDelegate.h:126
void endVertices(const std::string &elementName)
Callback function to finalize processing of vertices.
Definition: TriangleMeshPlyReaderDelegate-inl.h:112
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:20
void endFile()
Callback function to finalize processing of the mesh.
Definition: TriangleMeshPlyReaderDelegate-inl.h:147
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
Implementation of PlyReaderDelegate for simple triangle meshes.
Definition: TriangleMeshPlyReaderDelegate.h:34
struct SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData m_vertexData
int64_t overrun2
Used to check for buffer overruns.
Definition: TriangleMeshPlyReaderDelegate.h:107
Internal structure, the received for data from the "face" element.
Definition: TriangleMeshPlyReaderDelegate.h:111
double s
Definition: TriangleMeshPlyReaderDelegate.h:105
unsigned int edgeCount
Definition: TriangleMeshPlyReaderDelegate.h:113
double t
Definition: TriangleMeshPlyReaderDelegate.h:106
void processFace(const std::string &elementName)
Callback function to process one face.
Definition: TriangleMeshPlyReaderDelegate-inl.h:129
std::shared_ptr< MeshType > m_mesh
The mesh that will be created.
Definition: TriangleMeshPlyReaderDelegate.h:119
void * beginVertices(const std::string &elementName, size_t vertexCount)
Callback function, begin the processing of vertices.
Definition: TriangleMeshPlyReaderDelegate-inl.h:95
struct SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::FaceData m_faceData
unsigned int * indices
Definition: TriangleMeshPlyReaderDelegate.h:114
virtual bool fileIsAcceptable(const PlyReader &reader) override
Check whether this file is acceptable to the delegate, overridden from.
Definition: TriangleMeshPlyReaderDelegate-inl.h:80
int64_t overrun1
Used to check for buffer overruns.
Definition: TriangleMeshPlyReaderDelegate.h:104
double y
Definition: TriangleMeshPlyReaderDelegate.h:102
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:120