MEPP2 Project
calculate_vertex_normal.hpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <boost/graph/graph_traits.hpp>
14 #include <boost/graph/properties.hpp>
15 
16 #include <CGAL/boost/graph/helpers.h> // for is_border()
17 
20 
21 #ifndef NDEBUG
22 #include <cassert>
23 #endif
24 
25 namespace FEVV {
26 namespace Operators {
27 
41 template< typename HalfedgeGraph, typename PointMap, typename GeometryTraits >
45  const HalfedgeGraph &g,
46  const PointMap &pm,
47  const GeometryTraits &gt)
48 {
49  typedef typename GeometryTraits::Vector Vector;
50  typedef typename boost::graph_traits< HalfedgeGraph >::halfedge_descriptor
51  halfedge_descriptor;
52 
53  if(halfedge(v, g) == boost::graph_traits< HalfedgeGraph >::null_halfedge())
54  {
55  return gt.NULL_VECTOR; // instead throws an exception?
56  }
57 
58  Vector normal = gt.NULL_VECTOR;
59 #ifndef NDEBUG
60  int cpt = 0;
61  int nbBorders = 0;
62 #endif
63 try{
64  halfedge_descriptor he = halfedge(v, g);
65  halfedge_descriptor end = he;
66  do
67  {
68  if(!CGAL::is_border(he, g))
69  {
70  Vector n = FEVV::Operators::
71  calculate_face_normal< HalfedgeGraph, PointMap, GeometryTraits >(
72  face(he, g), g, pm, gt);
73  normal = gt.add_v(normal, n);
74 #ifndef NDEBUG
75  ++cpt;
76 #endif
77  }
78 #ifndef NDEBUG
79  else
80  ++nbBorders;
81 #endif
82  he = opposite(next(he, g), g);
83  } while(he != end);
84 #ifndef NDEBUG
85  assert(cpt == (static_cast< int >(degree(v, g)) - nbBorders));
86 #endif
87 }
88 catch(...)
89 {
90  return gt.NULL_VECTOR;
91 }
92  return gt.normalize(normal);
93 }
94 
107 template< typename HalfedgeGraph,
108  typename PointMap,
109  typename FaceNormalMap,
110  typename GeometryTraits >
111 typename GeometryTraits::Vector
114  const HalfedgeGraph &g,
115  const PointMap &/*pm*/,
116  const FaceNormalMap &fnm,
117  const GeometryTraits &gt)
118 {
119  typedef typename GeometryTraits::Vector Vector;
120  typedef typename boost::graph_traits< HalfedgeGraph >::halfedge_descriptor
121  halfedge_descriptor;
122 
123  if(halfedge(v, g) ==
124  boost::graph_traits< HalfedgeGraph >::null_halfedge()) // if ( degree(v, g)
125  // <= 1 )
126  return gt.NULL_VECTOR; // instead throws an exception?
127 
128  Vector normal = gt.NULL_VECTOR;
129 #ifndef NDEBUG
130  int cpt = 0;
131  int nbBorders = 0;
132 #endif
133 try{
134  halfedge_descriptor he = halfedge(v, g);
135  halfedge_descriptor end = he;
136  do
137  {
138  if(!CGAL::is_border(he, g))
139  {
140  normal = gt.add_v(normal, get(fnm, face(he, g)));
141 #ifndef NDEBUG
142  ++cpt;
143 #endif
144  }
145 #ifndef NDEBUG
146  else
147  ++nbBorders;
148 #endif
149  he = opposite(next(he, g), g);
150  } while(he != end);
151 #ifndef NDEBUG
152  assert(cpt == (static_cast< int >(degree(v, g)) - nbBorders));
153 #endif
154 }
155 catch(...)
156 {
157  return gt.NULL_VECTOR;
158 }
159  return gt.normalize(normal);
160 }
161 
162 } // namespace Operators
163 } // namespace FEVV
FEVV::DataStructures::AIF::next
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor next(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the next halfedge around its face.
Definition: Graph_traits_aif.h:599
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::DataStructures::AIF::degree
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::degree_size_type degree(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor u, const FEVV::DataStructures::AIF::AIFMesh &)
Definition: Graph_traits_aif.h:548
FEVV::DataStructures::AIF::opposite
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor opposite(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the halfedge with source and target swapped.
Definition: Graph_traits_aif.h:625
FEVV::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::DataStructures::AIF::halfedge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor halfedge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor v, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns a halfedge with target v.
Definition: Graph_traits_aif.h:296
Geometry_traits.h
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
calculate_face_normal.hpp
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::DataStructures::AIF::face
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_descriptor face(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the face incident to halfedge h.
Definition: Graph_traits_aif.h:664
FEVV::Operators::calculate_vertex_normal
GeometryTraits::Vector calculate_vertex_normal(typename boost::graph_traits< HalfedgeGraph >::vertex_descriptor v, const HalfedgeGraph &g, const PointMap &pm, const GeometryTraits &gt)
Computes the unit normal at considered vertex v as the average of the normals of incident faces.
Definition: calculate_vertex_normal.hpp:43