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

namespace CGoGN
{

/// INLINE FUNCTIONS

30
inline void Map2::init()
Pierre Kraemer's avatar
Pierre Kraemer committed
31
32
33
34
{
	m_phi2 = addRelation("phi2") ;
}

35
36
37
38
39
inline Map2::Map2() : Map1()
{
	init() ;
}

40
inline std::string Map2::mapTypeName() const
Pierre Kraemer's avatar
Pierre Kraemer committed
41
42
43
44
{
	return "Map2" ;
}

45
inline unsigned int Map2::dimension() const
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
48
49
{
	return 2 ;
}

50
51
52
inline void Map2::clear(bool removeAttrib)
{
	Map1::clear(removeAttrib) ;
Sylvain Thery's avatar
Sylvain Thery committed
53
54
	if (removeAttrib)
		init() ;
55
56
}

Sylvain Thery's avatar
Sylvain Thery committed
57
58
59
60
61
62
inline void Map2::update_topo_shortcuts()
{
	Map1::update_topo_shortcuts();
	m_phi2 = getRelation("phi2");
}

Pierre Kraemer's avatar
Pierre Kraemer committed
63
64
65
66
67
68
69
/*! @name Basic Topological Operators
 * Access and Modification
 *************************************************************************/

inline Dart Map2::newDart()
{
	Dart d = Map1::newDart() ;
70
	(*m_phi2)[dartIndex(d)] = d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
71
72
73
74
75
76
77
78
79
80
	if(m_isMultiRes)
	{
		pushLevel() ;
		for(unsigned int i = m_mrCurrentLevel + 1;  i < m_mrDarts.size(); ++i)
		{
			setCurrentLevel(i) ;
			(*m_phi2)[dartIndex(d)] = d ;
		}
		popLevel() ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
81
82
83
	return d ;
}

Sylvain Thery's avatar
Sylvain Thery committed
84
inline Dart Map2::phi2(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
85
{
86
	return (*m_phi2)[dartIndex(d)] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
87
88
89
}

template <int N>
Sylvain Thery's avatar
Sylvain Thery committed
90
inline Dart Map2::phi(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{
	assert( (N > 0) || !"negative parameters not allowed in template multi-phi");
	if (N < 10)
	{
		switch(N)
		{
			case 1 : return phi1(d) ;
			case 2 : return phi2(d) ;
			default : assert(!"Wrong multi-phi relation value") ; return d ;
		}
	}
	switch(N%10)
	{
		case 1 : return phi1(phi<N/10>(d)) ;
		case 2 : return phi2(phi<N/10>(d)) ;
		default : assert(!"Wrong multi-phi relation value") ; return d ;
	}
}

Sylvain Thery's avatar
Sylvain Thery committed
110
inline Dart Map2::alpha0(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
113
114
{
	return phi2(d) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
115
inline Dart Map2::alpha1(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
116
117
118
119
{
	return phi2(phi_1(d)) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
120
inline Dart Map2::alpha_1(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
121
122
123
124
{
	return phi1(phi2(d)) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
125
inline Dart Map2::phi2_1(Dart d) const
126
127
128
129
{
	return phi2(phi_1(d)) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
130
inline Dart Map2::phi12(Dart d) const
131
132
133
134
{
	return phi1(phi2(d)) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
135
136
inline void Map2::phi2sew(Dart d, Dart e)
{
137
138
139
140
141
142
	unsigned int d_index = dartIndex(d);
	unsigned int e_index = dartIndex(e);
	assert((*m_phi2)[d_index] == d) ;
	assert((*m_phi2)[e_index] == e) ;
	(*m_phi2)[d_index] = e ;
	(*m_phi2)[e_index] = d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
143
144
145
146
}

inline void Map2::phi2unsew(Dart d)
{
147
148
149
	unsigned int d_index = dartIndex(d);
	Dart e = (*m_phi2)[d_index] ;
	(*m_phi2)[d_index] = d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
150
	(*m_phi2)[dartIndex(e)] = e ;
Pierre Kraemer's avatar
Pierre Kraemer committed
151
152
153
154
155
156
}

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

Sylvain Thery's avatar
Sylvain Thery committed
157
inline bool Map2::sameVertex(Dart d, Dart e) const
Pierre Kraemer's avatar
Pierre Kraemer committed
158
159
160
161
{
	return sameOrientedVertex(d, e) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
162
inline bool Map2::sameEdge(Dart d, Dart e) const
Pierre Kraemer's avatar
Pierre Kraemer committed
163
164
165
166
{
	return d == e || phi2(d) == e ;
}

Sylvain Thery's avatar
Sylvain Thery committed
167
inline bool Map2::isBoundaryEdge(Dart d) const
untereiner's avatar
untereiner committed
168
{
Thery Sylvain's avatar
Thery Sylvain committed
169
	return isBoundaryMarked2(d) || isBoundaryMarked2(phi2(d));
untereiner's avatar
untereiner committed
170
171
}

Sylvain Thery's avatar
Sylvain Thery committed
172
inline bool Map2::sameOrientedFace(Dart d, Dart e) const
173
174
175
176
{
	return Map1::sameCycle(d, e) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
177
inline bool Map2::sameFace(Dart d, Dart e) const
178
179
180
181
{
	return sameOrientedFace(d, e) ;
}

Sylvain Thery's avatar
Sylvain Thery committed
182
inline unsigned int Map2::faceDegree(Dart d) const
183
184
185
186
{
	return Map1::cycleDegree(d) ;
}

187

Sylvain Thery's avatar
Sylvain Thery committed
188
inline int Map2::checkFaceDegree(Dart d, unsigned int le) const
189
190
191
192
193
{
	return Map1::checkCycleDegree(d,le) ;
}


Sylvain Thery's avatar
Sylvain Thery committed
194
inline bool Map2::sameVolume(Dart d, Dart e) const
195
196
197
198
{
	return sameOrientedVolume(d, e) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
199
200
201
202
/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
203
inline bool Map2::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const
Pierre Kraemer's avatar
Pierre Kraemer committed
204
{
205
	return Map1::foreach_dart_of_cc(d, f, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
206
207
}

Sylvain Thery's avatar
Sylvain Thery committed
208
inline bool Map2::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const
Pierre Kraemer's avatar
Pierre Kraemer committed
209
210
211
{
	return foreach_dart_of_cc(d, f, thread);
}
212

Sylvain Thery's avatar
Sylvain Thery committed
213
inline bool Map2::foreach_dart_of_vertex1(Dart d, FunctorType& f, unsigned int thread) const
214
215
216
217
{
	return Map1::foreach_dart_of_vertex(d,f,thread);
}

Sylvain Thery's avatar
Sylvain Thery committed
218
inline bool Map2::foreach_dart_of_edge1(Dart d, FunctorType& f, unsigned int thread) const
Pierre Kraemer's avatar
Pierre Kraemer committed
219
{
220
	return Map1::foreach_dart_of_edge(d,f,thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
221
222
223
}

} // namespace CGoGN