MEPP2 Project
flatfrequencycomputor.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 <cmath>
15 
16 int
17 cpd_to_pixel(int screen_resX,
18  int screen_resY,
19  double screen_size,
20  double user_distance,
21  double cpd);
22 
23 double
24 pixel_to_wDistance(int camera_vportY,
25  double camera_fov,
26  double camera_distance,
27  int nb_pixel);
28 
29 double
30 cpd_to_wDistance(int screen_resX,
31  int screen_resY,
32  double screen_size,
33  double user_distance,
34  int camera_vportY,
35  double camera_fov,
36  double camera_distance,
37  double cpd);
38 
39 double
40 pixel_to_cpd(int screen_resX,
41  int screen_resY,
42  double screen_size,
43  double user_distance,
44  int nb_pixel);
45 
46 int
47 wDistance_to_pixel(int camera_vportY,
48  double camera_fov,
49  double camera_distance,
50  double wDistance);
51 
52 double
53 wDistance_to_cpd(int screen_resX,
54  int screen_resY,
55  double screen_size,
56  double user_distance,
57  int camera_vportY,
58  double camera_fov,
59  double camera_distance,
60  double wDistance);
61 
62 template< typename Cam_t, typename GeometryTraits, typename Point_t >
63 double
64 compute_flat_frequency(const Cam_t &cam,
65  const Point_t &p1,
66  const Point_t &p2,
67  const GeometryTraits &geom_t,
68  const ScreenParam &screen,
69  const UserParam &user,
70  const SceneParam &scene)
71 {
72 
73  double cdist = geom_t.length((0.5 * (p1 + p2) - cam));
74 
75  double length = geom_t.length(p1 - p2);
76  // convert length to cpd
77  int npx = wDistance_to_pixel(scene.hvport, scene.fov, cdist, length);
78 
79  double cpd =
80  pixel_to_cpd(screen.hres, screen.vres, screen.diag, user.dist, npx);
81 
82  double max_cpd =
83  pixel_to_cpd(screen.hres, screen.vres, screen.diag, user.dist, 2);
84 
85  return std::min(cpd, max_cpd);
86 }
87 
88 template< typename Cam_t,
89  typename PointMap,
90  typename HalfedgeGraph,
91  typename GeometryTraits,
92  typename HalfEdge >
93 double
94 compute_flat_frequency(const Cam_t &cam,
95  const PointMap &point_map,
96  const HalfedgeGraph &mesh,
97  const GeometryTraits &geom_t,
98  const HalfEdge &halfedge,
99  const ScreenParam &screen,
100  const UserParam &user,
101  const SceneParam &scene)
102 {
103  auto opp = opposite(halfedge, mesh);
104  auto v1 = get(point_map, target(next(halfedge, mesh), mesh));
105  auto v2 = get(point_map, target(next(opp, mesh), mesh));
106 
107  typename GeometryTraits::Vector p1(
108  geom_t.get_x(v1), geom_t.get_y(v1), geom_t.get_z(v1));
109  typename GeometryTraits::Vector p2(
110  geom_t.get_x(v2), geom_t.get_y(v2), geom_t.get_z(v2));
111 
112  return compute_flat_frequency(cam, p1, p2, geom_t, screen, user, scene);
113 }
114 
115 #include "flatfrequencycomputor.inl"
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
compute_flat_frequency
double compute_flat_frequency(const Cam_t &cam, const Point_t &p1, const Point_t &p2, const GeometryTraits &geom_t, const ScreenParam &screen, const UserParam &user, const SceneParam &scene)
Definition: flatfrequencycomputor.hpp:64
UserParam
The parameters of the user.
Definition: types.h:43
ScreenParam::vres
int vres
Definition: types.h:33
types.h
cpd_to_wDistance
double cpd_to_wDistance(int screen_resX, int screen_resY, double screen_size, double user_distance, int camera_vportY, double camera_fov, double camera_distance, double cpd)
Definition: flatfrequencycomputor.inl:45
SceneParam::hvport
int hvport
Definition: types.h:58
ScreenParam
The parameters of the screen.
Definition: types.h:27
wDistance_to_pixel
int wDistance_to_pixel(int camera_vportY, double camera_fov, double camera_distance, double wDistance)
Definition: flatfrequencycomputor.inl:80
SceneParam
The parameters of the scene.
Definition: types.h:55
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
flatfrequencycomputor.inl
ScreenParam::hres
int hres
Definition: types.h:32
cpd_to_pixel
int cpd_to_pixel(int screen_resX, int screen_resY, double screen_size, double user_distance, double cpd)
Definition: flatfrequencycomputor.inl:14
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
FEVV::DataStructures::AIF::target
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor target(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the target vertex of e.
Definition: Graph_traits_aif.h:400
ScreenParam::diag
double diag
Definition: types.h:34
wDistance_to_cpd
double wDistance_to_cpd(int screen_resX, int screen_resY, double screen_size, double user_distance, int camera_vportY, double camera_fov, double camera_distance, double wDistance)
Definition: flatfrequencycomputor.inl:93
SceneParam::fov
double fov
Definition: types.h:59
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
pixel_to_wDistance
double pixel_to_wDistance(int camera_vportY, double camera_fov, double camera_distance, int nb_pixel)
Definition: flatfrequencycomputor.inl:31
pixel_to_cpd
double pixel_to_cpd(int screen_resX, int screen_resY, double screen_size, double user_distance, int nb_pixel)
Definition: flatfrequencycomputor.inl:63
UserParam::dist
double dist
Definition: types.h:46