map2MR_DualRegular.hpp 5.2 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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

25 26
#include "Algo/Topo/embedding.h"

27 28 29 30 31 32
namespace CGoGN
{

namespace Algo
{

33 34 35
namespace Surface
{

36 37 38 39 40 41 42 43 44 45 46
namespace MR
{

namespace Dual
{

namespace Regular
{

template <typename PFP>
Map2MR<PFP>::Map2MR(typename PFP::MAP& map) :
Sylvain Thery's avatar
Sylvain Thery committed
47
	MapManipulator("DualRegular2",&map),
48
	m_map(map),
untereiner's avatar
untereiner committed
49
	shareVertexEmbeddings(false)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
{
}

template <typename PFP>
Map2MR<PFP>::~Map2MR()
{
	unsigned int level = m_map.getCurrentLevel();
	unsigned int maxL = m_map.getMaxLevel();

	for(unsigned int i = maxL ; i > level ; --i)
		m_map.removeLevelBack();

	for(unsigned int i = 0 ; i < level ; ++i)
		m_map.removeLevelFront();
}

Sylvain Thery's avatar
Sylvain Thery committed
66 67 68 69 70 71 72 73 74 75 76
template <typename PFP>
MapManipulator* Map2MR<PFP>::create(GenericMap *gm)
{
	typename PFP::MAP* map = dynamic_cast<typename PFP::MAP*>(gm);
	if (map != NULL)
		return (new Map2MR<PFP>(*map));
	else
		return NULL;
}


77 78 79 80 81 82 83
template <typename PFP>
void Map2MR<PFP>::addNewLevel(bool embedNewVertices)
{
	m_map.pushLevel() ;

	m_map.addLevelBack() ;
	m_map.duplicateDarts(m_map.getMaxLevel());
untereiner's avatar
untereiner committed
84
	m_map.setCurrentLevel(m_map.getMaxLevel()) ;
85

untereiner's avatar
untereiner committed
86 87 88 89

	m_map.decCurrentLevel();
	TraversorE<typename PFP::MAP> te(m_map);
	for (Dart d = te.begin(); d != te.end(); d = te.next())
90
	{
untereiner's avatar
untereiner committed
91 92 93 94 95 96 97 98 99 100 101
		m_map.incCurrentLevel();

		Dart d2 = m_map.phi2(d);

		m_map.unsewFaces(d,false);
		Dart nf = m_map.newFace(4,false);
		m_map.sewFaces(d,nf,false);
		m_map.sewFaces(d2,m_map.phi1(m_map.phi1(nf)),false);

		// take care of edge embedding
		if(m_map.template isOrbitEmbedded<EDGE>())
102
		{
103 104 105 106
//			m_map.template setOrbitEmbedding<EDGE>(nf, m_map.template getEmbedding<EDGE>(d));
//			m_map.template setOrbitEmbedding<EDGE>(m_map.phi1(m_map.phi1(nf)), m_map.template getEmbedding<EDGE>(d2));
			Algo::Topo::setOrbitEmbedding<EDGE>(m_map, nf, m_map.template getEmbedding<EDGE>(d));
			Algo::Topo::setOrbitEmbedding<EDGE>(m_map, m_map.phi1(m_map.phi1(nf)), m_map.template getEmbedding<EDGE>(d2));
untereiner's avatar
untereiner committed
107 108 109 110 111 112 113 114 115 116
		}

		m_map.decCurrentLevel();
	}


	TraversorV<typename PFP::MAP> tv(m_map);
	for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
	{
		m_map.incCurrentLevel();
117

untereiner's avatar
untereiner committed
118
		m_map.PFP::MAP::TOPO_MAP::closeHole(m_map.phi1(m_map.phi2(d)),false);
119

untereiner's avatar
untereiner committed
120 121 122 123 124 125
		Dart temp = m_map.phi2(m_map.phi1(m_map.phi2(d)));
		Dart stop = temp;

		do
		{
			if(m_map.template isOrbitEmbedded<EDGE>())
126
			{
127 128
//				m_map.template setOrbitEmbedding<EDGE>(temp, m_map.template getEmbedding<EDGE>(	m_map.phi2(temp)));
				Algo::Topo::setOrbitEmbedding<EDGE>(m_map, temp, m_map.template getEmbedding<EDGE>(	m_map.phi2(temp)));
untereiner's avatar
untereiner committed
129
			}
130

untereiner's avatar
untereiner committed
131 132 133
			if(!shareVertexEmbeddings)
			{
				//if(m_map.template getEmbedding<VERTEX>(d) == EMBNULL)
134 135
				Algo::Topo::setOrbitEmbeddingOnNewCell<VERTEX>(m_map, temp);

untereiner's avatar
untereiner committed
136
				//m_map.template setOrbitEmbeddingOnNewCell<VERTEX>(d2) ;
137 138 139
			}


untereiner's avatar
untereiner committed
140 141 142 143 144 145
			temp = m_map.phi1(temp);
		}
		while(temp != stop);


		m_map.decCurrentLevel();
146 147
	}

untereiner's avatar
untereiner committed
148 149
	m_map.incCurrentLevel() ;

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
	m_map.popLevel() ;
}

template <typename PFP>
void Map2MR<PFP>::analysis()
{
	assert(m_map.getCurrentLevel() > 0 || !"analysis : called on level 0") ;

	m_map.decCurrentLevel() ;

	for(unsigned int i = 0; i < analysisFilters.size(); ++i)
		(*analysisFilters[i])() ;
}

template <typename PFP>
void Map2MR<PFP>::synthesis()
{
	assert(m_map.getCurrentLevel() < m_map.getMaxLevel() || !"synthesis : called on max level") ;

	for(unsigned int i = 0; i < synthesisFilters.size(); ++i)
		(*synthesisFilters[i])() ;

	m_map.incCurrentLevel() ;
}


} // namespace Regular

} // namespace Dual

} // namespace MR

182 183
} // namespace Surface

184 185 186
} // namespace Algo

} // namespace CGoGN