mergeVertices.hpp 3.96 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 38 39 40 41 42 43 44
template <typename PFP>
bool isBetween(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, Dart d, Dart e, Dart f)
{
	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>
David Cazier's avatar
David Cazier committed
46
void mergeVertex(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& 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 56 57 58 59 60 61 62
	{
		Dart e1 = map.alpha1(e) ;			// e1 stores next dart of vertex of e
		if (e1 == e)
			notempty = false ;				// last dart of vertex of e
		else {
			map.removeEdgeFromVertex(e) ;	// detach e from its vertex
		}
		// Searchs where e may be inserted in the vertex of d
		Dart d1 = d ;
		do
		{
Sylvain Thery's avatar
Sylvain Thery committed
63
			if (BooleanOperator::isBetween<PFP>(map, positions, e, d,
64 65 66
			                                                 map.alpha1(d))) break ;
			d = map.alpha1(d) ;
		} while (d != d1) ;
67

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

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

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

}

}

}
108 109

}