mapMulti.h 8.01 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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#ifndef __MAP_MULTI__
#define __MAP_MULTI__

Pierre Kraemer's avatar
Pierre Kraemer committed
28
#include "Topology/generic/genericmap.h"
29 30 31 32

namespace CGoGN
{

33 34
class MapMono;

Pierre Kraemer's avatar
Pierre Kraemer committed
35
class MapMulti : public GenericMap
36
{
37
	template<typename MAP> friend class DartMarkerTmpl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
38
	template<typename MAP> friend class DartMarkerStore ;
39

40 41 42 43 44
public:
	MapMulti()
	{
		initMR();
	}
45

46
	inline virtual void clear(bool removeAttrib);
47 48

protected:
49 50 51
	// protected copy constructor to prevent the copy of map
	MapMulti(const MapMulti& m): GenericMap(m) {}

52
	std::vector<AttributeMultiVector<Dart>*> m_involution;
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
	std::vector<AttributeMultiVector<Dart>*> m_permutation;
	std::vector<AttributeMultiVector<Dart>*> m_permutation_inv;

	/**
	 * container for multiresolution darts
	 */
	AttributeContainer m_mrattribs ;

	/**
	 * pointers to attributes of m_mrattribs that store indices of m_attribs[DART]
	 * (one for each level)
	 */
	std::vector< AttributeMultiVector<unsigned int>* > m_mrDarts ;

	/**
	 * pointer to attribute of m_mrattribs that stores darts insertion levels
	 */
	AttributeMultiVector<unsigned int>* m_mrLevels ;

	/**
	 * vector that stores the number of darts inserted on each resolution level
	 */
	std::vector<unsigned int> m_mrNbDarts ;

	/**
	 * current level in multiresolution map
	 */
	unsigned int m_mrCurrentLevel ;

	/**
	 * stack for current level temporary storage
	 */
	std::vector<unsigned int> m_mrLevelStack ;

	/****************************************
	 *          DARTS MANAGEMENT            *
	 ****************************************/
90

Pierre Kraemer's avatar
Pierre Kraemer committed
91
	inline Dart newDart();
92 93 94

	inline virtual void deleteDart(Dart d);

95
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
96 97 98
	inline unsigned int dartIndex(Dart d) const;

	inline Dart indexDart(unsigned int index) const;
99 100 101 102

	/**
	 * get the number of darts inserted in the given leveldart
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
103
	inline unsigned int getNbInsertedDarts(unsigned int level) const;
104 105 106 107

	/**
	 * get the number of darts that define the map of the given leveldart
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
108
	inline unsigned int getNbDarts(unsigned int level) const;
109 110 111 112

	/**
	 * @return the number of darts in the map
	 */
113
	inline unsigned int getNbDarts() const;
114

115 116
	inline AttributeContainer& getDartContainer();

117 118 119
	/**
	 * get the insertion level of a dart
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
120
	inline unsigned int getDartLevel(Dart d) const;
121

122
protected:
123 124 125
	/**
	 *
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
126
	inline void incDartLevel(Dart d) const ;
127 128 129 130

	/**
	 * duplicate a dart starting from current level
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
131
	inline void duplicateDart(Dart d) ;
132

Pierre Kraemer's avatar
Pierre Kraemer committed
133
	inline void duplicateDartAtOneLevel(Dart d, unsigned int level) ;
134 135 136 137 138 139 140 141

	/****************************************
	 *        RELATIONS MANAGEMENT          *
	 ****************************************/

	inline void addInvolution();
	inline void addPermutation();

142 143 144 145
	inline AttributeMultiVector<Dart>* getInvolutionAttribute(unsigned int i);
	inline AttributeMultiVector<Dart>* getPermutationAttribute(unsigned int i);
	inline AttributeMultiVector<Dart>* getPermutationInvAttribute(unsigned int i);

Pierre Kraemer's avatar
Pierre Kraemer committed
146 147 148
	virtual unsigned int getNbInvolutions() const = 0;
	virtual unsigned int getNbPermutations() const = 0;

149 150 151 152 153 154 155 156 157 158
	template <int I>
	inline Dart getInvolution(Dart d) const;

	template <int I>
	inline Dart getPermutation(Dart d) const;

	template <int I>
	inline Dart getPermutationInv(Dart d) const;

	template <int I>
Pierre Kraemer's avatar
Pierre Kraemer committed
159
	inline void involutionSew(Dart d, Dart e);
160 161

	template <int I>
Pierre Kraemer's avatar
Pierre Kraemer committed
162
	inline void involutionUnsew(Dart d);
163

164
	template <int I>
Pierre Kraemer's avatar
Pierre Kraemer committed
165
	inline void permutationSew(Dart d, Dart e);
166 167

	template <int I>
Pierre Kraemer's avatar
Pierre Kraemer committed
168
	inline void permutationUnsew(Dart d);
169

170
	virtual void compactTopo();
171

172 173 174
	/****************************************
	 *      MR CONTAINER MANAGEMENT         *
	 ****************************************/
175
public:
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
	/**
	 * get the MR attribute container
	 */
	AttributeContainer& getMRAttributeContainer() ;

	/**
	 * get the MR attribute container
	 */
	AttributeMultiVector<unsigned int>* getMRDartAttributeVector(unsigned int level) ;
	AttributeMultiVector<unsigned int>* getMRLevelAttributeVector();

	/****************************************
	 *     RESOLUTION LEVELS MANAGEMENT     *
	 ****************************************/

	void printMR() ;

	/**
	 * initialize the multiresolution attribute container
	 */
	void initMR() ;

	/**
	 * get the current resolution level
	 */
	unsigned int getCurrentLevel() ;

	/**
	 * set the current resolution level
	 */
	void setCurrentLevel(unsigned int l) ;

	/**
	 * increment the current resolution level
	 */
	void incCurrentLevel() ;

	/**
	 * decrement the current resolution level
	 */
	void decCurrentLevel() ;

	/**
	 * store current resolution level on a stack
	 */
	void pushLevel() ;

	/**
	 * set as current the resolution level of the top of the stack
	 */
	void popLevel() ;

	/**
	 * get the maximum resolution level
	 */
	unsigned int getMaxLevel() ;

	/**
	 * add a resolution level in the back of the level table
	 */
	void addLevelBack() ;

	/**
	 * add a resolution level in the front of the level table
	 */
	void addLevelFront();

	/**
	 * remove last resolution level
	 */
	void removeLevelBack() ;

	/**
	 * remove first resolution level
	 */
	void removeLevelFront();

	/**
	 * copy MRDarts from level-1 to level
	 */
	void copyLevel(unsigned int level);

	/**
	 * duplicate darts from level-1 to level
	 */
	void duplicateDarts(unsigned int newlevel);

	/****************************************
	 *           DARTS TRAVERSALS           *
	 ****************************************/

	/**
	 * Begin of map
	 * @return the first dart of the map
	 */
271
	inline Dart begin() const;
272 273 274 275 276

	/**
	 * End of map
	 * @return the end iterator (next of last) of the map
	 */
277
	inline Dart end() const;
278 279 280 281 282 283

	/**
	 * allow to go from a dart to the next
	 * in the order of storage
	 * @param d reference to the dart to be modified
	 */
284 285 286 287
	inline void next(Dart& d) const;

	/**
	 * Apply a functor on each dart of the map
288
	 * @param f a callable taking a Dart parameter
289
	 */
290 291 292 293 294
	template <typename FUNC>
	void foreach_dart(FUNC f) ;

	template <typename FUNC>
	void foreach_dart(FUNC& f) ;
295 296 297 298 299 300 301 302 303 304

	/****************************************
	 *             SAVE & LOAD              *
	 ****************************************/

	bool saveMapBin(const std::string& filename) const;

	bool loadMapBin(const std::string& filename);

	bool copyFrom(const GenericMap& map);
Pierre Kraemer's avatar
Pierre Kraemer committed
305

306 307
	bool copyFromOtherType(const MapMono& map);

Pierre Kraemer's avatar
Pierre Kraemer committed
308
	void restore_topo_shortcuts();
Sylvain Thery's avatar
Sylvain Thery committed
309 310

	virtual void dumpCSV() const;
311
} ;
312 313 314

} //namespace CGoGN

315
#include "Topology/generic/mapImpl/mapMulti.hpp"
316

317
#endif