TriangleMeshPlyReaderDelegate.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_DATASTRUCTURES_TRIANGLEMESHPLYREADERDELEGATE_H
#define SURGSIM_DATASTRUCTURES_TRIANGLEMESHPLYREADERDELEGATE_H
#include <array>
#include <memory>
#include "SurgSim/DataStructures/EmptyData.h"
#include "SurgSim/DataStructures/PlyReader.h"
#include "SurgSim/DataStructures/PlyReaderDelegate.h"
namespace SurgSim
{
namespace DataStructures
{
template <class M>
class TriangleMeshPlyReaderDelegate : public PlyReaderDelegate
{
public:
typedef M MeshType;
TriangleMeshPlyReaderDelegate();
explicit TriangleMeshPlyReaderDelegate(std::shared_ptr<MeshType> mesh);
std::shared_ptr<MeshType> getMesh();
bool registerDelegate(PlyReader* reader) override;
bool fileIsAcceptable(const PlyReader& reader) override;
void* beginVertices(const std::string& elementName, size_t vertexCount);
virtual void processVertex(const std::string& elementName);
void endVertices(const std::string& elementName);
void* beginFaces(const std::string& elementName, size_t faceCount);
void processFace(const std::string& elementName);
void endFaces(const std::string& elementName);
void* beginEdges(const std::string& elementName, size_t edgeCount);
void processEdge(const std::string& elementName);
void endEdges(const std::string& elementName);
void endFile();
protected:
bool hasTextureCoordinates();
struct VertexData
{
double x;
double y;
double z;
int64_t overrun1;
double s;
double t;
int64_t overrun2;
} m_vertexData;
struct ListData
{
unsigned int count;
unsigned int* indices;
int64_t overrun;
} m_listData;
std::shared_ptr<MeshType> m_mesh;
// Statically allocated index array to receive data for the faces
std::array<size_t, 3> m_face;
std::array<size_t, 2> m_edge;
private:
bool m_hasTextureCoordinates;
bool m_hasFaces;
bool m_hasEdges;
};
};
};
#include "SurgSim/DataStructures/TriangleMeshPlyReaderDelegate-inl.h"
#endif
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::ListData::indices
unsigned int * indices
Definition: TriangleMeshPlyReaderDelegate.h:119
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::getMesh
std::shared_ptr< MeshType > getMesh()
Gets the mesh.
Definition: TriangleMeshPlyReaderDelegate-inl.h:46
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::MeshType
M MeshType
Definition: TriangleMeshPlyReaderDelegate.h:37
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::hasTextureCoordinates
bool hasTextureCoordinates()
Definition: TriangleMeshPlyReaderDelegate-inl.h:189
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::processVertex
virtual void processVertex(const std::string &elementName)
Callback function to process one vertex.
Definition: TriangleMeshPlyReaderDelegate-inl.h:141
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::endFaces
void endFaces(const std::string &elementName)
Callback function to finalize processing of faces.
Definition: TriangleMeshPlyReaderDelegate-inl.h:175
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData
Internal structure, the receiver for data from the "vertex" element Provide space for standard ply ve...
Definition: TriangleMeshPlyReaderDelegate.h:104
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::registerDelegate
bool registerDelegate(PlyReader *reader) override
Registers the delegate with the reader, overridden from.
Definition: TriangleMeshPlyReaderDelegate-inl.h:52
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData::x
double x
Definition: TriangleMeshPlyReaderDelegate.h:106
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData::z
double z
Definition: TriangleMeshPlyReaderDelegate.h:108
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::ListData
Internal structure, the received for data from the "face" element.
Definition: TriangleMeshPlyReaderDelegate.h:116
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::processEdge
void processEdge(const std::string &elementName)
Definition: TriangleMeshPlyReaderDelegate-inl.h:204
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::m_hasTextureCoordinates
bool m_hasTextureCoordinates
Set to true if s/t coordinates are found in the .ply file.
Definition: TriangleMeshPlyReaderDelegate.h:132
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::endVertices
void endVertices(const std::string &elementName)
Callback function to finalize processing of vertices.
Definition: TriangleMeshPlyReaderDelegate-inl.h:148
SurgSim::DataStructures::PlyReader
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ...
Definition: PlyReader.h:85
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::m_face
std::array< size_t, 3 > m_face
Definition: TriangleMeshPlyReaderDelegate.h:127
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::TriangleMeshPlyReaderDelegate
TriangleMeshPlyReaderDelegate()
Default constructor.
Definition: TriangleMeshPlyReaderDelegate-inl.h:24
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::endFile
void endFile()
Callback function to finalize processing of the mesh.
Definition: TriangleMeshPlyReaderDelegate-inl.h:183
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::m_hasFaces
bool m_hasFaces
Set to true if faces are found in the .ply file.
Definition: TriangleMeshPlyReaderDelegate.h:135
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate
Implementation of PlyReaderDelegate for simple triangle meshes.
Definition: TriangleMeshPlyReaderDelegate.h:33
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::m_hasEdges
bool m_hasEdges
Set to true if edges are found in the .ply file.
Definition: TriangleMeshPlyReaderDelegate.h:138
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::m_vertexData
struct SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData m_vertexData
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData::overrun2
int64_t overrun2
Used to check for buffer overruns.
Definition: TriangleMeshPlyReaderDelegate.h:112
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData::s
double s
Definition: TriangleMeshPlyReaderDelegate.h:110
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::m_edge
std::array< size_t, 2 > m_edge
Definition: TriangleMeshPlyReaderDelegate.h:128
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData::t
double t
Definition: TriangleMeshPlyReaderDelegate.h:111
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::processFace
void processFace(const std::string &elementName)
Callback function to process one face.
Definition: TriangleMeshPlyReaderDelegate-inl.h:165
TriangleMeshPlyReaderDelegate-inl.h
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::m_mesh
std::shared_ptr< MeshType > m_mesh
The mesh that will be created.
Definition: TriangleMeshPlyReaderDelegate.h:124
PlyReader.h
PlyReaderDelegate.h
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::ListData::overrun
int64_t overrun
Used to check for buffer overruns.
Definition: TriangleMeshPlyReaderDelegate.h:120
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::beginVertices
void * beginVertices(const std::string &elementName, size_t vertexCount)
Callback function, begin the processing of vertices.
Definition: TriangleMeshPlyReaderDelegate-inl.h:131
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::fileIsAcceptable
bool fileIsAcceptable(const PlyReader &reader) override
Check whether this file is acceptable to the delegate, overridden from.
Definition: TriangleMeshPlyReaderDelegate-inl.h:111
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::ListData::count
unsigned int count
Definition: TriangleMeshPlyReaderDelegate.h:118
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData::overrun1
int64_t overrun1
Used to check for buffer overruns.
Definition: TriangleMeshPlyReaderDelegate.h:109
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::beginEdges
void * beginEdges(const std::string &elementName, size_t edgeCount)
Definition: TriangleMeshPlyReaderDelegate-inl.h:195
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::endEdges
void endEdges(const std::string &elementName)
Definition: TriangleMeshPlyReaderDelegate-inl.h:215
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::VertexData::y
double y
Definition: TriangleMeshPlyReaderDelegate.h:107
EmptyData.h
SurgSim::DataStructures::PlyReaderDelegate
PlyReaderDelegate abstract class.
Definition: PlyReaderDelegate.h:31
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::m_listData
struct SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::ListData m_listData
SurgSim::DataStructures::TriangleMeshPlyReaderDelegate::beginFaces
void * beginFaces(const std::string &elementName, size_t faceCount)
Callback function, begin the processing of faces.
Definition: TriangleMeshPlyReaderDelegate-inl.h:156