ihm2_PrimalRegular.hpp 9.14 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                                        *
*                                                                              *
*******************************************************************************/

untereiner's avatar
untereiner committed
25

26 27 28 29 30 31
namespace CGoGN
{

namespace Algo
{

untereiner's avatar
untereiner committed
32 33 34
namespace Surface
{

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

namespace Primal
{

namespace Regular
{

template <typename PFP>
IHM2<PFP>::IHM2(typename PFP::MAP& map) :
46 47
	m_map(map),
	shareVertexEmbeddings(true)
48 49 50 51 52 53 54
{
}

//if true : tri and quad else quad
template <typename PFP>
void IHM2<PFP>::addNewLevel(bool triQuad)
{
55
	unsigned int cur = m_map.getCurrentLevel() ; //pushLevel
56

57
	m_map.setCurrentLevel(m_map.getMaxLevel() + 1) ;
58

59
	// cut edges
60
	TraversorE<MAP> travE(m_map) ;
61 62 63 64 65 66 67 68 69 70 71 72 73 74
	for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
	{
		Dart dd = m_map.phi2(d) ;

		m_map.cutEdge(d) ;
		unsigned int eId = m_map.getEdgeId(d) ;
		m_map.setEdgeId(m_map.phi1(d), eId) ;
		m_map.setEdgeId(m_map.phi1(dd), eId) ;

		travE.skip(d) ;
		travE.skip(m_map.phi1(d)) ;
	}

	// split faces
75
	TraversorF<MAP> travF(m_map) ;
76 77 78 79 80 81 82 83 84 85 86
	for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
	{
		Dart old = d ;

		if(m_map.getDartLevel(old) == m_map.getMaxLevel())
			old = m_map.phi1(old) ;

		m_map.decCurrentLevel();
		unsigned int degree = m_map.faceDegree(old) ;
		m_map.incCurrentLevel();

87
		if((degree == 3) && triQuad)					// if subdividing a triangle
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
		{
			Dart dd = m_map.phi1(old) ;
			Dart e = m_map.phi1(m_map.phi1(dd)) ;
			m_map.splitFace(dd, e) ;					// insert a new edge
			travF.skip(dd) ;
			//unsigned int id = m_map.getNewEdgeId() ;
			unsigned int id = m_map.getTriRefinementEdgeId(m_map.phi_1(dd));
			m_map.setEdgeId(m_map.phi_1(dd), id) ;		// set the edge id of the inserted
			m_map.setEdgeId(m_map.phi_1(e), id) ;		// edge to the next available id

			dd = e ;
			e = m_map.phi1(m_map.phi1(dd)) ;
			m_map.splitFace(dd, e) ;
			travF.skip(dd) ;
			//id = m_map.getNewEdgeId() ;
			id = m_map.getTriRefinementEdgeId(m_map.phi_1(dd));
			m_map.setEdgeId(m_map.phi_1(dd), id) ;
			m_map.setEdgeId(m_map.phi_1(e), id) ;

			dd = e ;
			e = m_map.phi1(m_map.phi1(dd)) ;
			m_map.splitFace(dd, e) ;
			travF.skip(dd) ;
			//id = m_map.getNewEdgeId() ;
			id = m_map.getTriRefinementEdgeId(m_map.phi_1(dd));
			m_map.setEdgeId(m_map.phi_1(dd), id) ;
			m_map.setEdgeId(m_map.phi_1(e), id) ;

			travF.skip(e) ;
		}
		else											// if subdividing a polygonal face
		{
			Dart dd = m_map.phi1(old) ;
			Dart next = m_map.phi1(m_map.phi1(dd)) ;
			m_map.splitFace(dd, next) ;		// insert a first edge

			Dart ne = m_map.phi2(m_map.phi_1(dd)) ;
			Dart ne2 = m_map.phi2(ne) ;
			m_map.cutEdge(ne) ;				// cut the new edge to insert the central vertex
			travF.skip(dd) ;
			//unsigned int id = m_map.getNewEdgeId() ;
			unsigned int id = m_map.getQuadRefinementEdgeId(m_map.phi2(ne));
			m_map.setEdgeId(ne, id) ;
			m_map.setEdgeId(m_map.phi2(ne), id) ;			// set the edge id of the inserted
			//id = m_map.getNewEdgeId() ;
			id = m_map.getQuadRefinementEdgeId(ne2);
			m_map.setEdgeId(ne2, id) ;					// edges to the next available ids
			m_map.setEdgeId(m_map.phi2(ne2), id) ;

			dd = m_map.phi1(m_map.phi1(next)) ;
			while(dd != ne)				// turn around the face and insert new edges
			{							// linked to the central vertex
				Dart tmp = m_map.phi1(ne) ;
				m_map.splitFace(tmp, dd) ;
				travF.skip(tmp) ;
				Dart nne = m_map.phi2(m_map.phi_1(dd)) ;
				//id = m_map.getNewEdgeId() ;
				id = m_map.getQuadRefinementEdgeId(m_map.phi2(nne));
				m_map.setEdgeId(nne, id) ;
				m_map.setEdgeId(m_map.phi2(nne), id) ;
				dd = m_map.phi1(m_map.phi1(dd)) ;
			}
			travF.skip(ne) ;
		}
	}

	m_map.setCurrentLevel(cur) ;
155 156
}

untereiner's avatar
untereiner committed
157 158 159 160 161 162 163 164 165
//template <typename PFP>
//void IHM2<PFP>::checkTagging(unsigned int level)
//{
//	if(level != m_map.getMaxLevel())
//	{

//	}
//}

166 167 168
template <typename PFP>
void IHM2<PFP>::addLevelFront()
{
untereiner's avatar
untereiner committed
169 170
	//1. look for an irregular vertex
	Dart irregVertex = NIL;
171

172
	TraversorV<MAP> tv(m_map);
173 174 175 176 177 178
	bool found = false;
	for(Dart d = tv.begin() ; !found && d != tv.end() ; d = tv.next())
	{
		if(m_map.vertexDegree(d) != 6)
		{
			found = true;
untereiner's avatar
untereiner committed
179
			irregVertex = d;
180 181 182
		}
	}

untereiner's avatar
untereiner committed
183 184
	if(!found)
		irregVertex = tv.begin();
185

untereiner's avatar
untereiner committed
186 187
	//2. construct the topology of the differents levels
	unsigned int curLevel = 0;
188 189 190 191 192

	do
	{
		m_map.setCurrentLevel(curLevel);

193
		DartMarker<MAP> md(m_map);
untereiner's avatar
untereiner committed
194 195 196
		std::vector<Dart> visitedVertices;
		visitedVertices.reserve(1024);
		visitedVertices.push_back(irregVertex);
197 198 199 200

		std::cout << "getCurrentLevel = " << m_map.getCurrentLevel() << std::endl;

		for(unsigned int i = 0 ; i < visitedVertices.size() ; ++i)
201
		{
202
			Dart d = visitedVertices[i];
203

204
			Traversor2VE<MAP> tve(m_map, d);
205 206 207 208
			for(Dart eit = tve.begin() ; eit != tve.end() ; eit = tve.next())
			{
				//coarse all faces around the vertex
				if(!md.isMarked(eit))
209
				{
untereiner's avatar
untereiner committed
210 211 212 213
					Dart fit1 = eit;
					Dart fit2 = m_map.phi2(m_map.phi1(fit1));
					Dart fit3 = m_map.phi_1(m_map.phi2(m_map.phi1(fit1)));
					Dart fit4 = m_map.phi_1(m_map.phi2(m_map.phi_1(fit1)));
214

215 216 217 218
					md.template markOrbit<FACE>(fit1);
					md.template markOrbit<FACE>(fit2);
					md.template markOrbit<FACE>(fit3);
					md.template markOrbit<FACE>(fit4);
untereiner's avatar
untereiner committed
219 220 221 222 223 224 225 226 227 228 229 230 231

					visitedVertices.push_back(m_map.phi1(m_map.phi2(fit2)));
					visitedVertices.push_back(m_map.phi1(m_map.phi2(fit3)));

					//Tag edges


//					checkTagging();


//					increaseTriangleLevel(eit);
//					increaseTriangleLevel(fit1);
//					increaseTriangleLevel(fit2);
232 233 234 235 236 237 238 239 240 241 242 243 244 245


					m_map.setDartLevel(fit1, curLevel);
					m_map.setDartLevel(m_map.phi2(fit1), curLevel);
					m_map.setDartLevel(m_map.phi1(m_map.phi2(fit1)), curLevel);

					m_map.setDartLevel(fit2, curLevel);
					m_map.setDartLevel(m_map.phi2(fit2), curLevel);
					m_map.setDartLevel(m_map.phi1(m_map.phi2(fit2)), curLevel);

					m_map.setDartLevel(fit3, curLevel);
					m_map.setDartLevel(m_map.phi2(fit3), curLevel);
					m_map.setDartLevel(m_map.phi1(m_map.phi2(fit3)), curLevel);

untereiner's avatar
untereiner committed
246

untereiner's avatar
untereiner committed
247
					if(curLevel == m_map.getMaxLevel())
248 249 250 251 252 253 254 255 256 257 258 259 260
					{
						unsigned int id = m_map.getTriRefinementEdgeId(m_map.phi2(fit1));
						m_map.setEdgeId(m_map.phi2(fit1), id);
						m_map.setEdgeId(fit1, id);

						id = m_map.getTriRefinementEdgeId(m_map.phi2(fit2));
						m_map.setEdgeId(m_map.phi2(fit2), id);
						m_map.setEdgeId(fit2, id);

						id = m_map.getTriRefinementEdgeId(m_map.phi2(fit3));
						m_map.setEdgeId(m_map.phi2(fit3), id);
						m_map.setEdgeId(fit3, id);
					}
261
				}
262 263
			}
		}
264

265
		curLevel = curLevel - 1;
266

267
	} while(curLevel > 2);
untereiner's avatar
untereiner committed
268 269 270 271


//	m_map.setMaxLevel(curLevel);
//	std::cout << "nb levels = " << nbLevel+1 << std::endl;
272

untereiner's avatar
untereiner committed
273
//	m_map.setCurrentLevel(nbLevel); //m_maxLevel
274 275 276 277 278 279
}


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

282
	m_map.decCurrentLevel() ;
283

284 285
	for(unsigned int i = 0; i < analysisFilters.size(); ++i)
		(*analysisFilters[i])() ;
286 287 288 289 290 291

}

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

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

297
	m_map.incCurrentLevel() ;
298 299
}

untereiner's avatar
untereiner committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
template <typename PFP>
void IHM2<PFP>::import(Algo::Surface::Import::QuadTree& qt)
{
	std::cout << "  Create finer resolution levels.." << std::flush ;

	for(unsigned int i = 0; i < qt.depth; ++i)
		addNewLevel(true) ;

	std::cout << "..done" << std::endl ;
	std::cout << "  Embed finer resolution levels.." << std::flush ;

	m_map.setCurrentLevel(0) ;
	qt.embed<PFP>(m_map) ;
	m_map.setCurrentLevel(m_map.getMaxLevel()) ;

	std::cout << "..done" << std::endl ;
}

318 319 320 321 322 323
} // namespace Regular

} // namespace Primal

} // namespace MR

untereiner's avatar
untereiner committed
324 325
} // namespace Surface

326 327 328
} // namespace Algo

} // namespace CGoGN