TTK
Loading...
Searching...
No Matches
PlanarGraphLayout.cpp
Go to the documentation of this file.
1#include <PlanarGraphLayout.h>
2
3#if TTK_ENABLE_GRAPHVIZ
4#include <cgraph.h>
5#include <gvc.h>
6#endif
7
9 this->setDebugMsgPrefix("PlanarGraphLayout");
10}
12
13// Compute Dot Layout
15 // Output
16 float *layout,
17
18 // Input
19 const std::vector<size_t> &nodeIndices,
20 const std::string &dotString) const {
21#ifdef TTK_ENABLE_GRAPHVIZ
22 Timer t;
23
24 this->printMsg("Computing layout", 0, debug::LineMode::REPLACE);
25
26 // ---------------------------------------------------------
27 // Init GraphViz
28 // ---------------------------------------------------------
29 Agraph_t *G = agmemread(dotString.data());
30 GVC_t *gvc = gvContext();
31 gvLayout(gvc, G, "dot");
32
33 // ---------------------------------------------------------
34 // Get layout data from GraphViz
35 // ---------------------------------------------------------
36 for(auto i : nodeIndices) {
37 Agnode_t *n = agnode(G, const_cast<char *>(std::to_string(i).data()), 0);
38 if(n != nullptr) {
39 auto &coord = ND_coord(n);
40 size_t offset = i * 2;
41 layout[offset] = coord.x / 72; // points to inches
42 layout[offset + 1] = coord.y / 72; // points to inches
43 }
44 }
45
46 // ---------------------------------------------------------
47 // Free GraphViz memory
48 // ---------------------------------------------------------
49 gvFreeLayout(gvc, G);
50 agclose(G);
51 gvFreeContext(gvc);
52
53 this->printMsg("Computing layout", 1, t.getElapsedTime());
54
55 return 1;
56#else
57 TTK_FORCE_USE(layout);
58 TTK_FORCE_USE(nodeIndices);
59 TTK_FORCE_USE(dotString);
60
61 this->printErr("This filter requires GraphViz to compute a layout.");
62 return 0;
63#endif // TTK_ENABLE_GRAPHVIZ
64}
#define TTK_FORCE_USE(x)
Force the compiler to use the function/method parameter.
Definition: BaseClass.h:57
void setDebugMsgPrefix(const std::string &prefix)
Definition: Debug.h:364
~PlanarGraphLayout() override
int computeDotLayout(float *layout, const std::vector< size_t > &nodeIndices, const std::string &dotString) const
double getElapsedTime()
Definition: Timer.h:15
printMsg(debug::output::GREEN+"                           "+debug::output::ENDCOLOR+debug::output::GREEN+"▒"+debug::output::ENDCOLOR+debug::output::GREEN+"▒▒▒▒▒▒▒▒▒▒▒▒▒░"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)