importPlyData.h 4.08 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef _IMPORT_PLY_DATA_H
#define _IMPORT_PLY_DATA_H

#include <stdio.h>
#include <math.h>
#include <string>

#include "Algo/Import/ply.h"

namespace CGoGN
{

class PlyImportData
{
public:

	template <typename VEC>
	void vertexPosition(int i, VEC& P) { P[0] = vlist[i]->x; P[1] = vlist[i]->y; P[2] = vlist[i]->z;}
	
//	gmtl::Vec3f vertexPosition(int i) {return gmtl::Vec3f(vlist[i]->x, vlist[i]->y, vlist[i]->z);}

	template <typename VEC>
	void vertexNormal(int i, VEC& N) { N[0] = vlist[i]->nx; N[1] = vlist[i]->ny; N[2] = vlist[i]->nz;}
	
	template <typename VEC>
50
51
52
53
	void vertexColorUint8(int i, VEC& C) { C[0] = vlist[i]->red; C[1] = vlist[i]->green; C[2] = vlist[i]->blue;}

	template <typename VEC>
	void vertexColorFloat32(int i, VEC& C) { C[0] = vlist[i]->r; C[1] = vlist[i]->g; C[2] = vlist[i]->b;}
Pierre Kraemer's avatar
Pierre Kraemer committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67


	int nbVertices() { return nverts;}

	int nbFaces() { return nfaces;}

	/**
	* each vertex has a normal vector
	*/
	bool hasNormals() { return has_normals!=0;}

	/**
	* each vertex has a color vector
	*/
68
69
70
	bool hasColors() { return hasColorsUint8() || hasColorsFloat32() ;}
	bool hasColorsUint8() { return per_vertex_color_uint8 != 0 ;}
	bool hasColorsFloat32() { return per_vertex_color_float32 != 0 ;}
Pierre Kraemer's avatar
Pierre Kraemer committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

	/**
	* get the number of edges of a face
	*/
	int getFaceValence(int i) { return flist[i]->nverts;}

	/**
	* get a table (pointer) of int of vertex indices of 
	*/
	int* getFaceIndices(int i) { return flist[i]->verts;}

	PlyImportData();

	~PlyImportData();

	bool read_file(const std::string& filename);


protected:

	/* vertex and face definitions for a polygonal object */
	
	typedef struct Vertex {
	float x,y,z;
	float r,g,b;
96
	unsigned char red,green,blue;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
	float nx,ny,nz;
	void *other_props;       /* other properties */
	} Vertex;
	
	typedef struct Face {
	unsigned char nverts;    /* number of vertex indices in list */
	int *verts;              /* vertex index list */
	void *other_props;       /* other properties */
	} Face;
	
	static char *elem_names[]; 
	
	static PlyProperty vert_props[];
	
	static PlyProperty face_props[];
	
	
	/*** the PLY object ***/
	
	int nverts,nfaces;
	Vertex **vlist;
	Face **flist;
	
	PlyOtherProp *vert_other,*face_other;
	
122
	int per_vertex_color_float32, per_vertex_color_uint8 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
123
	int has_normals;
124
125
	
	char *old_locale;
Pierre Kraemer's avatar
Pierre Kraemer committed
126
127
128
129
130
131
132
};

} // namespace CGoGN


#endif