36 #define USE_PLY_WRAPPER 1
39 #define _strdup strdup
52 #define PLY_BINARY_BE 2
53 #define PLY_BINARY_LE 3
54 #define PLY_BINARY_NATIVE 4
61 #define PLY_START_TYPE 0
73 #define PLY_UINT_16 12
75 #define PLY_UINT_32 14
76 #define PLY_FLOAT_32 15
77 #define PLY_FLOAT_64 16
79 #define PLY_END_TYPE 17
84 #define PLY_STRIP_COMMENT_HEADER 0
150 #define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__)
153 #define REALLOCN(PTR,TYPE,OLD_N,NEW_N) \
156 { ALLOCN((PTR),TYPE,(NEW_N));} \
159 (PTR) = (TYPE *)realloc((PTR),(NEW_N)*sizeof(TYPE)); \
160 if (((PTR) == NULL) && ((NEW_N) != 0)) \
162 fprintf(stderr, "Memory reallocation failed on line %d in %s\n", \
163 __LINE__, __FILE__); \
164 fprintf(stderr, " tried to reallocate %d->%d\n", \
168 if ((NEW_N)>(OLD_N)) \
169 memset((char *)(PTR)+(OLD_N)*sizeof(TYPE), 0, \
170 ((NEW_N)-(OLD_N))*sizeof(TYPE)); \
174 #define ALLOCN(PTR,TYPE,N) \
175 { (PTR) = (TYPE *) calloc(((unsigned)(N)),sizeof(TYPE));\
176 if ((PTR) == NULL) { \
177 fprintf(stderr, "Memory allocation failed on line %d in %s\n", \
178 __LINE__, __FILE__); \
184 #define FREE(PTR) { free((PTR)); (PTR) = NULL; }
225 template<
class Real >
int PLYType(
void );
231 template<
class Real >
inline int PLYType(
void ){ fprintf( stderr ,
"[ERROR] Unrecognized type\n" ) , exit( 0 ); }
241 {
_strdup(
"vertex_indices" ) ,
PLY_INT ,
PLY_INT ,
offsetof(
PlyFace , vertices ) , 1 ,
PLY_UCHAR,
PLY_UCHAR ,
offsetof(
PlyFace,nr_vertices) },
250 template<
class Real >
287 template<
class Real >
327 template<
class Real >
370 template<
class Real >
384 for(
int c=0 ; c<3 ; c++ ) p.
color[c] = (
unsigned char)std::max< int >( 0 , std::min< int >( 255 , (
int)(
color[c]+0.5 ) ) );
437 template<
class Real >
452 for(
int c=0 ; c<3 ; c++ ) p.
color[c] = (
unsigned char)std::max< int >( 0 , std::min< int >( 255 , (
int)(
color[c]+0.5 ) ) );
509 template<
class Vertex ,
class Real >
512 template<
class Vertex ,
class Real >
527 if( !ply )
return false;
529 for(
int i=0 ; i<nr_elems ; i++ )
531 elem_name = elist[i];
535 for(
int i=0 ; i<nr_elems ; i++ )
546 for(
int i=0 ; i<nr_elems ; i++ ) free( ply->
elems[i] );
554 for(
int i=0 ; i<nr_elems ; i++ ) free( elist[i] );
560 for(
int i=0 ; i<propertyNum ; i++ )
561 if( readFlags ) readFlags[i] =
ply_get_property( ply , elem_name , &properties[i] )!=0;
563 for(
int j=0 ; j<nr_props ; j++ )
565 free( plist[j]->
name );
571 for(
int i=0 ; i<nr_elems ; i++ )
582 for(
int i=0 ; i<nr_elems ; i++ ) free(ply->
elems[i]);
591 for(
int i=0 ; i<nr_elems ; i++ ) free( elist[i] );
599 return PlyReadHeader( fileName , properties , propertyNum , readFlags , file_type );
603 template<
class Vertex>
605 std::vector<Vertex>& vertices,std::vector<std::vector<int> >& polygons,
608 char*** comments=
NULL,
int* commentNum=
NULL ,
bool* readFlags=
NULL );
610 template<
class Vertex>
612 const std::vector<Vertex>& vertices,
const std::vector<std::vector<int> >& polygons,
615 char** comments=
NULL,
const int& commentNum=0);
617 template<
class Vertex>
619 const std::vector<Vertex>& vertices ,
const std::vector< std::vector< int > >& polygons,
622 char** comments,
const int& commentNum)
624 int nr_vertices=int(vertices.size());
625 int nr_faces=int(polygons.size());
627 const char *elem_names[] = {
"vertex" ,
"face" };
635 for(
int i=0;i<propertyNum;i++)
642 if(comments && commentNum)
643 for(
int i=0;i<commentNum;i++)
650 for (
int i=0; i < int(vertices.size()); i++)
660 for (
int i=0; i < nr_faces; i++)
662 if(
int(polygons[i].
size())>maxFaceVerts)
665 maxFaceVerts=int(polygons[i].
size());
666 ply_face.
vertices=
new int[maxFaceVerts];
670 ply_face.
vertices[j]=polygons[i][j];
678 template<
class Vertex>
680 std::vector<Vertex>& vertices , std::vector<std::vector<int> >& polygons ,
683 char*** comments ,
int* commentNum ,
bool* readFlags )
707 for (i=0; i < nr_elems; i++) {
708 elem_name = elist[i];
712 for(i=0;i<nr_elems;i++){
721 for(i=0;i<nr_elems;i++){free(ply->
elems[i]);}
729 for(i=0;i<nr_elems;i++){free(elist[i]);}
736 for(
int i=0 ; i<propertyNum ; i++)
739 if( readFlags ) readFlags[i] = (hasProperty!=0);
741 vertices.resize(num_elems);
742 for (j=0; j < num_elems; j++)
ply_get_element (ply, (
void *) &vertices[j]);
747 polygons.resize(num_elems);
748 for (j=0; j < num_elems; j++)
751 polygons[j].resize(ply_face.nr_vertices);
752 for(k=0;k<ply_face.nr_vertices;k++) polygons[j][k]=ply_face.vertices[k];
753 delete[] ply_face.vertices;
758 for(j=0;j<nr_props;j++){
759 free(plist[j]->
name);
765 for(i=0;i<nr_elems;i++){
774 for(i=0;i<nr_elems;i++){free(ply->
elems[i]);}
783 for(i=0;i<nr_elems;i++){free(elist[i]);}
789 template<
class Vertex ,
class Real >
796 const char *elem_names[] = {
"vertex" ,
"face" };
806 for(
int i=0 ; i<Vertex::Components ; i++ )
ply_describe_property( ply ,
"vertex" , &Vertex::Properties[i] );
827 vertex = xForm * ( vertex * scale +translate );
832 std::vector< CoredVertexIndex >
polygon;
834 for( i=0 ; i<nr_faces ; i++ )
843 for(
int i=0 ; i<int(
polygon.size()) ; i++ )
853 template<
class Vertex ,
class Real >
860 const char *elem_names[] = {
"vertex" ,
"face" };
870 for(
int i=0 ; i<Vertex::WriteComponents ; i++ )
ply_describe_property( ply ,
"vertex" , &Vertex::WriteProperties[i] );
891 vertex = xForm * ( vertex );
896 std::vector< CoredVertexIndex >
polygon;
898 for( i=0 ; i<nr_faces ; i++ )
907 for(
int i=0 ; i<int(
polygon.size()) ; i++ )
void ply_describe_other_properties(PlyFile *, PlyOtherProp *, int)
PlyOtherElems * ply_get_other_element(PlyFile *, char *, int)
PlyOtherProp * ply_get_other_properties(PlyFile *, char *, int)
void ply_put_obj_info(PlyFile *, char *)
void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *)
void ply_close_custom(PlyFile *)
PlyFile * ply_write_custom(FILE *, int, const char **, int)
void ply_put_element(PlyFile *, void *)
struct PlyOtherProp PlyOtherProp
PlyFile * ply_open_for_writing(char *, int, const char **, int, float *)
void ply_put_element_setup(PlyFile *, const char *)
void ply_describe_other_elements(PlyFile *, PlyOtherElems *)
struct OtherData OtherData
PlyFile * ply_read_custom(FILE *, int *, char ***)
void ply_put_other_elements(PlyFile *)
void ply_describe_property(PlyFile *, const char *, PlyProperty *)
int PlyReadPolygons(char *fileName, std::vector< Vertex > &vertices, std::vector< std::vector< int > > &polygons, PlyProperty *properties, int propertyNum, int &file_type, char ***comments=NULL, int *commentNum=NULL, bool *readFlags=NULL)
PlyVertex< Real > operator*(XForm4x4< _Real > xForm, PlyVertex< Real > v)
static PlyProperty face_props[]
struct OtherElem OtherElem
void ply_header_complete(PlyFile *)
char ** ply_get_obj_info(PlyFile *, int *)
int PlyWritePolygons(char *fileName, CoredMeshData< Vertex > *mesh, int file_type, const Point3D< float > &translate, float scale, char **comments=NULL, int commentNum=0, XForm4x4< Real > xForm=XForm4x4< Real >::Identity())
int PLYType< char >(void)
PlyFile * ply_open_for_reading(char *, int *, char ***, int *, float *)
void ply_get_element_setup(PlyFile *, char *, int, PlyProperty *)
int PLYType< unsigned char >(void)
void ply_get_info(PlyFile *, float *, int *)
int PLYType< float >(void)
int PlyDefaultFileType(void)
struct PlyProperty PlyProperty
struct PlyOtherElems PlyOtherElems
void ply_get_element(PlyFile *, void *)
int PLYType< double >(void)
bool PlyReadHeader(char *fileName, PlyProperty *properties, int propertyNum, bool *readFlags, int &file_type)
void ply_element_count(PlyFile *, const char *, int)
int ply_get_property(PlyFile *, char *, PlyProperty *)
struct PlyElement PlyElement
void ply_free_other_elements(PlyOtherElems *)
int equal_strings(const char *, const char *)
char ** ply_get_comments(PlyFile *, int *)
PlyProperty ** ply_get_element_description(PlyFile *, char *, int *, int *)
void ply_put_comment(PlyFile *, char *)
boost::geometry::model::polygon< point_xy > polygon
virtual int polygonCount(void)=0
virtual int nextPolygon(std::vector< CoredVertexIndex > &vertices)=0
virtual int nextOutOfCorePoint(Vertex &p)=0
virtual int outOfCorePointCount(void)=0
std::vector< Vertex > inCorePoints
virtual void resetIterator(void)=0
static const int WriteComponents
PlyColorAndValueVertex(const Point3D< Real > &p)
PlyColorAndValueVertex(const Point3D< Real > &p, const unsigned char c[3], Real v)
static PlyProperty ReadProperties[]
static PlyProperty WriteProperties[]
PlyColorAndValueVertex(void)
_PlyColorAndValueVertex Wrapper
static const int ReadComponents
static const int WriteComponents
PlyColorVertex(const Point3D< Real > &p, const unsigned char c[3])
static PlyProperty WriteProperties[]
static PlyProperty ReadProperties[]
PlyColorVertex(const Point3D< Real > &p)
static const int ReadComponents
PlyOrientedVertex operator+(PlyOrientedVertex p) const
PlyOrientedVertex operator/(_Real s) const
static const int WriteComponents
static PlyProperty WriteProperties[]
PlyOrientedVertex & operator*=(_Real s)
PlyOrientedVertex operator*(_Real s) const
static const int ReadComponents
static PlyProperty ReadProperties[]
PlyOrientedVertex(Point3D< Real > p, Point3D< Real > n)
PlyOrientedVertex operator-(PlyOrientedVertex p) const
PlyOrientedVertex & operator-=(PlyOrientedVertex p)
PlyOrientedVertex Wrapper
PlyOrientedVertex & operator+=(PlyOrientedVertex p)
PlyOrientedVertex & operator/=(_Real s)
PlyValueVertex & operator*=(_Real s)
static PlyProperty ReadProperties[]
PlyValueVertex operator/(_Real s) const
PlyValueVertex & operator/=(_Real s)
static PlyProperty WriteProperties[]
static const int WriteComponents
PlyValueVertex operator-(PlyValueVertex p) const
PlyValueVertex operator+(PlyValueVertex p) const
PlyValueVertex operator*(_Real s) const
PlyValueVertex(Point3D< Real > p, Real v)
static const int ReadComponents
PlyValueVertex & operator+=(PlyValueVertex p)
PlyValueVertex & operator-=(PlyValueVertex p)
PlyVertex & operator*=(_Real s)
static const int WriteComponents
static const int ReadComponents
static PlyProperty WriteProperties[]
PlyVertex & operator+=(PlyVertex p)
PlyVertex operator/(_Real s) const
PlyVertex & operator/=(_Real s)
PlyVertex operator-(PlyVertex p) const
PlyVertex(Point3D< Real > p)
static PlyProperty ReadProperties[]
PlyVertex operator+(PlyVertex p) const
PlyVertex operator*(_Real s) const
PlyVertex & operator-=(PlyVertex p)
#define offsetof(STRUCTURE, FIELD)
PlyOtherProp * other_props
_PlyColorAndValueVertex & operator/=(_Real s)
_PlyColorAndValueVertex & operator-=(_PlyColorAndValueVertex p)
_PlyColorAndValueVertex & operator+=(_PlyColorAndValueVertex p)
_PlyColorAndValueVertex operator-(_PlyColorAndValueVertex p) const
_PlyColorAndValueVertex(Point3D< Real > p, Point3D< Real > c, Real v)
_PlyColorAndValueVertex operator/(_Real s) const
_PlyColorAndValueVertex(PlyColorAndValueVertex< Real > p)
_PlyColorAndValueVertex operator+(_PlyColorAndValueVertex p) const
_PlyColorAndValueVertex & operator*=(_Real s)
_PlyColorAndValueVertex operator*(_Real s) const
_PlyColorAndValueVertex(void)
_PlyColorVertex operator*(_Real s) const
_PlyColorVertex operator/(_Real s) const
_PlyColorVertex(Point3D< Real > p, Point3D< Real > c)
_PlyColorVertex & operator-=(_PlyColorVertex p)
_PlyColorVertex operator-(_PlyColorVertex p) const
_PlyColorVertex(PlyColorVertex< Real > p)
_PlyColorVertex & operator*=(_Real s)
_PlyColorVertex & operator+=(_PlyColorVertex p)
_PlyColorVertex operator+(_PlyColorVertex p) const
_PlyColorVertex & operator/=(_Real s)
unsigned char nr_vertices
PlyOtherElems * other_elems