1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#ifndef CGAL_PSURF_OPERATIONS_H_
#define CGAL_PSURF_OPERATIONS_H_
using namespace std;
//----------------------------------------------------------------
// some functors
//----------------------------------------------------------------
//computing the edge length
struct Edge_length {
template <class HalfEdge_handle>
double operator() (HalfEdge_handle h) {
double l = CGAL::sqrt(CGAL::squared_distance(h->prev()->vertex()->point(),
h->vertex()->point()));
return l;
}
};
//computing a the facet normal
struct Facet_unit_normal {
template < class Facet >
typename Facet::Vector_3 operator() (Facet & f) {
typename Facet::Halfedge_handle h = f.halfedge();
typename Facet::Vector_3 normal =
CGAL::cross_product(h->vertex()->point() -
h->opposite()->vertex()->point(),
h->next()->vertex()->point() -
h->opposite()->vertex()->point());
return normal / CGAL::sqrt(normal * normal);
}
};
//----------------------------------------------------------------
// operations on hedges, facets etc, handled using property maps
//----------------------------------------------------------------
template <class TPoly , class HEdgePropertyMap> class T_PolyhedralSurf_hedge_ops
{
protected:
typedef typename TPoly::Vertex Vertex;
typedef typename TPoly::Halfedge_handle Halfedge_handle;
typedef typename TPoly::Halfedge Halfedge;
typedef typename TPoly::Facet_handle Facet_handle;
typedef typename TPoly::Facet Facet;
typedef typename TPoly::Vertex_iterator Vertex_iterator;
typedef typename TPoly::Halfedge_iterator Halfedge_iterator;
typedef typename TPoly::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator;
public:
static void compute_edges_length(TPoly& P, HEdgePropertyMap& hepm);
static double compute_mean_edges_length_around_vertex(Vertex * v, HEdgePropertyMap& hepm);
};
template <class TPoly , class HEdgePropertyMap>
void T_PolyhedralSurf_hedge_ops<TPoly, HEdgePropertyMap>::
compute_edges_length(TPoly& P, HEdgePropertyMap& hepm)
{
Halfedge_iterator itb = P.halfedges_begin(), ite = P.halfedges_end();
for(; itb!=ite; itb++) {
Halfedge_handle h = itb;
double l = Edge_length()(h);
put(hepm, h, l);
//cerr << "[" << l << "," << get(hepm, h) << "] ";
}
}
template <class TPoly , class HEdgePropertyMap>
double T_PolyhedralSurf_hedge_ops<TPoly, HEdgePropertyMap>::
compute_mean_edges_length_around_vertex(Vertex * v, HEdgePropertyMap& hepm)
{
Halfedge_around_vertex_circulator hedgeb = v->vertex_begin(), hedgee = hedgeb;
int count_he = 0;
double sum = 0.;
CGAL_For_all(hedgeb, hedgee){
sum += get(hepm, hedgeb);
count_he++;
}
return sum/count_he;
}
//-------------------------------------------------------------------------------
// operations on facets
//-------------------------------------------------------------------------------
template <class TPoly , class FacetPropertyMap> class T_PolyhedralSurf_facet_ops
{
protected:
typedef typename TPoly::Vertex Vertex;
typedef typename TPoly::Halfedge_handle Halfedge_handle;
typedef typename TPoly::Halfedge Halfedge;
typedef typename TPoly::Facet_handle Facet_handle;
typedef typename TPoly::Facet Facet;
typedef typename TPoly::Vertex_iterator Vertex_iterator;
typedef typename TPoly::Halfedge_iterator Halfedge_iterator;
typedef typename TPoly::Facet_iterator Facet_iterator;
typedef typename TPoly::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator;
public:
static void compute_facets_normals(TPoly& P, FacetPropertyMap& fpm);
static typename TPoly::Traits::Vector_3 compute_vertex_average_unit_normal(Vertex * v, const FacetPropertyMap& fpm);
};
template <class TPoly , class FacetPropertyMap>
void T_PolyhedralSurf_facet_ops<TPoly, FacetPropertyMap>::
compute_facets_normals(TPoly& P, FacetPropertyMap& fpm)
{
//iterator returning facet handles
Facet_iterator itb = P.facets_begin(), ite = P.facets_end();
for(; itb!=ite; itb++)
put(fpm, itb, Facet_unit_normal()(*itb));
}
template <class TPoly , class FacetPropertyMap>
typename TPoly::Traits::Vector_3 T_PolyhedralSurf_facet_ops<TPoly, FacetPropertyMap>::
compute_vertex_average_unit_normal(Vertex * v, const FacetPropertyMap& fpm)
{
Facet_handle f;
Vector_3 sum(0., 0., 0.), n;
Halfedge_around_vertex_circulator hedgeb = v->vertex_begin(), hedgee = hedgeb;
do{
if (hedgeb->is_border_edge()){
hedgeb++;
continue;
}
f = hedgeb->facet();
n = get(fpm, f);
sum = (sum + n);
hedgeb++;
}
while (hedgeb != hedgee);
sum = sum / std::sqrt(sum * sum);
return sum;
}
#endif
|