mapCommon.h 9.3 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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
/*******************************************************************************
* 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_COMMON__
#define __MAP_COMMON__

#include "Topology/generic/attributeHandler.h"
Sylvain Thery's avatar
Sylvain Thery committed
29
#include "Topology/generic/cells.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33

namespace CGoGN
{

Pierre Kraemer's avatar
Pierre Kraemer committed
34
template <typename MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
35 36 37 38
class MapCommon : public MAP_IMPL
{
	typedef MAP_IMPL IMPL;

39 40 41 42 43 44
protected:
	// protected copy constructor to prevent the copy of map
	MapCommon(const MapCommon<MAP_IMPL>& m) : MAP_IMPL(m) {}
public:
	MapCommon() {}

Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47 48 49 50 51 52 53 54 55
	/****************************************
	 *           DARTS TRAVERSALS           *
	 ****************************************/
public:

	//! For an orbit of a given dimension, return the number of incident cells of an other given dimension
	/*! @param d a dart
	 */
	template <unsigned int ORBIT, unsigned int INCIDENT>
	unsigned int degree(Dart d) const;

Sylvain Thery's avatar
Sylvain Thery committed
56
	template <unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
57
	bool sameOrbit(Cell<ORBIT> c1, Cell<ORBIT> c2, unsigned int thread = 0) const;
Sylvain Thery's avatar
Sylvain Thery committed
58

Pierre Kraemer's avatar
Pierre Kraemer committed
59 60 61 62 63 64 65 66 67
	/****************************************
	 *         EMBEDDING MANAGEMENT         *
	 ****************************************/

	/**
	 * get the cell index of the given dimension associated to dart d
	 * @return EMBNULL if the orbit of d is not attached to any cell
	 */
	template<unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
