mergeVertices.hpp 3.99 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 28 29 30
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

namespace Algo
{

31 32 33
namespace Surface
{

34 35 36
namespace BooleanOperator
{

37
template <typename PFP>
Sylvain Thery's avatar
Sylvain Thery committed
38
bool isBetween(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, Dart d, Dart e, Dart f)
39 40 41 42 43 44
{
	return CGoGN::Geom::isBetween(positions[map.phi1(d)]-positions[d],
	                 positions[map.phi1(e)]-positions[e],
	                 positions[map.phi1(f)]-positions[f]);
}

45
template <typename PFP>
Sylvain Thery's avatar
Sylvain Thery committed
46
void mergeVertex(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, Dart d, Dart e, int precision)
47
{
David Cazier's avatar
David Cazier committed
48
	assert(positions[d].isNear(positions[e], precision) && !map.sameVertex(d, e)) ;
49

50
	bool notempty = true ;
David Cazier's avatar
David Cazier committed
51
	do // While vertex of e contains more than one dart
52 53 54 55
	{
		Dart e1 = map.alpha1(e) ;			// e1 stores next dart of vertex of e
		if (e1 == e)
			notempty = false ;				// last dart of vertex of e
Thomas Jund's avatar
Thomas Jund committed
56 57
		else
		{
58 59 60 61 62 63
			map.removeEdgeFromVertex(e) ;	// detach e from its vertex
		}
		// Searchs where e may be inserted in the vertex of d
		Dart d1 = d ;
		do
		{
Thomas Jund's avatar
Thomas Jund committed
64 65
			if (isBetween<PFP>(map, positions, e, d, map.alpha1(d)))
				break ;
66 67
			d = map.alpha1(d) ;
		} while (d != d1) ;
68

69 70
		// Inserted e in the correct place (after d)
		map.insertEdgeInVertex(d, e) ;
71

72 73 74 75 76
		// Go on with next darts
		d = e ;
		e = e1 ;
	} while (notempty) ;
}
77

78
template <typename PFP>
Sylvain Thery's avatar
Sylvain Thery committed
79
void mergeVertices(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, int precision)
80
{
81
	// TODO optimiser en triant les sommets
Pierre Kraemer's avatar
Pierre Kraemer committed
82
	// map.template enableQuickTraversal<VERTEX>();
David Cazier's avatar
David Cazier committed
83
	TraversorV<typename PFP::MAP> travV1(map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
84
	CellMarker<typename PFP::MAP, VERTEX> vM(map);
David Cazier's avatar
David Cazier committed
85
	for(Dart d1 = travV1.begin() ; d1 != travV1.end() ; d1 = travV1.next())
86
	{
David Cazier's avatar
David Cazier committed
87 88 89
		vM.mark(d1);
		TraversorV<typename PFP::MAP> travV2(map) ;
		for(Dart d2 = travV2.begin() ; d2 != travV2.end() ; d2 = travV2.next())
90
		{
David Cazier's avatar
David Cazier committed
91
			if(!vM.isMarked(d2))
92
			{
David Cazier's avatar
David Cazier committed
93
				if(positions[d1].isNear(positions[d2], precision))
94
				{
Thomas Jund's avatar
Thomas Jund committed
95 96 97 98
					if (map.sameVertex(d1,d2))
						std::cout << "fusion: sameVertex" << std::endl ;
					if (!map.sameVertex(d1,d2))
						mergeVertex<PFP>(map,positions,d1,d2,precision);
99 100 101 102
				}
			}
		}
	}
David Cazier's avatar
David Cazier committed
103
	//	map.template disableQuickTraversal<VERTEX>();
104 105 106 107 108 109 110
}

}

}

}
111 112

}