MEPP2 Project
no_normal_flip_for_collapse.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 namespace FEVV {
22 namespace Operators {
43 template< typename HalfedgeGraph,
44  typename PointMap,
45  typename GeometryTraits = typename FEVV::Geometry_traits<HalfedgeGraph> >
47  const HalfedgeGraph& g,
48  const PointMap& pm,
49  typename boost::graph_traits<HalfedgeGraph>::edge_descriptor e,
51  const typename GeometryTraits::Point& new_pos_v,
52  const GeometryTraits &gt)
53  {
54  typename boost::graph_traits<HalfedgeGraph>::halfedge_descriptor h1 = halfedge(e, g);
55  typename boost::graph_traits<HalfedgeGraph>::halfedge_descriptor h2 = opposite(h1, g);
56  auto iterator_range = CGAL::halfedges_around_target(v, g);
57  for (auto h : iterator_range)
58  {
59  if (CGAL::is_border(h, g))
60  continue;
61 
62  // cases of the incident faces to the collapsed edge
63  typename boost::graph_traits<HalfedgeGraph>::face_descriptor f = face(h, g); // we know that f!=null_face()
64  if (f == face(h1, g))
65  continue;
66  if (f == face(h2, g))
67  continue;
68 
69  // other faces
70  typename GeometryTraits::Point p1 = get(pm, source(h, g));
71  typename GeometryTraits::Point p0 = get(pm, source(prev(h, g), g));
72 
73  typename GeometryTraits::Vector face_normal, face_normal_after_collapse;
74  // get the normal of the current face
75  // check if the current face is not null
76  bool b = FEVV::Math::Vector::are_collinear<GeometryTraits>(gt.sub_p(p0, p1), gt.sub_p(get(pm, v), p1));
77  if (!b)
78  face_normal = gt.normal(p0, p1, get(pm, v));
79  else
80  {
81  face_normal = typename GeometryTraits::Vector(std::numeric_limits<typename GeometryTraits::Scalar>::quiet_NaN(),
82  std::numeric_limits<typename GeometryTraits::Scalar>::quiet_NaN(),
83  std::numeric_limits<typename GeometryTraits::Scalar>::quiet_NaN());
84  }
85  // simulation of the new face after collapse and check if its normal has the same sign
86  face_normal_after_collapse = gt.normal(p0, p1, new_pos_v);
87 
88  const typename GeometryTraits::Scalar sign = gt.dot_product(face_normal, face_normal_after_collapse);
89  if (sign < 0.0)
90  return false;
91  }
92  return true;
93  }
94 
95 } // namespace Operators
96 } // namespace FEVV
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
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::Geometry_traits< HalfedgeGraph >
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::DataStructures::AIF::source
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor source(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the source vertex of e.
Definition: Graph_traits_aif.h:387
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::Operators::no_normal_flip_for_collapse
bool no_normal_flip_for_collapse(const HalfedgeGraph &g, const PointMap &pm, typename boost::graph_traits< HalfedgeGraph >::edge_descriptor e, typename boost::graph_traits< HalfedgeGraph >::vertex_descriptor v, const typename GeometryTraits::Point &new_pos_v, const GeometryTraits &gt)
Function used to detected a local normal flip due to a vertex position change.
Definition: no_normal_flip_for_collapse.hpp:46
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::prev
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor prev(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the previous halfedge around its face.
Definition: Graph_traits_aif.h:612
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
MatrixOperations.hpp
FEVV::face_normal
@ face_normal
Definition: properties.h:77