Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

import2tables.h 6.39 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
96
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef _IMPORT2TABLE_H
#define _IMPORT2TABLE_H

#include <fstream>
#include <iostream>
#include <vector>
#include <string>

//#include "Topology/generic/attributeHandler.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"

#include "gzstream.h"
#include "openctm.h"
#include "assimp.h"
#include "aiScene.h"

namespace CGoGN
{

namespace Algo
{

namespace Import
{

	namespace ImportSurfacique
	{
		enum ImportType {UNKNOWNSURFACE,TRIAN,TRIANBGZ,PLY,PLYPTM,OFF,OBJ,CTM,VRML};
	}

	namespace ImportVolumique
	{
		enum ImportType {UNKNOWNVOLUME,TET,TRIANBGZ,PLY};
	}


template <typename PFP>
class MeshTablesSurface
{
protected:
	unsigned m_nbVertices;

	unsigned m_nbFaces;

	unsigned int m_lab;
	/**
	* number of edges per face
	*/
	std::vector<short> m_nbEdges;

	/**
	* table of emb indice (for each edge, first vertex)
	*/
	std::vector<unsigned int> m_emb;

	/**
	 * we need direct access to container itself to insert new lines while reading points
	 */
	AttribContainer& m_container;

	/**
	 * table of positions
	 */
	typename PFP::TVEC3& m_positions;

	static ImportSurfacique::ImportType getFileType(const std::string& filename);

	void extractMeshRec(const struct aiScene* scene, const struct aiNode* nd, struct aiMatrix4x4* trafo);

public:
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename VEC3::DATA_TYPE DATA_TYPE ;

	inline unsigned getNbFaces() const { return m_nbFaces;}

	inline unsigned getNbVertices() const { return m_nbVertices;}

	inline short getNbEdgesFace(int i) const  { return m_nbEdges[i];}

	inline unsigned int getEmbIdx(int i) { return  m_emb[i];}

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

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

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

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

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

	bool importMesh(const std::string& filename, ImportSurfacique::ImportType kind);

	bool importPlyPTM(const std::string& filename, typename PFP::TFRAME& Frame, typename PFP::TRGBFUNCS& RGBfunctions);

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

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

	/**
	 * @param container container of vertex orbite
	 * @param idPositions id of position attribute in the container
	 * @param idLabels id of label attribute in the container
	 */
	MeshTablesSurface(AttribContainer& container, typename PFP::TVEC3& positions):
		m_container(container), m_positions(positions)
	{
	}

	MeshTablesSurface(AttribContainer& container, typename PFP::TVEC3& positions, const std::string& filename):
		m_container(container), m_positions(positions)
	{
		importMesh(filename);
	}
};


template <typename PFP>
class MeshTablesVolume
{
public:


protected:
	unsigned m_nbVertices;

	unsigned m_nbFaces;

	unsigned m_nbVolumes;

	/**
	* number of edges per face
	*/
	std::vector<short> m_nbEdges;

	/**
	* table of emb ptr (for each face, first vertex)
	*/
	std::vector<unsigned int> m_emb;

	/**
	 * we need direct access to container itself to insert new lines while reading points
	 */
	AttribContainer& m_container;

	/**
	 * table of positions
	 */
	typename PFP::TVEC3& m_positions;

	static ImportVolumique::ImportType getFileType(const std::string& filename);

public:
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename VEC3::DATA_TYPE DATA_TYPE ;

	typedef Geom::Vector<6,DATA_TYPE> VEC6;
	typedef Geom::Matrix<3,3,DATA_TYPE> MAT33;
	typedef Geom::Matrix<3,6,DATA_TYPE> MAT36;

	inline short getNbEdgesFace(int i) const  { return m_nbEdges[i];}

	inline unsigned getNbVolumes() const { return m_nbVolumes; }

	inline unsigned getNbFaces() const { return m_nbFaces; }

	inline unsigned getNbVertices() const { return m_nbVertices; }

	//inline short getNbVerticesPerFace(int i) const  { return m_nbVerticesPerFace[i]; }

	//inline short getNbFacesPerVolume(int i) const { return m_nbFacesPerVolume[i]; }

	inline unsigned int getEmbIdx(int i) { return  m_emb[i]; }

	bool importTet(const std::string& filename,float scaleFactor);

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

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

	bool importMesh(const std::string& filename, ImportVolumique::ImportType kind, float scaleFactor);

	MeshTablesVolume(AttribContainer& container, typename PFP::TVEC3& pos ):
		m_container(container), m_positions(pos)
	{
	}

	MeshTablesVolume(AttribContainer& container, typename PFP::TVEC3& pos, const std::string& filename):
		m_container(container), m_positions(pos)
	{
		importMesh(filename);
	}
};

} // namespace Import

} // namespace Algo

} // namespace CGoGN

#include "Algo/Import/import2tablesSurface.hpp"
#include "Algo/Import/import2tablesVolume.hpp"

#endif