| 1 |
/* |
| 2 |
|
| 3 |
Header for PLY polygon files. |
| 4 |
|
| 5 |
- Greg Turk, March 1994 |
| 6 |
|
| 7 |
A PLY file contains a single polygonal _object_. |
| 8 |
|
| 9 |
An object is composed of lists of _elements_. Typical elements are |
| 10 |
vertices, faces, edges and materials. |
| 11 |
|
| 12 |
Each type of element for a given object has one or more _properties_ |
| 13 |
associated with the element type. For instance, a vertex element may |
| 14 |
have as properties three floating-point values x,y,z and three unsigned |
| 15 |
chars for red, green and blue. |
| 16 |
|
| 17 |
--------------------------------------------------------------- |
| 18 |
|
| 19 |
Copyright (c) 2020, Georgia Institute of Technology |
| 20 |
All rights reserved. |
| 21 |
|
| 22 |
Redistribution and use in source and binary forms, with or without |
| 23 |
modification, are permitted provided that the following conditions are met: |
| 24 |
|
| 25 |
Redistributions of source code must retain the above copyright notice, this |
| 26 |
list of conditions and the following disclaimer. Redistributions in binary form |
| 27 |
must reproduce the above copyright notice, this list of conditions and the |
| 28 |
following disclaimer in the documentation and/or other materials provided with |
| 29 |
the distribution. |
| 30 |
|
| 31 |
Neither the name of the Georgia Institute of Technology nor the names of its |
| 32 |
contributors may be used to endorse or promote products derived from this |
| 33 |
software without specific prior written permission. |
| 34 |
|
| 35 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 36 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED |
| 37 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 38 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 39 |
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 40 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 41 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 42 |
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 44 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 |
|
| 46 |
*/ |
| 47 |
|
| 48 |
#ifndef PLY_INCLUDED |
| 49 |
#define PLY_INCLUDED |
| 50 |
|
| 51 |
#include <vector> |
| 52 |
#include <string> |
| 53 |
#include <functional> |
| 54 |
#include <math.h> |
| 55 |
#include "PlyFile.h" |
| 56 |
#include "Geometry.h" |
| 57 |
#include "DataStream.h" |
| 58 |
#include "MyMiscellany.h" |
| 59 |
#include "Array.h" |
| 60 |
|
| 61 |
namespace PoissonRecon |
| 62 |
{ |
| 63 |
namespace PLY |
| 64 |
{ |
| 65 |
// Converts from C-type to PLY type |
| 66 |
template< class Scalar > int Type( void ); |
| 67 |
|
| 68 |
// Converts from C-type to PLY name |
| 69 |
template< typename Integer > struct Traits{ static const std::string name; }; |
| 70 |
|
| 71 |
// A structure representing a face |
| 72 |
template< typename Index > |
| 73 |
struct Edge |
| 74 |
{ |
| 75 |
Index v1 , v2; |
| 76 |
static const PlyProperty Properties[]; |
| 77 |
}; |
| 78 |
|
| 79 |
// A structure representing a face |
| 80 |
template< typename Index , bool UseCharIndex=false > |
| 81 |
struct Face |
| 82 |
{ |
| 83 |
unsigned int nr_vertices; |
| 84 |
Index *vertices; |
| 85 |
|
| 86 |
static const PlyProperty Properties[]; |
| 87 |
}; |
| 88 |
|
| 89 |
inline int DefaultFileType( void ); |
| 90 |
|
| 91 |
// PLY read header functionality |
| 92 |
|
| 93 |
// Get the properties (and return the file type) |
| 94 |
inline int ReadVertexHeader( std::string fileName , std::vector< PlyProperty > &properties ); |
| 95 |
|
| 96 |
// Test which properties are represented by elements of the vertex factory (and return the file type) |
| 97 |
template< typename VertexFactory > |
| 98 |
int ReadVertexHeader( std::string fileName , const VertexFactory &vFactory , bool *readFlags ); |
| 99 |
|
| 100 |
// Test which properties are represented by elements of the vertex factory and add the others to the property list (and return the file type) |
| 101 |
template< typename VertexFactory > |
| 102 |
int ReadVertexHeader( std::string fileName , const VertexFactory &vFactory , bool *readFlags , std::vector< PlyProperty > &unprocessedProperties ); |
| 103 |
|
| 104 |
// PLY write mesh functionality |
| 105 |
template< typename VertexFactory , typename Index , class Real , int Dim , typename OutputIndex=int , bool UseCharIndex=false > |
| 106 |
void Write( std::string fileName , const VertexFactory &vFactory , size_t vertexNum , size_t polygonNum , InputDataStream< typename VertexFactory::VertexType > &vertexStream , InputDataStream< std::vector< Index > > &polygonStream , int file_type , const std::vector< std::string >& comments ); |
| 107 |
|
| 108 |
template< typename VertexFactory , typename Index , class Real , int Dim , typename OutputIndex=int > |
| 109 |
void Write( std::string fileName , const VertexFactory &vFactory , size_t vertexNum , size_t edgeNum , InputDataStream< typename VertexFactory::VertexType > &vertexStream , InputDataStream< std::pair< Index , Index > > &edgeStream , int file_type , const std::vector< std::string >& comments ); |
| 110 |
|
| 111 |
template< typename VertexFactory , typename Index , bool UseCharIndex=false > |
| 112 |
void WritePolygons( std::string fileName , const VertexFactory &vFactory , const std::vector< typename VertexFactory::VertexType > &vertices , const std::vector< std::vector< Index > > &polygons , int file_type , const std::vector< std::string > &comments ); |
| 113 |
|
| 114 |
// PLY read mesh functionality |
| 115 |
template< typename VertexFactory , typename Index > |
| 116 |
void ReadPolygons( std::string fileName , const VertexFactory &vFactory , std::vector< typename VertexFactory::VertexType > &vertices , std::vector< std::vector< Index > >& polygons , int &file_type , std::vector< std::string > &comments , bool* readFlags=NULL ); |
| 117 |
|
| 118 |
template< typename VertexFactory , typename Index > |
| 119 |
void ReadEdges( std::string fileName , const VertexFactory &vFactory , std::vector< typename VertexFactory::VertexType > &vertices , std::vector< std::pair< Index , Index > >& edges , int &file_type , std::vector< std::string > &comments , bool* readFlags=NULL ); |
| 120 |
} |
| 121 |
#include "Ply.inl" |
| 122 |
} |
| 123 |
|
| 124 |
#endif // PLY_INCLUDED |