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

map2MR_PrimalRegular.hpp 7.65 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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

untereiner's avatar
untereiner committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace Algo
{

namespace MR
{

namespace Primal
{

namespace Regular
{

template <typename PFP>
Map2MR<PFP>::Map2MR(typename PFP::MAP& map) :
	m_map(map),
untereiner's avatar
untereiner committed
43
44
	shareVertexEmbeddings(true),
	filter(F_None)
Pierre Kraemer's avatar
Pierre Kraemer committed
45
{
untereiner's avatar
untereiner committed
46

Pierre Kraemer's avatar
Pierre Kraemer committed
47
48
}

49
50
51
52
53
54
55
56
57
58
59
60
61
template <typename PFP>
Map2MR<PFP>::~Map2MR()
{
	unsigned int level = m_map.getCurrentLevel();
	unsigned int maxL = m_map.getMaxLevel();

	for(unsigned int i = maxL ; i > level ; --i)
		m_map.removeLevelBack();

	for(unsigned int i = 0 ; i < level ; ++i)
		m_map.removeLevelFront();
}

untereiner's avatar
untereiner committed
62
template <typename PFP>
63
void Map2MR<PFP>::addNewLevel(bool triQuad)
Pierre Kraemer's avatar
Pierre Kraemer committed
64
{
untereiner's avatar
untereiner committed
65
	m_map.pushLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
66

untereiner's avatar
untereiner committed
67
68
69
	m_map.addLevelBack() ;
	m_map.duplicateDarts(m_map.getMaxLevel());
	m_map.setCurrentLevel(m_map.getMaxLevel()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
70
71

	// cut edges
untereiner's avatar
untereiner committed
72
	TraversorE<typename PFP::MAP> travE(m_map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
73
74
	for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
	{
75
76
77
78
79
80
81
//		if(!shareVertexEmbeddings)
//		{
//			if(m_map.template getEmbedding<VERTEX>(d) == EMBNULL)
//				m_map.template setOrbitEmbeddingOnNewCell<VERTEX>(d) ;
//			if(m_map.template getEmbedding<VERTEX>(m_map.phi1(d)) == EMBNULL)
//				m_map.template setOrbitEmbeddingOnNewCell<VERTEX>(d) ;
//		}
Pierre Kraemer's avatar
Pierre Kraemer committed
82

untereiner's avatar
untereiner committed
83
		m_map.cutEdge(d) ;
84
		travE.skip(d) ;
untereiner's avatar
untereiner committed
85
		travE.skip(m_map.phi1(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
86
87
88
89

	}

	// split faces
untereiner's avatar
untereiner committed
90
	TraversorF<typename PFP::MAP> travF(m_map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
91
92
93
	for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
	{
		Dart old = d ;
untereiner's avatar
untereiner committed
94
95
		if(m_map.getDartLevel(old) == m_map.getMaxLevel())
			old = m_map.phi1(old) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
96

untereiner's avatar
untereiner committed
97
98
99
		m_map.decCurrentLevel() ;
		unsigned int degree = m_map.faceDegree(old) ;
		m_map.incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
100

101
		if(triQuad && (degree == 3))					// if subdividing a triangle
Pierre Kraemer's avatar
Pierre Kraemer committed
102
		{
untereiner's avatar
untereiner committed
103
104
105
			Dart dd = m_map.phi1(old) ;
			Dart e = m_map.phi1(m_map.phi1(dd)) ;
			m_map.splitFace(dd, e) ;
106
			travF.skip(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
107
108

			dd = e ;
untereiner's avatar
untereiner committed
109
110
			e = m_map.phi1(m_map.phi1(dd)) ;
			m_map.splitFace(dd, e) ;
111
			travF.skip(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
112
113

			dd = e ;
untereiner's avatar
untereiner committed
114
115
			e = m_map.phi1(m_map.phi1(dd)) ;
			m_map.splitFace(dd, e) ;
116
			travF.skip(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
117

118
			travF.skip(e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
119
120
121
		}
		else							// if subdividing a polygonal face
		{
untereiner's avatar
untereiner committed
122
123
124
			Dart dd = m_map.phi1(old) ;
			Dart next = m_map.phi1(m_map.phi1(dd)) ;
			m_map.splitFace(dd, next) ;		// insert a first edge
Pierre Kraemer's avatar
Pierre Kraemer committed
125

126
			Dart ne = m_map.phi2(m_map.phi_1(dd)) ;
untereiner's avatar
untereiner committed
127
			m_map.cutEdge(ne) ;				// cut the new edge to insert the central vertex
128
			travF.skip(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
129

untereiner's avatar
untereiner committed
130
			dd = m_map.phi1(m_map.phi1(next)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
131
132
			while(dd != ne)				// turn around the face and insert new edges
			{							// linked to the central vertex
untereiner's avatar
untereiner committed
133
134
				Dart tmp = m_map.phi1(ne) ;
				m_map.splitFace(tmp, dd) ;
135
				travF.skip(tmp) ;
untereiner's avatar
untereiner committed
136
				dd = m_map.phi1(m_map.phi1(dd)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
137
			}
138
			travF.skip(ne) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
139
140
141
		}
	}

untereiner's avatar
untereiner committed
142
	m_map.popLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
143
144
}

145
template <typename PFP>
untereiner's avatar
untereiner committed
146
void Map2MR<PFP>::addNewLevelSqrt3()
147
148
149
150
151
152
153
{
	m_map.pushLevel() ;

	m_map.addLevelBack() ;
	m_map.duplicateDarts(m_map.getMaxLevel());
	m_map.setCurrentLevel(m_map.getMaxLevel()) ;

154
155
156
157
158
159
160
161
	//split faces
	TraversorF<typename PFP::MAP> t(m_map) ;
	for (Dart dit = t.begin(); dit != t.end(); dit = t.next())
	{
		//if it is an even level (triadic refinement) and a boundary face
		if((m_map.getCurrentLevel()%2 == 0) && m_map.isBoundaryFace(dit))
		{
			//find the boundary edge
162
			Dart df = m_map.findBoundaryEdgeOfFace(dit);
163
			//trisection of the boundary edge
164
165
166
167
168
169
			m_map.cutEdge(df) ;
			m_map.splitFace(m_map.phi2(df), m_map.phi1(m_map.phi1(m_map.phi2(df)))) ;

			df = m_map.phi1(df);
			m_map.cutEdge(df) ;
			m_map.splitFace(m_map.phi2(df), m_map.phi1(m_map.phi1(m_map.phi2(df)))) ;
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
		}
		else
		{
			Dart d1 = m_map.phi1(dit);
			m_map.splitFace(dit, d1) ;
			m_map.cutEdge(m_map.phi_1(dit)) ;
			Dart x = m_map.phi2(m_map.phi_1(dit)) ;
			Dart dd = m_map.phi1(m_map.phi1(m_map.phi1((x))));
			while(dd != x)
			{
				Dart next = m_map.phi1(dd) ;
				m_map.splitFace(dd, m_map.phi1(x)) ;
				dd = next ;
			}

			Dart cd = m_map.phi2(x);

			Dart fit = cd ;
			do
			{
				t.skip(fit);
				fit = m_map.phi2(m_map.phi_1(fit));
			} while(fit != cd);
		}
	}

	//swap edges
	TraversorE<typename PFP::MAP> te(m_map) ;
	for (Dart dit = te.begin(); dit != te.end(); dit = te.next())
	{
200
		if(!m_map.isBoundaryEdge(dit) && m_map.getDartLevel(dit) < m_map.getCurrentLevel())
201
202
203
204
205
206
207
			m_map.flipEdge(dit);
	}

	m_map.popLevel() ;
}

template <typename PFP>
untereiner's avatar
untereiner committed
208
void Map2MR<PFP>::addNewLevelSqrt2()
209
210
211
212
213
214
215
{
	m_map.pushLevel() ;

	m_map.addLevelBack() ;
	m_map.duplicateDarts(m_map.getMaxLevel());
	m_map.setCurrentLevel(m_map.getMaxLevel()) ;

216
	//split faces
untereiner's avatar
untereiner committed
217
	TraversorF<typename PFP::MAP> t(m_map) ;
218
219
220
	for (Dart dit = t.begin(); dit != t.end(); dit = t.next())
	{
		Dart d1 = m_map.phi1(dit);
untereiner's avatar
untereiner committed
221
222
		m_map.splitFace(dit, d1) ;
		m_map.cutEdge(m_map.phi_1(dit)) ;
223
		Dart x = m_map.phi2(m_map.phi_1(dit)) ;
untereiner's avatar
untereiner committed
224
		Dart dd = m_map.phi1(m_map.phi1(m_map.phi1((x))));
225
226
227
		while(dd != x)
		{
			Dart next = m_map.phi1(dd) ;
untereiner's avatar
untereiner committed
228
			m_map.splitFace(dd, m_map.phi1(x)) ;
229
230
231
232
233
234
235
236
237
			dd = next ;
		}

		Dart cd = m_map.phi2(x);

		Dart fit = cd ;
		do
		{
			t.skip(fit);
untereiner's avatar
untereiner committed
238
			fit = m_map.phi2(m_map.phi_1(fit));
239
240
241
242
243
244
		} while(fit != cd);
	}

	m_map.popLevel() ;
}

untereiner's avatar
untereiner committed
245
246
template <typename PFP>
void Map2MR<PFP>::analysis()
Pierre Kraemer's avatar
Pierre Kraemer committed
247
{
untereiner's avatar
untereiner committed
248
	assert(m_map.getCurrentLevel() > 0 || !"analysis : called on level 0") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
249

untereiner's avatar
untereiner committed
250
	m_map.decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
251
252
253
254
255

	for(unsigned int i = 0; i < analysisFilters.size(); ++i)
		(*analysisFilters[i])() ;
}

untereiner's avatar
untereiner committed
256
257
template <typename PFP>
void Map2MR<PFP>::synthesis()
Pierre Kraemer's avatar
Pierre Kraemer committed
258
{
untereiner's avatar
untereiner committed
259
	assert(m_map.getCurrentLevel() < m_map.getMaxLevel() || !"synthesis : called on max level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
260
261
262
263

	for(unsigned int i = 0; i < synthesisFilters.size(); ++i)
		(*synthesisFilters[i])() ;

untereiner's avatar
untereiner committed
264
265
266
267
268
269
270
271
272
273
//	for(unsigned int i = 0; i < synthesisFilters.size(); ++i)
//	{
//		if((filter == F_LowPass && m_map.getCurrentLevel() <= thresholdHigh) ||
//		(filter == F_HighPass && m_map.getCurrentLevel() >= thresholdLow) ||
//		(filter == F_BandPass && (thresholdLow >= m_map.getCurrentLevel() &&  m_map.getCurrentLevel() <= thresholdHigh)))
//			(*synthesisFilters[i])(true) ;
//		else
//			(*synthesisFilters[i])(false) ;
//	}

untereiner's avatar
untereiner committed
274
	m_map.incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
275
276
}

untereiner's avatar
untereiner committed
277
278
279
280
281
282
283
284
285

} // namespace Regular

} // namespace Primal

} // namespace MR

} // namespace Algo

Pierre Kraemer's avatar
Pierre Kraemer committed
286
} // namespace CGoGN