Tulip  4.10.0
Better Visualization Through Research
TLPBExportImport.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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  "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  TLPBExport(const tlp::PluginContext *context) :ExportModule(context) {}
83  ~TLPBExport() {}
84 
85  bool exportGraph(std::ostream &);
86 
87  std::string icon() const {
88  return ":/tulip/gui/icons/tlpb32x32.png";
89  }
90 
91  tlp::MutableContainer<tlp::node> nodeIndex;
92  tlp::MutableContainer<tlp::edge> edgeIndex;
93 
94  tlp::node getNode(tlp::node n) {
95  return nodeIndex.get(n.id);
96  }
97 
98  tlp::edge getEdge(tlp::edge e) {
99  return edgeIndex.get(e.id);
100  }
101 
102  void getSubGraphs(tlp::Graph*, std::vector<tlp::Graph*>&);
103 
104  void writeAttributes(std::ostream&, tlp::Graph*);
105 };
106 
107 /// Import plugin for TLPB format
108 /**
109  *
110  * \brief This plugin reads a Tulip graph using a binary format
111  *
112  */
113 class TLPBImport:public tlp::ImportModule {
114 public:
115  PLUGININFORMATION("TLPB Import", "David Auber, Patrick Mary", "13/07/2012",
116  "Imports a graph recorded in a file using the Tulip binary format", "1.2", "File")
117 
118  TLPBImport(tlp::PluginContext* context);
119  ~TLPBImport() {}
120 
121  std::string icon() const {
122  return ":/tulip/gui/icons/tlpb32x32.png";
123  }
124 
125  std::list<std::string> fileExtensions() const {
126  std::list<std::string> l;
127  l.push_back("tlpb");
128  l.push_back("tlpb.gz");
129  return l;
130  }
131 
132  bool importGraph();
133 };
134 
135 /*@}*/
136 
137 //Don't ask why it is David favorite 9 digit number.
138 #define TLPB_MAGIC_NUMBER 578374683
139 #define TLPB_MAJOR 1
140 #define TLPB_MINOR 2
141 
142 // structures used in both tlpb import/export plugins
143 struct TLPBHeader {
144  unsigned int magicNumber;
145  unsigned char major;
146  unsigned char minor;
147  unsigned int numNodes;
148  unsigned int numEdges;
149 
150  TLPBHeader(unsigned int nbN = 0, unsigned int nbE = 0)
151  : magicNumber(TLPB_MAGIC_NUMBER), major(TLPB_MAJOR), minor(TLPB_MINOR), numNodes(nbN), numEdges(nbE) {}
152 
153  bool checkCompatibility() {
154  return ((magicNumber == TLPB_MAGIC_NUMBER) &&
155  (major == TLPB_MAJOR) &&
156  (minor <= TLPB_MINOR));
157  }
158 };
159 
160 #define MAX_EDGES_TO_WRITE 64000
161 #define MAX_EDGES_TO_READ MAX_EDGES_TO_WRITE
162 #define MAX_RANGES_TO_WRITE MAX_EDGES_TO_WRITE
163 #define MAX_RANGES_TO_READ MAX_RANGES_TO_WRITE
164 #define MAX_VALUES_TO_WRITE MAX_EDGES_TO_WRITE
165 #define MAX_VALUES_TO_READ MAX_VALUES_TO_WRITE
166 
167 #endif // TLPBIMPORTEXPORT_H
168 ///@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
unsigned int id
id The identifier of the node.
Definition: Node.h:43
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.
unsigned int id
id The identifier of the edge.
Definition: Edge.h:43