VPTissue Reference Manual
VoronoiTesselation.h
Go to the documentation of this file.
1 #ifndef SIMPT_EDITOR_VORONOI_TESSELATION_H_INCLUDED
2 #define SIMPT_EDITOR_VORONOI_TESSELATION_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include <QGraphicsPolygonItem>
23 
24 #include <QBrush>
25 #include <QPointF>
26 #include <QRectF>
27 
28 #include <boost/polygon/point_data.hpp>
29 #include <boost/polygon/voronoi.hpp>
30 
31 #include <list>
32 #include <map>
33 
34 class QGraphicsLineItem;
35 class QGraphicsSceneMouseEvent;
36 
37 namespace SimPT_Editor {
38 
43 {
44 public:
51  VoronoiTesselation(const QPolygonF &boundaryPolygon, QGraphicsItem *parent = nullptr);
52 
56  virtual ~VoronoiTesselation();
57 
58 
64  std::list<QPolygonF> GetCellPolygons();
65 
66 protected:
68  virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
69 
71  virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
72 
73 private:
74  void UpdateTesselation();
75  void RedrawLines();
76 
77 private:
81  struct ClippedEdge
82  {
83  ClippedEdge()
84  : edge(QLineF()), clippedP1(false), nextBoundaryP1(QPointF()), clippedP2(false), nextBoundaryP2(QPointF())
85  {}
86 
87  ClippedEdge(QLineF e, bool c1, QPointF nBP1, bool c2, QPointF nBP2)
88  : edge(e), clippedP1(c1), nextBoundaryP1(nBP1), clippedP2(c2), nextBoundaryP2(nBP2)
89  {}
90 
91  QLineF edge;
92  bool clippedP1;
93  QPointF nextBoundaryP1;
94  bool clippedP2;
95  QPointF nextBoundaryP2;
96  };
97 
98  void AddEdge(const boost::polygon::voronoi_diagram<double>::edge_type *edge, QPolygonF &polygon, std::map<const boost::polygon::voronoi_diagram<double>::edge_type*, ClippedEdge> &clippingCache);
99  ClippedEdge GetClippedEdge(const boost::polygon::voronoi_diagram<double>::edge_type *edge, std::map<const boost::polygon::voronoi_diagram<double>::edge_type*, ClippedEdge> &clippingCache);
100  ClippedEdge ClipEdge(const boost::polygon::voronoi_diagram<double>::edge_type *edge);
101 
102 private:
103  static boost::polygon::point_data<long> ToVoronoiPoint(const QPointF &point);
104  static QPointF FromVoronoiPoint(const boost::polygon::voronoi_diagram<double>::vertex_type &point);
105 
106 private:
107  std::vector<QPointF> m_points;
108  std::list<QPolygonF> m_cell_polygons;
109  std::list<QGraphicsLineItem*> m_lines;
110 
111 private:
112  static const QRectF g_point_rect;
113  static const QBrush g_point_brush;
114  static const double g_points_precision;
115 };
116 
117 } // namespace
118 
119 #endif // end-of-include-guard
Namespace for SimPT tissue editor package.
Definition: Cell.h:32
virtual ~VoronoiTesselation()
Destructor.
see the online Qt documentation
see the online Qt documentation
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Reimplementation of QGraphicsItem::mouseDoubleClickEvent to add a point to the tesselation.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Reimplementation of QGraphicsItem::mousePressEvent to remove a point from the tesselation.
std::list< QPolygonF > GetCellPolygons()
Returns the polygons of cell of the Voronoi tesselation.
VoronoiTesselation(const QPolygonF &boundaryPolygon, QGraphicsItem *parent=nullptr)
Constructor.
see the online Qt documentation
Graphics item for Voronoi tesselation of a polygon.