import2tables.h 7.23 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

41
#ifdef CGOGN_WITH_ASSIMP
42 43 44
#include "assimp.h"
#include "aiPostProcess.h"
#include "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
namespace Import
{

template <typename PFP>
class MeshTablesSurface
{
62
public:
63
	typedef typename PFP::MAP MAP ;
64
    typedef typename PFP::VEC3 VEC3 ;
65
	typedef typename VEC3::DATA_TYPE DATA_TYPE ;
66
	typedef typename PFP::REAL REAL ;
67

68
protected:
69
	MAP& m_map;
Pierre Kraemer's avatar
Pierre Kraemer committed
70

71
	unsigned int m_nbVertices;
Pierre Kraemer's avatar
Pierre Kraemer committed
72

73
	unsigned int m_nbFaces;
Pierre Kraemer's avatar
Pierre Kraemer committed
74 75

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

Pierre Kraemer's avatar
Pierre Kraemer committed
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;

87
#ifdef CGOGN_WITH_ASSIMP
88
	void extractMeshRec(AttributeContainer& container, VertexAttribute<VEC3, MAP>& 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

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

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
99
    bool importObj(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 importPly(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
102

103 104
    //bool importPlyPTM(const std::string& filename, std::vector<std::string>& attrNames);

105
	bool importPlySLFgeneric(const std::string& filename, std::vector<std::string>& attrNames);
106

107
#ifdef CGOGN_WITH_ASSIMP
Pierre Kraemer's avatar
Pierre Kraemer committed
108
	bool importASSIMP(const std::string& filename, std::vector<std::string>& attrNames);
Sylvain Thery's avatar
Sylvain Thery committed
109
#endif	
Pierre Kraemer's avatar
Pierre Kraemer committed
110

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

113 114 115 116
	bool importSTLAscii(const std::string& filename, std::vector<std::string>& attrNames);

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

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
public:
    //static ImportType getFileType(const std::string& filename);

    bool mergeCloseVertices();

    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 importMesh(const std::string& filename, std::vector<std::string>& attrNames);

    bool importVoxellisation(Algo::Surface::Modelisation::Voxellisation& voxellisation, std::vector<std::string>& attrNames);

134 135
	bool importPlySLFgenericBin(const std::string& filename, std::vector<std::string>& attrNames);

136 137 138 139
	template <typename PFP3>
	bool import3DMap(typename PFP3::MAP& map, std::vector<std::string>& attrNames);


140
	MeshTablesSurface(MAP& map):
Pierre Kraemer's avatar
Pierre Kraemer committed
141
		m_map(map)
142
    { }
Pierre Kraemer's avatar
Pierre Kraemer committed
143 144
};

145 146 147
} // namespace Import

} // namespace Surface
148 149 150 151


namespace Volume
{
152

153 154 155
namespace Import
{

Pierre Kraemer's avatar
Pierre Kraemer committed
156 157 158
template <typename PFP>
class MeshTablesVolume
{
159
public:
160
	typedef typename PFP::MAP MAP ;
161 162 163 164 165
    typedef typename PFP::VEC3 VEC3 ;
    typedef typename VEC3::DATA_TYPE DATA_TYPE ;
    typedef typename PFP::REAL REAL;

private:
166
	MAP& m_map;
167

168
	unsigned int m_nbVertices;
Pierre Kraemer's avatar
Pierre Kraemer committed
169

170
    unsigned int m_nbVolumes;
Pierre Kraemer's avatar
Pierre Kraemer committed
171

172 173 174 175
    /**
     * number of faces per volume
     */
    std::vector<short> m_nbFaces;
Pierre Kraemer's avatar
Pierre Kraemer committed
176 177 178 179 180 181

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

182
    //Tetrahedra
Pierre Kraemer's avatar
Pierre Kraemer committed
183

184 185 186 187 188 189 190 191 192 193 194 195 196
    /**
     * @brief importTet
     * @param filename
     * @param attrNames
     * @return
     */
    bool importTet(const std::string& filename, std::vector<std::string>& attrNames);

    bool importOFFWithELERegions(const std::string& filenameOFF, const std::string& filenameELE, std::vector<std::string>& attrNames);

    bool importNodeWithELERegions(const std::string& filenameNode, const std::string& filenameELE, std::vector<std::string>& attrNames);

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

198
    bool importTs(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
199

200
    //TODO Hexahedra : not working yet
Pierre Kraemer's avatar
Pierre Kraemer committed
201

202
    bool importMSH(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
203

204
    bool importVTU(const std::string& filename, std::vector<std::string>& attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
205

206 207 208 209
    bool importNAS(const std::string& filename, std::vector<std::string>& attrNames);

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

210 211
	//TODO Moka / OVM not working

212 213 214 215 216 217
    //bool importMoka(const std::string& filename, std::vector<std::string>& attrNames);

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

public:
    inline unsigned getNbVertices() const { return m_nbVertices; }
Pierre Kraemer's avatar
Pierre Kraemer committed
218

219
    inline unsigned getNbVolumes() const { return m_nbVolumes; }
Pierre Kraemer's avatar
Pierre Kraemer committed
220

221
    inline short getNbFacesVolume(int i) const { return m_nbFaces[i]; }
Pierre Kraemer's avatar
Pierre Kraemer committed
222

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

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

227
	MeshTablesVolume(MAP& map):
228
		m_map(map)
229
    { }
Pierre Kraemer's avatar
Pierre Kraemer committed
230 231
};

232

Pierre Kraemer's avatar
Pierre Kraemer committed
233 234
} // namespace Import

235
} // namespace Volume
236 237


Pierre Kraemer's avatar
Pierre Kraemer committed
238 239 240 241 242 243 244 245
} // namespace Algo

} // namespace CGoGN

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

#endif