mapMulti.h 7.7 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
{

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

38 39 40 41 42
public:
	MapMulti()
	{
		initMR();
	}
43

Pierre Kraemer's avatar
Pierre Kraemer committed
44
	inline virtual void clear(bool removeAttrib);
45 46

protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
47
	std::vector<AttributeMultiVector<Dart>*> m_involution;
48 49 50 51 52 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
	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            *
	 ****************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
85

Pierre Kraemer's avatar
Pierre Kraemer committed
86
	inline Dart newDart();
87 88 89

	inline virtual void deleteDart(Dart d);

Pierre Kraemer's avatar
Pierre Kraemer committed
90
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
91 92 93
	inline unsigned int dartIndex(Dart d) const;

	inline Dart indexDart(unsigned int index) const;
94 95 96 97

	/**
	 * get the number of darts inserted in the given leveldart
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
98
	unsigned int getNbInsertedDarts(unsigned int level) const;
99 100 101 102

	/**
	 * get the number of darts that define the map of the given leveldart
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
103
	unsigned int getNbDarts(unsigned int level) const;
104 105 106 107

	/**
	 * @return the number of darts in the map
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
108
	virtual unsigned int getNbDarts() const;
109

110 111
	inline AttributeContainer& getDartContainer();

112 113 114
	/**
	 * get the insertion level of a dart
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
115
	unsigned int getDartLevel(Dart d) const;
116

117
protected:
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
	/**
	 *
	 */
	void incDartLevel(Dart d) const ;

	/**
	 * duplicate a dart starting from current level
	 */
	void duplicateDart(Dart d) ;

	void duplicateDartAtOneLevel(Dart d, unsigned int level) ;

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139 140
	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
141 142 143
	virtual unsigned int getNbInvolutions() const = 0;
	virtual unsigned int getNbPermutations() const = 0;

144 145 146 147 148 149 150 151 152 153
	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
154
	inline void involutionSew(Dart d, Dart e);
155 156

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

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

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

165
	inline virtual void compactTopo();
166

167 168 169
	/****************************************
	 *      MR CONTAINER MANAGEMENT         *
	 ****************************************/
170
public:
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 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
	/**
	 * 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
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
266
	inline Dart begin() const;
267 268 269 270 271

	/**
	 * End of map
	 * @return the end iterator (next of last) of the map
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
272
	inline Dart end() const;
273 274 275 276 277 278

	/**
	 * allow to go from a dart to the next
	 * in the order of storage
	 * @param d reference to the dart to be modified
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
279 280 281 282 283 284 285
	inline void next(Dart& d) const;

	/**
	 * Apply a functor on each dart of the map
	 * @param f a ref to the functor obj
	 */
	bool foreach_dart(FunctorType& f) ;
286 287 288 289 290 291 292 293 294 295

	/****************************************
	 *             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
296 297

	void restore_topo_shortcuts();
298
} ;
299 300 301

} //namespace CGoGN

302 303
#include "Topology/generic/mapMulti.hpp"

304
#endif