importNodeEle.hpp 6.9 KB
Newer Older
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
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "Algo/Modelisation/polyhedron.h"
#include <vector>

namespace CGoGN
{

namespace Algo
{

34
35
36
namespace Volume
{

37
38
39
40
41
42
43
44
namespace Import 
{

template <typename PFP>
bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenameNode, const std::string& filenameELE, std::vector<std::string>& attrNames)
{
	typedef typename PFP::VEC3 VEC3;

45
	VertexAttribute<VEC3> position = map.template addAttribute<VEC3, VERTEX>("position") ;
46
47
	attrNames.push_back(position.name()) ;

48
	AttributeContainer& container = map.template getAttributeContainer<VERTEX>() ;
49
50

	unsigned int m_nbVertices = 0, m_nbFaces = 0, m_nbEdges = 0, m_nbVolumes = 0;
51
	VertexAutoAttribute< NoMathIONameAttribute< std::vector<Dart> > > vecDartsPerVertex(map, "incidents");
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

	//open file
	std::ifstream fnode(filenameNode.c_str(), std::ios::in);
	if (!fnode.good())
	{
		CGoGNerr << "Unable to open file " << filenameNode << CGoGNendl;
		return false;
	}

	std::ifstream fele(filenameELE.c_str(), std::ios::in);
	if (!fele.good())
	{
		CGoGNerr << "Unable to open file " << filenameELE << CGoGNendl;
		return false;
	}

	std::string line;

//	do
//	{
//		std::getline(fnode,line);
//	}while(line.rfind("#") == 0);

	//Reading NODE file
	//First line: [# of points] [dimension (must be 3)] [# of attributes] [# of boundary markers (0 or 1)]
	unsigned int nbe;
	{
		do
		{
			std::getline(fnode,line);
		}while(line.size() == 0);

		std::stringstream oss(line);
		oss >> m_nbVertices;
		oss >> nbe;
		oss >> nbe;
		oss >> nbe;
	}

	//Reading number of tetrahedra in ELE file
	unsigned int nbv;
	{
		do
		{
			std::getline(fele,line);
		}while(line.size() == 0);

		std::stringstream oss(line);
		oss >> m_nbVolumes;
		oss >> nbv ; oss >> nbv;
	}

	CGoGNout << "nb points = " << m_nbVertices << " / nb faces = " << m_nbFaces << " / nb edges = " << m_nbEdges << " / nb tet = " << m_nbVolumes << CGoGNendl;

	//Reading vertices
	//Remaining lines: [point #] [x] [y] [z] [optional attributes] [optional boundary marker]
	std::vector<unsigned int> verticesID;
	verticesID.reserve(m_nbVertices);

	for(unsigned int i = 0 ; i < m_nbVertices ; ++i)
	{
		do
		{
			std::getline(fnode,line);
		}while(line.size() == 0);

		std::stringstream oss(line);

		int idv;
		oss >> idv;

		float x,y,z;
		oss >> x;
		oss >> y;
		oss >> z;
		//we can read colors informations if exists
		VEC3 pos(x,y,z);

		unsigned int id = container.insertLine();
		position[id] = pos;

		verticesID.push_back(id);
	}

	std::vector<std::vector<Dart> > vecDartPtrEmb;
	vecDartPtrEmb.reserve(m_nbVertices);

	DartMarkerNoUnmark m(map) ;

	//Read and embed tetrahedra TODO
	for(unsigned i = 0; i < m_nbVolumes ; ++i)
	{
		do
		{
			std::getline(fele,line);
		} while(line.size() == 0);

		std::stringstream oss(line);
		oss >> nbe;

152
		Dart d = Surface::Modelisation::createTetrahedron<PFP>(map,false);
untereiner's avatar
untereiner committed
153

154
		Geom::Vec4ui pt;
155
156
157
158
159
160
161
162
//		oss >> pt[0];
//		--(pt[0]);
//		oss >> pt[1];
//		--(pt[1]);
//		oss >> pt[2];
//		--(pt[2]);
//		oss >> pt[3];
//		--(pt[3]);
163
164
165
166
167
168
		oss >> pt[1];
		--(pt[1]);
		oss >> pt[2];
		--(pt[2]);
		oss >> pt[3];
		--(pt[3]);
169
170
		oss >> pt[0];
		--(pt[0]);
171
172
173
174
175
176
177

		//regions ?
		//oss >> nbe;

		// Embed three vertices
		for(unsigned int j = 0 ; j < 3 ; ++j)
		{
178
			FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesID[pt[2-j]]);
Pierre Kraemer's avatar
Pierre Kraemer committed
179
			map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb);
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

			//store darts per vertices to optimize reconstruction
			Dart dd = d;
			do
			{
				m.mark(dd) ;
				vecDartsPerVertex[pt[2-j]].push_back(dd);
				dd = map.phi1(map.phi2(dd));
			} while(dd != d);

			d = map.phi1(d);

		}

		//Embed the last vertex
		d = map.phi_1(map.phi2(d));

197
		FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesID[pt[3]]);
Pierre Kraemer's avatar
Pierre Kraemer committed
198
		map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb);
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

		//store darts per vertices to optimize reconstruction
		Dart dd = d;
		do
		{
			m.mark(dd) ;
			vecDartsPerVertex[pt[3]].push_back(dd);
			dd = map.phi1(map.phi2(dd));
		} while(dd != d);

	}

	fnode.close();
	fele.close();

	//Association des phi3
	unsigned int nbBoundaryFaces = 0 ;
	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (m.isMarked(d))
		{
			std::vector<Dart>& vec = vecDartsPerVertex[map.phi1(d)];

			Dart good_dart = NIL;
			for(typename std::vector<Dart>::iterator it = vec.begin(); it != vec.end() && good_dart == NIL; ++it)
			{
225
226
227
				if(map.template getEmbedding<VERTEX>(map.phi1(*it)) == map.template getEmbedding<VERTEX>(d) &&
				   map.template getEmbedding<VERTEX>(map.phi_1(*it)) == map.template getEmbedding<VERTEX>(map.phi_1(d)) /*&&
				   map.template getEmbedding<VERTEX>(*it) == map.template getEmbedding<VERTEX>(map.phi1(d)) */)
228
229
230
231
232
233
234
235
				{
					good_dart = *it ;
				}
			}

			if (good_dart != NIL)
			{
				map.sewVolumes(d, good_dart, false);
236
				m.template unmarkOrbit<FACE>(d);
237
238
239
			}
			else
			{
Pierre Kraemer's avatar
Pierre Kraemer committed
240
				m.unmarkOrbit<PFP::MAP::FACE_OF_PARENT>(d);
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
				++nbBoundaryFaces;
			}
		}
	}

	if (nbBoundaryFaces > 0)
	{
		std::cout << "closing" << std::endl ;
		map.closeMap();
		CGoGNout << "Map closed (" << nbBoundaryFaces << " boundary faces)" << CGoGNendl;
	}

	return true;
}

} // namespace Import

258
259
}

260
261
262
} // namespace Algo

} // namespace CGoGN