mergeVertices.hpp 3.65 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 31 32 33
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

namespace Algo
{

namespace BooleanOperator
{

34 35 36 37 38 39 40 41
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]);
}

42
template <typename PFP>
43
void mergeVertex(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, Dart d, Dart e)
44 45
{
	assert(Geom::arePointsEquals(positions[d],positions[e]) && !map.sameVertex(d,e));
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  // d1 traverses the vertex of d (following the alpha1 permutation)
  // y is a temporay buffer to stop the loop
  Dart d1=d;
  // e1 traverses the vertex of e (following the alpha1 permutation)
  Dart e1=e;
  bool notempty = true;
  do {
	if (map.phi2_1(e1) == e1) notempty = false;
	// detach z from its vertex
	map.removeEdgeFromVertex(e1);
	// Searchs the dart of the vertex of x where tz may be inserted
	Dart nd1 = d1;
	do {
	  if (CGoGN::Algo::BooleanOperator::isBetween<PFP>(map,positions,e1,d1,map.phi2_1(d1))) break;
	  d1 = map.phi2_1(d1);
	} while (d1 != nd1);
	map.insertEdgeInVertex(d1,e1);
	d1 = e1;
  } while (notempty);
65

66 67
  // 0-embed z on the vertex of x without copy of the vertex
//  positions[d] = ;
68 69
}

70 71


72
template <typename PFP>
73
void mergeVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions)
74
{
75
	// TODO optimiser en triant les sommets
76 77
	for(Dart d = map.begin() ; d != map.end() ; map.next(d))
	{
78
		CellMarker<VERTEX> vM(map);
79
		vM.mark(d);
80
		std::cout << "." ; std::cout.flush() ;
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
		for(Dart dd = map.begin() ; dd != map.end() ; map.next(dd))
		{
			if(!vM.isMarked(dd))
			{
				if(Geom::arePointsEquals(positions[d],positions[dd]))
				{
					mergeVertex<PFP>(map,positions,d,dd);
				}
			}
		}
	}
}

}

}

}