Adaptagrams
expansion.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_EXPANSION_H
26 #define DIALECT_EXPANSION_H
27 
28 #include <memory>
29 #include <map>
30 #include <string>
31 #include <deque>
32 
33 #include "libvpsc/rectangle.h"
34 #include "libavoid/geomtypes.h"
35 
36 #include "libdialect/commontypes.h"
37 #include "libdialect/treeplacement.h"
38 #include "libdialect/ortho.h"
39 
40 namespace dialect {
41 
42 class ExpansionGoal;
43 
99 public:
107  ExpansionManager(TreePlacement_SP tp, vpsc::Dim primaryDim=vpsc::HORIZONTAL, double padding=-1);
108 
110  bool isAxial(vpsc::Dim dim) { return dim == m_axialDim; }
111 
113  bool isTransverse(vpsc::Dim dim) { return dim == m_transDim; }
114 
116  double estimateCost(void) const;
117 
121  std::map<vpsc::Dim, double> estimateCostByDimension(void) const;
122 
126  std::map<vpsc::Dim, double> estimateCostByDimension2(void) const;
127 
129  std::map<CardinalDir, double> estimateCostByDirection(void) const;
130 
132  ExpansionGoals getGoals(void) { return m_goals; }
133 
139  ProjSeq_SP extendProjSeq(ProjSeq_SP ps0);
140 
141 private:
142 
143  ExpansionGoal_SP addGoalInDirec(CardinalDir dir);
144  void computeGoals(vpsc::Dim dim);
145 
146  TreePlacement_SP m_tp;
147  vpsc::Dim m_primaryDim;
148  double m_padding;
150  vpsc::Dim m_axialDim;
152  vpsc::Dim m_transDim;
154  unsigned m_goalCounter = 0;
156  ExpansionGoals m_goals;
157  ExpansionGoals m_primaryDimGoals;
158  ExpansionGoals m_secondaryDimGoals;
159 };
160 
161 struct ContainedSegment;
162 typedef std::shared_ptr<ContainedSegment> ContainedSegment_SP;
163 
171 public:
172 
179  ExpansionGoal(unsigned id, TreePlacement_SP tp, CardinalDir direc, double padding)
180  : m_id(id), m_tp(tp), m_direc(direc), m_padding(padding) {
181  // The generated SepCos will operate at right angles to the direction of this
182  // goal, i.e. in the constant dimension of this goal's direction.
183  m_dim = Compass::constDim.at(m_direc);
184  }
185 
192  ContainedSegment_SP computeContainedSegment(bool ignoreCollateralTreeBoxes=false);
193 
195  CardinalDir getDirec(void) const { return m_direc; }
196 
203  ProjSeq_SP tryExpansionRec(ProjSeq_SP ps0, std::deque<ExpansionGoal_SP> &remainingGoals);
204 
205 private:
206 
210  void computeGoalSegmentEndpoints(Avoid::Point &p0, Avoid::Point &p1);
211 
212  unsigned m_id;
213  TreePlacement_SP m_tp;
215  CardinalDir m_direc;
216  double m_padding;
218  vpsc::Dim m_dim;
219 };
220 
221 struct ContainedSegment {
222 
224  ContainedSegment(unsigned goalID, Avoid::Point basept, Avoid::Point localGoalPt, Avoid::Point globalGoalPt,
225  double padding, TreePlacement_SP tp, vpsc::Dim sepDim);
226 
230  double measureShortage(void) const;
231 
233  std::string toString(void) const;
234 
241  void makeRoomForTreeNode(ProjSeq_SP ps0, bool doProject = true);
242 
244  unsigned goalID;
246  Avoid::Point basept;
248  Avoid::Point localGoalPt;
250  Avoid::Point globalGoalPt;
252  double padding;
254  TreePlacement_SP tp;
256  vpsc::Dim sepDim;
258  LineSegment localGoalSeg;
260  LineSegment globalGoalSeg;
261 
262 private:
276  void addSepCoForPtAndNode(Avoid::Point &pt, Node_SP &node, dimensions nodeDims, SepCoSet &sepcos, Node_SP &treeBox);
277 };
278 
279 
280 } // namespace dialect
281 
282 #endif // DIALECT_EXPANSION_H
The ExpansionManager class.
Definition: expansion.h:98
ContainedSegment_SP computeContainedSegment(bool ignoreCollateralTreeBoxes=false)
Compute the contained segment for this goal.
Definition: expansion.cpp:229
double estimateCost(void) const
Estimate the cost of expanding.
Definition: expansion.cpp:104
std::map< CardinalDir, double > estimateCostByDirection(void) const
Estimate the cost of expanding in each cardinal direction.
Definition: expansion.cpp:140
ExpansionGoal(unsigned id, TreePlacement_SP tp, CardinalDir direc, double padding)
Standard constructor.
Definition: expansion.h:179
bool isAxial(vpsc::Dim dim)
Check whether a given dimension is axial w.r.t. this manager&#39;s placement.
Definition: expansion.h:110
The ExpansionGoal class.
Definition: expansion.h:170
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
ProjSeq_SP tryExpansionRec(ProjSeq_SP ps0, std::deque< ExpansionGoal_SP > &remainingGoals)
Try to expand, and work recursively, attempting all remaining goals.
Definition: expansion.cpp:290
Contains the interface for various geometry types and classes.
ExpansionManager(TreePlacement_SP tp, vpsc::Dim primaryDim=vpsc::HORIZONTAL, double padding=-1)
Standard constructor.
Definition: expansion.cpp:52
ExpansionGoals getGoals(void)
Access the goals.
Definition: expansion.h:132
bool isTransverse(vpsc::Dim dim)
Check whether a given dimension is transverse w.r.t. this manager&#39;s placement.
Definition: expansion.h:113
The Point class defines a point in the plane.
Definition: geomtypes.h:52
std::map< vpsc::Dim, double > estimateCostByDimension2(void) const
Estimate the cost of expanding in each dimension. This method computes the initial separation constra...
Definition: expansion.cpp:117
ProjSeq_SP extendProjSeq(ProjSeq_SP ps0)
Extend a given projection sequence with those projections necessary to achieve all expansion goals of...
Definition: expansion.cpp:186
The x-dimension (0).
Definition: rectangle.h:43
Dim
Indicates the x- or y-dimension.
Definition: rectangle.h:41
std::map< vpsc::Dim, double > estimateCostByDimension(void) const
Estimate the cost of expanding in each dimension. This method looks at the length of contained segmen...
Definition: expansion.cpp:109
CardinalDir getDirec(void) const
Get the direction of the goal.
Definition: expansion.h:195