68
	inline unsigned int getEmbedding(Cell<ORBIT> d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
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

	/**
	 * Set the cell index of the given dimension associated to dart d
	 */
	template <unsigned int ORBIT>
	void setDartEmbedding(Dart d, unsigned int emb) ;

	/**
	 * Set the cell index of the given dimension associated to dart d
	 * !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding) !!! WARNING !!!
	 */
	template <unsigned int ORBIT>
	void initDartEmbedding(Dart d, unsigned int emb) ;

	/**
	 * Copy the index of the cell associated to a dart over an other dart
	 * @param orbit the id of orbit embedding
	 * @param dest the dart to overwrite
	 * @param src the dart to copy
	 */
	template <unsigned int ORBIT>
	inline void copyDartEmbedding(Dart dest, Dart src) ;

	/**
	* Set the index of the associated cell to all the darts of an orbit
	* @param orbit orbit to embed
	* @param d a dart of the topological vertex
	* @param em index of attribute to store as embedding
	*/
	template <unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
99
	void setOrbitEmbedding(Cell<ORBIT> d, unsigned int em) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
100 101 102 103 104 105

	/**
	 * Set the index of the associated cell to all the darts of an orbit
	 * !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding)!!! WARNING !!!
	 */
	template <unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
106
	void initOrbitEmbedding(Cell<ORBIT> d, unsigned int em) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
107 108 109 110 111 112 113 114

	/**
	* Associate an new cell to all darts of an orbit
	* @param orbit orbit to embed
	* @param d a dart of the topological cell
	* @return index of the attribute in table
	*/
	template <unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
115
	unsigned int setOrbitEmbeddingOnNewCell(Cell<ORBIT> d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
116 117 118 119 120 121

	/**
	 * Associate an new cell to all darts of an orbit
	 * !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding)!!! WARNING !!!
	 */
	template <unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
122
	unsigned int initOrbitEmbeddingOnNewCell(Cell<ORBIT> d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
123 124 125 126 127 128 129 130

	/**
	 * Copy the cell associated to a dart over an other dart
	 * @param orbit attribute orbit to use
	 * @param d the dart to overwrite (dest)
	 * @param e the dart to copy (src)
	 */
	template <unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
131
	void copyCellAttributes(Cell<ORBIT> d, Cell<ORBIT> e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133 134 135

	/****************************************
	 *         BOUNDARY MANAGEMENT          *
	 ****************************************/
136

Pierre Kraemer's avatar
Pierre Kraemer committed
137
protected:
138 139


Pierre Kraemer's avatar
Pierre Kraemer committed
140 141 142
	/**
	 * mark a dart as  belonging to boundary
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
143
	template <unsigned int DIM>
Pierre Kraemer's avatar
Pierre Kraemer committed
144 145 146 147 148
	void boundaryMark(Dart d) ;

	/**
	 * unmark a dart from the boundary
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
149
	template <unsigned int DIM>
Pierre Kraemer's avatar
Pierre Kraemer committed
150 151 152
	void boundaryUnmark(Dart d) ;

	/**
153
	 * mark an orbit as belonging to boundary
Pierre Kraemer's avatar
Pierre Kraemer committed
154
	 */
155 156
	template <unsigned int DIM, unsigned int ORBIT>
	void boundaryMarkOrbit(Cell<ORBIT> c) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158

	/**
159
	 * unmark an orbit from the boundary
Pierre Kraemer's avatar
Pierre Kraemer committed
160
	 */
161 162
	template <unsigned int DIM, unsigned int ORBIT>
	void boundaryUnmarkOrbit(Cell<ORBIT> c) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
163

Pierre Kraemer's avatar
Pierre Kraemer committed
164 165 166 167 168 169
	/**
	 * clear all boundary markers
	 */
	template<unsigned int DIM>
	void boundaryUnmarkAll() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172 173
public:
	/**
	 * test if a dart belong to the boundary
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
174 175
	template <unsigned int DIM>
	inline bool isBoundaryMarked(Dart d) const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
176

Pierre Kraemer's avatar
Pierre Kraemer committed
177 178 179
	inline bool isBoundaryMarkedCurrent(Dart d) const ;

	inline bool isBoundaryMarked(unsigned int dim, Dart d) const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
180 181 182 183 184 185 186 187 188 189 190

	/****************************************
	 *        ATTRIBUTES MANAGEMENT         *
	 ****************************************/

	/**
	* Create an attribute for a given orbit
	* @param nameAttr attribute name
	* @return an AttributeHandler
	*/
	template <typename T, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
191
	inline AttributeHandler<T, ORBIT, MAP_IMPL> addAttribute(const std::string& nameAttr = "") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
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

	/**
	 * remove an attribute
	 * @param attr a handler to the attribute to remove
	 * @return true if remove succeed else false
	 */
	template <typename T, unsigned int ORBIT>
	inline bool removeAttribute(AttributeHandler<T, ORBIT, MAP_IMPL>& attr) ;

	/**
	* search an attribute for a given orbit
	* @param nameAttr attribute name
	* @return an AttributeHandler
	*/
	template <typename T, unsigned int ORBIT>
	inline AttributeHandler<T, ORBIT, MAP_IMPL> getAttribute(const std::string& nameAttr) ;

	/**
	* check if an attribute exist ( get, test if valid and add if necessary)
	* @param nameAttr attribute name
	* @return an AttributeHandler
	*/
	template <typename T, unsigned int ORBIT>
	AttributeHandler<T, ORBIT, MAP_IMPL> checkAttribute(const std::string& nameAttr) ;

	/**
	 * swap the content of two attributes (efficient, only swap pointers)
	 */
	template <typename T, unsigned int ORBIT>
	bool swapAttributes(AttributeHandler<T, ORBIT, MAP_IMPL>& attr1, AttributeHandler<T, ORBIT, MAP_IMPL>& attr2) ;

	/**
	 * copy the content of src attribute to dst attribute
	 */
	template <typename T, unsigned int ORBIT>
	bool copyAttribute(AttributeHandler<T, ORBIT, MAP_IMPL>& dst, AttributeHandler<T, ORBIT, MAP_IMPL>& src) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
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 280 281 282
	/**
	 * get a DartAttribute to an involution of the map
	 */
	inline DartAttribute<Dart, MAP_IMPL> getInvolution(unsigned int i);

	/**
	 * get a DartAttribute to a permutation of the map
	 */
	inline DartAttribute<Dart, MAP_IMPL> getPermutation(unsigned int i);

	/**
	 * get a DartAttribute to a permutation of the map
	 */
	inline DartAttribute<Dart, MAP_IMPL> getPermutationInv(unsigned int i);

	/****************************************
	 *     QUICK TRAVERSAL MANAGEMENT       *
	 ****************************************/

	template <unsigned int ORBIT>
	void enableQuickTraversal() ;

	template <unsigned int ORBIT>
	void updateQuickTraversal() ;

	template <unsigned int ORBIT>
	const AttributeMultiVector<Dart>* getQuickTraversal() const;

	template <unsigned int ORBIT>
	void disableQuickTraversal() ;

	template <unsigned int ORBIT, unsigned int INCI>
	void enableQuickIncidentTraversal();

	template <unsigned int ORBIT, unsigned int INCI>
	void updateQuickIncidentTraversal();

	template <unsigned int ORBIT, unsigned int INCI>
	const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* getQuickIncidentTraversal() const;

	template <unsigned int ORBIT, unsigned int INCI>
	void disableQuickIncidentTraversal();

	template <unsigned int ORBIT, unsigned int ADJ>
	void enableQuickAdjacentTraversal();

	template <unsigned int ORBIT, unsigned int ADJ>
	void updateQuickAdjacentTraversal();

	template <unsigned int ORBIT, unsigned int INCI>
	const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* getQuickAdjacentTraversal() const;

	template <unsigned int ORBIT, unsigned int ADJ>
	void disableQuickAdjacentTraversal();
Pierre Kraemer's avatar
Pierre Kraemer committed
283 284 285 286 287 288 289
};

} //namespace CGoGN

#include "Topology/generic/mapCommon.hpp"

#endif