Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/TLPBExportImport.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 /**
00021  *
00022  * This file is part of Tulip (www.tulip-software.org)
00023  *
00024  * Authors: David Auber and the Tulip development Team
00025  * from LaBRI, University of Bordeaux
00026  *
00027  * Tulip is free software; you can redistribute it and/or modify
00028  * it under the terms of the GNU Lesser General Public License
00029  * as published by the Free Software Foundation, either version 3
00030  * of the License, or (at your option) any later version.
00031  *
00032  * Tulip is distributed in the hope that it will be useful,
00033  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00034  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00035  * See the GNU General Public License for more details.
00036  *
00037  */
00038 #ifndef TLPBIMPORTEXPORT_H
00039 #define TLPBIMPORTEXPORT_H
00040 
00041 #include <iostream>
00042 #include <tulip/TulipPluginHeaders.h>
00043 #include <tulip/ExportModule.h>
00044 #include <tulip/ImportModule.h>
00045 
00046 // some compilation environments define major and minor as preprocessor macros
00047 // undefine them in that case
00048 #ifdef major
00049 #undef major
00050 #endif
00051 
00052 #ifdef minor
00053 #undef minor
00054 #endif
00055 
00056 /**
00057  * The plugins below export/import a Tulip graph
00058  * using the following binary format:
00059  * format header = <magic_number, major, minor> (uint16 + uint8 +uint8)
00060  * nb_nodes = uint32
00061  * nb_edges = uint32
00062  * edges = nb_edges * <source, target> (uint32+uint32)
00063  * nb_subgraphs = uint32
00064  * subgraphs = nb_subgraphs * <subgraph_id, parent_graph_id, nodes_desc, edges_desc>
00065  * nodes_desc = nb_nodes_intervals * <first_node, last_node>
00066  * edges_desc = nb_edges_intervals *<first_edge, last_edge>
00067  * nb_properties = uint32
00068  * properties = <prop_name, graph_id, type, default_node_val, default_edge_val, nodes_val, edges_val>
00069  * prop_name = length + utf8 text
00070  * graph_id = uint32
00071  * type = length + utf8 text
00072  * default_node_val = type dependant (method readb)
00073  * default_edge_val = type dependant (method readb)
00074  * nb_nodes_val = uint32
00075  * nodes_val = nb_nodes_val * <node, node_val> (uint32 + type dependant)
00076  * nb_edges_val = uint32
00077  * edges_val = nb_edges_val * <edge, edge_val> (uint32 + type dependant)
00078  * graph_attributes = (nb_subgraphs + 1) * <graph_id, graph_attributes_list>*
00079  */
00080 
00081 /*@{*/
00082 /// Export plugin for TLPB format
00083 /**
00084  *
00085  * \brief This plugin saves a Tulip graph using a binary format
00086  *
00087  */
00088 class TLPBExport: public tlp::ExportModule {
00089 public:
00090 
00091   PLUGININFORMATION("TLPB Export", "David Auber, Patrick Mary","13/07/2012","Saves a graph in Tulip binary format","1.0","File")
00092 
00093   std::string fileExtension() const {
00094     return "tlpb";
00095   }
00096 
00097   TLPBExport(const tlp::PluginContext *context) :ExportModule(context) {}
00098   ~TLPBExport() {}
00099 
00100   bool exportGraph(std::ostream &);
00101 
00102   std::string icon() const {
00103     return ":/tulip/gui/icons/tlpb32x32.png";
00104   }
00105 
00106   tlp::MutableContainer<tlp::node> nodeIndex;
00107   tlp::MutableContainer<tlp::edge> edgeIndex;
00108 
00109   tlp::node getNode(tlp::node n) {
00110     return nodeIndex.get(n.id);
00111   }
00112 
00113   tlp::edge getEdge(tlp::edge e) {
00114     return edgeIndex.get(e.id);
00115   }
00116 
00117   void getSubGraphs(tlp::Graph*, std::vector<tlp::Graph*>&);
00118 
00119   void writeAttributes(std::ostream&, tlp::Graph*);
00120 };
00121 
00122 /// Import plugin for TLPB format
00123 /**
00124  *
00125  * \brief This plugin reads a Tulip graph using a binary format
00126  *
00127  */
00128 class TLPBImport:public tlp::ImportModule {
00129 public:
00130   PLUGININFORMATION("TLPB Import", "David Auber, Patrick Mary", "13/07/2012",
00131                     "Reads a graph in Tulip binary format", "1.0", "File")
00132 
00133   TLPBImport(tlp::PluginContext* context);
00134   ~TLPBImport() {}
00135 
00136   std::string icon() const {
00137     return ":/tulip/gui/icons/tlpb32x32.png";
00138   }
00139 
00140   std::list<std::string> fileExtensions() const {
00141     return std::list<std::string>(1, "tlpb");
00142   }
00143 
00144   bool importGraph();
00145 };
00146 
00147 /*@}*/
00148 
00149 //Don't ask why it is David favorite 9 digit number.
00150 #define TLPB_MAGIC_NUMBER 578374683
00151 #define TLPB_MAJOR 1
00152 #define TLPB_MINOR 0
00153 
00154 // structures used in both tlpb import/export plugins
00155 struct TLPBHeader {
00156   unsigned int magicNumber;
00157   unsigned char major;
00158   unsigned char minor;
00159   unsigned int numNodes;
00160   unsigned int numEdges;
00161 
00162   TLPBHeader(unsigned int nbN = 0, unsigned int nbE = 0)
00163     : magicNumber(TLPB_MAGIC_NUMBER), major(TLPB_MAJOR), minor(TLPB_MINOR), numNodes(nbN), numEdges(nbE) {}
00164 
00165   bool checkCompatibility() {
00166     return ((magicNumber == TLPB_MAGIC_NUMBER) &&
00167             (major == TLPB_MAJOR) &&
00168             (minor <= TLPB_MINOR));
00169   }
00170 };
00171 
00172 #define MAX_EDGES_TO_WRITE 64000
00173 #define MAX_EDGES_TO_READ MAX_EDGES_TO_WRITE
00174 #define MAX_RANGES_TO_WRITE MAX_EDGES_TO_WRITE
00175 #define MAX_RANGES_TO_READ MAX_RANGES_TO_WRITE
00176 #define MAX_VALUES_TO_WRITE MAX_EDGES_TO_WRITE
00177 #define MAX_VALUES_TO_READ MAX_VALUES_TO_WRITE
00178 
00179 #endif // TLPBIMPORTEXPORT_H
 All Classes Files Functions Variables Enumerations Enumerator Properties