PlyReader.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_PLYREADER_H
#define SURGSIM_DATASTRUCTURES_PLYREADER_H
#include <string>
#include <functional>
#include <memory>
#include <unordered_map>
#include <vector>
namespace SurgSim
{
namespace DataStructures
{
class PlyReaderDelegate;
class PlyReader
{
public:
enum Type
{
TYPE_INVALID = 0,
TYPE_CHAR,
TYPE_SHORT,
TYPE_INT,
TYPE_UNSIGNED_CHAR,
TYPE_UNSIGNED_SHORT,
TYPE_UNSIGNED_INT,
TYPE_FLOAT,
TYPE_DOUBLE,
TYPE_COUNT
};
typedef std::function<void* (const std::string&, size_t)> StartElementCallbackType;
typedef std::function<void (const std::string&)> StandardCallbackType;
explicit PlyReader(const std::string& filename);
virtual ~PlyReader();
bool isValid() const;
bool requestElement(const std::string& elementName,
std::function<void* (const std::string&, size_t)> startElementCallback,
std::function<void (const std::string&)> processElementCallback,
std::function<void (const std::string&)> endElementCallback);
bool requestScalarProperty(const std::string& elementName, const std::string& propertyName,
int dataType, int dataOffset);
bool requestListProperty(const std::string& elementName,
const std::string& propertyName,
int dataType, int dataOffset,
int countType, int countOffset);
bool hasElement(const std::string& elementName) const;
bool hasProperty(const std::string& elementName, const std::string& propertyName) const;
bool isScalar(const std::string& elementName, const std::string& propertyName) const;
bool parseWithDelegate(std::shared_ptr<PlyReaderDelegate> delegate);
void setStartParseFileCallback(std::function<void (void)> startParseFileCallback);
void setEndParseFileCallback(std::function<void (void)> endParseFileCallback);
bool setDelegate(std::shared_ptr<PlyReaderDelegate> delegate);
void parseFile();
private:
friend class PlyReaderTests;
bool requestProperty(const std::string& elementName,
const std::string& propertyName,
int dataType, int dataOffset,
int countType, int countOffset);
std::string m_filename;
struct PropertyInfo
{
std::string propertyName;
int dataType;
int dataOffset;
int countType;
int countOffset;
};
struct ElementInfo
{
std::string name;
StartElementCallbackType startElementCallback;
StandardCallbackType processElementCallback;
StandardCallbackType endElementCallback;
std::vector<PropertyInfo> requestedProperties;
};
std::unordered_map<std::string, ElementInfo> m_requestedElements;
struct Data;
std::unique_ptr<Data> m_data;
std::shared_ptr<PlyReaderDelegate> m_delegate;
std::function<void(void)> m_startParseFileCallback;
std::function<void(void)> m_endParseFileCallback;
};
} // DataStructures
} // SurgSim
#endif // SURGSIM_DATASTRUCTURES_PLYREADER_H
SurgSim::DataStructures::PlyReader::parseFile
void parseFile()
Parse the file.
Definition: PlyReader.cpp:211
SurgSim::DataStructures::PlyReader::TYPE_INVALID
Definition: PlyReader.h:91
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::PlyReader::TYPE_COUNT
Definition: PlyReader.h:100
SurgSim::DataStructures::PlyReader::hasProperty
bool hasProperty(const std::string &elementName, const std::string &propertyName) const
Query if &#39;elementName&#39; has the given property.
Definition: PlyReader.cpp:350
SurgSim::DataStructures::PlyReader::TYPE_INT
Definition: PlyReader.h:94
SurgSim::DataStructures::PlyReader::~PlyReader
virtual ~PlyReader()
Destructor.
Definition: PlyReader.cpp:74
SurgSim::DataStructures::PlyReader::hasElement
bool hasElement(const std::string &elementName) const
Query if this elementName is in the .ply file.
Definition: PlyReader.cpp:343
SurgSim::DataStructures::PlyReader::requestScalarProperty
bool requestScalarProperty(const std::string &elementName, const std::string &propertyName, int dataType, int dataOffset)
Request a scalar property for parsing.
Definition: PlyReader.cpp:118
SurgSim::DataStructures::PlyReader::PropertyInfo
Information about the property on the .ply file.
Definition: PlyReader.h:230
SurgSim::DataStructures::PlyReader::setStartParseFileCallback
void setStartParseFileCallback(std::function< void(void)> startParseFileCallback)
Register callback to be called at the begining of parseFile.
Definition: PlyReader.cpp:132
SurgSim::DataStructures::PlyReader::m_delegate
std::shared_ptr< PlyReaderDelegate > m_delegate
The delegate.
Definition: PlyReader.h:258
SurgSim::DataStructures::PlyReader::StandardCallbackType
std::function< void(const std::string &)> StandardCallbackType
The callback that is used for the processing and the end of processing, the parameter passed is the n...
Definition: PlyReader.h:111
SurgSim::DataStructures::PlyReader::TYPE_UNSIGNED_INT
Definition: PlyReader.h:97
SurgSim::DataStructures::PlyReader::m_data
std::unique_ptr< Data > m_data
Definition: PlyReader.h:253
SurgSim::DataStructures::PlyReader::TYPE_UNSIGNED_CHAR
Definition: PlyReader.h:95
SurgSim::DataStructures::PlyReader::PropertyInfo::dataType
int dataType
Type of the receiving data.
Definition: PlyReader.h:233
SurgSim::DataStructures::PlyReader::TYPE_DOUBLE
Definition: PlyReader.h:99
SurgSim::DataStructures::PlyReader::PropertyInfo::propertyName
std::string propertyName
Name of the property.
Definition: PlyReader.h:232
SurgSim::DataStructures::PlyReader::Data
Definition: PlyReader.cpp:34
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::PlyReader::PropertyInfo::dataOffset
int dataOffset
Location for the receiving data.
Definition: PlyReader.h:234
SurgSim::DataStructures::PlyReader::Type
Type
Values that represent the data type/size of requested data.
Definition: PlyReader.h:89
SurgSim::DataStructures::PlyReader::PlyReader
PlyReader(const std::string &filename)
Constructor.
Definition: PlyReader.cpp:60
SurgSim::DataStructures::PlyReader::ElementInfo::processElementCallback
StandardCallbackType processElementCallback
Callback to be used for each processed element.
Definition: PlyReader.h:244
SurgSim::DataStructures::PlyReader::setDelegate
bool setDelegate(std::shared_ptr< PlyReaderDelegate > delegate)
Sets a delegate for parsing.
Definition: PlyReader.cpp:196
SurgSim::DataStructures::PlyReader::m_filename
std::string m_filename
The name of the .ply file.
Definition: PlyReader.h:227
SurgSim::DataStructures::PlyReader::PropertyInfo::countOffset
int countOffset
For lists, location of the receiving data for the count.
Definition: PlyReader.h:236
SurgSim::DataStructures::PlyReader::requestListProperty
bool requestListProperty(const std::string &elementName, const std::string &propertyName, int dataType, int dataOffset, int countType, int countOffset)
Request a list property for parsing.
Definition: PlyReader.cpp:124
SurgSim::DataStructures::PlyReader::isScalar
bool isScalar(const std::string &elementName, const std::string &propertyName) const
Query if the property of the give element is scalar.
Definition: PlyReader.cpp:364
SurgSim::DataStructures::PlyReader::TYPE_CHAR
Definition: PlyReader.h:92
SurgSim::DataStructures::PlyReader::PlyReaderTests
friend class PlyReaderTests
Definition: PlyReader.h:209
SurgSim::DataStructures::PlyReader::TYPE_UNSIGNED_SHORT
Definition: PlyReader.h:96
SurgSim::DataStructures::PlyReader::TYPE_SHORT
Definition: PlyReader.h:93
SurgSim::DataStructures::PlyReader::requestElement
bool requestElement(const std::string &elementName, std::function< void *(const std::string &, size_t)> startElementCallback, std::function< void(const std::string &)> processElementCallback, std::function< void(const std::string &)> endElementCallback)
Request element to be processed during parsing.
Definition: PlyReader.cpp:94
SurgSim::DataStructures::PlyReader::m_startParseFileCallback
std::function< void(void)> m_startParseFileCallback
Callback to be executed at the start of &#39;parseFile&#39;.
Definition: PlyReader.h:261
SurgSim::DataStructures::PlyReader::m_requestedElements
std::unordered_map< std::string, ElementInfo > m_requestedElements
Definition: PlyReader.h:249
SurgSim::DataStructures::PlyReader::requestProperty
bool requestProperty(const std::string &elementName, const std::string &propertyName, int dataType, int dataOffset, int countType, int countOffset)
Generic Internal function to handle list and scalar properties, see requestScalarProperty() and reque...
Definition: PlyReader.cpp:142
SurgSim::DataStructures::PlyReader::StartElementCallbackType
std::function< void *(const std::string &, size_t)> StartElementCallbackType
The callback that is being used to indicate the start of an element, the parameters that are passed i...
Definition: PlyReader.h:107
SurgSim::DataStructures::PlyReader::ElementInfo::startElementCallback
StartElementCallbackType startElementCallback
Callback to be used when the element is first encountered.
Definition: PlyReader.h:243
SurgSim::DataStructures::PlyReader::ElementInfo::requestedProperties
std::vector< PropertyInfo > requestedProperties
All the properties that are wanted.
Definition: PlyReader.h:246
SurgSim::DataStructures::PlyReader::ElementInfo::name
std::string name
Name of the element.
Definition: PlyReader.h:242
SurgSim::DataStructures::PlyReader::isValid
bool isValid() const
Query if this object is valid.
Definition: PlyReader.cpp:89
SurgSim::DataStructures::PlyReader::m_endParseFileCallback
std::function< void(void)> m_endParseFileCallback
Callback to be executed at the end of &#39;parseFile&#39;.
Definition: PlyReader.h:264
SurgSim::DataStructures::PlyReader::ElementInfo
Information about the element in the .ply file.
Definition: PlyReader.h:240
SurgSim::DataStructures::PlyReader::setEndParseFileCallback
void setEndParseFileCallback(std::function< void(void)> endParseFileCallback)
Register callback to be called at the end of parseFile.
Definition: PlyReader.cpp:137
SurgSim::DataStructures::PlyReader::TYPE_FLOAT
Definition: PlyReader.h:98
SurgSim::DataStructures::PlyReader::parseWithDelegate
bool parseWithDelegate(std::shared_ptr< PlyReaderDelegate > delegate)
Sets a delegate for parsing and then parse the file.
Definition: PlyReader.cpp:333
SurgSim::DataStructures::PlyReader::ElementInfo::endElementCallback
StandardCallbackType endElementCallback
Callback to be used after all the elements have been processed.
Definition: PlyReader.h:245
SurgSim::DataStructures::PlyReader::PropertyInfo::countType
int countType
For lists, type of the receiving data for the count of listelements.
Definition: PlyReader.h:235