30 #include <gsl/gsl_vector.h> 65 Point& rotate(
double theta,
68 if (axis < 0 or axis > 2) {
69 std::cerr <<
"Axis " << axis <<
" unavailable for rotation, " 70 <<
" space in 3D has axis 0, 1 or 2.\n";
73 double& xref = *(&x + (axis + 1)%3);
74 double& yref = *(&x + (axis + 2)%3);
75 double new_x = std::cos(theta)*xref - std::sin(theta)*yref;
76 yref = std::sin(theta)*xref + std::cos(theta)*yref;
82 double angle(
int axis = 2)
const 84 if (axis < 0 or axis > 2) {
85 std::cerr <<
"Axis " << axis <<
" unavailable for rotation, " 86 <<
" space in 3D has axis 0, 1 or 2.\n";
90 return std::atan2(z, y);
92 return std::atan2(x, z);
93 return std::atan2(y, x);
98 return std::sqrt(x*x + y*y + z*z);
101 template<
typename Value_Type>
102 Point& operator+=(Value_Type value) {
115 template<
typename Value_Type>
116 Point& operator*=(Value_Type value) {
129 template<
typename Value_Type>
130 Point& operator-=(Value_Type value) {
143 template<
typename Value_Type>
144 Point& operator/=(Value_Type value) {
158 std::ostream& operator<<(std::ostream& out,
161 out << point.x <<
" " << point.y <<
" " << point.z;
175 inline static bool writeResToFile =
false;
176 inline static std::string fileNameBegin =
"graph/begin";
177 inline static std::string fileName3DRes =
"graph/3D";
178 inline static std::string fileNameProject =
"graph/project";
179 inline static std::string fileName2DRes =
"graph/2D";
181 inline static constexpr
double externalLegSizeRation = 0.70;
182 inline static constexpr
double absAngleMultiple = 4;
183 inline static constexpr
double decouplingDistance = -1;
185 inline static constexpr
double defaultNodeSizeFactor = 16.50;
186 inline static constexpr
double defaultAngleFactor = 6.50;
187 inline static constexpr
double defaultExternalLayout = 0.95;
188 inline static constexpr
double defaultExternalRepulsion = 2.00;
189 inline static constexpr
double defaultLegsRepulsion = 4.00;
190 inline static constexpr
double defaultNodeLegsRepulsion = 3.00;
191 inline static constexpr
double defaultExtensionFactor = 1.00;
192 inline static constexpr
double defaultAbsAngleFactor = 0.00;
193 inline static constexpr
double default_3DFactor = 0.10;
194 inline static constexpr
double defaultCrossEnergyValue = 1.00;
195 inline static constexpr
double defaultSpecialAnglesValue = 6.50;
197 inline static bool enable3D =
true;
198 inline static double nodeSizeFactor = defaultNodeSizeFactor;
199 inline static double angleFactor = defaultAngleFactor;
200 inline static double externalRepulsion = defaultExternalRepulsion;
201 inline static double externalLayout = defaultExternalLayout;
202 inline static double legsRepulsion = defaultLegsRepulsion;
203 inline static double nodeLegsRepulsion = defaultNodeLegsRepulsion;
204 inline static double extensionFactor = defaultExtensionFactor;
205 inline static double absAngleFactor = 0;
206 inline static double _3DFactor = default_3DFactor;
207 inline static double specialAnglesValue = 0;
215 std::vector<std::pair<int, int>>
const& init);
219 Graph& operator=(
Graph const& other) =
default;
228 size_t size()
const {
232 double& getPosition(
size_t pos) {
233 if (pos / 2 > nodes.size()) {
234 std::cerr << nodes.size() <<
", " << pos << std::endl;
235 std::cerr <<
"IndexError.\n";
238 return (pos % 2 == 0) ? nodes[pos / 2].x : nodes[pos / 2].y;
241 double getPosition(
size_t pos)
const {
242 if (pos / 2 > nodes.size()) {
243 std::cerr << nodes.size() <<
", " << pos << std::endl;
244 std::cerr <<
"IndexError.\n";
247 return (pos % 2 == 0) ? nodes[pos / 2].x : nodes[pos / 2].y;
250 std::vector<Point>& getNodes();
252 std::vector<Point>
const& getNodes()
const;
261 std::map<size_t, size_t>& mapping)
const;
263 void addEdge(
int left,
int right);
265 void setSide(
int pos,
int t_side);
279 double computeEnergy(
bool verbose =
false);
281 int minimize(
int mode = 0);
285 void project(
bool only2DRotation =
false,
286 bool keepExternal =
false);
292 void flip(
int axis = -1);
296 void scale(
double s);
298 void rotate(
double theta);
300 void move(
double x,
double y);
302 Point getCenter()
const;
306 void write(std::string
const& fileName)
const;
308 void addNode(
double x,
double y);
310 void deleteNode(
size_t i);
318 gsl_vector* allocGslVector();
322 void fillGslVector(gsl_vector* x);
324 void readGslVector(gsl_vector
const* x);
326 void initExternalDistance();
328 static void initPoint(
Point& p,
size_t N);
330 void gatherExternalNodes();
332 bool tryPermutation(
int order = 1,
double energy = -1);
340 std::vector<Point> nodes;
342 std::vector<int> loop;
344 std::vector<int> external;
346 std::vector<int> side;
350 std::vector<Energy> energies;
357 const double* factor;
359 std::function<double(Graph const& g)> func;
365 Energy(
double const& t_factor,
366 std::function<
double(
Graph const& g)>
const& t_func,
367 std::string
const& t_name =
"Energy")
373 double compute(
Graph const& g,
374 bool verbose =
false)
const 376 if (verbose and *factor != 0) {
377 auto energy = func(g);
378 std::cout << name <<
": ";
379 std::cout << energy << std::endl;
380 return *factor * energy;
382 return (*factor == 0) ? 0 : *factor * func(g);
433 return Point(-A.x, -A.y);
440 return Point(A.x - B.x, A.y - B.y);
479 inline double distance2(
Point const& A,
483 return std::max(1e-10,
484 std::pow(A.x - B.x, 2)
485 + std::pow(A.y - B.y, 2)
486 + std::pow(A.z - B.z, 2));
487 return std::max(1e-10,
488 std::pow(A.x - B.x, 2)
489 + std::pow(A.y - B.y, 2));
492 inline double distance(
Point const& A,
495 return std::sqrt(distance2(A, B));
498 inline double remainder(
double angle)
500 if (std::abs(std::abs(angle) - M_PI/2) < 1e-10)
501 return ((angle < 0) ? -1 : 1) * M_PI/2;
502 return std::atan2(std::sin(angle), std::cos(angle));
505 inline double angle(
Point const& ref,
509 Point newA = (A - ref).rotate(-(B - ref).angle());
523 res.a = (A.x == B.x) ? 0 : (A.y - B.y) / (A.x - B.x);
524 res.b = A.y - res.a * A.x;
Definition: planargraph.h:353
Definition: latexLink.h:52
Definition: planargraph.h:513
std::ostream & operator<<(std::ostream &fout, csl::Type type)
Expr operator+(const Expr &a, const Expr &b)
Expr operator-(const Expr &a, const Expr &b)
Definition: planargraph.h:169
Expr operator/(const Expr &a, const Expr &b)
Expr operator*(const Expr &a, const Expr &b)
Definition: planargraph.h:34