1 /** \file
2  * \brief Declaration of interface for algorithms that arrange/pack
3  * layouts of connected components.
4  *
5  * \author Carsten Gutwenger
6  *
7  * \par License:
8  * This file is part of the Open Graph Drawing Framework (OGDF).
9  *
10  * \par
11  * Copyright (C)<br>
12  * See README.md in the OGDF root directory for details.
13  *
14  * \par
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * Version 2 or 3 as published by the Free Software Foundation;
18  * see the file LICENSE.txt included in the packaging of this file
19  * for details.
20  *
21  * \par
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * \par
28  * You should have received a copy of the GNU General Public
29  * License along with this program; if not, see
30  * http://www.gnu.org/copyleft/gpl.html
31  */
32 
33 #pragma once
34 
35 #include <ogdf/basic/GraphAttributes.h>
36 
37 
38 
39 namespace ogdf {
40 
41 
42 /**
43  * \brief Base class of algorithms that arrange/pack layouts of connected
44  *        components.
45  *
46  * \see PlanarizationLayout<BR>PlanarizationGridLayout
47  */
48 class OGDF_EXPORT CCLayoutPackModule {
49 public:
50 	//! Initializes a layout packing module.
CCLayoutPackModule()51 	CCLayoutPackModule() { }
52 
~CCLayoutPackModule()53 	virtual ~CCLayoutPackModule() { }
54 
55 	/**
56 	 * \brief Arranges the rectangles given by \p box.
57 	 *
58 	 * The algorithm call takes an input an array \p box of rectangles with
59 	 * real coordinates and computes in \p offset the offset to (0,0) of each
60 	 * rectangle in the layout.
61 	 *
62 	 * This method is the actual algorithm call and must be overridden by derived
63 	 * classes.
64 	 * @param box is the array of input rectangles.
65 	 * @param offset is assigned the offset of each rectangle to the origin (0,0).
66 	 *        The offset of a rectangle is its lower left point in the layout.
67 	 * @param pageRatio is the desired page ratio (width / height) of the
68 	 *        resulting layout.
69 	 */
70 	virtual void call(Array<DPoint> &box,
71 		Array<DPoint> &offset,
72 		double pageRatio = 1.0) = 0;
73 
74 	/**
75 	 * \brief Arranges the rectangles given by \p box.
76 	 *
77 	 * The algorithm call takes an input an array \p box of rectangles with
78 	 * real coordinates and computes in \p offset the offset to (0,0) of each
79 	 * rectangle in the layout.
80 	 * @param box is the array of input rectangles.
81 	 * @param offset is assigned the offset of each rectangle to the origin (0,0).
82 	 *        The offset of a rectangle is its lower left point in the layout.
83 	 * @param pageRatio is the desired page ratio (width / height) of the
84 	 *        resulting layout.
85 	 */
operator()86 	void operator()(Array<DPoint> &box,
87 		Array<DPoint> &offset,
88 		double pageRatio = 1.0)
89 	{
90 		call(box,offset,pageRatio);
91 	}
92 
93 	/**
94 	 * \brief Arranges the rectangles given by \p box.
95 	 *
96 	 * The algorithm call takes an input an array \p box of rectangles with
97 	 * integer coordinates and computes in \p offset the offset to (0,0) of each
98 	 * rectangle in the layout.
99 	 *
100 	 * This method is the actual algorithm call and must be overridden by derived
101 	 * classes.
102 	 * @param box is the array of input rectangles.
103 	 * @param offset is assigned the offset of each rectangle to the origin (0,0).
104 	 *        The offset of a rectangle is its lower left point in the layout.
105 	 * @param pageRatio is the desired page ratio (width / height) of the
106 	 *        resulting layout.
107 	 */
108 	virtual void call(Array<IPoint> &box,
109 		Array<IPoint> &offset,
110 		double pageRatio = 1.0) = 0;
111 
112 	/**
113 	 * \brief Arranges the rectangles given by \p box.
114 	 *
115 	 * The algorithm call takes an input an array \p box of rectangles with
116 	 * integer coordinates and computes in \p offset the offset to (0,0) of each
117 	 * rectangle in the layout.
118 	 * @param box is the array of input rectangles.
119 	 * @param offset is assigned the offset of each rectangle to the origin (0,0).
120 	 *        The offset of a rectangle is its lower left point in the layout.
121 	 * @param pageRatio is the desired page ratio (width / height) of the
122 	 *        resulting layout.
123 	 */
operator()124 	void operator()(Array<IPoint> &box,
125 		Array<IPoint> &offset,
126 		double pageRatio = 1.0)
127 	{
128 		call(box,offset,pageRatio);
129 	}
130 
131 	/**
132 	 * \brief Checks if the rectangles in \p box do not overlap for given offsets.
133 	 *
134 	 * This function serves for checking if the computed offsets are correct in
135 	 * the sense that the rectangles do not overlap in the resulting layout.
136 	 * @param box is the array of rectangles.
137 	 * @param offset is the array of corresponding offsets.
138 	 */
139 	static bool checkOffsets(const Array<DPoint> &box,
140 		const Array<DPoint> &offset);
141 
142 	/**
143 	 * \brief Checks if the rectangles in \p box do not overlap for given offsets.
144 	 *
145 	 * This function serves for checking if the computed offsets are correct in
146 	 * the sense that the rectangles do not overlap in the resulting layout.
147 	 * @param box is the array of rectangles.
148 	 * @param offset is the array of corresponding offsets.
149 	 */
150 	static bool checkOffsets(const Array<IPoint> &box,
151 		const Array<IPoint> &offset);
152 
153 
154 	OGDF_MALLOC_NEW_DELETE
155 
156 private:
157 	/**
158 	 * \brief Checks if the rectangles in \p box do not overlap for given offsets.
159 	 *
160 	 * @param box is the array of rectangles.
161 	 * @param offset is the array of corresponding offsets.
162 	 * @tparam POINT is the generic point type.
163 	 */
164 	template<class POINT>
165 	static bool checkOffsetsTP(
166 		const Array<POINT> &box,
167 		const Array<POINT> &offset);
168 };
169 
170 }
171