Adaptagrams
routing.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libdialect - A library for computing DiAlEcT layouts:
5  * D = Decompose/Distribute
6  * A = Arrange
7  * E = Expand/Emend
8  * T = Transform
9  *
10  * Copyright (C) 2018 Monash University
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  * See the file LICENSE.LGPL distributed with the 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): Steve Kieffer <http://skieffer.info>
23 */
24 
25 #ifndef DIALECT_ROUTING_H
26 #define DIALECT_ROUTING_H
27 
28 #include <map>
29 #include <string>
30 #include <vector>
31 #include <utility>
32 
33 #include "libavoid/libavoid.h"
34 
35 #include "libdialect/commontypes.h"
36 #include "libdialect/opts.h"
37 #include "libdialect/ortho.h"
38 #include "libdialect/logging.h"
39 
40 namespace dialect {
41 
42 typedef std::pair<Avoid::ConnDirFlags, Avoid::ConnDirFlags> EdgeConnDirs;
43 typedef std::map<id_type, EdgeConnDirs> EdgeConnDirsById;
44 
46 enum class RouteProcessing {
48  NONE,
50  RECORD,
54 };
55 
58 
62 
65  void addNodes(const NodesById &nodes);
66 
74  void addEdges(const EdgesById &edges, const EdgeConnDirsById *connDirs = nullptr);
75 
81 
84  void recordRoutes(bool refine = false);
85 
89  EdgesById edges;
91  std::map<id_type, Avoid::ConnRef*> edgeIdToConnRef;
93  std::map<id_type, Avoid::ShapeRef*> nodeIdToShapeRef;
94 };
95 
96 
103 public:
110  LeaflessOrthoRouter(Graph_SP G, const HolaOpts &opts);
111 
114  /* The only newly allocated objects are the ConnRefs and ShapeRefs allocated
115  * in the constructor.
116  *
117  * But the libavoid::Router takes responsibility for these, and frees them
118  * all in its own destructor.
119  *
120  * Since we keep a Router instance, not a pointer, our Router is automatically
121  * destroyed when this LeaflessOrthoRouter is destroyed.
122  *
123  * So there is nothing for us to do.
124  */
125  }
126 
128  void route(Logger *logger = nullptr);
129 
136  void setShapeBufferDistanceIELScalar(double a);
137 
143  bool recordEachAttempt = false;
144  std::vector<std::string> routingAttemptTglf;
145 
146 private:
147 
150  CardinalDir departureDir(const Edge_SP &e, const Node_SP &u) const;
151 
154  inline bool isSoleDirec(Avoid::ConnDirFlags dirs) const {
155  return dirs == Avoid::ConnDirUp || dirs == Avoid::ConnDirUp || dirs == Avoid::ConnDirLeft || dirs == Avoid::ConnDirRight;
156  }
157 
158  Graph_SP m_graph;
159  size_t m_n; // number of nodes in the graph
160  RoutingAdapter m_ra;
161  double m_iel;
162 
166  SparseIdMatrix2d<Avoid::ConnDirFlags>::type m_allowedConnDirs;
167 
168 };
169 
170 
171 
172 
173 } // namespace dialect
174 
175 #endif // DIALECT_ROUTING_H
Does a special orthogonal routing in a graph having no leaves, ensuring that at least two distinct si...
Definition: routing.h:102
void route(Logger *logger=nullptr)
Do the routing.
Definition: routing.cpp:236
unsigned int ConnDirFlags
One or more Avoid::ConnDirFlag options.
Definition: connend.h:83
Standard libavoid include file which includes all libavoid header files.
RouteProcessing
Control how much processing should be done on connector routes by the RoutingAdapter.
Definition: routing.h:46
LeaflessOrthoRouter(Graph_SP G, const HolaOpts &opts)
Standard constructor.
Definition: routing.cpp:192
This option specifies the point should be given visibility to the right side of the shape that it is ...
Definition: connend.h:75
void setShapeBufferDistanceIELScalar(double a)
Set the Router&#39;s shapeBufferDistance parameter as a scalar multiple of the ideal edge length read fro...
Definition: routing.cpp:212
This option specifies the point should be given visibility to the left side of the shape that it is l...
Definition: connend.h:72
bool recordEachAttempt
Definition: routing.h:143
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
Record the connector routes in the Edges, exactly as returned by the Router.
void addNodes(const NodesById &nodes)
Add nodes.
Definition: routing.cpp:53
~LeaflessOrthoRouter(void)
Destructor.
Definition: routing.h:113
std::map< id_type, Avoid::ShapeRef * > nodeIdToShapeRef
Lookup a Node&#39;s associated ShapeRef* by the Node&#39;s ID.
Definition: routing.h:93
Don&#39;t do anything.
void addEdges(const EdgesById &edges, const EdgeConnDirsById *connDirs=nullptr)
Add edges.
Definition: routing.cpp:64
EdgesById edges
Lookup for Edges.
Definition: routing.h:89
std::map< id_type, Avoid::ConnRef * > edgeIdToConnRef
Lookup an Edge&#39;s associated ConnRef* by the Edge&#39;s ID.
Definition: routing.h:91
RouterFlag
Flags that can be passed to the router during initialisation to specify options.
Definition: router.h:70
RoutingAdapter(Avoid::RouterFlag flag)
Standard Constructor.
Definition: routing.h:61
void route(RouteProcessing processing=RouteProcessing::RECORD)
Do the routing.
Definition: routing.cpp:121
Avoid::Router router
The Router.
Definition: routing.h:87
The Router class represents a libavoid router instance.
Definition: router.h:386
This option specifies the point should be given visibility to the top of the shape that it is located...
Definition: connend.h:66
Adapter to easily apply libavoid::Routers to libdialect::Graphs.
Definition: routing.h:57
void recordRoutes(bool refine=false)
Record the routes in the Edges.
Definition: routing.cpp:126