2009-02-06 13:37:46 +00:00
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Copyright (c) 2001-2015, RWTH-Aachen University *
|
|
|
|
|
* Department for Computer Graphics and Multimedia *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* www.openmesh.org *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-09 15:47:49 +00:00
|
|
|
*---------------------------------------------------------------------------*
|
2015-04-28 11:33:32 +00:00
|
|
|
* This file is part of OpenMesh. *
|
|
|
|
|
*---------------------------------------------------------------------------*
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without *
|
|
|
|
|
* modification, are permitted provided that the following conditions *
|
|
|
|
|
* are met: *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, *
|
|
|
|
|
* this list of conditions and the following disclaimer. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright *
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the *
|
|
|
|
|
* documentation and/or other materials provided with the distribution. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 3. Neither the name of the copyright holder nor the names of its *
|
|
|
|
|
* contributors may be used to endorse or promote products derived from *
|
|
|
|
|
* this software without specific prior written permission. *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
|
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
|
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
|
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
|
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
|
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
|
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
|
|
|
|
|
* *
|
|
|
|
|
/*===========================================================================*\
|
2009-06-04 08:46:29 +00:00
|
|
|
|
|
|
|
|
/*===========================================================================*\
|
2009-06-09 15:47:49 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* $Revision$ *
|
|
|
|
|
* $Date$ *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
|
|
|
|
\*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//
|
|
|
|
|
// Implements a reader module for OFF files
|
|
|
|
|
//
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __PLYREADER_HH__
|
|
|
|
|
#define __PLYREADER_HH__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=== INCLUDES ================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include <OpenMesh/Core/System/config.h>
|
|
|
|
|
#include <OpenMesh/Core/Utils/SingletonT.hh>
|
|
|
|
|
#include <OpenMesh/Core/IO/reader/BaseReader.hh>
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//== NAMESPACES ===============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenMesh {
|
|
|
|
|
namespace IO {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== FORWARDS =================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseImporter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== IMPLEMENTATION ===========================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Implementation of the PLY format reader. This class is singleton'ed by
|
|
|
|
|
SingletonT to OFFReader.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
2012-09-23 14:49:46 +00:00
|
|
|
class OPENMESHDLLEXPORT _PLYReader_ : public BaseReader
|
2009-02-06 13:37:46 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
_PLYReader_();
|
|
|
|
|
|
|
|
|
|
std::string get_description() const { return "PLY polygon file format"; }
|
|
|
|
|
std::string get_extensions() const { return "ply"; }
|
|
|
|
|
std::string get_magic() const { return "PLY"; }
|
|
|
|
|
|
|
|
|
|
bool read(const std::string& _filename,
|
2009-12-07 10:26:25 +00:00
|
|
|
BaseImporter& _bi,
|
|
|
|
|
Options& _opt);
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-11-17 13:54:16 +00:00
|
|
|
bool read(std::istream& _is,
|
2009-12-07 10:26:25 +00:00
|
|
|
BaseImporter& _bi,
|
|
|
|
|
Options& _opt);
|
2009-11-17 13:54:16 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
bool can_u_read(const std::string& _filename) const;
|
|
|
|
|
|
|
|
|
|
enum ValueType {
|
2009-12-07 10:31:37 +00:00
|
|
|
Unsupported,
|
|
|
|
|
ValueTypeINT8, ValueTypeCHAR,
|
|
|
|
|
ValueTypeUINT8, ValueTypeUCHAR,
|
|
|
|
|
ValueTypeINT16, ValueTypeSHORT,
|
|
|
|
|
ValueTypeUINT16, ValueTypeUSHORT,
|
|
|
|
|
ValueTypeINT32, ValueTypeINT,
|
|
|
|
|
ValueTypeUINT32, ValueTypeUINT,
|
2009-02-06 13:37:46 +00:00
|
|
|
ValueTypeFLOAT32, ValueTypeFLOAT,
|
2011-06-02 13:33:49 +00:00
|
|
|
ValueTypeFLOAT64, ValueTypeDOUBLE
|
2009-02-06 13:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
bool can_u_read(std::istream& _is) const;
|
|
|
|
|
|
2012-10-08 11:44:29 +00:00
|
|
|
bool read_ascii(std::istream& _in, BaseImporter& _bi, const Options& _opt) const;
|
|
|
|
|
bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap, const Options& _opt) const;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
float readToFloatValue(ValueType _type , std::fstream& _in) const;
|
2014-10-24 08:52:07 +00:00
|
|
|
void readCustomProperty(std::istream& _in, BaseImporter& _bi, VertexHandle _vh, const std::string& _propName, const ValueType _valueType) const;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-11-17 13:54:16 +00:00
|
|
|
void readValue(ValueType _type , std::istream& _in, float& _value) const;
|
2009-12-07 10:31:37 +00:00
|
|
|
void readValue(ValueType _type, std::istream& _in, double& _value) const;
|
2009-11-17 13:54:16 +00:00
|
|
|
void readValue(ValueType _type , std::istream& _in, unsigned int& _value) const;
|
|
|
|
|
void readValue(ValueType _type , std::istream& _in, int& _value) const;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
void readInteger(ValueType _type, std::istream& _in, int& _value) const;
|
|
|
|
|
void readInteger(ValueType _type, std::istream& _in, unsigned int& _value) const;
|
|
|
|
|
|
2012-10-08 11:44:29 +00:00
|
|
|
/// Read unsupported properties in PLY file
|
2009-12-07 10:31:37 +00:00
|
|
|
void consume_input(std::istream& _in, int _count) const {
|
|
|
|
|
_in.read(reinterpret_cast<char*>(&buff[0]), _count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mutable unsigned char buff[8];
|
|
|
|
|
|
2012-10-08 11:44:29 +00:00
|
|
|
/// Available per file options for reading
|
2009-02-06 13:37:46 +00:00
|
|
|
mutable Options options_;
|
2009-12-07 10:31:37 +00:00
|
|
|
|
|
|
|
|
/// Options that the user wants to read
|
2009-02-06 13:37:46 +00:00
|
|
|
mutable Options userOptions_;
|
|
|
|
|
|
|
|
|
|
mutable unsigned int vertexCount_;
|
|
|
|
|
mutable unsigned int faceCount_;
|
|
|
|
|
|
|
|
|
|
mutable ValueType vertexType_;
|
|
|
|
|
mutable uint vertexDimension_;
|
|
|
|
|
|
|
|
|
|
mutable ValueType faceIndexType_;
|
|
|
|
|
mutable ValueType faceEntryType_;
|
|
|
|
|
|
|
|
|
|
enum VertexProperty {
|
|
|
|
|
XCOORD,YCOORD,ZCOORD,
|
|
|
|
|
TEXX,TEXY,
|
2009-06-09 15:47:49 +00:00
|
|
|
COLORRED,COLORGREEN,COLORBLUE,COLORALPHA,
|
2014-10-24 08:52:07 +00:00
|
|
|
XNORM,YNORM,ZNORM, CUSTOM_PROP,
|
2009-06-09 15:47:49 +00:00
|
|
|
UNSUPPORTED
|
2009-02-06 13:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
/// Stores sizes of property types
|
|
|
|
|
mutable std::map<ValueType, int> scalar_size_;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2009-12-07 10:31:37 +00:00
|
|
|
// Number of vertex properties
|
2009-02-06 13:37:46 +00:00
|
|
|
mutable unsigned int vertexPropertyCount_;
|
2014-10-24 08:52:07 +00:00
|
|
|
struct VertexPropertyInfo
|
|
|
|
|
{
|
|
|
|
|
VertexProperty property;
|
|
|
|
|
ValueType value;
|
|
|
|
|
std::string name;//for custom properties
|
|
|
|
|
VertexPropertyInfo():property(UNSUPPORTED),value(Unsupported),name(""){}
|
|
|
|
|
VertexPropertyInfo(VertexProperty _p, ValueType _v):property(_p),value(_v),name(""){}
|
|
|
|
|
VertexPropertyInfo(VertexProperty _p, ValueType _v, const std::string& _n):property(_p),value(_v),name(_n){}
|
|
|
|
|
};
|
|
|
|
|
mutable std::map< int , VertexPropertyInfo > vertexPropertyMap_;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== TYPE DEFINITION ==========================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Declare the single entity of the PLY reader
|
|
|
|
|
extern _PLYReader_ __PLYReaderInstance;
|
2012-09-24 10:10:22 +00:00
|
|
|
OPENMESHDLLEXPORT _PLYReader_& PLYReader();
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
} // namespace IO
|
|
|
|
|
} // namespace OpenMesh
|
|
|
|
|
//=============================================================================
|
|
|
|
|
#endif
|
|
|
|
|
//=============================================================================
|