Adaptagrams
router.h
Go to the documentation of this file.
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libavoid - Fast, Incremental, Object-avoiding Line Router
5  *
6  * Copyright (C) 2004-2015 Monash University
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  * See the file LICENSE.LGPL distributed with the library.
13  *
14  * Licensees holding a valid commercial license may use this file in
15  * accordance with the commercial license agreement provided with the
16  * library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Michael Wybrow
23 */
24 
27 
28 
29 #ifndef AVOID_ROUTER_H
30 #define AVOID_ROUTER_H
31 
32 #include <ctime>
33 #include <list>
34 #include <utility>
35 #include <string>
36 
37 #include "libavoid/dllexport.h"
38 #include "libavoid/connector.h"
39 #include "libavoid/vertices.h"
40 #include "libavoid/graph.h"
41 #include "libavoid/timer.h"
42 #include "libavoid/hyperedge.h"
43 #include "libavoid/actioninfo.h"
44 #include "libavoid/hyperedgeimprover.h"
45 
46 
47 namespace Avoid {
48 
49 // LineReps: Used for highlighting certain areas in debugging output.
50 struct LineRep
51 {
52  Point begin;
53  Point end;
54 };
55 typedef std::list<LineRep> LineReps;
56 
57 
58 typedef std::list<unsigned int> IntList;
59 
60 class ShapeRef;
61 class JunctionRef;
62 class ClusterRef;
63 typedef std::list<ClusterRef *> ClusterRefList;
64 class Obstacle;
65 typedef std::list<Obstacle *> ObstacleList;
66 class DebugHandler;
67 
71 {
78 };
79 
80 
81 static const unsigned int runningTo = 1;
82 static const unsigned int runningFrom = 2;
83 static const unsigned int runningToAndFrom = runningTo | runningFrom;
84 
89 {
98 
107 
115 
124 
132 
143 
150 
155 
163 
164  // Used for determining the size of the routing parameter array.
165  // This should always we the last value in the enum.
166  lastRoutingParameterMarker
167 };
168 
169 // Backwards compatibility
170 typedef enum RoutingParameter PenaltyType;
171 
172 
175 {
191 
211 
229 
238 
250 
276 
286 
287 
288  // Used for determining the size of the routing options array.
289  // This should always we the last value in the enum.
290  lastRoutingOptionMarker
291 };
292 
300 {
321 };
322 
323 // NOTE: This is an internal helper class that should not be used by the user.
324 //
325 // This class allows edges in the visibility graph to store a
326 // pointer to a boolean registering when a connector needs to
327 // reroute, while allowing connectors to be deleted without
328 // needing to scan and remove these references from the visibility
329 // graph. Instead the bool is stored in this delegate and the
330 // connector is alerted later, so long as it hasn't since been
331 // deleted.
332 class ConnRerouteFlagDelegate {
333  public:
334  ConnRerouteFlagDelegate();
335  ~ConnRerouteFlagDelegate();
336  bool *addConn(ConnRef *conn);
337  void removeConn(ConnRef *conn);
338  void alertConns(void);
339  private:
340  std::list<std::pair<ConnRef *, bool> > m_mapping;
341 };
342 
343 static const double zeroParamValue = 0;
344 static const double chooseSensibleParamValue = -1;
345 
346 // NOTE: This is an internal helper class that should not be used by the user.
347 //
348 // It is used by libtopology to add additional functionality to libavoid
349 // while keeping libavoid dependency free.
350 class TopologyAddonInterface
351 {
352  public:
353  TopologyAddonInterface()
354  {
355  }
356  virtual ~TopologyAddonInterface()
357  {
358  }
359  virtual TopologyAddonInterface *clone(void) const
360  {
361  return new TopologyAddonInterface(*this);
362  }
363 
364  virtual void improveOrthogonalTopology(Router *router)
365  {
366  (void)(router); // Avoid unused parameter warning.
367  }
368  virtual bool outputCode(FILE *fp) const
369  {
370  (void)(fp); // Avoid unused parameter warning.
371  return false;
372  }
373  virtual bool outputDeletionCode(FILE *fp) const
374  {
375  (void)(fp); // Avoid unused parameter warning.
376  return false;
377  }
378 };
379 
380 
385 //
386 class AVOID_EXPORT Router {
387  public:
392  Router(const unsigned int flags);
393 
399  virtual ~Router();
400 
401  ObstacleList m_obstacles;
402  ConnRefList connRefs;
403  ClusterRefList clusterRefs;
404  EdgeList visGraph;
405  EdgeList invisGraph;
406  EdgeList visOrthogGraph;
407  ContainsMap contains;
408  VertInfList vertices;
409  ContainsMap enclosingClusters;
410 
411  bool PartialTime;
412  bool SimpleRouting;
413  bool ClusteredRouting;
414 
415  // Poly-line routing options:
416  bool IgnoreRegions;
417  bool UseLeesAlgorithm;
418  bool InvisibilityGrph;
419 
420  // General routing options:
421  bool SelectiveReroute;
422 
423  bool PartialFeedback;
424  bool RubberBandRouting;
425 
426 
427  // Instrumentation:
428 #ifdef AVOID_PROFILE
429  Timer timers;
430 #endif
431  int st_checked_edges;
432 
453  void setTransactionUse(const bool transactions);
454 
462  bool transactionUse(void) const;
463 
479  bool processTransaction(void);
480 
495  void deleteShape(ShapeRef *shape);
496 
515  void moveShape(ShapeRef *shape, const Polygon& newPoly,
516  const bool first_move = false);
517 
535  void moveShape(ShapeRef *shape, const double xDiff, const double yDiff);
536 
549  void deleteJunction(JunctionRef *junction);
550 
563  void deleteConnector(ConnRef *connector);
564 
578  void moveJunction(JunctionRef *junction, const Point& newPosition);
579 
597  void moveJunction(JunctionRef *junction, const double xDiff,
598  const double yDiff);
599 
626  void setRoutingParameter(const RoutingParameter parameter,
627  const double value = chooseSensibleParamValue);
628 
635  double routingParameter(const RoutingParameter parameter) const;
636 
642  void setRoutingOption(const RoutingOption option, const bool value);
643 
649  bool routingOption(const RoutingOption option) const;
650 
655  // method. See its documentation for more details.
661  void setRoutingPenalty(const RoutingParameter penType,
662  const double penVal = chooseSensibleParamValue);
663 
669  HyperedgeRerouter *hyperedgeRerouter(void);
670 
682  void outputInstanceToSVG(std::string filename = std::string());
683 
694  virtual unsigned int newObjectId(void) const;
695 
703  bool objectIdIsUnused(const unsigned int id) const;
704 
743  virtual bool shouldContinueTransactionWithProgress(
744  unsigned int elapsedTime, unsigned int phaseNumber,
745  unsigned int totalPhases, double proportion);
746 
763  newAndDeletedObjectListsFromHyperedgeImprovement(void) const;
764 
765  void setDebugHandler(DebugHandler *handler);
766  DebugHandler *debugHandler(void) const;
767 
768  // Processes the actions list for the transaction. You shouldn't
769  // need to cal this. Instead use processTransaction().
770  void processActions(void);
771 
772  void deleteCluster(ClusterRef *cluster);
773  void attachedShapes(IntList &shapes, const unsigned int shapeId,
774  const unsigned int type);
775  void attachedConns(IntList &conns, const unsigned int shapeId,
776  const unsigned int type);
777  void markPolylineConnectorsNeedingReroutingForDeletedObstacle(
778  Obstacle *obstacle);
779  void generateContains(VertInf *pt);
780  void printInfo(void);
781  void regenerateStaticBuiltGraph(void);
782  void destroyOrthogonalVisGraph(void);
783  void setStaticGraphInvalidated(const bool invalidated);
784  ConnType validConnType(const ConnType select = ConnType_None) const;
785  bool isInCrossingPenaltyReroutingStage(void) const;
786  void markAllObstaclesAsMoved(void);
787  ShapeRef *shapeContainingPoint(const Point& point);
788  void performContinuationCheck(unsigned int phaseNumber,
789  size_t stepNumber, size_t totalSteps);
790  void registerSettingsChange(void);
791 
799  void setTopologyAddon(TopologyAddonInterface *topologyAddon);
800  void improveOrthogonalTopology(void);
801 
802  // Testing and debugging methods.
803  bool existsOrthogonalSegmentOverlap(const bool atEnds = false);
804  bool existsOrthogonalFixedSegmentOverlap(const bool atEnds = false);
805  bool existsOrthogonalTouchingPaths(void);
806  int existsCrossings(const bool optimisedForConnectorType = false);
807  bool existsInvalidOrthogonalPaths(void);
808 
809  // Outputs the current diagram. Used for visualising individual
810  // steps of various algorithms. lineReps can be used to draw
811  // attention to specific parts of the diagram that have changed
812  // between steps.
813  void outputDiagramSVG(std::string instanceName = std::string(),
814  LineReps *lineReps = nullptr);
815 
816  void outputDiagramText(std::string instanceName = std::string());
817  void outputDiagram(std::string instanceName = std::string());
818 
819  private:
820  friend class ShapeRef;
821  friend class ConnRef;
822  friend class JunctionRef;
823  friend class Obstacle;
824  friend class ClusterRef;
825  friend class ShapeConnectionPin;
826  friend class MinimumTerminalSpanningTree;
827  friend class ConnEnd;
828  friend struct HyperedgeTreeNode;
829  friend class HyperedgeRerouter;
830  friend class HyperedgeImprover;
831 
832  unsigned int assignId(const unsigned int suggestedId);
833  void addShape(ShapeRef *shape);
834  void addJunction(JunctionRef *junction);
835  void addCluster(ClusterRef *cluster);
836  void modifyConnector(ConnRef *conn);
837  void modifyConnector(ConnRef *conn, unsigned int type,
838  const ConnEnd &connEnd, bool connPinUpdate = false);
839  void modifyConnectionPin(ShapeConnectionPin *pin);
840 
841  void removeObjectFromQueuedActions(const void *object);
842  void newBlockingShape(const Polygon& poly, int pid);
843  void checkAllBlockedEdges(int pid);
844  void checkAllMissingEdges(void);
845  void adjustContainsWithAdd(const Polygon& poly, const int p_shape);
846  void adjustContainsWithDel(const int p_shape);
847  void adjustClustersWithAdd(const PolygonInterface& poly,
848  const int p_cluster);
849  void adjustClustersWithDel(const int p_cluster);
850  void rerouteAndCallbackConnectors(void);
851  void improveCrossings(void);
852 
853  ActionInfoList actionList;
854  unsigned int m_largest_assigned_id;
855  bool m_consolidate_actions;
856  bool m_currently_calling_destructors;
857  double m_routing_parameters[lastRoutingParameterMarker];
858  bool m_routing_options[lastRoutingOptionMarker];
859 
860  ConnRerouteFlagDelegate m_conn_reroute_flags;
861  HyperedgeRerouter m_hyperedge_rerouter;
862 
863  // Progress tracking and transaction cancelling.
864  clock_t m_transaction_start_time;
865  bool m_abort_transaction;
866 
867  TopologyAddonInterface *m_topology_addon;
868 
869  // Overall modes:
870  bool m_allows_polyline_routing;
871  bool m_allows_orthogonal_routing;
872 
873  bool m_static_orthogonal_graph_invalidated;
874  bool m_in_crossing_rerouting_stage;
875 
876  bool m_settings_changes;
877 
878  HyperedgeImprover m_hyperedge_improver;
879 
880  DebugHandler *m_debug_handler;
881 };
882 
883 
884 }
885 
886 
887 
888 #endif
Orthogonal edge segments are nudged apart in the x-dimension.
Definition: router.h:315
This option specifies that the router should maintain the structures necessary to allow orthogonal co...
Definition: router.h:77
The ConnEnd class represents different possible endpoints for connectors.
Definition: connend.h:110
This option specifies that the router should maintain the structures necessary to allow poly-line con...
Definition: router.h:74
The ConnRef class represents a connector object.
Definition: connector.h:131
This parameter defines the spacing distance that will be used for nudging apart overlapping corners a...
Definition: router.h:154
Initial routes are searched for in the visibility graph.
Definition: router.h:308
Contains the interface for the HyperedgeRerouter class.
The ClusterRef class represents a cluster object.
Definition: viscluster.h:55
This penalty is applied whenever a connector path travels in the direction opposite of the destinatio...
Definition: router.h:162
A dynamic Polygon, to which points can be easily added and removed.
Definition: geomtypes.h:207
This parameter defines the spacing distance that will be added to the sides of each shape when determ...
Definition: router.h:149
With crossing penalties enabled, crossing detection is performed to find all crossings.
Definition: router.h:311
This penalty is applied for each segment in the connector path beyond the first. This should always n...
Definition: router.h:97
This penalty is applied to port selection choice when the other end of the connector being routed doe...
Definition: router.h:142
The HyperedgeNewAndDeletedObjectLists class stores lists of objects created and deleted during hypere...
Definition: hyperedge.h:79
Orthogonal edge segments are nudged apart in the y-dimension.
Definition: router.h:317
std::list< ConnRef * > ConnRefList
A list of ConnRef objects.
Definition: connector.h:47
The orthogonal visibility graph is built by conducting a scan in each dimension. This is the y-dimens...
Definition: router.h:306
The HyperedgeRerouter class is a convenience object that can be used to register hyperedges to be rer...
Definition: hyperedge.h:129
The orthogonal visibility graph is built by conducting a scan in each dimension. This is the x-dimens...
Definition: router.h:303
This penalty is applied whenever a connector path crosses another connector path. It takes shared pat...
Definition: router.h:114
ConnType
Describes the type of routing that is performed for each connector.
Definition: connector.h:53
The ShapeConnectionPin class represents a fixed point or "pin" on a shape that can be connected to...
Definition: connectionpin.h:96
RouterFlag
Flags that can be passed to the router during initialisation to specify options.
Definition: router.h:70
This penalty is applied whenever a connector path shares some segments with an immovable portion of a...
Definition: router.h:131
The Point class defines a point in the plane.
Definition: geomtypes.h:52
TransactionPhases
Types of routing phases reported by Router::shouldContinueTransactionWithProgress().
Definition: router.h:299
Not a real phase, but represents the router is finished (or has aborted) the transaction and you may ...
Definition: router.h:320
libavoid: Object-avoiding orthogonal and polyline connector routing library.
Definition: actioninfo.cpp:33
RoutingOption
Types of routing options that can be enabled.
Definition: router.h:174
This penalty is applied whenever a connector path crosses a cluster boundary.
Definition: router.h:123
This penalty is applied in its full amount to tight acute bends in the connector path. A smaller portion of the penalty is applied for slight bends, i.e., where the bend is close to 180 degrees. This is useful for polyline routing where there is some evidence that tighter corners are worse for readability, but that slight bends might not be so bad, especially when smoothed by curves.
Definition: router.h:106
The Router class represents a libavoid router instance.
Definition: router.h:386
The ShapeRef class represents a shape object.
Definition: shape.h:81
The JunctionRef class represents a fixed or free-floating point that connectors can be attached to...
Definition: junction.h:57
Crossing connectors are rerouted to search for better routes.
Definition: router.h:313
Contains the interface for the ConnRef class.
RoutingParameter
Types of routing parameters and penalties that can be used to tailor the style and improve the qualit...
Definition: router.h:88
A common interface used by the Polygon classes.
Definition: geomtypes.h:150