// constructive heuristics for orthogonal representation OR void LongestPathCompaction::constructiveHeuristics( PlanRep &PG, OrthoRep &OR, const RoutingChannel<int> &rc, GridLayoutMapped &drawing) { OGDF_ASSERT(OR.isOrientated()); // x-coordinates of vertical segments CompactionConstraintGraph<int> Dx(OR, PG, odEast, rc.separation()); Dx.insertVertexSizeArcs(PG, drawing.width(), rc); NodeArray<int> xDx(Dx.getGraph(), 0); computeCoords(Dx, xDx); // y-coordinates of horizontal segments CompactionConstraintGraph<int> Dy(OR, PG, odNorth, rc.separation()); Dy.insertVertexSizeArcs(PG, drawing.height(), rc); NodeArray<int> yDy(Dy.getGraph(), 0); computeCoords(Dy, yDy); // final coordinates of vertices for(node v : PG.nodes) { drawing.x(v) = xDx[Dx.pathNodeOf(v)]; drawing.y(v) = yDy[Dy.pathNodeOf(v)]; } }
// improvement heuristics for orthogonal drawing void LongestPathCompaction::improvementHeuristics( PlanRep &PG, OrthoRep &OR, const RoutingChannel<int> &rc, GridLayoutMapped &drawing) { OGDF_ASSERT(OR.isOrientated()); int costs, lastCosts; int steps = 0, maxSteps = m_maxImprovementSteps; if (maxSteps == 0) maxSteps = numeric_limits<int>::max(); // OPTIMIZATION POTENTIAL: // update constraint graphs "incrementally" by only re-inserting // visibility arcs costs = 0; do { lastCosts = costs; ++steps; // x-coordinates of vertical segments CompactionConstraintGraph<int> Dx(OR, PG, odEast, rc.separation()); Dx.insertVertexSizeArcs(PG, drawing.width(), rc); Dx.insertVisibilityArcs(PG, drawing.x(),drawing.y()); NodeArray<int> xDx(Dx.getGraph(), 0); computeCoords(Dx, xDx); // final x-coordinates of vertices for(node v : PG.nodes) { drawing.x(v) = xDx[Dx.pathNodeOf(v)]; } // y-coordinates of horizontal segments CompactionConstraintGraph<int> Dy(OR, PG, odNorth, rc.separation()); Dy.insertVertexSizeArcs(PG, drawing.height(), rc); Dy.insertVisibilityArcs(PG, drawing.y(),drawing.x()); NodeArray<int> yDy(Dy.getGraph(), 0); computeCoords(Dy, yDy); // final y-coordinates of vertices for(node v : PG.nodes) { drawing.y(v) = yDy[Dy.pathNodeOf(v)]; } costs = Dx.computeTotalCosts(xDx) + Dy.computeTotalCosts(yDy); } while (steps < maxSteps && (steps == 1 || costs < lastCosts)); }
void motion(int x, int y) { float selx, sely; if (middle_mouse && !left_mouse) { if (mousex != x || mousey != y) { trackball(lastquat, (2.0*mousex - W) / W, (H - 2.0*mousey) / H, (2.0*x - W) / W, (H - 2.0*y) / H); spinning = 1; } else { spinning = 0; } changeState(); } else { computeCoords(sel_piece, x, y, &selx, &sely); moveSelection(selx, sely); } mousex = x; mousey = y; glutPostRedisplay(); }
void mouse(int b, int s, int x, int y) { float selx, sely; mousex = x; mousey = y; curX = x; curY = y; if (s == GLUT_DOWN) { switch (b) { case GLUT_LEFT_BUTTON: if (solving) { freeSolutions(); solving = 0; glutChangeToMenuEntry(1, "Solving", 1); glutSetWindowTitle("glpuzzle"); movingPiece = 0; } left_mouse = GL_TRUE; sel_piece = selectPiece(mousex, mousey); if (computeCoords(sel_piece, mousex, mousey, &selx, &sely)) { grabPiece(sel_piece, selx, sely); } glutPostRedisplay(); break; case GLUT_MIDDLE_BUTTON: middle_mouse = GL_TRUE; glutPostRedisplay(); break; } } else { switch (b) { case GLUT_LEFT_BUTTON: left_mouse = GL_FALSE; dropSelection(); glutPostRedisplay(); break; case GLUT_MIDDLE_BUTTON: middle_mouse = GL_FALSE; glutPostRedisplay(); break; } } motion(x, y); }
int Puzzle_Window::handle(int event) { int x = Fl::event_x(); int y = Fl::event_y(); switch (event) { case FL_KEY: switch (Fl::event_key()) { case FL_Escape: case 'Q': case 'q': exit(0); break; case 'S': case 's': solve_cb(this,0); break; case 'D': case 'd': piece = selectPiece(x, y); delete_cb(this,0); break; case 'R': case 'r': reset_cb(this,0); break; case 'O': case 'o': reset_view_cb(this,0); break; default: break; } return 1; case FL_PUSH: mousex = curX = x; mousey = curY = y; switch (Fl::event_button()) { case 1: set_solving(0); left_mouse = true; sel_piece = selectPiece(mousex, mousey); if (!sel_piece) { left_mouse = false; middle_mouse = true; // let it rotate object } else { float selx, sely; if (computeCoords(sel_piece, mousex, mousey, &selx, &sely)) { grabPiece(sel_piece, selx, sely); } } redraw(); break; case 2: middle_mouse = true; redraw(); break; default: piece = selectPiece(x, y); if (piece) menu->child(2)->activate(); else menu->child(2)->deactivate(); menu->popup(x, y); return 1; } // fall through to drag handler: case FL_DRAG: if (middle_mouse && !left_mouse) { if (mousex != x || mousey != y) { trackball(lastquat, (2.0*mousex - W) / W, (H - 2.0*mousey) / H, (2.0*x - W) / W, (H - 2.0*y) / H); spinning = 1; } else { spinning = 0; } changeState(); } else { float selx, sely; computeCoords(sel_piece, x, y, &selx, &sely); moveSelection(selx, sely); } mousex = x; mousey = y; redraw(); return 1; case FL_RELEASE: if (left_mouse) { left_mouse = false; dropSelection(); redraw(); } else if (middle_mouse) { middle_mouse = GL_FALSE; redraw(); } return 1; } return Fl_Gl_Window::handle(event); }