ihm3.h 11.8 KB
Newer Older
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
21 22 23 24 25 26 27
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __IMPLICIT_HIERARCHICAL_MAP3__
#define __IMPLICIT_HIERARCHICAL_MAP3__

28
#include "Topology/map/embeddedMap3.h"
29
#include "Algo/Multiresolution/filter.h"
30 31 32 33 34 35 36

namespace CGoGN
{

namespace Algo
{

37 38 39
namespace Volume
{

untereiner's avatar
untereiner committed
40
namespace IHM
41 42
{

Pierre Kraemer's avatar
Pierre Kraemer committed
43
template<typename T, unsigned int ORBIT> class AttributeHandler_IHM ;
44

Pierre Kraemer's avatar
Pierre Kraemer committed
45 46
typedef EmbeddedMap3::IMPL EMap3_IMPL;

47
class ImplicitHierarchicalMap3 : public EmbeddedMap3
48
{
Pierre Kraemer's avatar
Pierre Kraemer committed
49
	template<typename T, unsigned int ORBIT> friend class AttributeHandler_IHM ;
50 51

public:
52 53 54 55 56
	FunctorType* vertexVertexFunctor ;
	FunctorType* edgeVertexFunctor ;
	FunctorType* faceVertexFunctor ;
	FunctorType* volumeVertexFunctor ;

57 58 59 60 61
	unsigned int m_curLevel ;
	unsigned int m_maxLevel ;
	unsigned int m_edgeIdCount ;
	unsigned int m_faceIdCount;

Pierre Kraemer's avatar
Pierre Kraemer committed
62 63 64
	DartAttribute<unsigned int, EMap3_IMPL> m_dartLevel ;
	DartAttribute<unsigned int, EMap3_IMPL> m_edgeId ;
	DartAttribute<unsigned int, EMap3_IMPL> m_faceId ;
65

Sylvain Thery's avatar
Sylvain Thery committed
66
	AttributeMultiVector<unsigned int>* m_nextLevelCell[NB_ORBITS] ;
67

68 69
//    std::vector<Algo::MR::Filter*> synthesisFilters ;
//    std::vector<Algo::MR::Filter*> analysisFilters ;
70

71 72 73 74 75
public:
	ImplicitHierarchicalMap3() ;

	~ImplicitHierarchicalMap3() ;

76
	static const unsigned int DIMENSION = 3 ;
77 78 79 80 81

	//!
	/*!
	 *
	 */
82 83
	void update_topo_shortcuts();

84 85 86 87
	//!
	/*!
	 *
	 */
88
	void initImplicitProperties() ;
89

90 91 92 93 94 95
	/**
	 * clear the map
	 * @param remove attrib remove attribute (not only clear the content)
	 */
	void clear(bool removeAttrib);

96 97 98
	/*! @name Attributes Management
	 *  To handles Attributes for each level of an implicit 3-map
	 *************************************************************************/
99

100 101 102 103 104
	//@{
	//!
	/*!
	 *
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
105 106
	template <typename T, unsigned int ORBIT>
	AttributeHandler_IHM<T, ORBIT> addAttribute(const std::string& nameAttr) ;
untereiner's avatar
untereiner committed
107

108 109 110 111
	//!
	/*!
	 *
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113
	template <typename T, unsigned int ORBIT>
	AttributeHandler_IHM<T, ORBIT> getAttribute(const std::string& nameAttr) ;
114
	//@}
untereiner's avatar
untereiner committed
115

116 117 118
	/*! @name Basic Topological Operators
	 *  Redefinition of the basic topological operators
	 *************************************************************************/
119

120
	//@{
121 122
	virtual Dart newDart() ;

Sylvain Thery's avatar
Sylvain Thery committed
123
	Dart phi1(Dart d) const;
124

Sylvain Thery's avatar
Sylvain Thery committed
125
	Dart phi_1(Dart d) const;
126

Sylvain Thery's avatar
Sylvain Thery committed
127
	Dart phi2(Dart d) const;
128

129
private:
Sylvain Thery's avatar
Sylvain Thery committed
130
	Dart phi2bis(Dart d) const;
131 132

public:
Sylvain Thery's avatar
Sylvain Thery committed
133
	Dart phi3(Dart d) const;
134

Sylvain Thery's avatar
Sylvain Thery committed
135
	Dart alpha0(Dart d) const;
136

Sylvain Thery's avatar
Sylvain Thery committed
137
	Dart alpha1(Dart d) const;
138

Sylvain Thery's avatar
Sylvain Thery committed
139
	Dart alpha2(Dart d) const;
140

Sylvain Thery's avatar
Sylvain Thery committed
141
	Dart alpha_2(Dart d) const;
142
	//@}
143

untereiner's avatar
untereiner committed
144 145 146 147
	/*! @name Topological Operators with Cells id management
	 *  Topological operations on Hierarchical Implicit 3-maps
	 *************************************************************************/

148 149 150 151
//	void deleteVolume(Dart d);

	bool isWellEmbedded();

untereiner's avatar
untereiner committed
152 153
	//@{

154 155 156 157 158 159
	//!
	/*!
	 *
	 */
	void swapEdges(Dart d, Dart e);

160 161 162 163




164 165
//    void addSynthesisFilter(Algo::MR::Filter* f) { synthesisFilters.push_back(f) ; }
//    void addAnalysisFilter(Algo::MR::Filter* f) { analysisFilters.push_back(f) ; }
166

167 168
//    void clearSynthesisFilters() { synthesisFilters.clear() ; }
//    void clearAnalysisFilters() { analysisFilters.clear() ; }
169

170 171
//    void analysis() ;
//    void synthesis() ;
172

173 174 175 176 177 178 179 180 181 182
	//!
	/*!
	 *
	 */
	void saveRelationsAroundVertex(Dart d, std::vector<std::pair<Dart, Dart> >& vd);

	void unsewAroundVertex(std::vector<std::pair<Dart, Dart> >& vd);

	Dart quadranguleFace(Dart d);

183
	void deleteVertexSubdividedFace(Dart d);
untereiner's avatar
untereiner committed
184
	//@}
185

186 187 188 189 190
	void setVertexVertexFunctor(FunctorType* f) { vertexVertexFunctor = f ; }
	void setEdgeVertexFunctor(FunctorType* f) { edgeVertexFunctor = f ; }
	void setFaceVertexFunctor(FunctorType* f) { faceVertexFunctor = f ; }
	void setVolumeVertexFunctor(FunctorType* f) { volumeVertexFunctor = f ; }

191 192 193 194 195
	void computeVertexVertexFunctor(Dart d) { (*vertexVertexFunctor)(d); }
	void computeEdgeVertexFunctor(Dart d) { (*edgeVertexFunctor)(d); }
	void computeFaceVertexFunctor(Dart d) { (*faceVertexFunctor)(d); }
	void computerVolumeVertexFunctor(Dart d) { (*volumeVertexFunctor)(d); }

196 197 198 199
	/*! @name Levels Management
	 *  Operations to manage the levels of an Implicit Hierarchical 3-map
	 *************************************************************************/

untereiner's avatar
untereiner committed
200 201 202 203 204
	void incCurrentLevel();

	void decCurrentLevel();


205 206 207 208 209
	//@{
	//!
	/*!
	 *
	 */
Sylvain Thery's avatar
Sylvain Thery committed
210
	unsigned int getCurrentLevel() const ;
211

212 213 214 215
	//!
	/*!
	 *
	 */
216 217
	void setCurrentLevel(unsigned int l) ;

218 219 220 221
	//!
	/*!
	 *
	 */
Sylvain Thery's avatar
Sylvain Thery committed
222
	unsigned int getMaxLevel() const ;
223

224 225 226 227
	//!
	/*!
	 *
	 */
Sylvain Thery's avatar
Sylvain Thery committed
228
	unsigned int getDartLevel(Dart d) const ;
229

230 231 232 233
	//!
	/*!
	 *
	 */
234
	void setDartLevel(Dart d, unsigned int i) ;
235
	//@}
236

237 238 239
	/*! @name Id Management
	 * Operations to manage the ids of edges and faces
	 *************************************************************************/
240

241 242 243
	//@{
	//! Give a new unique id to all the edges of the map
	/*!
244 245 246
	 */
	void initEdgeId() ;

247 248
	//! Return the next available edge id
	/*!
249 250 251
	 */
	unsigned int getNewEdgeId() ;

252 253
	//! Return the id of the edge of d
	/*!
254
	 */
255 256
	unsigned int getEdgeId(Dart d) ;

257 258
	//! Set an edge id to all darts from an orbit of d
	/*!
259
	 */
260 261
	void setEdgeId(Dart d, unsigned int i, unsigned int orbit); //TODO a virer
	void setEdgeId(Dart d, unsigned int i);
262

263 264
	//! Give a new unique id to all the faces of the map
	/*!
265
	 */
266 267
	void initFaceId() ;

268 269
	//! Return the next available face id
	/*!
270 271 272
	 */
	unsigned int getNewFaceId() ;

273 274
	//! Return the id of the face of d
	/*!
275
	 */
276 277
	unsigned int getFaceId(Dart d) ;

278 279
	//! Set a face id to all darts from an orbit of d
	/*!
280
	 */
281
	void setFaceId(Dart d, unsigned int i, unsigned int orbit); //TODO a virer
282
	void setFaceId(unsigned int orbit, Dart d);
283
	//@}
284

285 286 287
	/*! @name Cells Information
	 * Operations to manage the cells informations :
	 *************************************************************************/
288

289 290 291
	//@{
	//! Return the level of insertion of the vertex of d
	/*!
292
	 */
Sylvain Thery's avatar
Sylvain Thery committed
293
	unsigned int vertexInsertionLevel(Dart d) const;
294

295 296
	//! Return the level of the edge of d in the current level map
	/*!
297 298 299
	 */
	unsigned int edgeLevel(Dart d) ;

300 301
	//! Return the level of the face of d in the current level map
	/*!
302 303 304
	 */
	unsigned int faceLevel(Dart d);

305 306
	//! Return the level of the volume of d in the current level map
	/*!
307 308 309
	 */
	unsigned int volumeLevel(Dart d);

310 311
	//! Return the oldest dart of the face of d in the current level map
	/*!
312 313 314
	 */
	Dart faceOldestDart(Dart d);

315 316
	//! Return the oldest dart of the volume of d in the current level map
	/*!
317 318 319
	 */
	Dart volumeOldestDart(Dart d);

320 321 322
	//! Return true if the edge of d in the current level map
	//! has already been subdivided to the next level
	/*!
323 324 325
	 */
	bool edgeIsSubdivided(Dart d) ;

326 327 328 329 330
	//! Return true if the edge of d in the current level map
	//! is subdivided to the next level,
	//! none of its resulting edges is in turn subdivided to the next level
	//! and the middle vertex is of degree 2
	/*!
untereiner's avatar
untereiner committed
331 332 333
	 */
	bool edgeCanBeCoarsened(Dart d);

334 335 336 337 338 339
	//! Return true if the face of d in the current level map
	//! has already been subdivided to the next level
	/*!
	 */
	bool faceIsSubdivided(Dart d) ;

340 341
	//!
	/*!
342 343 344
	 */
	bool faceCanBeCoarsened(Dart d);

345 346
	//! Return true if the volume of d in the current level map
	//! has already been subdivided to the next level
347
	/*!
untereiner's avatar
untereiner committed
348
	 */
349
	bool volumeIsSubdivided(Dart d);
untereiner's avatar
untereiner committed
350

351 352
	//!
	/*!
untereiner's avatar
untereiner committed
353 354 355
	 */
	bool volumeIsSubdividedOnce(Dart d);

356 357 358 359

	/*! @name
	 *************************************************************************/

360 361
	//!
	/*!
362
	 */
363
	bool neighborhoodLevelDiffersMoreThanOne(Dart d);
untereiner's avatar
untereiner committed
364

365 366
	//! wired !!!
	/*!
367
	 */
368
	bool coarsenNeighborhoodLevelDiffersMoreThanOne(Dart d);
369 370 371 372 373 374 375
	//@}

	/*! @name Cell Functors
	 * Redefition of the 3-maps map traversor
	 *************************************************************************/

	//@{
376
	virtual Dart begin() const;
377

378
	virtual Dart end() const;
379

380
	virtual void next(Dart& d) const ;
381

382
	void foreach_dart_of_vertex(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const ;
383

384
	void foreach_dart_of_edge(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const ;
385

386 387
	void foreach_dart_of_oriented_face(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const;
	void foreach_dart_of_face(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const ;
388

389 390
	void foreach_dart_of_oriented_volume(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const;
	void foreach_dart_of_volume(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const ;
391

392
	void foreach_dart_of_cc(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const ;
untereiner's avatar
untereiner committed
393

394
	void foreach_dart_of_vertex2(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const;
untereiner's avatar
untereiner committed
395

396
	void foreach_dart_of_edge2(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const;
untereiner's avatar
untereiner committed
397

398
	void foreach_dart_of_face2(Dart d, std::function<void (Dart)> f, unsigned int thread = 0) const;
399 400
	//@}

401
    template <unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
402
	unsigned int getEmbedding(Dart d) const;
403 404
} ;

Pierre Kraemer's avatar
Pierre Kraemer committed
405
template <typename T, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
406
class AttributeHandler_IHM : public AttributeHandler<T, ORBIT, EMap3_IMPL>
407 408 409 410
{
public:
	typedef T DATA_TYPE ;

Pierre Kraemer's avatar
Pierre Kraemer committed
411
	AttributeHandler_IHM() : AttributeHandler<T, ORBIT, EMap3_IMPL>()
412 413
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
414
	AttributeHandler_IHM(ImplicitHierarchicalMap3* m, AttributeMultiVector<T>* amv) : AttributeHandler<T, ORBIT, EMap3_IMPL>(m, amv)
415 416 417 418
	{}

	AttributeMultiVector<T>* getDataVector() const
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
419
		return AttributeHandler<T, ORBIT, EMap3_IMPL>::getDataVector() ;
420 421 422 423
	}

	bool isValid() const
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
424
		return AttributeHandler<T, ORBIT, EMap3_IMPL>::isValid() ;
425 426
	}

427
	virtual T& operator[](Dart d) ;
428

429
	virtual const T& operator[](Dart d) const ;
430 431 432

	T& operator[](unsigned int a)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
433
		return AttributeHandler<T, ORBIT, EMap3_IMPL>::operator[](a) ;
434 435 436 437
	}

	const T& operator[](unsigned int a) const
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
438
		return AttributeHandler<T, ORBIT, EMap3_IMPL>::operator[](a) ;
439
	}
440

441
} ;
442

untereiner's avatar
untereiner committed
443
template <typename T>
444
class VertexAttribute_IHM : public IHM::AttributeHandler_IHM<T, VERTEX>
untereiner's avatar
untereiner committed
445 446
{
public:
447 448
	VertexAttribute_IHM() : IHM::AttributeHandler_IHM<T, VERTEX>() {}
	VertexAttribute_IHM(const IHM::AttributeHandler_IHM<T, VERTEX>& ah) : IHM::AttributeHandler_IHM<T, VERTEX>(ah) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
449
//	VertexAttribute_IHM<T>& operator=(const IHM::AttributeHandler_IHM<T, VERTEX>& ah) { this->IHM::AttributeHandler_IHM<T, VERTEX>::operator=(ah); return *this; }
untereiner's avatar
untereiner committed
450 451
};

Pierre Kraemer's avatar
Pierre Kraemer committed
452
} // namespace IHM
453

Pierre Kraemer's avatar
Pierre Kraemer committed
454 455 456 457 458
} // namespace Volume

} // namespace Algo

} // namespace CGoGN
459 460 461 462

#include "Algo/ImplicitHierarchicalMesh/ihm3.hpp"

#endif
463 464 465 466 467

////!
///*!
// */
//bool faceIsSubdividedOnce(Dart d);