MorphoGraphX  2.0-1-227
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
mgx::PlyFile Class Reference

#include <PlyFile.hpp>

Classes

class  Element
 
class  Property
 

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. More...
 
void clear ()
 Remove any element from the file, and reset version number and format. More...
 
bool init (FORMAT_TYPES format=BINARY_LITTLE_ENDIAN, const QString &version="1.0")
 Initialize the file with a format and a version. More...
 
bool validate ()
 Validate the content. More...
 
void allocate ()
 Allocate all the properties of all the element in the file. More...
 
FORMAT_TYPES format () const
 Format of the file. More...
 
bool setFormat (FORMAT_TYPES f)
 Set the file format, checking the validity of the argument. More...
 
bool setVersion (QString version)
 Set the format version, checking it's validity. More...
 
const QString & version () const
 Version fo the format. More...
 
Elementelement (size_t idx)
 Access an element by index. More...
 
const Elementelement (size_t idx) const
 Access an element by index. More...
 
Elementelement (const QString &name)
 Access an element by name. More...
 
const Elementelement (const QString &name) const
 Access an element by name. More...
 
ElementcreateElement (const QString &name, size_t nb_elements)
 Create a element name with nb_elements items. More...
 
ElementcurrentElement ()
 Get the current element (i.e. More...
 
bool hasElement (const QString &name) const
 Check if the element name exists. More...
 
size_t nbElements () const
 Return the number of elements in the file. More...
 
bool attach (Element *el)
 Attach an element to the file. More...
 
bool detach (Element *el)
 Detach an element from the file. More...
 
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. More...
 
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. More...
 
 operator bool () const
 Check if the last call to PlyFile::validate was successful of not. More...
 
const QStringList & comments () const
 See the comments currently defined. More...
 
void addComment (QString line)
 Add a comment. More...
 
void clearComments ()
 Remove all comments. More...
 
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. More...
 
static char const *const typeNames [NB_TYPES+1][3]
 Array of C-string representation of the types. More...
 
static char const *const formatNames [4]
 Array of C-string representation of the formats. More...
 

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:

Definition at line 64 of file PlyFile.hpp.

Member Enumeration Documentation

◆ FORMAT_TYPES

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.

Definition at line 99 of file PlyFile.hpp.

◆ TYPE

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.

INVALID_TYPE 

Definition at line 68 of file PlyFile.hpp.

Constructor & Destructor Documentation

◆ PlyFile()

mgx::PlyFile::PlyFile ( )

Create a new file.

Member Function Documentation

◆ _attach()

void mgx::PlyFile::_attach ( Element el)

◆ _detach()

void mgx::PlyFile::_detach ( Element el)

◆ addComment()

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

Add a comment.

If the line contains new lines, it will be split

◆ allocate()

void mgx::PlyFile::allocate ( )

Allocate all the properties of all the element in the file.

◆ attach()

bool mgx::PlyFile::attach ( Element el)

Attach an element to the file.

◆ clear()

void mgx::PlyFile::clear ( )

Remove any element from the file, and reset version number and format.

◆ clearComments()

void mgx::PlyFile::clearComments ( )
inline

Remove all comments.

Definition at line 677 of file PlyFile.hpp.

◆ comments()

const QStringList& mgx::PlyFile::comments ( ) const
inline

See the comments currently defined.

Definition at line 663 of file PlyFile.hpp.

◆ contentPosition()

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

Get the position of the content in a file.

This is set by PlyFile::parseHeader

Definition at line 645 of file PlyFile.hpp.

◆ createElement()

Element* mgx::PlyFile::createElement ( const QString &  name,
size_t  nb_elements 
)

Create a element name with nb_elements items.

◆ currentElement()

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

Get the current element (i.e.

the last one created with createElement

Definition at line 589 of file PlyFile.hpp.

◆ detach()

bool mgx::PlyFile::detach ( Element el)

Detach an element from the file.

◆ element() [1/4]

Element* mgx::PlyFile::element ( const QString &  name)

Access an element by name.

◆ element() [2/4]

const Element* mgx::PlyFile::element ( const QString &  name) const

Access an element by name.

◆ element() [3/4]

Element* mgx::PlyFile::element ( size_t  idx)

Access an element by index.

◆ element() [4/4]

const Element* mgx::PlyFile::element ( size_t  idx) const

Access an element by index.

◆ error()

bool mgx::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.

◆ format()

FORMAT_TYPES mgx::PlyFile::format ( ) const
inline

Format of the file.

Definition at line 539 of file PlyFile.hpp.

◆ hasElement()

bool mgx::PlyFile::hasElement ( const QString &  name) const

Check if the element name exists.

◆ init()

bool mgx::PlyFile::init ( FORMAT_TYPES  format = BINARY_LITTLE_ENDIAN,
const QString &  version = "1.0" 
)

Initialize the file with a format and a version.

◆ isValid()

bool mgx::PlyFile::isValid ( ) const
inline

Check if the last call to PlyFile::validate was successful of not.

Definition at line 652 of file PlyFile.hpp.

◆ nbElements()

size_t mgx::PlyFile::nbElements ( ) const
inline

Return the number of elements in the file.

Definition at line 600 of file PlyFile.hpp.

◆ operator bool()

mgx::PlyFile::operator bool ( ) const
inline

Check if the last call to PlyFile::validate was successful of not.

Definition at line 658 of file PlyFile.hpp.

◆ parseAsciiContent()

bool mgx::PlyFile::parseAsciiContent ( QFile &  f)
protected

◆ parseBinaryContent()

bool mgx::PlyFile::parseBinaryContent ( QFile &  f,
bool  little_endian 
)
protected

◆ parseContent()

bool mgx::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.

◆ parseHeader()

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

Parse the head of a PLY file.

Returns
True if the header has been correctly parsed

◆ parseType()

TYPE mgx::PlyFile::parseType ( QString  typeName) const
protected

◆ readElement()

bool mgx::PlyFile::readElement ( const QStringList &  fields)
protected

◆ readFormat()

bool mgx::PlyFile::readFormat ( const QStringList &  fields)
protected

◆ readProperty()

bool mgx::PlyFile::readProperty ( const QStringList &  fields)
protected

◆ save()

bool mgx::PlyFile::save ( const QString &  filename) const

Save the file to filename.

◆ setFormat()

bool mgx::PlyFile::setFormat ( FORMAT_TYPES  f)
inline

Set the file format, checking the validity of the argument.

Definition at line 545 of file PlyFile.hpp.

◆ setVersion()

bool mgx::PlyFile::setVersion ( QString  version)

Set the format version, checking it's validity.

◆ validate()

bool mgx::PlyFile::validate ( )

Validate the content.

This must be called before writing

◆ version()

const QString& mgx::PlyFile::version ( ) const
inline

Version fo the format.

Definition at line 561 of file PlyFile.hpp.

◆ writeAsciiContent()

bool mgx::PlyFile::writeAsciiContent ( QFile &  f) const
protected

◆ writeBinaryContent()

bool mgx::PlyFile::writeBinaryContent ( QFile &  f,
bool  little_endian 
) const
protected

◆ writeHeader()

bool mgx::PlyFile::writeHeader ( QFile &  f) const
protected

Member Data Documentation

◆ _comments

QStringList mgx::PlyFile::_comments
protected

Definition at line 716 of file PlyFile.hpp.

◆ _contentPosition

qint64 mgx::PlyFile::_contentPosition
protected

Definition at line 719 of file PlyFile.hpp.

◆ _element_map

QHash<QString, int> mgx::PlyFile::_element_map
protected

Definition at line 707 of file PlyFile.hpp.

◆ _elements

QList<Element*> mgx::PlyFile::_elements
protected

Definition at line 706 of file PlyFile.hpp.

◆ _format

FORMAT_TYPES mgx::PlyFile::_format
protected

Definition at line 714 of file PlyFile.hpp.

◆ _version

QString mgx::PlyFile::_version
protected

Definition at line 715 of file PlyFile.hpp.

◆ _version_major

int mgx::PlyFile::_version_major
protected

Definition at line 717 of file PlyFile.hpp.

◆ _version_minor

int mgx::PlyFile::_version_minor
protected

Definition at line 717 of file PlyFile.hpp.

◆ current_element

Element* mgx::PlyFile::current_element
protected

Definition at line 709 of file PlyFile.hpp.

◆ filename

QString mgx::PlyFile::filename
protected

Definition at line 711 of file PlyFile.hpp.

◆ formatNames

char const* const mgx::PlyFile::formatNames[4]
static

Array of C-string representation of the formats.

Definition at line 109 of file PlyFile.hpp.

◆ is_valid

bool mgx::PlyFile::is_valid
protected

Definition at line 718 of file PlyFile.hpp.

◆ line_nb

int mgx::PlyFile::line_nb
protected

Definition at line 712 of file PlyFile.hpp.

◆ typeNames

char const* const mgx::PlyFile::typeNames[NB_TYPES+1][3]
static

Array of C-string representation of the types.

Definition at line 94 of file PlyFile.hpp.

◆ typeSizes

const unsigned int mgx::PlyFile::typeSizes[NB_TYPES]
static

Array holding the size in byte of the various types.

Definition at line 90 of file PlyFile.hpp.


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