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.28 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-2011, 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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
* 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"

Sylvain Thery's avatar
Sylvain Thery committed
37
#ifdef WITH_ASSIMP
Pierre Kraemer's avatar
Pierre Kraemer committed
38
39
40
#include "gzstream.h"
#include "assimp.h"
#include "aiScene.h"
Sylvain Thery's avatar
Sylvain Thery committed
41
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
44
45
46
47
48
49
50
51
52
53

namespace CGoGN
{

namespace Algo
{

namespace Import
{

	namespace ImportSurfacique
	{
Sylvain Thery's avatar
Sylvain Thery committed
54
		enum ImportType { UNKNOWNSURFACE, TRIAN, TRIANBGZ, PLY, PLYPTM, PLYPTMgeneric, OFF, OBJ, CTM, VRML, AHEM };
Pierre Kraemer's avatar
Pierre Kraemer committed
55
56
57
58
	}

	namespace ImportVolumique
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
59
		enum ImportType { UNKNOWNVOLUME ,TET ,TRIANBGZ ,PLY };
Pierre Kraemer's avatar
Pierre Kraemer committed
60
61
62
63
64
65
66
	}


template <typename PFP>
class MeshTablesSurface
{
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
67
68
	typename PFP::MAP& m_map;

69
	unsigned int m_nbVertices;
Pierre Kraemer's avatar
Pierre Kraemer committed
70

71
	unsigned int m_nbFaces;
Pierre Kraemer's avatar
Pierre Kraemer committed
72
73

	unsigned int m_lab;
Pierre Kraemer's avatar
Pierre Kraemer committed
74

Pierre Kraemer's avatar
Pierre Kraemer committed
75
76
77
78
79
80
81
82
83
84
85
86
	/**
	* 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;

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

Sylvain Thery's avatar
Sylvain Thery committed
87
#ifdef WITH_ASSIMP
88
	void extractMeshRec(AttributeContainer& container, AttributeHandler<typename PFP::VEC3>& positions, const struct aiScene* scene, const struct aiNode* nd, struct aiMatrix4x4* trafo);
Sylvain Thery's avatar
Sylvain Thery committed
89
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
90
91
92
93
94

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

Pierre Kraemer's avatar
Pierre Kraemer committed
95
	inline unsigned getNbFaces() const { return m_nbFaces; }
Pierre Kraemer's avatar
Pierre Kraemer committed
96

Pierre Kraemer's avatar
Pierre Kraemer committed
97
	inline unsigned getNbVertices() const { return m_nbVertices; }
Pierre Kraemer's avatar
Pierre Kraemer committed
98

Pierre Kraemer's avatar
Pierre Kraemer committed
99
	inline short getNbEdgesFace(int i) const  { return m_nbEdges[i]; }
Pierre Kraemer's avatar
Pierre Kraemer committed
100

Pierre Kraemer's avatar
Pierre Kraemer committed
101
	inline unsigned int getEmbIdx(int i) { return  m_emb[i]; }
Pierre Kraemer's avatar
Pierre Kraemer committed
102

Pierre Kraemer's avatar
Pierre Kraemer committed
103
	bool importMesh(const std::string& filename, std::vector<std::string>& attrNames, ImportSurfacique::ImportType kind);
Pierre Kraemer's avatar
Pierre Kraemer committed
104

Pierre Kraemer's avatar
Pierre Kraemer committed
105
	bool importTrian(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
106

Pierre Kraemer's avatar
Pierre Kraemer committed
107
	bool importTrianBinGz(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
108

Pierre Kraemer's avatar
Pierre Kraemer committed
109
	bool importOff(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
110

Pierre Kraemer's avatar
Pierre Kraemer committed
111
	bool importObj(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
112

Pierre Kraemer's avatar
Pierre Kraemer committed
113
	bool importPly(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
114

Pierre Kraemer's avatar
Pierre Kraemer committed
115
	bool importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames);
116
	bool importPlyPTMgeneric(const std::string& filename, std::vector<std::string>& attrNames);
Sylvain Thery's avatar
Sylvain Thery committed
117
#ifdef WITH_ASSIMP
Pierre Kraemer's avatar
Pierre Kraemer committed
118
	bool importASSIMP(const std::string& filename, std::vector<std::string>& attrNames);
Sylvain Thery's avatar
Sylvain Thery committed
119
#endif	
120
	bool mergeCloseVertices();
Pierre Kraemer's avatar
Pierre Kraemer committed
121

122
	bool importAHEM(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
123
124
125
126
127
128

	/**
	 * @param container container of vertex orbite
	 * @param idPositions id of position attribute in the container
	 * @param idLabels id of label attribute in the container
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
129
130
	MeshTablesSurface(typename PFP::MAP& map):
		m_map(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
131
132
133
134
135
136
137
138
139
	{
	}
};


template <typename PFP>
class MeshTablesVolume
{
protected:
140
141
	typename PFP::MAP& m_map;

142
	unsigned int m_nbVertices;
Pierre Kraemer's avatar
Pierre Kraemer committed
143

144
	unsigned int m_nbFaces;
Pierre Kraemer's avatar
Pierre Kraemer committed
145

146
	unsigned int m_nbVolumes;
Pierre Kraemer's avatar
Pierre Kraemer committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

	/**
	* 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;

	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;

168
	inline short getNbEdgesFace(int i) const  { return m_nbEdges[i]; }
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171
172
173
174
175
176
177
178
179
180
181

	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]; }

182
	bool importMesh(const std::string& filename, std::vector<std::string>& attrNames, ImportVolumique::ImportType kind, float scaleFactor);
Pierre Kraemer's avatar
Pierre Kraemer committed
183

184
	bool importTet(const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor);
Pierre Kraemer's avatar
Pierre Kraemer committed
185

186
	bool importPly(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
187

188
	bool importTrianBinGz(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
189

190
191
	MeshTablesVolume(typename PFP::MAP& map):
		m_map(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
	{
	}
};

} // namespace Import

} // namespace Algo

} // namespace CGoGN

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

#endif