MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
mgx::util::PlyFile Class Reference

Class representing the content of a PLY file. More...

#include <PlyFile.hpp>

Classes

class  Element
 Class representing an element. More...
 
class  Property
 Class representing a property in an element. More...
 

Public Types

enum  TYPE {
  CHAR, UCHAR, SHORT, USHORT,
  INT, UINT, FLOAT, DOUBLE,
  NB_TYPES, INVALID_TYPE
}
 Enumeration for the possible types of the properties. More...
 
enum  FORMAT_TYPES { UNSPECIFIED_FORMAT, ASCII, BINARY_LITTLE_ENDIAN, BINARY_BIG_ENDIAN }
 Enumeration of the possible file formats. More...
 

Public Member Functions

 PlyFile ()
 Create a new file.
 
void clear ()
 Remove any element from the file, and reset version number and format.
 
bool init (FORMAT_TYPES format=BINARY_LITTLE_ENDIAN, const QString &version="1.0")
 Initialize the file with a format and a version.
 
bool validate ()
 Validate the content. More...
 
void allocate ()
 Allocate all the properties of all the element in the file.
 
FORMAT_TYPES format () const
 Format of the file.
 
bool setFormat (FORMAT_TYPES f)
 Set the file format, checking the validity of the argument.
 
bool setVersion (QString version)
 Set the format version, checking it's validity.
 
const QStringversion () const
 Version fo the format.
 
Elementelement (size_t idx)
 Access an element by index.
 
const Elementelement (size_t idx) const
 Access an element by index.
 
Elementelement (const QString &name)
 Access an element by name.
 
const Elementelement (const QString &name) const
 Access an element by name.
 
ElementcreateElement (const QString &name, size_t nb_elements)
 Create a element name with nb_elements items.
 
ElementcurrentElement ()
 Get the current element (i.e. More...
 
bool hasElement (const QString &name) const
 Check if the element name exists.
 
size_t nbElements () const
 Return the number of elements in the file.
 
bool attach (Element *el)
 Attach an element to the file.
 
bool detach (Element *el)
 Detach an element from the file.
 
bool parseHeader (const QString &filename)
 Parse the head of a PLY file. More...
 
bool parseContent ()
 Parse the content of the current file. More...
 
bool error (const QString err) const
 Write the error on standard out, possibly with file and line number if they have been specified. More...
 
bool save (const QString &filename) const
 Save the file to filename.
 
qint64 contentPosition () const
 Get the position of the content in a file. More...
 
bool isValid () const
 Check if the last call to PlyFile::validate was successful of not.
 
 operator bool () const
 Check if the last call to PlyFile::validate was successful of not.
 
const QStringListcomments () const
 See the comments currently defined.
 
void addComment (QString line)
 Add a comment. More...
 
void clearComments ()
 Remove all comments.
 
void _attach (Element *el)
 
void _detach (Element *el)
 

Static Public Attributes

static const unsigned int typeSizes [NB_TYPES]
 Array holding the size in byte of the various types.
 
static char const *const typeNames [NB_TYPES+1]
 Array of C-string representation of the types.
 
static char const *const formatNames [4]
 Array of C-string representation of the formats.
 

Protected Member Functions

bool parseAsciiContent (QFile &f)
 
bool parseBinaryContent (QFile &f, bool little_endian)
 
bool readFormat (const QStringList &fields)
 
bool readElement (const QStringList &fields)
 
bool readProperty (const QStringList &fields)
 
bool writeHeader (QFile &f) const
 
bool writeAsciiContent (QFile &f) const
 
bool writeBinaryContent (QFile &f, bool little_endian) const
 
TYPE parseType (QString typeName) const
 

Protected Attributes

QList< Element * > _elements
 
QHash< QString, int > _element_map
 
Elementcurrent_element
 
QString filename
 
int line_nb
 
FORMAT_TYPES _format
 
QString _version
 
QStringList _comments
 
int _version_major
 
int _version_minor
 
bool is_valid
 
qint64 _contentPosition
 

Detailed Description

Class representing the content of a PLY file.

A PLY file is a collection of elements, with a format and a version number (that currently should be 1.0).

Each element has a name, that must be unique in the file, a size (i.e. how many items they contain), and a set of properties, shared by the elements.

Each property has:

Member Enumeration Documentation

Enumeration of the possible file formats.

Enumerator
UNSPECIFIED_FORMAT 

The format is not yet specified.

ASCII 

The content is written in ASCII.

BINARY_LITTLE_ENDIAN 

The content is written in binary with little endian representation of numbers.

BINARY_BIG_ENDIAN 

The content is written in binary with big endian representation of numbers.

Enumeration for the possible types of the properties.

Enumerator
CHAR 

8 bits signed integer

UCHAR 

8 bits unsigned integer

SHORT 

16 bits signed integer

USHORT 

16 bits unsigned integer

INT 

32 bits signed integer

UINT 

32 bits unsigned integer

FLOAT 

32 bits floating point

DOUBLE 

64 bits floating point

NB_TYPES 

Number of types, also used to mark an invalid type.

Member Function Documentation

void mgx::util::PlyFile::addComment ( QString  line)

Add a comment.

If the line contains new lines, it will be split

qint64 mgx::util::PlyFile::contentPosition ( ) const
inline

Get the position of the content in a file.

This is set by PlyFile::parseHeader

Element* mgx::util::PlyFile::currentElement ( )
inline

Get the current element (i.e.

the last one created with createElement

bool mgx::util::PlyFile::error ( const QString  err) const

Write the error on standard out, possibly with file and line number if they have been specified.

Then, returns false.

bool mgx::util::PlyFile::parseContent ( )

Parse the content of the current file.

The file's header must have been parsed. This gives the user the opportunity to change the memory type of the properties before reading. Also, any property with a INVALID_TYPE memory type will be skipped instead of read.

bool mgx::util::PlyFile::parseHeader ( const QString filename)

Parse the head of a PLY file.

Returns
True if the header has been correctly parsed
bool mgx::util::PlyFile::validate ( )

Validate the content.

This must be called before writing


The documentation for this class was generated from the following file: