Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
freespace.h
Go to the documentation of this file.
1 #ifndef FREESPACE_H
2 #define FREESPACE_H
3 
4 #include <types.h>
5 #include <interval.h>
6 #include <components.h>
7 #include <array2d.h>
8 #include <numeric.h>
9 
10 #include <QLineF>
11 
12 #include <cmath>
13 
14 #include <boost/smart_ptr.hpp>
15 
16 namespace frechet { namespace fs {
27 class Cell {
28 public:
32 
33 public:
36 
41 
42 public:
43  /*
44  * Free-Space segments of a cell
45  * */
47  double& a() { return L.lower(); }
49  double& b() { return L.upper(); }
51  double& c() { return B.lower(); }
53  double& d() { return B.upper(); }
54 
56  double a() const { return L.lower(); }
58  double b() const { return L.upper(); }
60  double c() const { return B.lower(); }
62  double d() const { return B.upper(); }
63 
68  const data::Interval& LB(bool l) { return l ? L:B; }
69 };
70 
71 // TODO type_traits: Interval, IntervalPair, and Cell are trivially-copyable
72 
83 class FreeSpace {
84 
85 public:
86  const Curve &P;
87  const Curve &Q;
88  const int n;
89  const int m;
90 
92  typedef boost::shared_ptr<FreeSpace> ptr;
93 
95  static const QRectF UNIT_RECT;
97  static const double DET_MINIMUM;
98 private:
100 
109 
110 public:
116  FreeSpace(const Curve& ap, const Curve& aq);
121  FreeSpace(const FreeSpace& that);
122 
125 
133  size_t component(int i, int j)
134  {
135  if (cellEmptyBounds(i,j))
137  else
138  return _components.representative(i,j);
139  }
144  void calculateFreeSpace(double epsilon);
150  void calculateBounds(double epsilon);
151 
152  /*
153  * Free-Space Cells
154  * */
160  Cell& cell(int x, int y) {
161  Q_ASSERT(x>=0 && x < n);
162  Q_ASSERT(y>=0 && y < m);
163  return cells.at(x,y);
164  }
170  const Cell& cell(int x, int y) const {
171  Q_ASSERT(x>=0 && x < n);
172  Q_ASSERT(y>=0 && y < m);
173  return cells.at(x,y);
174  }
181  bool cellEmptyIntervals(int i, int j) const;
188  bool cellEmptyBounds(int i, int j) const;
189 
196  bool cellFull(int i, int j) const;
197 
205  bool isParallel(int i, int j) const {
206  return determinant(i,j) == 0.0;
207  }
208 
217  bool isAlmostParallel(int i, int j) const {
218  return abs(determinant(i,j)) < DET_MINIMUM;
219  }
220 
225  bool wrapRight() const { return P.isClosed(); }
230  bool wrapTop() const { return Q.isClosed(); }
231 
237  QRectF segmentBounds(int i, int j);
238 
246  std::list<data::Interval> collectFreeVerticalIntervals(int i) const;
247 
248 public:
249  //void calculateGridOffsets();
264  template<typename Float>
265  static void calculateFreeSpaceSegment(const Point& p, const Point& q, const Point& r,
266  double epsilon,
267  data::Interval& result);
276 
277 private:
283  double determinant(int i, int j) const;
284 
298  template<typename Float>
300  const Point& p1, const Point& p2,
301  const Point& q1, const Point& q2,
302  double epsilon,
303  double lambda[2]);
304 };
305 
306 } } // namespace frechet
307 
308 #include <freespace_impl.h>
309 
310 #endif // FREESPACE_H
Components & components()
Definition: freespace.h:124
static const QRectF UNIT_RECT
the unit rectangle [0,1]x[0,1]
Definition: freespace.h:95
double b() const
Definition: freespace.h:58
bool cellFull(int i, int j) const
test if a cell is completely covered by the free-space area
Definition: freespace.cpp:190
bool isParallel(int i, int j) const
test if the free-space area of a cell is a degenerate ellipse, i.e. two parallel lines....
Definition: freespace.h:205
static void fixBorderCase(data::Interval *N, data::Interval *E, data::Interval *S, data::Interval *W)
fix border case at the joint of four intervals
Definition: freespace.cpp:252
size_t component(int i, int j)
find the component ID for a cell. Empty cells return NO_COMPONENT.
Definition: freespace.h:133
QRectF segmentBounds(int i, int j)
Definition: freespace.cpp:211
double d() const
Definition: freespace.h:62
bool wrapTop() const
if Q is a closed curve, the free space diagram wraps at top edge
Definition: freespace.h:230
global definitions for all algorithms.
double determinant(int i, int j) const
Definition: freespace.cpp:200
void calculateFreeSpace(double epsilon)
calculate all free space intervals
Definition: freespace.cpp:35
bool isAlmostParallel(int i, int j) const
test if the free-space area of a cell is a almost degenerate ellipse, This is the case if the determi...
Definition: freespace.h:217
static void calculateFreeSpaceSegment(const Point &p, const Point &q, const Point &r, double epsilon, data::Interval &result)
compute intervals for one point and segment. As parameters we expect a point on one curve (P,...
Definition: freespace_impl.h:8
static const double DET_MINIMUM
minimum determinant to avoid roundoff errors
Definition: freespace.h:97
data::Interval B
Definition: freespace.h:31
a pair of horizonal / vertical intervals.
Definition: interval.h:456
double a() const
Definition: freespace.h:56
const data::Interval & LB(bool l)
Definition: freespace.h:68
Components _components
tracks connected components for k-Frechet algorithm
Definition: freespace.h:108
data::IntervalPair bounds
Definition: freespace.h:40
bool cellEmptyIntervals(int i, int j) const
test if a cell is empty
Definition: freespace.cpp:182
double upper() const
Definition: interval.h:96
data::Interval L
Definition: freespace.h:31
QPointF Point
a point in the plane; with double floating point precision. This type is heavily used throughout all ...
Definition: types.h:14
double & a()
Definition: freespace.h:47
double & b()
Definition: freespace.h:49
Free-Space connected components and their projections to the domain axes.
Definition: components.h:27
QPolygonF Curve
a polygonal curve in the plane; with double floating point precision. This type is heavily used throu...
Definition: types.h:20
double lower() const
Definition: interval.h:92
A simple two-dimensional array of fixed size.
Definition: array2d.h:19
std::list< data::Interval > collectFreeVerticalIntervals(int i) const
traverse one column of the free-space and find all connected intervals. This method is needed by the ...
Definition: freespace.cpp:217
double & c()
Definition: freespace.h:51
bool wrapRight() const
if P is a closed curve, the free space diagram wraps at right edge
Definition: freespace.h:225
data::Array2D< Cell > cells
free line segments as Intervals subset of [0..1]
Definition: freespace.h:106
const int m
number of vertexes in Q
Definition: freespace.h:89
bool cellEmptyBounds(int i, int j) const
test if the bounding box of a cell is empty
Definition: freespace.cpp:174
void calculateBounds(double epsilon)
calculate the bounding boxes of the free-space areas (k-Frechet only)
Definition: freespace.cpp:112
The FreeSpace class models the Free-Space Diagram calculated from two curves.
Definition: freespace.h:83
holds data for one cell of the free-space diagram
Definition: freespace.h:27
component_id_t representative(int i, int j)
find the component ID of a cell
Definition: components.cpp:202
double & d()
Definition: freespace.h:53
const int n
number of vertexes in P
Definition: freespace.h:88
an interval of two double values.
Definition: interval.h:31
FreeSpace(const Curve &ap, const Curve &aq)
default constructor with two input curves
Definition: freespace.cpp:14
static const component_id_t NO_COMPONENT
empty cells have an invalid component ID
Definition: components.h:60
Number abs(const Number &x)
abs() function template for arbitrary numerical types
Definition: numeric.h:91
const Curve & Q
second input curve
Definition: freespace.h:87
void calculateEllipseBoundaries(const Point &p1, const Point &p2, const Point &q1, const Point &q2, double epsilon, double lambda[2])
compute the bounding box of one cell in the free-space are. As parameters we expect two segments of P...
boost::shared_ptr< FreeSpace > ptr
smart pointer to FreeSpace object
Definition: freespace.h:92
Cell & cell(int x, int y)
Definition: freespace.h:160
const Curve & P
first input curve
Definition: freespace.h:86
const Cell & cell(int x, int y) const
Definition: freespace.h:170
double c() const
Definition: freespace.h:60