Adaptagrams
treeplacement.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_TREEPLACEMENT_H
26 #define DIALECT_TREEPLACEMENT_H
27 
28 #include <string>
29 #include <memory>
30 #include <map>
31 #include <set>
32 
33 #include "libvpsc/rectangle.h"
34 
35 #include "libdialect/commontypes.h"
36 #include "libdialect/faces.h"
37 #include "libdialect/graphs.h"
38 #include "libdialect/trees.h"
39 #include "libdialect/ortho.h"
40 #include "libdialect/opts.h"
41 #include "libdialect/constraints.h"
42 #include "libdialect/logging.h"
43 
44 namespace dialect {
45 
50 FaceSet_SP reattachTrees(Graph_SP core, Trees trees, HolaOpts opts, Logger *logger=nullptr);
51 
53 TreePlacement_SP chooseBestPlacement(TreePlacements tps, HolaOpts opts);
54 
58 #ifndef SWIG
59 // We hide this from SWIG, lest it complain, "Nothing known about base class 'std::enable_shared_from_this..."
60 // http://swig.10945.n7.nabble.com/Nothing-known-about-base-class-std-enable-shared-from-this-tp14603p14604.html
61  : public std::enable_shared_from_this<TreePlacement>
62 #endif
63 {
64 public:
65  TreePlacement(Tree_SP tree, Face &face, Node_SP faceRoot,
66  CompassDir dp, CardinalDir dg, bool flip=false)
67  : m_ID(nextID++),
68  m_tree(tree),
69  m_face(face),
70  m_faceRoot(faceRoot),
71  m_placementDir(dp),
72  m_growthDir(dg),
73  m_flip(flip),
74  m_cost(0),
75  m_boxNode(nullptr) {}
76 
78  CompassDir getPlacementDir(void) const { return m_placementDir; }
79 
81  CardinalDir getGrowthDir(void) const { return m_growthDir; }
82 
84  bool isExternal(void) const { return m_face.isExternal(); }
85 
87  id_type id(void) const { return m_ID; }
88 
93  size_t getNumPotentialNbrs(void);
94 
96  double estimateCost(void);
97 
99  Node_SP getRootNode(void) const { return m_faceRoot; }
100 
102  Face &getFace(void) { return m_face; }
103 
108  void insertTreeNode(double padding=0) { m_face.insertTreeNode(shared_from_this(), padding); }
109 
111  std::string toString(void) const;
112 
129  Node_SP buildTreeBox(double padding=0) const;
130 
132  void recordBoxNode(Node_SP &boxNode) { m_boxNode = boxNode; }
133 
135  bool hasBoxNode(void) { return m_boxNode != nullptr; }
136 
138  Node_SP getBoxNode(void) { return m_boxNode; }
139 
146  ProjSeq_SP buildBestProjSeq(double padding=0, bool doCostlierDimensionFirst=false,
147  ExpansionEstimateMethod expansionMethod=ExpansionEstimateMethod::CONSTRAINTS) {
148  return m_face.buildBestProjSeq(shared_from_this(), padding, doCostlierDimensionFirst, expansionMethod);
149  }
150 
165  bool somePointOppositeSegment(LineSegment &seg, Avoid::Point &pt, double padding=-1, bool openInterval=false);
166 
168  void applyGeometryToTree(void);
169 
175  void insertTreeIntoGraph(Graph &G, NodesById &treeNodes, NodesById &bufferNodes, EdgesById &treeEdges);
176 
178  size_t size(void) const { return m_tree->size(); }
179 
183  void setRootAligns(vpsc::Dim dim, std::set<id_type> &idSet) { m_rootAligns[dim] = idSet; }
184 
188  bool rootIsAlignedWith(vpsc::Dim dim, id_type id);
189 
190 private:
191 
193  static id_type nextID;
195  const id_type m_ID;
196 
198  Tree_SP m_tree;
200  Face &m_face;
202  Node_SP m_faceRoot;
204  CompassDir m_placementDir;
206  CardinalDir m_growthDir;
208  bool m_flip;
209 
211  double m_cost;
213  Node_SP m_boxNode = nullptr;
214 
216  std::map<vpsc::Dim, std::set<id_type>> m_rootAligns;
217 
218 };
219 
220 
221 } // namespace dialect
222 
223 #endif // DIALECT_TREEPLACEMENT_H
void setRootAligns(vpsc::Dim dim, std::set< id_type > &idSet)
Tell the TreePlacement which Nodes are aligned with its root node in a given dimension.
Definition: treeplacement.h:183
bool isExternal(void) const
Check whether this is the external face or not.
Definition: faces.h:340
CompassDir getPlacementDir(void) const
Get the placement direction.
Definition: treeplacement.h:78
The Graph class represents graphs consisting of nodes and edges.
Definition: graphs.h:180
TreePlacement_SP chooseBestPlacement(TreePlacements tps, HolaOpts opts)
Choose the best TreePlacement from among a list of alternatives.
Definition: treeplacement.cpp:95
ProjSeq_SP buildBestProjSeq(double padding=0, bool doCostlierDimensionFirst=false, ExpansionEstimateMethod expansionMethod=ExpansionEstimateMethod::CONSTRAINTS)
Build the best projection sequence for this tree placement.
Definition: treeplacement.h:146
bool rootIsAlignedWith(vpsc::Dim dim, id_type id)
Check whether the root node is aligned with a given node, in a given dimension.
Definition: treeplacement.cpp:337
double estimateCost(void)
Estimate the cost of this placement.
Definition: treeplacement.cpp:195
ProjSeq_SP buildBestProjSeq(TreePlacement_SP tp, double padding=0, bool doCostlierDimensionFirst=false, ExpansionEstimateMethod estimateMethod=ExpansionEstimateMethod::CONSTRAINTS)
Build the best projection sequence for a given tree placement.
Definition: faces.cpp:585
bool somePointOppositeSegment(LineSegment &seg, Avoid::Point &pt, double padding=-1, bool openInterval=false)
Compute some point belonging to the tree box and lying opposite a given line segment.
Definition: treeplacement.cpp:267
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
std::string toString(void) const
Get a string representation.
Definition: treeplacement.cpp:173
FaceSet_SP reattachTrees(Graph_SP core, Trees trees, HolaOpts opts, Logger *logger=nullptr)
Given a planar orthogonal core, and the corresponding Trees (as resulting from the peeling process)...
Definition: treeplacement.cpp:54
CardinalDir getGrowthDir(void) const
Get the growth direction.
Definition: treeplacement.h:81
Node_SP getBoxNode(void)
Get the box node.
Definition: treeplacement.h:138
size_t getNumPotentialNbrs(void)
Check the number of "potential neighbours" of this tree, if placed according to this placement...
Definition: treeplacement.cpp:184
Definition: treeplacement.h:57
size_t size(void) const
Check the size (i.e. number of nodes in) the Tree.
Definition: treeplacement.h:178
Node_SP buildTreeBox(double padding=0) const
Determine the size of the tree minus the root node, and the position relative to the root node...
Definition: treeplacement.cpp:201
The Point class defines a point in the plane.
Definition: geomtypes.h:52
ExpansionEstimateMethod
Definition: opts.h:62
bool isExternal(void) const
Check whether the placement is into the external face.
Definition: treeplacement.h:84
Dim
Indicates the x- or y-dimension.
Definition: rectangle.h:41
void recordBoxNode(Node_SP &boxNode)
Record the Node representing the box for the Tree.
Definition: treeplacement.h:132
void insertTreeNode(TreePlacement_SP tp, double padding=0)
To be used after the face has been expanded to make room for the tree. This method adds a large node ...
Definition: faces.cpp:471
id_type id(void) const
Get the unique ID of this instance.
Definition: treeplacement.h:87
Represents a single face of a 4-planar, orthogonal layout.
Definition: faces.h:306
Face & getFace(void)
Access the Face to which this placement belongs.
Definition: treeplacement.h:102
void insertTreeNode(double padding=0)
Insert a node representing the Tree into the Face to which this placement belongs.
Definition: treeplacement.h:108
Node_SP getRootNode(void) const
Get the Node at which the Tree would be rooted:
Definition: treeplacement.h:99
bool hasBoxNode(void)
Check whether this TreePlacement has a box node yet.
Definition: treeplacement.h:135
void insertTreeIntoGraph(Graph &G, NodesById &treeNodes, NodesById &bufferNodes, EdgesById &treeEdges)
Insert the tree into a given Graph.
Definition: treeplacement.cpp:325
void applyGeometryToTree(void)
Rotate, flip, and translate the tree as necessary to match this placement.
Definition: treeplacement.cpp:301