map1.cpp 4.36 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "Topology/map/map1.h"

namespace CGoGN
{

/*! @name Generator and Deletor
 *  To generate or delete faces in a 1-map
 *************************************************************************/

Dart Map1::newOrientedFace(unsigned nbEdges)
{
	assert(nbEdges > 0 || !"Cannot create a face with no edge") ;
	Dart d = newDart() ;			// Create the first edge
Pierre Kraemer's avatar
Pierre Kraemer committed
38
	for (unsigned int i = 1 ; i < nbEdges ; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
39
40
41
42
		Map1::cutEdge(d) ;				// Subdivide nbEdges-1 times this edge
	return d ;
}

Sylvain Thery's avatar
Sylvain Thery committed
43
44
45
46
47
48
49
50
51
52
Dart Map1::newBoundaryFace(unsigned nbEdges)
{
	assert(nbEdges > 0 || !"Cannot create a face with no edge") ;
	Dart d = newDart() ;			// Create the first edge
	boundaryMark(d);
	for (unsigned int i = 1 ; i < nbEdges ; ++i)
		Map1::cutEdge(d) ;				// Subdivide nbEdges-1 times this edge
	return d ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
void Map1::deleteOrientedFace(Dart d)
{
	Dart e = phi1(d) ;
	while (e != d)
	{
		Dart f = phi1(e) ;
		deleteDart(e) ;
		e = f ;
	}
	deleteDart(d) ;
}

/*! @name Topological Operators
 *  Topological operations on 1-maps
 *************************************************************************/

void Map1::reverseFace(Dart d)
{
	Dart e = phi1(d) ;			// Dart e is the first edge of the new face
	if (e == d) return ;		// Only one edge: nothing to do
	if (phi1(e) == d) return ;	// Only two edges: nothing to do

	phi1unsew(d) ;				// Detach e from the face of d

	Dart dNext = phi1(d) ;		// While the face of d contains more than two edges
	while (dNext != d)
	{
		phi1unsew(d) ;			// Unsew the edge after d
		phi1sew(e,dNext) ;		// Sew it after e (thus in reverse order)
		dNext = phi1(d) ;
	}
	phi1sew(e,d) ;				// Sew the last edge
}

/*! @name Topological Queries
 *  Return or set various topological information
 *************************************************************************/

bool Map1::sameOrientedFace(Dart d, Dart e)
{
	Dart dNext = d ;
	do
	{
		if (dNext == e)
			return true ;
		dNext = phi1(dNext) ;
	} while (dNext != d) ;
	return false ;
}

unsigned int Map1::faceDegree(Dart d)
{
	unsigned int count = 0 ;
	Dart dNext = d ;
	do
	{
		++count ;
		dNext = phi1(dNext) ;
	} while (dNext != d) ;
	return count ;
}

bool Map1::isFaceTriangle(Dart d)
{
	return (phi1(d) != d) && (phi1(phi1(phi1(d))) == d) ;
}

/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
124
bool Map1::foreach_dart_of_oriented_face(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
125
126
127
128
129
130
131
132
133
134
135
136
{
	Dart dNext = d ;
	do
	{
		if (f(dNext))
			return true ;
		dNext = phi1(dNext) ;
	} while (dNext != d) ;
	return false ;
}

} // namespace CGoGN