ihm3.h 12.4 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
{

40
namespace IHM
41 42
{

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

45
class ImplicitHierarchicalMap3 : public EmbeddedMap3
46
{
47
    template<typename T, unsigned int ORBIT> friend class AttributeHandler_IHM ;
48 49

public:
50 51 52 53 54
	FunctorType* vertexVertexFunctor ;
	FunctorType* edgeVertexFunctor ;
	FunctorType* faceVertexFunctor ;
	FunctorType* volumeVertexFunctor ;

55 56 57 58
    unsigned int m_curLevel ;
    unsigned int m_maxLevel ;
    unsigned int m_edgeIdCount ;
    unsigned int m_faceIdCount;
59

60 61 62
	DartAttribute<unsigned int, EmbeddedMap3> m_dartLevel ;
	DartAttribute<unsigned int, EmbeddedMap3> m_edgeId ;
	DartAttribute<unsigned int, EmbeddedMap3> m_faceId ;
63

64
    AttributeMultiVector<unsigned int>* m_nextLevelCell[NB_ORBITS] ;
65

66 67
//    std::vector<Algo::MR::Filter*> synthesisFilters ;
//    std::vector<Algo::MR::Filter*> analysisFilters ;
68

69
public:
70
    ImplicitHierarchicalMap3() ;
71

72
    ~ImplicitHierarchicalMap3() ;
73

74
    static const unsigned int DIMENSION = 3 ;
75

76 77 78 79 80
    //!
    /*!
     *
     */
    void update_topo_shortcuts();
81

82 83 84 85 86
    //!
    /*!
     *
     */
    void initImplicitProperties() ;
87

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

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

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

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

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

118 119
    //@{
    virtual Dart newDart() ;
120

121
    Dart phi1(Dart d) const;
122

123
    Dart phi_1(Dart d) const;
124

125
    Dart phi2(Dart d) const;
126

127
private:
128
    Dart phi2bis(Dart d) const;
129 130

public:
131
    Dart phi3(Dart d) const;
132

133
    Dart alpha0(Dart d) const;
134

135
    Dart alpha1(Dart d) const;
136

137
    Dart alpha2(Dart d) const;
138

139 140
    Dart alpha_2(Dart d) const;
    //@}
141

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

146 147 148 149
//	void deleteVolume(Dart d);

	bool isWellEmbedded();

untereiner's avatar
untereiner committed
150 151
	//@{

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

158 159 160 161




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

165 166
//    void clearSynthesisFilters() { synthesisFilters.clear() ; }
//    void clearAnalysisFilters() { analysisFilters.clear() ; }
167

168 169
//    void analysis() ;
//    void synthesis() ;
170

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

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

	Dart quadranguleFace(Dart d);

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

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

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

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

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
    void incCurrentLevel();

    void decCurrentLevel();


    //@{
    //!
    /*!
     *
     */
    unsigned int getCurrentLevel() const ;

    //!
    /*!
     *
     */
    void setCurrentLevel(unsigned int l) ;

    //!
    /*!
     *
     */
    unsigned int getMaxLevel() const ;

    //!
    /*!
     *
     */
    unsigned int getDartLevel(Dart d) const ;

    //!
    /*!
     *
     */
    void setDartLevel(Dart d, unsigned int i) ;
233
	//@}
234

235 236 237
	/*! @name Id Management
	 * Operations to manage the ids of edges and faces
	 *************************************************************************/
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
    //! Give a new unique id to all the edges of the map
    /*!
     */
    void initEdgeId() ;

    //! Return the next available edge id
    /*!
     */
    unsigned int getNewEdgeId() ;

    //! Return the id of the edge of d
    /*!
     */
    unsigned int getEdgeId(Dart d) ;

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

    //! Give a new unique id to all the faces of the map
    /*!
     */
    void initFaceId() ;

    //! Return the next available face id
    /*!
     */
    unsigned int getNewFaceId() ;

    //! Return the id of the face of d
    /*!
     */
    unsigned int getFaceId(Dart d) ;

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

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

287
	//@{
288 289 290 291
    //! Return the level of insertion of the vertex of d
    /*!
     */
    unsigned int vertexInsertionLevel(Dart d) const;
292

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

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

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

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

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

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

324 325 326 327 328
	//! 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
329 330 331
	 */
	bool edgeCanBeCoarsened(Dart d);

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

338 339
	//!
	/*!
340 341 342
	 */
	bool faceCanBeCoarsened(Dart d);

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

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

354 355 356 357

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

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

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

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

	//@{
374
    Dart begin() const;
375

376
    Dart end() const;
377

378
    void next(Dart& d) const ;
379 380

	template <unsigned int ORBIT, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
381
	void foreach_dart_of_orbit(Cell<ORBIT> c, FUNC f) const ;
382
	template <unsigned int ORBIT, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
383
	void foreach_dart_of_orbit(Cell<ORBIT> c, FUNC& f) const ;
384 385

	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
386
	void foreach_dart_of_vertex(Dart d, FUNC& f) const ;
387 388

	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
389
	void foreach_dart_of_edge(Dart d, FUNC& f) const ;
390

391
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
392
	void foreach_dart_of_oriented_face(Dart d, FUNC& f) const;
393

394
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
395
	void foreach_dart_of_face(Dart d, FUNC& f) const ;
396

397
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
398
	void foreach_dart_of_oriented_volume(Dart d, FUNC& f) const;
399

400
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
401
	void foreach_dart_of_volume(Dart d, FUNC& f) const ;
402

403
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
404
	void foreach_dart_of_vertex1(Dart d, FUNC& f) const;
405

406
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
407
	void foreach_dart_of_edge1(Dart d, FUNC& f) const;
408

409
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
410
	void foreach_dart_of_vertex2(Dart d, FUNC& f) const;
untereiner's avatar
untereiner committed
411

412
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
413
	void foreach_dart_of_edge2(Dart d, FUNC& f) const;
untereiner's avatar
untereiner committed
414

415
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
416
	void foreach_dart_of_face2(Dart d, FUNC& f) const;
untereiner's avatar
untereiner committed
417

418
	template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
419
	void foreach_dart_of_cc(Dart d, FUNC& f) const ;
420 421
	//@}

422 423
//    template <unsigned int ORBIT>
//	unsigned int getEmbedding(Cell<ORBIT> c) const;
424 425
} ;

Pierre Kraemer's avatar
Pierre Kraemer committed
426
template <typename T, unsigned int ORBIT>
427
class AttributeHandler_IHM : public AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3>
428 429 430 431
{
public:
	typedef T DATA_TYPE ;

432
	AttributeHandler_IHM() : AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3>()
433 434
	{}

435
	AttributeHandler_IHM(ImplicitHierarchicalMap3* m, AttributeMultiVector<T>* amv) : AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3>(m, amv)
436 437 438 439
	{}

	AttributeMultiVector<T>* getDataVector() const
	{
440
		return AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3>::getDataVector() ;
441 442 443 444
	}

	bool isValid() const
	{
445
		return AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3>::isValid() ;
446 447
	}

448
	virtual T& operator[](Dart d) ;
449

450
	virtual const T& operator[](Dart d) const ;
451 452 453

	T& operator[](unsigned int a)
	{
454
		return AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3>::operator[](a) ;
455 456 457 458
	}

	const T& operator[](unsigned int a) const
	{
459
		return AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3>::operator[](a) ;
460
	}
461

462
} ;
463

untereiner's avatar
untereiner committed
464
template <typename T>
465
class VertexAttribute_IHM : public IHM::AttributeHandler_IHM<T, VERTEX>
untereiner's avatar
untereiner committed
466 467
{
public:
468 469
	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
470
//	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
471 472
};

Pierre Kraemer's avatar
Pierre Kraemer committed
473
} // namespace IHM
474

Pierre Kraemer's avatar
Pierre Kraemer committed
475 476 477 478 479
} // namespace Volume

} // namespace Algo

} // namespace CGoGN
480 481 482 483

#include "Algo/ImplicitHierarchicalMesh/ihm3.hpp"

#endif
484 485 486 487 488

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