lefer  0.1.0
A C++ library to draw evenly-spaced and non-overlapping curves in a flow field using the Jobard and Lefer (1997) algorithm.
lefer.hpp
Go to the documentation of this file.
1 #include <vector>
2 
3 
4 namespace lefer {
5 
6 double distance (double x1, double y1, double x2, double y2);
7 static int _grid_index_as_1d(int x, int y, int grid_width);
8 
9 
10 class FlowField {
11 private:
12  double** _flow_field;
13  int _field_width;
14 public:
15  FlowField(double** flow_field, int field_width);
16  int get_field_width();
17  int get_flow_field_col(double x);
18  int get_flow_field_row(double y);
19  bool off_boundaries(double x, double y);
20  double get_angle(double x, double y);
21 };
22 
23 struct Point {
24  double x;
25  double y;
26 };
27 
28 
32 class Curve {
33 public:
35  int _curve_id;
36  std::vector<double> _x;
37  std::vector<double> _y;
38  std::vector<int> _direction;
39  std::vector<int> _step_id;
41 public:
42  Curve(int id, int n_steps);
43  void insert_step(double x_coord, double y_coord, int direction_id);
44 };
45 
46 
47 struct DensityCell {
48  std::vector<double> x;
49  std::vector<double> y;
50  int capacity;
52 };
53 
54 
55 class DensityGrid {
56 private:
57  std::vector<DensityCell> _grid;
58  int _width;
59  int _height;
60  int _n_elements;
61  double _d_sep;
62 public:
63  DensityGrid(int flow_field_width, int flow_field_height, double d_sep, int cell_capacity);
64  int get_density_col (double x);
65  int get_density_row (double y);
66  int get_density_index (double x, double y);
67  int get_density_index (int col, int row);
68  bool off_boundaries(double x, double y);
69  void insert_coord(double x, double y);
70  void insert_curve_coords(Curve* curve);
71  bool is_valid_next_step(double x, double y);
72 };
73 
74 
75 
77 public:
78  std::vector<Point> _points;
79  int _capacity;
81 
82 public:
83  SeedPointsQueue(int n_steps);
84  bool is_empty();
85  void insert_coord(double x, double y);
86  void insert_point(Point p);
87 };
88 
89 
90 
91 SeedPointsQueue collect_seedpoints (Curve* curve, double d_sep);
92 
93 
94 
95 Curve draw_curve(int curve_id,
96  double x_start,
97  double y_start,
98  int n_steps,
99  double step_length,
100  double d_sep,
101  FlowField* flow_field,
102  DensityGrid* density_grid);
103 
104 
105 std::vector<Curve> even_spaced_curves(double x_start,
106  double y_start,
107  int n_curves,
108  int n_steps,
109  int min_steps_allowed,
110  double step_length,
111  double d_sep,
112  FlowField* flow_field,
113  DensityGrid* density_grid);
114 
115 
116 
117 std::vector<Curve> non_overlapping_curves(std::vector<Point> starting_points,
118  int n_steps,
119  int min_steps_allowed,
120  double step_length,
121  double d_sep,
122  FlowField* flow_field,
123  DensityGrid* density_grid);
124 
125 
126 
127 } // namespace lefer
Definition: lefer.hpp:32
std::vector< double > _x
Definition: lefer.hpp:36
std::vector< int > _step_id
Definition: lefer.hpp:39
int _steps_taken
Definition: lefer.hpp:40
int _curve_id
Definition: lefer.hpp:35
std::vector< int > _direction
Definition: lefer.hpp:38
std::vector< double > _y
Definition: lefer.hpp:37
void insert_step(double x_coord, double y_coord, int direction_id)
Definition: main.cpp:402
Curve(int id, int n_steps)
Definition: main.cpp:393
Definition: lefer.hpp:55
int get_density_index(double x, double y)
Definition: main.cpp:468
void insert_curve_coords(Curve *curve)
Definition: main.cpp:505
bool is_valid_next_step(double x, double y)
Definition: main.cpp:512
int get_density_row(double y)
Definition: main.cpp:463
bool off_boundaries(double x, double y)
Definition: main.cpp:478
DensityGrid(int flow_field_width, int flow_field_height, double d_sep, int cell_capacity)
Definition: main.cpp:441
int get_density_col(double x)
Definition: main.cpp:458
void insert_coord(double x, double y)
Definition: main.cpp:489
Definition: lefer.hpp:10
double get_angle(double x, double y)
Definition: main.cpp:364
int get_flow_field_col(double x)
Definition: main.cpp:346
int get_flow_field_row(double y)
Definition: main.cpp:350
bool off_boundaries(double x, double y)
Definition: main.cpp:354
int get_field_width()
Definition: main.cpp:341
FlowField(double **flow_field, int field_width)
Definition: main.cpp:335
Definition: lefer.hpp:76
int _space_used
Definition: lefer.hpp:80
SeedPointsQueue(int n_steps)
Definition: main.cpp:568
bool is_empty()
Definition: main.cpp:574
void insert_coord(double x, double y)
Definition: main.cpp:578
void insert_point(Point p)
Definition: main.cpp:584
int _capacity
Definition: lefer.hpp:79
std::vector< Point > _points
Definition: lefer.hpp:78
Definition: lefer.hpp:4
double distance(double x1, double y1, double x2, double y2)
Definition: main.cpp:293
SeedPointsQueue collect_seedpoints(Curve *curve, double d_sep)
Definition: main.cpp:591
Curve draw_curve(int curve_id, double x_start, double y_start, int n_steps, double step_length, double d_sep, FlowField *flow_field, DensityGrid *density_grid)
Definition: main.cpp:35
std::vector< Curve > non_overlapping_curves(std::vector< Point > starting_points, int n_steps, int min_steps_allowed, double step_length, double d_sep, FlowField *flow_field, DensityGrid *density_grid)
Definition: main.cpp:221
std::vector< Curve > even_spaced_curves(double x_start, double y_start, int n_curves, int n_steps, int min_steps_allowed, double step_length, double d_sep, FlowField *flow_field, DensityGrid *density_grid)
Definition: main.cpp:120
Definition: lefer.hpp:47
std::vector< double > y
Definition: lefer.hpp:49
std::vector< double > x
Definition: lefer.hpp:48
int capacity
Definition: lefer.hpp:50
int space_used
Definition: lefer.hpp:51
Definition: lefer.hpp:23
double y
Definition: lefer.hpp:25
double x
Definition: lefer.hpp:24