mapBrowser.hpp 4.58 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
/*******************************************************************************
* 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
{


inline MapBrowserSelector::MapBrowserSelector(AttribMap& m, const FunctorSelect& fs) :
30
31
32
33
34
35
36
37
38
	m_map(m)
{
	m_selector = fs.copy();
}

inline MapBrowserSelector::~MapBrowserSelector()
{
	delete m_selector;
}
39
40
41

inline Dart MapBrowserSelector::begin() const
{
42
	Dart d = m_map.realBegin() ;
43
	while ( (d != m_map.realEnd()) && !m_selector->operator()(d) )
44
45
46
		m_map.realNext(d);

	return d;
47
48
49
50
51
52
53
54
55
56
57
58
59
}

inline Dart MapBrowserSelector::end() const
{
	return m_map.realEnd() ;
}

inline void MapBrowserSelector::next(Dart& d) const
{
	do
	{
		m_map.realNext(d) ;
	}
60
	while ( (d != m_map.realEnd()) && !m_selector->operator()(d) ) ;
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
}


inline MapBrowserLinked::MapBrowserLinked(AttribMap& m) :
	m_map(m), autoAttribute(true), m_first(NIL), m_end(NIL)
{
	m_links = m.addAttribute<Dart, DART>("") ;
}

inline MapBrowserLinked::MapBrowserLinked(AttribMap& m, DartAttribute<Dart>& links) :
	m_map(m), autoAttribute(false), m_links(links), m_first(NIL), m_end(NIL)
{
}

inline MapBrowserLinked::MapBrowserLinked(AttribMap& m, DartAttribute<Dart>& links, Dart first, Dart end) :
	m_map(m), autoAttribute(false), m_links(links), m_first(first), m_end(end)
{
}

inline MapBrowserLinked::~MapBrowserLinked()
{
	if (autoAttribute)
		m_map.removeAttribute(m_links) ;
}

inline DartAttribute<Dart>& MapBrowserLinked::getLinkAttr()
{
	return m_links;
}

inline void MapBrowserLinked::clear()
{
	m_first = NIL ;
	m_end = NIL ;
}

inline Dart MapBrowserLinked::begin() const
{
	return m_first ;
}

inline Dart MapBrowserLinked::end() const
{
	return NIL ;
}

inline void MapBrowserLinked::next(Dart& d) const
{
	assert(d != NIL) ;
	d = m_links[d] ;
}

inline void MapBrowserLinked::pushFront(Dart d)
{
	assert(d != NIL) ;
	m_links[d] = m_first ;
	m_first = d ;
	if (m_end == NIL)		// empty list
		m_end = d ;
}

inline void MapBrowserLinked::pushBack(Dart d)
{
	assert(d != NIL) ;
	m_links[d] = NIL ;
	if (m_first == NIL)		// empty list
	{
		m_first = d ;
		m_end = d ;
	}
	else
	{
		m_links[m_end] = d ;
		m_end = d ;
	}
}

inline void MapBrowserLinked::popFront()
{
	if (m_first == m_end)	// one element or empty list
	{
		m_first = NIL ;
		m_end = NIL ;
	}
	else m_first = m_links[m_first] ;
}


inline void MapBrowserLinked::addSelected(const FunctorSelect& fs)
{
	for (Dart d = m_map.begin() ; d != m_map.end() ; m_map.next(d))
	{
		if (fs(d))
			//			pushFront(d) ;
			pushBack(d); // better tot use push_back for memory access
	}
}

// operator() for use of foreach_cell
inline bool MapBrowserLinked::operator()(Dart d)
{
	pushFront(d) ;
	return false ;
}

inline void MapBrowserLinked::append(MapBrowserLinked& mbl)
{
	// nothing to append
	if (mbl.m_end == NIL)
		return;
	if (m_end == NIL)
	{
		m_first = mbl.m_first;
		m_end = mbl.m_end;
		return;
	}

	m_links[m_end] = mbl.m_first;
	m_end = mbl.m_end;
}


} // namespace CGoGN