Loading [MathJax]/jax/output/HTML-CSS/config.js
Free Electron
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
geodesic_cpp_03_02_2008/geodesic_constants_and_simple_functions.h
1 //Copyright (C) 2008 Danil Kirsanov, MIT License
2 #ifndef GEODESIC_CONSTANTS_20071231
3 #define GEODESIC_CONSTANTS_20071231
4 
5 // some constants and simple math functions
6 
7 #include <assert.h>
8 #include <math.h>
9 #include <limits>
10 #include <fstream>
11 
12 namespace geodesic{
13 
14 #ifndef M_PI
15 #define M_PI 3.14159265358979323846
16 #endif
17 
18 //double const GEODESIC_INF = std::numeric_limits<double>::max();
19 double const GEODESIC_INF = 1e100;
20 
21 //in order to avoid numerical problems with "infinitely small" intervals,
22 //we drop all the intervals smaller than SMALLEST_INTERVAL_RATIO*edge_length
23 double const SMALLEST_INTERVAL_RATIO = 1e-6;
24 //double const SMALL_EPSILON = 1e-10;
25 
26 
27 inline double cos_from_edges(double const a, //compute the cosine of the angle given the lengths of the edges
28  double const b,
29  double const c)
30 {
31  assert(a>1e-50);
32  assert(b>1e-50);
33  assert(c>1e-50);
34 
35  double result = (b*b + c*c - a*a)/(2.0*b*c);
36  result = std::max(result, -1.0);
37  return std::min(result, 1.0);
38 }
39 
40 inline double angle_from_edges(double const a, //compute the cosine of the angle given the lengths of the edges
41  double const b,
42  double const c)
43 {
44  return acos(cos_from_edges(a,b,c));
45 }
46 
47 template<class Points, class Faces>
48 inline bool read_mesh_from_file(char* filename,
49  Points& points,
50  Faces& faces)
51 {
52  std::ifstream file(filename);
53  assert(file.is_open());
54  if(!file.is_open()) return false;
55 
56  unsigned num_points;
57  file >> num_points;
58  assert(num_points>=3);
59 
60  unsigned num_faces;
61  file >> num_faces;
62 
63  points.resize(num_points*3);
64  for(typename Points::iterator i=points.begin(); i!=points.end(); ++i)
65  {
66  file >> *i;
67  }
68 
69  faces.resize(num_faces*3);
70  for(typename Faces::iterator i=faces.begin(); i!=faces.end(); ++i)
71  {
72  file >> *i;
73  }
74  file.close();
75 
76  return true;
77 }
78 
79 } //geodesic
80 
81 #endif //GEODESIC_CONSTANTS_20071231
Definition: geodesic_cpp_03_02_2008/geodesic_algorithm_base.h:11