From 8402eb01a21f8b0a6a5e9f0081895990c843c29c Mon Sep 17 00:00:00 2001 From: Antoine Lambert Date: Tue, 14 Nov 2023 22:16:01 +0100 Subject: [PATCH] plugins/import: Wrap OGDF graph generators (WIP) --- library/talipot-ogdf/CMakeLists.txt | 5 +- .../talipot-ogdf/include/talipot/OGDFUtils.h | 23 +++++++ library/talipot-ogdf/src/OGDFUtils.cpp | 39 ++++++++++++ plugins/import/CMakeLists.txt | 1 + plugins/import/OGDF/CMakeLists.txt | 18 ++++++ plugins/import/OGDF/OGDFPetersenGraph.cpp | 62 +++++++++++++++++++ 6 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 library/talipot-ogdf/include/talipot/OGDFUtils.h create mode 100644 library/talipot-ogdf/src/OGDFUtils.cpp create mode 100644 plugins/import/OGDF/CMakeLists.txt create mode 100644 plugins/import/OGDF/OGDFPetersenGraph.cpp diff --git a/library/talipot-ogdf/CMakeLists.txt b/library/talipot-ogdf/CMakeLists.txt index 3a9042bc02..dbcf8d1acf 100644 --- a/library/talipot-ogdf/CMakeLists.txt +++ b/library/talipot-ogdf/CMakeLists.txt @@ -7,7 +7,8 @@ ENDIF(WIN32) DISABLE_COMPILER_WARNINGS() -SET(TalipotOGDF_SRCS src/TalipotToOGDF.cpp src/OGDFLayoutPluginBase.cpp) +SET(TalipotOGDF_SRCS src/TalipotToOGDF.cpp src/OGDFLayoutPluginBase.cpp + src/OGDFUtils.cpp) ADD_LIBRARY(${LibTalipotOGDFName} SHARED ${TalipotOGDF_SRCS}) @@ -21,7 +22,7 @@ INSTALL( ARCHIVE DESTINATION ${TalipotLibInstallDir}) INSTALL(FILES include/talipot/OGDFLayoutPluginBase.h - include/talipot/TalipotToOGDF.h + include/talipot/TalipotToOGDF.h include/talipot/OGDFUtils.h DESTINATION ${TalipotIncludeInstallDir}/talipot/) IF(TALIPOT_ACTIVATE_PYTHON_WHEEL_TARGET) diff --git a/library/talipot-ogdf/include/talipot/OGDFUtils.h b/library/talipot-ogdf/include/talipot/OGDFUtils.h new file mode 100644 index 0000000000..7929e4a694 --- /dev/null +++ b/library/talipot-ogdf/include/talipot/OGDFUtils.h @@ -0,0 +1,23 @@ +/** + * + * Copyright (C) 2023 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#ifndef TALIPOT_OGDF_UTILS_H +#define TALIPOT_OGDF_UTILS_H + +#include +#include + +TLP_OGDF_SCOPE tlp::Graph *convertOGDFGraphToTalipotGraph(ogdf::Graph &graph, + tlp::Graph *tlpGraph = nullptr); + +#endif // TALIPOT_OGDF_UTILS_H diff --git a/library/talipot-ogdf/src/OGDFUtils.cpp b/library/talipot-ogdf/src/OGDFUtils.cpp new file mode 100644 index 0000000000..304b59d7ed --- /dev/null +++ b/library/talipot-ogdf/src/OGDFUtils.cpp @@ -0,0 +1,39 @@ +/** + * + * Copyright (C) 2023 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include + +using namespace std; + +tlp::Graph *TLP_OGDF_SCOPE convertOGDFGraphToTalipotGraph(ogdf::Graph &graph, + tlp::Graph *tlpGraph) { + if (!tlpGraph) { + tlpGraph = tlp::newGraph(); + } else { + tlpGraph->clear(); + } + + unordered_map nodesMap; + + for (ogdf::node n : graph.nodes) { + nodesMap[n] = tlpGraph->addNode(); + } + + for (ogdf::edge e : graph.edges) { + tlpGraph->addEdge(nodesMap[e->source()], nodesMap[e->target()]); + } + + return tlpGraph; +} diff --git a/plugins/import/CMakeLists.txt b/plugins/import/CMakeLists.txt index a72982d6b5..26e46ed00f 100644 --- a/plugins/import/CMakeLists.txt +++ b/plugins/import/CMakeLists.txt @@ -2,6 +2,7 @@ ADD_SUBDIRECTORY(SocialNetwork) ADD_SUBDIRECTORY(BibTeX) ADD_SUBDIRECTORY(Graphviz) ADD_SUBDIRECTORY(Git) +ADD_SUBDIRECTORY(OGDF) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${TalipotCoreBuildInclude} ${TalipotCoreInclude} ${TalipotGUIInclude}) diff --git a/plugins/import/OGDF/CMakeLists.txt b/plugins/import/OGDF/CMakeLists.txt new file mode 100644 index 0000000000..69564636c9 --- /dev/null +++ b/plugins/import/OGDF/CMakeLists.txt @@ -0,0 +1,18 @@ +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${TalipotCoreBuildInclude} + ${TalipotCoreInclude} ${OGDFInclude} ${TalipotOGDFInclude}) + +SET(PLUGINS_SRCS OGDFPetersenGraph.cpp) + +DISABLE_COMPILER_WARNINGS() + +TALIPOT_ADD_PLUGIN( + NAME + OGDFGraphGenerators + SRCS + ${PLUGINS_SRCS} + LINKS + ${LibTalipotCoreName} + ${LibTalipotOGDFName} + ${OGDF_LIBRARY} + INSTALL_DIR + ${TalipotPluginsInstallDir}) diff --git a/plugins/import/OGDF/OGDFPetersenGraph.cpp b/plugins/import/OGDF/OGDFPetersenGraph.cpp new file mode 100644 index 0000000000..978862ab9b --- /dev/null +++ b/plugins/import/OGDF/OGDFPetersenGraph.cpp @@ -0,0 +1,62 @@ +/** + * + * Copyright (C) 2023 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include +#include + +#include + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes on the outer cycle.", + + // m + "the length of jumps for the inner part.", +}; + +//================================================================================= + +class OGDFPetersenGraph : public tlp::ImportModule { +public: + PLUGININFORMATION( + "Petersen Graph (OGDF)", "Antoine Lambert", "11/2023", + "Creates an outer cycle of nodes 1, ..., n, each of which has a direct neighbor (a " + "corresponding inner node). For two outer nodes i, j, there is an edge between their " + "corresponding inner nodes if the absolute difference of i and j equals the jump length m.", + "1.0", "Graph") + + OGDFPetersenGraph(tlp::PluginContext *context) : tlp::ImportModule(context) { + addInParameter("n", paramHelp[0].data(), "5"); + addInParameter("m", paramHelp[1].data(), "2"); + } + + bool importGraph() override { + uint n = 5; + uint m = 2; + + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("m", m); + } + + ogdf::Graph g; + petersenGraph(g, n, m); + convertOGDFGraphToTalipotGraph(g, graph); + + return true; + } +}; + +PLUGIN(OGDFPetersenGraph)