import2tables.h 6.43 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef _IMPORT2TABLE_H
#define _IMPORT2TABLE_H

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

#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"

36
#include "Utils/gzstream.h"
37

38
#include "Algo/Import/importFileTypes.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
39
#include "Algo/Modelisation/voxellisation.h"
40

Sylvain Thery's avatar
Sylvain Thery committed
41
#ifdef WITH_ASSIMP
42 43 44
#include "Assimp/assimp.h"
#include "Assimp/aiPostProcess.h"
#include "Assimp/aiScene.h"
Sylvain Thery's avatar
Sylvain Thery committed
45
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47 48 49 50 51 52

namespace CGoGN
{

namespace Algo
{

53 54 55
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
56 57 58 59 60 61 62
namespace Import
{

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

65
	unsigned int m_nbVertices;
Pierre Kraemer's avatar
Pierre Kraemer committed
66

67
	unsigned int m_nbFaces;
Pierre Kraemer's avatar
Pierre Kraemer committed
68 69

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

Pierre Kraemer's avatar
Pierre Kraemer committed
71 72 73 74 75 76 77 78 79 80
	/**
	* 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;

81
	static ImportType getFileType(const std::string& filename);
Pierre Kraemer's avatar
Pierre Kraemer committed
82

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

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

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

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
99
	bool importMesh(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
100

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
105
	bool importOff(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 108
    bool importVoxellisation(Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector<std::string>& attrNames);

109 110
	bool importMeshBin(const std::string& filename, std::vector<std::string>& attrNames);

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

115
	// bool importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames);
116
	bool importPlySLFgeneric(const std::string& filename, std::vector<std::string>& attrNames);
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
117
	bool importPlySLFgenericBin(const std::string& filename, std::vector<std::string>& attrNames);
118

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

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

126 127 128 129
	bool importSTLAscii(const std::string& filename, std::vector<std::string>& attrNames);

	bool importSTLBin(const std::string& filename, std::vector<std::string>& attrNames);

Pierre Kraemer's avatar
Pierre Kraemer committed
130 131 132 133 134
	/**
	 * @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
135 136
	MeshTablesSurface(typename PFP::MAP& map):
		m_map(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139 140
	{
	}
};

141 142 143 144 145 146 147 148 149
}
}


namespace Volume
{
namespace Import
{

Pierre Kraemer's avatar
Pierre Kraemer committed
150 151 152 153
template <typename PFP>
class MeshTablesVolume
{
protected:
154 155
	typename PFP::MAP& m_map;

156
	unsigned int m_nbVertices;
Pierre Kraemer's avatar
Pierre Kraemer committed
157

158
	unsigned int m_nbFaces;
Pierre Kraemer's avatar
Pierre Kraemer committed
159

160
	unsigned int m_nbVolumes;
Pierre Kraemer's avatar
Pierre Kraemer committed
161 162 163 164 165 166 167 168 169 170 171

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

172
	static ImportType getFileType(const std::string& filename);
Pierre Kraemer's avatar
Pierre Kraemer committed
173 174 175 176 177 178 179 180 181

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;

182
	inline short getNbEdgesFace(int i) const  { return m_nbEdges[i]; }
Pierre Kraemer's avatar
Pierre Kraemer committed
183 184 185 186 187 188 189 190 191 192 193 194 195

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

Pierre Kraemer's avatar
Pierre Kraemer committed
196
	bool importMesh(const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
197

198
	bool importTet(const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
199

200 201
	MeshTablesVolume(typename PFP::MAP& map):
		m_map(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
202 203 204 205
	{
	}
};

206

Pierre Kraemer's avatar
Pierre Kraemer committed
207 208
} // namespace Import

209 210 211
}


Pierre Kraemer's avatar
Pierre Kraemer committed
212 213 214 215 216 217 218 219
} // namespace Algo

} // namespace CGoGN

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

#endif