Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
graph_model.h
Go to the documentation of this file.
1 #ifndef GRAPH_MODEL_H
2 #define GRAPH_MODEL_H
3 
4 #include <boundary.h>
5 #include <freespace.h>
6 #include <boost/container/map.hpp>
7 
8 namespace frechet { namespace reach {
9 
10 using namespace data;
11 using namespace fs;
12 
17 struct IndexRange {
21  int lower;
23  int upper;
24 
26  IndexRange();
33  IndexRange(Orientation ori, int l, int u);
34 
38  bool empty() const;
42  void clear();
46  int len() const;
47 
53  bool contains(int i) const;
59  bool contains(const IndexRange& that) const;
65  bool operator==(const IndexRange& that) const;
71  bool operator!=(const IndexRange& that) const;
72 
78  IndexRange operator+ (const IndexRange& b) const;
84  IndexRange operator+ (int offset) const;
90  IndexRange operator- (int offset) const;
91 
97  IndexRange operator& (const IndexRange& b) const;
103  IndexRange& operator+= (const IndexRange& b);
109  IndexRange& operator-= (int offset);
110 
116  IndexRange& operator&= (const IndexRange& b);
117 
123  bool intersects(const IndexRange& b) const;
124 };
125 
126 
127 
132 struct Placement
133 {
138  double w;
141 };
142 
144 typedef std::vector<frechet::reach::Placement> Placements;
145 
150 enum Bias: uint8_t {
152  LOWER=1,
153  UPPER=2,
155 };
156 
163 Bias operator| (Bias a, Bias b);
170 Bias& operator|= (Bias& a, Bias b);
171 
175 struct BoundsIndex {
177  int index;
185  BoundsIndex(int i, Bias b) : index(i),bias(b) {}
191  BoundsIndex operator+ (int offset) const {
192  return BoundsIndex(index+offset,bias);
193  }
194 };
195 
208 private:
211  typedef boost::container::map<double,BoundsIndex> Map;
216  int _dim;
217 
218  friend class GraphModel;
219 
220 public:
224  GraphModelAxis();
225 
234  void insert1(double x, Bias bias);
241  void insert2(double x, Bias bias);
242 
248  const BoundsIndex& lookup(double x) const;
254  const BoundsIndex* lookupLowerEqual(double x) const;
260  const BoundsIndex* lookupLarger(double x) const;
261 
267  void createReverseMap(std::vector<Interval>& result) const;
268 
269 private:
274  void remove(double x);
279  void indexify(int start);
280 };
281 
297 class GraphModel {
298 
299 private:
301  GraphModelAxis axis[2];
303  std::vector<Interval> reversed[2];
304 
305 public:
307  typedef boost::shared_ptr<GraphModel> ptr;
308 
313 
318  void init(const FreeSpace::ptr fs);
322  bool empty() const;
323 
328  int dim1(Orientation ori) const;
333  int dim2(Orientation ori) const;
334 
342  int lowerShiftedHorizontally(int hindex) const {
343  double x = reversed[HORIZONTAL][hindex].lower();
344  double offset = dim1(HORIZONTAL);
345  return map_lower(HORIZONTAL,x+offset);
346  }
347 
356  Q_ASSERT(r.ori==HORIZONTAL);
357  return IndexRange(HORIZONTAL,
358  lowerShiftedHorizontally(r.lower),
359  lowerShiftedHorizontally(r.upper));
360  }
365  int count2(Orientation ori) const;
369  int count2() const;
370 
378  IndexRange map(Orientation ori, const Interval&,
379  bool upperBoundInclusive) const;
380 
387  IndexRange map(Pointer b) const;
388 
394  int map_lower(Pointer p) const;
400  int map_upper(Pointer p) const;
401 
408  int map_lower(Orientation ori, double x) const;
416  int map_upper(Orientation ori, double x, bool inclusive) const;
417 
424  IndexRange mapClosest(Orientation ori, const Interval& ival) const;
425 
432  const std::vector<Interval>& reverseMap(Orientation ori) const {
433  return reversed[ori];
434  }
435 
443  IndexRange mergedHMask(const IndexRange& m1, const IndexRange& m2) const;
444 
445 private:
450  void initVertical(const FreeSpace::ptr fs);
455  void initHorizontal(const FreeSpace::ptr fs);
456 };
457 
458 } } // namespace frechet::reach
459 
460 #endif // GRAPH_MODEL_H
Bias
bias of a GraphModel boundary (how shall we explain this?)
Definition: graph_model.h:150
std::vector< frechet::reach::Placement > Placements
a list of Placement objects
Definition: graph_model.h:144
Bias operator|(Bias a, Bias b)
union operator
int _max_index
maximum node index
Definition: graph_model.h:214
model the mapping of free-space intervals to nodes in a frechet::reach::Graph.
Definition: graph_boost.h:109
Bias bias
bias: inclusive to lower / upper interval
Definition: graph_model.h:179
boundary is inclusive to adjacent upper interval
Definition: graph_model.h:153
global definitions for all algorithms.
boost::shared_ptr< GraphModel > ptr
smart pointer to a GraphModel object
Definition: graph_model.h:307
boundary interval in the reachability structure. Represents an interval on the boundary of the FreeSp...
Definition: boundary.h:285
BoundsIndex(int i, Bias b)
default constructor
Definition: graph_model.h:185
boost::container::map< double, BoundsIndex > Map
maps free-space coordinates to graph nodes (identified by node index, with an optional bias to adjace...
Definition: graph_model.h:211
int upper
upper index (exclusive)
Definition: graph_model.h:23
int index
index of node in reachability graph
Definition: graph_model.h:177
int lower
lower index (inclusive)
Definition: graph_model.h:21
mapping within a GraphModel
Definition: graph_model.h:175
GraphModel()
empty constructor
Definition: graph_model.h:312
a range of node indices in a Reachability Graph
Definition: graph_model.h:17
Orientation
Segment Orientation.
Definition: boundary.h:31
boundary is inclusive to adjacent lower interval
Definition: graph_model.h:152
boundary is not inclusive to any interval
Definition: graph_model.h:151
Bias & operator|=(Bias &a, Bias b)
union operator
placement of a diagonal point in free-space diagram When calculating valid placements in [buchin06]
Definition: graph_model.h:132
manages a mapping between free-space intervals (continous, floating point) to reachability graph node...
Definition: graph_model.h:207
Orientation ori
horizontal or vertical part of the reachability structure?
Definition: graph_model.h:19
IndexRange shiftedHorizontally(const IndexRange &r) const
map a node range to its counterpart in the duplicated part of a double-free-space
Definition: graph_model.h:355
Interval fs
Free-Space Interval.
Definition: graph_model.h:135
int _dim
width or height of the free-space diagram
Definition: graph_model.h:216
const std::vector< Interval > & reverseMap(Orientation ori) const
create a reverse map, mapping graph nodes to free-space interval
Definition: graph_model.h:432
an interval of two double values.
Definition: interval.h:31
boost::shared_ptr< FreeSpace > ptr
smart pointer to FreeSpace object
Definition: freespace.h:92
int lowerShiftedHorizontally(int hindex) const
map a node index to its counterpart in the duplicated part of a double-free-space
Definition: graph_model.h:342
IndexRange gn
mapping to nodes of the reachability graph (see GraphModel)
Definition: graph_model.h:140