mapMulti.h 7.46 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

44 45
	virtual void clear(bool removeAttrib)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
46
		GenericMap::clear(removeAttrib);
47 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 85 86 87 88
		initMR();
	}

protected:
	std::vector<AttributeMultiVector<Dart>*> m_permutation;
	std::vector<AttributeMultiVector<Dart>*> m_permutation_inv;
	std::vector<AttributeMultiVector<Dart>*> m_involution;

	/**
	 * 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            *
	 ****************************************/
89
public:
90 91 92 93
	inline virtual Dart newDart();

	inline virtual void deleteDart(Dart d);

Pierre Kraemer's avatar
Pierre Kraemer committed
94 95 96
	inline unsigned int dartIndex(Dart d) const;

	inline Dart indexDart(unsigned int index) const;
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

	/**
	 * get the number of darts inserted in the given leveldart
	 */
	unsigned int getNbInsertedDarts(unsigned int level) ;

	/**
	 * get the number of darts that define the map of the given leveldart
	 */
	virtual unsigned int getNbDarts(unsigned int level) ;

	/**
	 * @return the number of darts in the map
	 */
	virtual unsigned int getNbDarts() ;

113 114
	inline AttributeContainer& getDartContainer();

115 116 117 118 119
	/**
	 * get the insertion level of a dart
	 */
	unsigned int getDartLevel(Dart d) const ;

120
protected:
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	/**
	 *
	 */
	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
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 166
	inline virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);

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 266 267 268 269 270 271 272 273 274 275 276 277 278 279
	/**
	 * 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
	 */
	inline virtual Dart begin() const;

	/**
	 * End of map
	 * @return the end iterator (next of last) of the map
	 */
	inline virtual Dart end() const;

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

	/****************************************
	 *             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
290 291

	void restore_topo_shortcuts();
292
} ;
293 294 295

} //namespace CGoGN

296 297
#include "Topology/generic/mapMulti.hpp"

298
#endif