Tulip  5.1.0
Large graphs analysis and drawing
TLPBExportImport.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef TLPBIMPORTEXPORT_H
22 #define TLPBIMPORTEXPORT_H
23 
24 #include <iostream>
25 #include <tulip/TulipPluginHeaders.h>
26 #include <tulip/ExportModule.h>
27 #include <tulip/ImportModule.h>
28 
29 // some compilation environments define major and minor as preprocessor macros
30 // undefine them in that case
31 #ifdef major
32 #undef major
33 #endif
34 
35 #ifdef minor
36 #undef minor
37 #endif
38 
39 /**
40  * The plugins below export/import a Tulip graph
41  * using the following binary format:
42  * format header = <magic_number, major, minor> (uint16 + uint8 +uint8)
43  * nb_nodes = uint32
44  * nb_edges = uint32
45  * edges = nb_edges * <source, target> (uint32+uint32)
46  * nb_subgraphs = uint32
47  * subgraphs = nb_subgraphs * <subgraph_id, parent_graph_id, nodes_desc, edges_desc>
48  * nodes_desc = nb_nodes_intervals * <first_node, last_node>
49  * edges_desc = nb_edges_intervals *<first_edge, last_edge>
50  * nb_properties = uint32
51  * properties = <prop_name, graph_id, type, default_node_val, default_edge_val, nodes_val, edges_val>
52  * prop_name = length + utf8 text
53  * graph_id = uint32
54  * type = length + utf8 text
55  * default_node_val = type dependant (method readb)
56  * default_edge_val = type dependant (method readb)
57  * nb_nodes_val = uint32
58  * nodes_val = nb_nodes_val * <node, node_val> (uint32 + type dependant)
59  * nb_edges_val = uint32
60  * edges_val = nb_edges_val * <edge, edge_val> (uint32 + type dependant)
61  * graph_attributes = (nb_subgraphs + 1) * <graph_id, graph_attributes_list>*
62  */
63 
64 /*@{*/
65 /// Export plugin for TLPB format
66 /**
67  *
68  * \brief This plugin saves a Tulip graph using a binary format
69  *
70  */
71 class TLPBExport: public tlp::ExportModule {
72 public:
73 
74  PLUGININFORMATION("TLPB Export", "David Auber, Patrick Mary","13/07/2012",
75  "<p>Supported extensions: tlpb, tlpbz (compressed), tlpb.gz (compressed)</p><p>Exports a graph in a file using the Tulip binary format.",
76  "1.2","File")
77 
78  std::string fileExtension() const {
79  return "tlpb";
80  }
81 
82  std::list<std::string> gzipFileExtensions() const {
83  std::list<std::string> ext;
84  ext.push_back("tlpb.gz");
85  ext.push_back("tlpbz");
86  return ext;
87  }
88 
89  TLPBExport(const tlp::PluginContext *context) :ExportModule(context) {}
90  ~TLPBExport() {}
91 
92  bool exportGraph(std::ostream &);
93 
94  std::string icon() const {
95  return ":/tulip/gui/icons/tlpb32x32.png";
96  }
97 
98  inline tlp::node getNode(tlp::node n) {
99  assert(graph->isElement(n));
100  return tlp::node(graph->nodePos(n));
101  }
102 
103  inline tlp::edge getEdge(tlp::edge e) {
104  assert(graph->isElement(e));
105  return tlp::edge(graph->edgePos(e));
106  }
107 
108  void getSubGraphs(tlp::Graph*, std::vector<tlp::Graph*>&);
109 
110  void writeAttributes(std::ostream&, tlp::Graph*);
111 };
112 
113 /// Import plugin for TLPB format
114 /**
115  *
116  * \brief This plugin reads a Tulip graph using a binary format
117  *
118  */
119 class TLPBImport:public tlp::ImportModule {
120 public:
121  PLUGININFORMATION("TLPB Import", "David Auber, Patrick Mary", "13/07/2012",
122  "<p>Supported extensions: tlpb, tlpb.gz (compressed), tlpbz (compressed)</p><p>Imports a graph recorded in a file using the Tulip binary format.</p>", "1.2", "File")
123 
124  TLPBImport(tlp::PluginContext* context);
125  ~TLPBImport() {}
126 
127  std::string icon() const {
128  return ":/tulip/gui/icons/tlpb32x32.png";
129  }
130 
131  std::list<std::string> fileExtensions() const {
132  std::list<std::string> l;
133  l.push_back("tlpb");
134  return l;
135  }
136 
137  std::list<std::string> gzipFileExtensions() const {
138  std::list<std::string> ext;
139  ext.push_back("tlpb.gz");
140  ext.push_back("tlpbz");
141  return ext;
142  }
143 
144  bool importGraph();
145 };
146 
147 /*@}*/
148 
149 //Don't ask why it is David favorite 9 digit number.
150 #define TLPB_MAGIC_NUMBER 578374683
151 #define TLPB_MAJOR 1
152 #define TLPB_MINOR 2
153 
154 // structures used in both tlpb import/export plugins
155 struct TLPBHeader {
156  unsigned int magicNumber;
157  unsigned char major;
158  unsigned char minor;
159  unsigned int numNodes;
160  unsigned int numEdges;
161 
162  TLPBHeader(unsigned int nbN = 0, unsigned int nbE = 0)
163  : magicNumber(TLPB_MAGIC_NUMBER), major(TLPB_MAJOR), minor(TLPB_MINOR), numNodes(nbN), numEdges(nbE) {}
164 
165  bool checkCompatibility() {
166  return ((magicNumber == TLPB_MAGIC_NUMBER) &&
167  (major == TLPB_MAJOR) &&
168  (minor <= TLPB_MINOR));
169  }
170 };
171 
172 #define MAX_EDGES_TO_WRITE 64000
173 #define MAX_EDGES_TO_READ MAX_EDGES_TO_WRITE
174 #define MAX_RANGES_TO_WRITE MAX_EDGES_TO_WRITE
175 #define MAX_RANGES_TO_READ MAX_RANGES_TO_WRITE
176 #define MAX_VALUES_TO_WRITE MAX_EDGES_TO_WRITE
177 #define MAX_VALUES_TO_READ MAX_VALUES_TO_WRITE
178 
179 #endif // TLPBIMPORTEXPORT_H
180 ///@endcond
Graph * importGraph(const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL, Graph *newGraph=NULL)
Imports a graph using the specified import plugin with the parameters stored in the DataSet...
The edge struct represents an edge in a Graph object.
Definition: Edge.h:39
The node struct represents a node in a Graph object.
Definition: Node.h:39
#define PLUGININFORMATION(NAME, AUTHOR, DATE, INFO, RELEASE, GROUP)
Declare meta-information for a plugin This is an helper macro that defines every function related to ...
Definition: Plugin.h:203
Contains runtime parameters for a plugin.
Definition: PluginContext.h:39
bool exportGraph(Graph *graph, std::ostream &outputStream, const std::string &format, DataSet &dataSet, PluginProgress *progress=NULL)
Exports a graph using the specified export plugin with parameters stored in the DataSet.