Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
freespaceview.h
Go to the documentation of this file.
1 #ifndef FREESPACEVIEW_H
2 #define FREESPACEVIEW_H
3 
4 #include <baseview.h>
5 #include <grid.h>
6 #include <freespace.h>
7 #include <fs_path.h>
8 #include <k_frechet/kalgorithm.h>
9 #include <palette.h>
10 #include <intervalview.h>
11 
12 #include <array2d.h>
13 #include <QPolygonF>
14 #include <QGraphicsItemGroup>
15 
16 namespace frechet { namespace view {
17 
18 class FreeSpaceView;
40 class CellView : public QGraphicsItemGroup
41 {
42 private:
44  int i;
46  int j;
49 
51  QRectF cellBounds;
53  QPainterPath clipShape;
54 
56  QGraphicsPolygonItem* _poly;
59  QGraphicsEllipseItem* _ellipse;
61  bool useEllipse;
63  QGraphicsLineItem* _bounds[4];
64 
69  enum What {
70  MASK = 0x00f,
71  NOTHING = 0x00,
72  POLY = 0x01,
73  ELLIPSE = 0x02,
74 
75  BOUNDS = 0x10,
76 
79  } what;
80 
81 public:
85  typedef boost::shared_ptr<Matrix> MatrixPtr;
86 
93  CellView(FreeSpaceView* parent, int i, int j);
95  virtual ~CellView();
96 
102  void setColor(QColor areaColor, QColor borderColor=QColor());
103 
110  void update(double eps, bool showBounds, QLineF bounds[4]);
111 
113  virtual QPainterPath shape() const {
114  return clipShape;
115  }
117  virtual QRectF boundingRect() const {
118  return cellBounds;
119  }
122  bool dropUnusedItems();
123 
124 private:
125  friend class FreeSpaceView;
127  static const double DET_MINIMUM;
129  static const double MAX_DIAMETER;
130 
131  //void addLine(QLineF,int i);
139  QPolygonF createPolygon(int i, int j, bool* thin);
140 
142  QGraphicsPolygonItem* getPoly();
144  QGraphicsEllipseItem* getEllipse();
147  QGraphicsLineItem* getBounds(int i);
149  void setBounds(QLineF bounds[4]);
150 
153  void dodraw(What what);
156  void dropUnusedItem(QGraphicsItem** item);
157 
161  static void setBrushColor(QAbstractGraphicsShapeItem* item, QColor col);
165  static void setPenColor(QAbstractGraphicsShapeItem* item, QColor col);
170  static void setBoundsPenColor(QGraphicsLineItem** bounds, int len, QColor col);
174  static void setPenStyle(QAbstractGraphicsShapeItem* item, Qt::PenStyle style);
179  static void setPenStyleWidth(QAbstractGraphicsShapeItem* item, Qt::PenStyle style, float width);
180 
181 };
199 class FreeSpaceView : public BaseView
200 {
201  Q_OBJECT
202 public:
205  QPen GRID_PEN [4];
206  QPen AREA_PEN;
207  QPen BOUNDS_PEN;
208  QPen PATH_PEN;
209  static const QBrush AREA_BRUSH1;
210  static const QBrush AREA_BRUSH2;
211  static const double TF_MAX_ARG;
212  static const QColor LIGHT_GRAY;
213  static const QColor AREA_COLOR;
214 
219  FreeSpaceView(QWidget *parent = 0);
221  virtual ~FreeSpaceView();
222 
224  void populateScene();
225 
227  bool showBounds() const { return _showBounds; }
228 
231  virtual void dropUnusedItems() override;
233  virtual void segmentSelected(GraphicsHoverLineItem *item) override;
234 
235 signals:
238  void curveFinished(bool yes);
245  void hiliteSegment(int loc, int a, int b);
246 
247 public slots:
254  void calculateFreeSpace(double epsilon);
259  void showBounds(bool show);
260 
266  void showGreedyResult();
272  void showOptimalResult();
277  void hideResult();
282  void showPath(bool show);
283 
291  void onHiliteSegment(int loc, int a, int b);
298  void onAlgorithmChanged(int alg);
304  void hilitePoint(QPointF p);
305 
311  virtual void saveSettings(QSettings& settings, QString group);
317  virtual void restoreSettings(QSettings& settings, QString group);
318 
319 private:
320  friend class CellView;
322  bool path_ok;
328 
331 
335  QGraphicsItemGroup *pathView;
337  QGraphicsPathItem *select;
338 
343  CellView* getCellView(int i, int j);
344 
347  void updateView(double eps);
348 
350  void updateBounds();
351 
353  void updateIntervals();
354 
357  void showResult(const data::BitSet* resultSet);
358 
363  void createBoundsRect(int i, int j, QLineF result[4]);
364 
369  void createReachabilityRect(int i, int j, QLineF result[4]);
370 
377  QLineF boundsLine(QPointF a, QPointF b, int i, int j);
378 
383  QTransform createEllipseTransform(int i, int j);
384 
389  static bool validTransform(const QTransform& tf);
390 
394  static bool validTransformArg(double x);
395 
399  void addGridLine(QLineF line, LineStyle style);
400 
408  void doHiliteSegment(GraphicsHoverLineItem::Location loc, int a, int b);
409 };
410 
411 } } // namespace frechet::view
412 
413 #endif // FREESPACEVIEW_H
base class for view widgets.
Definition: baseview.h:79
QGraphicsPolygonItem * _poly
content area may be a polygon (created on demand)
Definition: freespaceview.h:56
QGraphicsLineItem * _bounds[4]
boundary lines of the content area
Definition: freespaceview.h:63
virtual void segmentSelected(GraphicsHoverLineItem *item) override
called when the mouse hovers over a sensitve line item
void setColor(QColor areaColor, QColor borderColor=QColor())
update drawing colors
static void setPenStyle(QAbstractGraphicsShapeItem *item, Qt::PenStyle style)
update pen style (dotted,solid,...) of a graphics item
void showOptimalResult()
show the optimal result of the k-Frechet (brute-force) algorithms. Highlights all components that are...
static bool validTransform(const QTransform &tf)
validity test for a transformation. If transform parameters become excessively large,...
QPen BOUNDS_PEN
pen for bounding rectangles
bool path_ok
true, if there is a feasible path
What
display mode; what is displayed? Flags can be combined (except Poly and Ellipse).
Definition: freespaceview.h:69
QGraphicsPathItem * select
highlighted line segment (or nullptr)
void addGridLine(QLineF line, LineStyle style)
add a grid line to the graphics scene
static const QColor LIGHT_GRAY
used for disabled components (k-Frechet)
FreeSpaceView * parent
pointer to parent
Definition: freespaceview.h:48
bool _showBounds
true, if bounding rectangle are shown
virtual QPainterPath shape() const
void dropUnusedItem(QGraphicsItem **item)
release an unused item
QGraphicsEllipseItem * getEllipse()
global definitions for all algorithms.
bool useEllipse
true if an ellipse is to be shown
Definition: freespaceview.h:61
IntervalView * intervalView[2]
k-Frechet: show component intervals below and to the left
static void setBoundsPenColor(QGraphicsLineItem **bounds, int len, QColor col)
update pen color of several graphics item
display a clipped ellipse
Definition: freespaceview.h:73
void hiliteSegment(int loc, int a, int b)
raised when the mouse moves over a highlighted segment This signal triggers the display of associated...
FreeSpaceView(QWidget *parent=0)
default constructor
void populateScene()
create the grid lines and an array of CellView objects
void createReachabilityRect(int i, int j, QLineF result[4])
create a set of line segments for reachability intervals
QGraphicsItemGroup * pathView
the feasible path
void onHiliteSegment(int loc, int a, int b)
highlight a segment of the feasible path
CellView(FreeSpaceView *parent, int i, int j)
default constructor
virtual QRectF boundingRect() const
static const QColor AREA_COLOR
color for content area (except k-Frechet)
Display k-Frechet intervals, i.e. projections of connected components to the domain axes.
Definition: intervalview.h:33
static const QBrush AREA_BRUSH2
brush (fill color) for content area
display the free-space diagram.
boost::shared_ptr< Matrix > MatrixPtr
pointer to an array of cell views
Definition: freespaceview.h:85
QGraphicsLineItem * getBounds(int i)
display bounding rect
Definition: freespaceview.h:75
void setBounds(QLineF bounds[4])
update bounding rectangle
void onAlgorithmChanged(int alg)
updatee free-space diagram when a new algorithm is selected. For example, for the k-Frechet algorithm...
QPainterPath clipShape
shape used for clipping ellipses
Definition: freespaceview.h:53
void updateBounds()
update bounding rectangles
void createBoundsRect(int i, int j, QLineF result[4])
create a boundary rectangle for a cell
QPen PATH_PEN
pen for feasible path
QGraphicsPolygonItem * getPoly()
QPolygonF createPolygon(int i, int j, bool *thin)
create a polygon that draws the content area
void showGreedyResult()
show the result of the k-Frechet greedy algorithms. Highlights all components that are part of the so...
a QGraphicsLitem that can handle mouse hover events. It is used to highlight mouse sensitve polygon s...
Definition: baseview.h:239
int i
column index in free-space grid
Definition: freespaceview.h:44
virtual ~FreeSpaceView()
destructor; releases all items
display polygon plus bounding rect
Definition: freespaceview.h:78
QTransform createEllipseTransform(int i, int j)
compute the transformation for drawing an ellipse
void hideResult()
hide results of the k-Frechet algorithms. Remove gray-out, display all components in their original c...
a color map.
Definition: palette.h:17
static const double DET_MINIMUM
determines when a hige ellipse is replaced by two parallel lines
bool dropUnusedItems()
release graphics items that are not currently displayed
enum frechet::view::CellView::What what
QRectF cellBounds
bounding rectangle
Definition: freespaceview.h:51
void update(double eps, bool showBounds, QLineF bounds[4])
update display
virtual void dropUnusedItems() override
release graphics items that are currently not drawn implements empty method from super-class
static void setPenStyleWidth(QAbstractGraphicsShapeItem *item, Qt::PenStyle style, float width)
update pen style and pen width of a graphics item
QPen AREA_PEN
pen for content area
QLineF boundsLine(QPointF a, QPointF b, int i, int j)
calculates one boundary line
void curveFinished(bool yes)
raised when after decision variant of the curve algorithm
A simple two-dimensional array of fixed size.
Definition: array2d.h:19
virtual void restoreSettings(QSettings &settings, QString group)
load settings from application preferences
void dodraw(What what)
update content
static const double TF_MAX_ARG
max. value for affine transforms
CellView * getCellView(int i, int j)
get a free-space cell view
virtual ~CellView()
destructor
display ellipse plus bounding rect
Definition: freespaceview.h:77
virtual void saveSettings(QSettings &settings, QString group)
store settings to application preferences
static void setBrushColor(QAbstractGraphicsShapeItem *item, QColor col)
update brush (fill) color of a graphics item
A simple bit vector of fixed size.
Definition: bitset.h:16
displays one cell of the free-space diagram.
Definition: freespaceview.h:40
empty cell. display nothing
Definition: freespaceview.h:71
LineStyle
display style of grid lines in free-space diagram
Definition: grid.h:15
void showPath(bool show)
show or hide feasible path
static const double MAX_DIAMETER
what's this?
static bool validTransformArg(double x)
validity test for a transformation
static void setPenColor(QAbstractGraphicsShapeItem *item, QColor col)
update pen (edge) color of a graphics item
int j
row index in free-space grid
Definition: freespaceview.h:46
data::Array2D< CellView * > Matrix
an array of cell views
Definition: freespaceview.h:83
void updateIntervals()
update component intervals (k-Frechet only)
CellView::MatrixPtr cells
free space areas for all cells (i,j)
static const QBrush AREA_BRUSH1
brush (fill color) for content area
QGraphicsEllipseItem * _ellipse
Definition: freespaceview.h:59
void doHiliteSegment(GraphicsHoverLineItem::Location loc, int a, int b)
highlight a line segment
Location
location of the polygon segment
Definition: baseview.h:243
void hilitePoint(QPointF p)
hilite on point inf the diagram (used for animation only)
void updateView(double eps)
update free-space view in response to a change of epsilon
void showResult(const data::BitSet *resultSet)
show the result of a k-Frechet algorithm
void calculateFreeSpace(double epsilon)
update free-space diagram when epsilon changes. If the curve algorithm is selected,...