map1.hpp 6.13 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

/// INLINE FUNCTIONS

30
inline void Map1::init()
Pierre Kraemer's avatar
Pierre Kraemer committed
31
32
33
34
35
{
	m_phi1 = addRelation("phi1") ;
	m_phi_1 = addRelation("phi_1") ;
}

36
37
38
39
40
inline Map1::Map1() : AttribMap()
{
	init() ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
41
42
inline std::string Map1::mapTypeName()
{
43
	return "Map1" ;
Pierre Kraemer's avatar
Pierre Kraemer committed
44
45
46
47
}

inline unsigned int Map1::dimension()
{
48
49
50
51
52
53
	return 1 ;
}

inline void Map1::clear(bool removeAttrib)
{
	AttribMap::clear(removeAttrib) ;
Sylvain Thery's avatar
Sylvain Thery committed
54
55
	if (removeAttrib)
		init() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
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
152
153
154
}

/*! @name Basic Topological Operators
 * Access and Modification
 *************************************************************************/

inline Dart Map1::newDart()
{
	Dart d = GenericMap::newDart() ;
	(*m_phi1)[d.index] = d ;
	(*m_phi_1)[d.index] = d ;
	return d ;
}

inline Dart Map1::phi1(Dart d)
{
	return (*m_phi1)[d.index] ;
}

inline Dart Map1::phi_1(Dart d)
{
	return (*m_phi_1)[d.index] ;
}

template <int N>
inline Dart Map1::phi(Dart d)
{
	assert((N > 0) || !"negative parameters not allowed in template multi-phi");
	if (N < 10)
	{
		switch(N)
		{
			case 1 : return phi1(d) ;
			default : assert(!"Wrong multi-phi relation value") ; return d ;
		}
	}
	switch(N%10)
	{
		case 1 : return phi1(phi<N/10>(d)) ;
		default : assert(!"Wrong multi-phi relation value") ; return d ;
	}
}

inline Dart Map1::alpha1(Dart d)
{
	return phi1(d) ;
}

inline Dart Map1::alpha_1(Dart d)
{
	return phi_1(d) ;
}

inline void Map1::phi1sew(Dart d, Dart e)
{
	Dart f = (*m_phi1)[d.index] ;
	Dart g = (*m_phi1)[e.index] ;
	(*m_phi1)[d.index] = g ;
	(*m_phi1)[e.index] = f ;
	(*m_phi_1)[g.index] = d ;
	(*m_phi_1)[f.index] = e ;
}

inline void Map1::phi1unsew(Dart d)
{
	Dart e = (*m_phi1)[d.index] ;
	Dart f = (*m_phi1)[e.index] ;
	(*m_phi1)[d.index] = f ;
	(*m_phi1)[e.index] = e ;
	(*m_phi_1)[f.index] = d ;
	(*m_phi_1)[e.index] = e ;
}

inline int Map1::getDartsPerTriangle()
{
	return 3 ;
}

/*! @name Generator and Deletor
 *  To generate or delete faces in a 1-map
 *************************************************************************/

inline Dart Map1::newFace(unsigned int nbEdges)
{
	return newOrientedFace(nbEdges) ;
}

inline void Map1::deleteFace(Dart d)
{
	deleteOrientedFace(d) ;
}

/*! @name Topological Operators
 *  Topological operations on 1-maps
 *************************************************************************/

inline void Map1::cutEdge(Dart d)
{
	Dart e = newDart() ;	// Create a new dart
Pierre Kraemer's avatar
Pierre Kraemer committed
155
	phi1sew(d, e) ;			// Insert dart e between d and phi1(d)
Pierre Kraemer's avatar
Pierre Kraemer committed
156
157
158
159
160
161
162
163
164
165
166
}

inline void Map1::collapseEdge(Dart d)
{
	phi1unsew(phi_1(d)) ;	// Dart before d is linked to its successor
	deleteDart(d) ;			// Dart d is erased
}

inline void Map1::splitFace(Dart d, Dart e)
{
	assert(d != e && sameOrientedFace(d, e)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
167
168
	Map1::cutEdge(phi_1(d));		// cut the edge before d (insert a new dart before d)
	Map1::cutEdge(phi_1(e));		// cut the edge before e (insert a new dart before e)
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171
	phi1sew(phi_1(d), phi_1(e)) ;	// phi1sew between the 2 new inserted darts
}

Thomas's avatar
Thomas committed
172
173
174
175
176
177
178
179
inline void Map1::linkVertices(Dart d, Dart e)
{
	assert(d != e && !sameOrientedFace(d, e)) ;
	Map1::cutEdge(phi_1(d));		// cut the edge before d (insert a new dart before d)
	Map1::cutEdge(phi_1(e));		// cut the edge before e (insert a new dart before e)
	phi1sew(phi_1(d), phi_1(e)) ;	// phi1sew between the 2 new inserted darts
}

Pierre Kraemer's avatar
Pierre Kraemer committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
inline void Map1::mergeFaces(Dart d, Dart e)
{
	assert(!sameOrientedFace(d, e)) ;
	phi1sew(d, phi_1(e)) ;
	phi1sew(e, phi_1(d)) ;
	deleteOrientedFace(d) ;
}

/*! @name Topological Queries
 *  Return or set various topological information
 *************************************************************************/

inline bool Map1::sameFace(Dart d, Dart e)
{
	return sameOrientedFace(d, e) ;
}

/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
201
inline bool Map1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
202
203
204
205
{
	return f(d) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
206
inline bool Map1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
207
208
209
210
{
	return f(d) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
211
inline bool Map1::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
212
{
Sylvain Thery's avatar
Sylvain Thery committed
213
	return foreach_dart_of_oriented_face(d, f, thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
214
215
}

Sylvain Thery's avatar
Sylvain Thery committed
216
inline bool Map1::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
217
{
Sylvain Thery's avatar
Sylvain Thery committed
218
	return foreach_dart_of_oriented_face(d, f, thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
219
220
}

Sylvain Thery's avatar
Sylvain Thery committed
221
inline bool Map1::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
222
{
Sylvain Thery's avatar
Sylvain Thery committed
223
	return foreach_dart_of_oriented_face(d, f, thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
224
225
226
}

} // namespace CGoGN