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