10 using namespace reach;
12 const QPen
CurveView::PEN_A(QColor(255,0,0,180), 2.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
13 const QPen
CurveView::PEN_B(QColor(0,0,255,180), 2.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
23 polygon_a(nullptr), polygon_b(nullptr),
24 diagonals_a(nullptr), diagonals_b(nullptr),
25 select_a(nullptr), select_b(nullptr),
28 view()->setMouseTracking(
true);
29 view()->viewport()->setMouseTracking(
true);
45 poly->PTriangulation().edges(),
46 poly->c_diagonals(),
true,
55 poly->QTriangulation().edges(),
108 QGraphicsItemGroup* group =
new QGraphicsItemGroup();
109 group->setAcceptHoverEvents(hover);
110 group->setHandlesChildEvents(
false);
111 for(
int i=0; i+1 < poly.size(); ++i) {
112 QLineF line(poly[i],poly[i+1]);
115 scene->addItem(group);
120 QGraphicsItemGroup* group,
121 Triangulation::Edge_range dr,
126 if (group==
nullptr) {
127 group =
new QGraphicsItemGroup();
128 group->setAcceptHoverEvents(hover);
129 group->setHandlesChildEvents(
false);
130 scene->addItem(group);
132 for(
auto d = dr.first; d != dr.second; ++d)
134 if (d.is_outer_edge())
continue;
135 if (exclude.find(d.segment()) != exclude.end())
continue;
136 if (d.is_polygon_edge() && !with_edges)
continue;
138 QLineF line = d.line();
145 QGraphicsItemGroup* group,
151 if (group==
nullptr) {
152 group =
new QGraphicsItemGroup();
153 group->setAcceptHoverEvents(hover);
154 group->setHandlesChildEvents(
false);
155 scene->addItem(group);
157 for(
const Segment& s : d)
159 if (s.is_edge(P.size()-1) && !with_edges)
continue;
169 QGraphicsItemGroup* group,
182 settings.beginGroup(group);
183 settings.setValue(
"separate.curves",
_separate);
191 settings.beginGroup(group);
192 _separate = settings.value(
"separate.curves",
false).toBool();
209 QPointF offseta, offsetb;
217 double ar_hor = (ra.width()+rb.width()+sep_hor) /
std::max(ra.height(),rb.height());
218 double ar_vert = (ra.height()+rb.height()+sep_vert) /
std::max(ra.width(),rb.width());
220 if (ar_hor < ar_vert) {
222 offseta = QPointF(-ra.width()-sep_hor/2, -ra.height()/2) - ra.topLeft();
223 offsetb = QPointF(sep_hor/2, -rb.height()/2) - rb.topLeft();
227 offseta = QPointF(-ra.width()/2, -ra.height()-sep_vert/2) - ra.topLeft();
228 offsetb = QPointF(-rb.width()/2, sep_vert/2) - rb.topLeft();
233 QTransform ta = QTransform::fromTranslate(offseta.x(),offseta.y());
234 QTransform tb = QTransform::fromTranslate(offsetb.x(),offsetb.y());
246 .united(rb.translated(offsetb.x(),offsetb.y()));
255 if (!fspath || fspath->empty())
275 const FSPath::ptr fspath = FrechetViewApplication::instance()->getFSPath();
276 if (!fspath || fspath->empty())
280 const Curve& P = FrechetViewApplication::instance()->getP();
281 const Curve& Q = FrechetViewApplication::instance()->getQ();
284 QPainterPath path_a, path_b;
291 Q_ASSERT(line.p1()!=line.p2());
295 fspath->mapToQ(mapped);
302 Q_ASSERT(line.p1() != line.p2());
306 fspath->mapToP(mapped);
331 Curve p = fspath->getPath(a);
357 bool poly_alg = (FrechetViewApplication::instance()->currentAlgorithm()
358 == FrechetViewApplication::ALGORITHM_POLYGON);
base class for view widgets.
Represents a polygon line segment from node i to j.
used for segments that are not mouse sensitive
QGraphicsItemGroup * addPolygonToScene(const Curve &poly, QPen pen, GraphicsHoverLineItem::Location hover)
add a polygon curve to the graphics scene
void onAlgorithmChanged(int alg)
called when the user changes the current algorithm. Update the curve display accordingly (e....
QGraphicsItemGroup * polygon_b
graphics items for (boundary of) curve Q
QGraphicsView * view() const
QGraphicsLineItem * createLineItem(QLineF line, QPen pen, frechet::poly::Segment seg, QGraphicsItemGroup *group, GraphicsHoverLineItem::Location hover)
create a line segment graphics item
global definitions for all algorithms.
static const QPen PEN_PASSIVE_DIAGS
std::set< Segment > Segments
a set of Segment objects
void hiliteSegment(int loc, int a, int b)
raised when a mouse sensitive line segment is highlighted. Parameters identify the location of the li...
void populateScene(const Curve &P, const Curve &Q, frechet::poly::Algorithm::ptr alg)
set up the graphics scene with polygonal curves
void setSeparateCurves(bool sep)
update the display to show curves separately, or not
friend class GraphicsHoverLineItem
static QLineF mapToSegment(const Curve &C, double x1, double x2)
given a polygonal curve and two offsets, compute the corresponding line segment
boost::shared_ptr< Algorithm > ptr
(smart) pointer to an Algorithm object
virtual void restoreSettings(QSettings &settings, QString group)
load settings from application preferences
a segment of the feasible paht (displayed in the free-space diagram)
static const QPen PEN_T_DIAGS
pen for drawing the t-diagonals in P
static void addPolygon(QPainterPath &ppath, const QPolygonF &poly)
add a polygon curve segment to a QPainterPath
Curve findShortestPathP(int qa, int qb, Triangulation &tri)
given a diagonal in Q, compute the mapped shortest-path in P.
void setupMatrix()
set up transformation matrix to account for zoom,rotate,scroll
const Location loc
location on screen
QGraphicsItemGroup * diagonals_b
static const QPen PEN_A
pen for drawing the curve P
CurveView(QWidget *parent=0)
default constructor with parent
QGraphicsScene * scene
scene that is displayed by graphicsView
static const QPen PEN_SELECT
pen for drawing selected polygon segment
GraphicsHoverLineItem * selected_item
the currently selected mouse sensitve polyon segment (or nullptr)
a QGraphicsLitem that can handle mouse hover events. It is used to highlight mouse sensitve polygon s...
static const QPen PEN_C_DIAGS
pen for drawing the c-diagonals in P
QPointF Point
a point in the plane; with double floating point precision. This type is heavily used throughout all ...
virtual void saveSettings(QSettings &settings, QString group)
store settings to application preferences
static const QPen PEN_B
pen for drawing the curve Q
boost::shared_ptr< FSPath > ptr
smart pointer to an FSPath object
QGraphicsItemGroup * addSegmentsToScene(QGraphicsItemGroup *group, frechet::poly::Triangulation::Edge_range d, const frechet::poly::Segments &exclude, bool with_edges, QPen pen, GraphicsHoverLineItem::Location hover)
add a number of line segments to the graphics scene
const int a
parameters loc,a, and b identify a segment.
static const double SEPARATOR
distance when curves are displayed separately
QPolygonF Curve
a polygonal curve in the plane; with double floating point precision. This type is heavily used throu...
QRectF polygon_bounds
boundary rectangle for both curves
void onHiliteSegment(int loc, int a, int b)
called when a line segment should be highlighted
QGraphicsItemGroup * diagonals_a
graphics items for diagonals of curve P
virtual void restoreSettings(QSettings &settings, QString group)
load view settings to application prefs
QGraphicsView * graphicsView
the embedded QGraphicsView
QGraphicsItemGroup * polygon_a
graphics items for (boundary of) curve P
void doHiliteSegment(GraphicsHoverLineItem::Location loc, int a, int b)
highlight a line segment
bool _separate
draw curves separately?
virtual void saveSettings(QSettings &settings, QString group)
store view settings to application prefs
QGraphicsPathItem * select_a
highlited items for curve P
a feasible-path for simple polygons.
virtual void segmentSelected(GraphicsHoverLineItem *item) override
called when the mouse hovers over a sensitive line segment. Updates the corresponding line segments.
Location
location of the polygon segment
Curve findShortestPathQ(int pa, int pb, Triangulation &tri)
given a diagonal in P, compute the mapped shortest-path in Q
QGraphicsPathItem * select_b
highlited items for curve Q
double max(double a, double b)
maximum function with checks for NAN
static void setPenWidth(QGraphicsItem *item, double width)
update the pen width of a graphics item
static void addLine(QPainterPath &ppath, const QLineF &line)
add a line segment to a QPainterPath