MEPP2 Project
flatcontrastcomputor.h
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 <cmath>
14 #include <algorithm> // for std::max()
15 
16 
17 template< typename GeometryTraits, typename Vector_t >
18 double
19 compute_flat_contrast(const GeometryTraits &geom,
20  const Vector_t &n1,
21  const Vector_t &n2,
22  const Vector_t &ldir)
23 {
24  double cos_phi = geom.dot_product(n1, n2);
25  cos_phi = std::fabs(cos_phi);
26  double gcontrast = std::sqrt(fabs(1. - cos_phi) / (1. + cos_phi));
27 
28  auto ns = n1 + n2;
29  auto nd = n1 - n2;
30 
31  double n = geom.dot_product(ns, ldir);
32  double m = geom.dot_product(nd, ldir);
33 
34  double theta = (std::max)(n, 0.);
35  double alpha = std::abs(m);
36 
37  double lcontrast = (theta == 0 || (alpha != alpha))
38  ? 0.
39  : alpha / theta; // (alpha != alpha) instead of isnan
40  return lcontrast * gcontrast;
41 }
42 
43 
44 template< typename Light_t,
45  typename GeometryTraits,
46  typename HalfedgeGraph,
47  typename FaceNormalMap,
48  typename HalfEdge >
49 double
50 compute_flat_contrast(const GeometryTraits &geom,
51  const Light_t &ldir,
52  const HalfedgeGraph &mesh,
53  const FaceNormalMap &f_nm,
54  const HalfEdge &halfedge)
55 {
56  auto op_f = opposite(halfedge, mesh);
57  auto f1 = face(halfedge, mesh);
58  auto f2 = face(op_f, mesh);
59 
60  auto normal_f1 = get(f_nm, f1);
61  auto normal_f2 = get(f_nm, f2);
62  return compute_flat_contrast(geom, normal_f1, normal_f2, ldir);
63 }
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::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
boost::get
boost::property_map< FEVV::DataStructures::AIF::AIFMesh, boost::vertex_index_t >::const_type get(const boost::vertex_index_t &, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the vertex index property map of the mesh.
Definition: Graph_properties_aif.h:108
FEVV::Filters::fabs
double fabs(const v_Curv< HalfedgeGraph > &input)
Definition: curvature.hpp:54
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
compute_flat_contrast
double compute_flat_contrast(const GeometryTraits &geom, const Vector_t &n1, const Vector_t &n2, const Vector_t &ldir)
Definition: flatcontrastcomputor.h:19