39
39
template <class LCC>
40
40
typename LCC::Vector compute_normal_of_cell_2
41
(const LCC& /*amap*/, typename LCC::Dart_const_handle adart)
41
(const LCC& amap, typename LCC::Dart_const_handle adart)
43
43
// TODO Better approximation by using Newell's method
44
44
// Nx += (Vy - V'y) * (Vz + V'z);
45
45
// Ny += (Vz - V'z) * (Vx + V'x);
46
46
// Nz += (Vx - V'x) * (Vy + V'y);
47
47
// But problem with functor since this is not the sum of normal vectors.
49
49
typedef typename LCC::Point Point;
50
50
typedef typename LCC::Vector Vector;
51
51
typename LCC::Dart_const_handle start=adart;
52
52
Vector normal(CGAL::NULL_VECTOR);
54
while ( !start->is_free(0) && start->beta(0)!=adart )
55
start = start->beta(0);
54
while ( !amap.template is_free<0>(start) &&
55
amap.template beta<0>(start)!=adart )
56
start = amap.template beta<0>(start);
57
if ( start->is_free(1) || start->beta(1)->other_extremity()==NULL )
58
if ( amap.template is_free<1>(start) ||
59
amap.other_extremity(amap.template beta<1>(start))==LCC::null_handle )
60
62
unsigned int nb = 0;
61
adart = start->beta(1);
63
const Point* prev = &LCC::point(start);
64
const Point* curr = &LCC::point(adart);
65
for ( ; adart!=start && adart->other_extremity()!=NULL;
66
adart=adart->beta(1) )
63
adart = amap.template beta<1>(start);
65
const Point* prev = &amap.point(start);
66
const Point* curr = &amap.point(adart);
67
for ( ; adart!=start && amap.other_extremity(adart)!=LCC::null_handle;
68
adart=amap.template beta<1>(adart) )
68
const Point* next = &LCC::point(adart->other_extremity());
70
const Point* next = &amap.point( amap.other_extremity(adart));
69
71
if ( !typename LCC::Traits::Collinear_3()(*prev, *curr, *next) )
71
73
normal = typename LCC::Traits::Construct_sum_of_vectors()
102
104
(normal, CGAL::compute_normal_of_cell_2(amap,it));
106
if ( nb<2 ) return normal;
108
if ( nb<2 ) return normal;
107
109
return (typename LCC::Traits::Construct_scaled_vector()(normal, 1.0/nb));
111
// Compute the barycenter of a given i-cell
112
// General case, 1<i<=dimension
113
template<class LCC, unsigned int i, unsigned int dim=LCC::dimension>
114
struct Barycenter_functor
116
static typename LCC::Point run(const LCC& amap,
117
typename LCC::Dart_const_handle adart)
119
CGAL_static_assertion(0<i && i<=LCC::dimension);
120
CGAL_assertion(adart != LCC::null_handle);
122
typename LCC::Vector vec
123
(typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
127
CGAL::CMap_one_dart_per_incident_cell_const_iterator<LCC,0,i,i>
129
for ( ++it; it.cont(); ++it)
131
vec = typename LCC::Traits::Construct_sum_of_vectors()
132
(vec, typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
137
return typename LCC::Traits::Construct_translated_point()
138
(CGAL::ORIGIN, typename LCC::Traits::Construct_scaled_vector()
143
// Compute the barycenter of a given 1-cell
144
template<class LCC, unsigned int dim>
145
struct Barycenter_functor<LCC, 1, dim>
147
static typename LCC::Point run(const LCC& amap,
148
typename LCC::Dart_const_handle adart)
150
CGAL_static_assertion(1<=LCC::dimension);
151
CGAL_assertion(adart != LCC::null_handle);
152
typename LCC::Dart_const_handle d2=amap.other_extremity(adart);
153
if (d2==amap.null_handle) return amap.point(adart);
154
return typename LCC::Traits::Construct_midpoint()
160
// Compute the barycenter of a given 2-cell
161
template<class LCC, unsigned int dim>
162
struct Barycenter_functor<LCC, 2, dim>
164
static typename LCC::Point run(const LCC& amap,
165
typename LCC::Dart_const_handle adart)
167
CGAL_static_assertion(2<=LCC::dimension);
168
CGAL_assertion(adart != LCC::null_handle);
170
typename LCC::Vector vec
171
(typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
175
typename LCC::template Dart_of_cell_range<2,2>::const_iterator
176
vhit = amap.template darts_of_cell<2,2>(adart).begin(),
177
vhend = amap.template darts_of_cell<2,2>(adart).end();
178
for( ++vhit; vhit!=vhend; ++vhit )
180
vec = typename LCC::Traits::Construct_sum_of_vectors()
181
(vec, typename LCC::Traits::Construct_vector()(CGAL::ORIGIN,
185
return typename LCC::Traits::Construct_translated_point()
186
(CGAL::ORIGIN, typename LCC::Traits::Construct_scaled_vector()
110
191
} // namespace CGAL