Menu

save metric

Help
2010-12-10
2013-04-20
  • d.allouche david

    Hi,
    i have a  general question,
    how can i do for exporting metric in tabular file using tulip ?

    (i mean , degree distribution , betweeness ….)  after tulip generation data are available in the .tlp file
    but i don't know how to export it into a text file using tulip gui .

    cheers dave

     
  • David Auber

    David Auber - 2010-12-15

    Hi,

    It is not possible directly with the GUI.
    you can write an export plugin to do that or wait for the python script view that will be available soon (we just need to finish the packaging)

    However it is a nice feature that we could add in the plug-in server (put a feature request for that if you want).

    Wishes,
    David.

     
  • David Auber

    David Auber - 2011-01-18

    Hi,

    You will find in the post the source code of an export plugin that save all nodes/edges properties in a csv file.

    CPP file:

    #include "csvexport.h"

    EXPORTPLUGIN(CsvExport, "CSV", "David Auber","18/01/2011","Alpha","0.1");

    using namespace tlp;
    using namespace std;

    /*
    const char * paramHelp = {
        // number of clusters
        HTML_HELP_OPEN() \
        HTML_HELP_DEF( "type", "unsigned int" ) \
        HTML_HELP_BODY() \
        "Determine the number of desired clusters, if 0 the algorithm will find determine the optimal number of clusters" \
         HTML_HELP_CLOSE(),
    };
    */
    //================================================================================
    CsvExport::CsvExport(AlgorithmContext context):ExportModule(context) {
    //    addParameter<unsigned int>("shifting", paramHelp, 0, false);
    //    addParameter<DoubleProperty>("Edge weights", paramHelp, 0, false);
    }
    //================================================================================
    CsvExport::~CsvExport() {
    }
    //================================================================================
    bool CsvExport::exportGraph(std::ostream &os, Graph *g) {

        //nodes
        Iterator<string> *it(g->getProperties());
        os << "node_id";
        if (it->hasNext()) os << " ; ";
        while(it->hasNext()) {
           string str = it->next();
           os << str;
           if (it->hasNext()) os << " ; ";
        } delete it;
        os << endl;
        node n;
        forEach(n, g->getNodes()) {
            os << n;
            Iterator<string> *it(g->getProperties());
            if (it->hasNext()) os << " ; ";
            while(it->hasNext()) {
               string str = it->next();
               PropertyInterface *prop = g->getProperty(str);
               os << prop->getNodeStringValue(n);
               if (it->hasNext()) os << " ; ";
            } delete it;
            os << endl;
        }

        //edges
        it = g->getProperties();
        os << "src_id ; tgt_id";
        if (it->hasNext()) os << " ; ";
        while(it->hasNext()) {
           string str = it->next();
           os << str;
           if (it->hasNext()) os << " ; ";
        } delete it;
        os << endl;
        edge e;
        forEach(e, g->getEdges()) {
            os << g->source(e) << ";" << g->target(e);
            Iterator<string> *it(g->getProperties());
            if (it->hasNext()) os << " ; ";
            while(it->hasNext()) {
               string str = it->next();
               PropertyInterface *prop = g->getProperty(str);
               os << prop->getEdgeStringValue(e);
               if (it->hasNext()) os << " ; ";
            } delete it;
            os << endl;
        }

        return true;
    }
    //================================================================================

    HEADER file:

    #ifndef CSVEXPORT_H
    #define CSVEXPORT_H

    #include <iostream>
    #include <tulip/TulipPlugin.h>

    /** \addtogroup export */
    /*@{*/
    class CsvExport: public tlp::ExportModule {
    public:
      CsvExport(tlp::AlgorithmContext context);
      ~CsvExport();
      bool exportGraph(std::ostream &,tlp::Graph *);
    };
    /*@}*/
    #endif // CSVEXPORT_H

    CMAKE file:

    CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

    PROJECT(csvexport)
    SET(PLUGIN_NAME csvexport)

    FIND_PACKAGE( Qt4 REQUIRED)
    FIND_PACKAGE( TULIP3 REQUIRED)
    include(${QT_USE_FILE})

    include_directories(${TULIP_INCLUDE_DIR} ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})

    ##-----------------------------------------------------------------------------------
    SET(PLUGIN_SRCS csvexport.cpp csvexport.h)
    ADD_LIBRARY(${PLUGIN_NAME}-${TULIP_PLUGIN_VERSION} SHARED ${PLUGIN_SRCS})
    TARGET_LINK_LIBRARIES(${PLUGIN_NAME}-${TULIP_PLUGIN_VERSION} ${TULIP_LIBRARY})
    ADD_DEPENDENCIES(${PLUGIN_NAME}-${TULIP_PLUGIN_VERSION} ${TULIP_LIBRARY})

    ##-----------------------------------------------------------------------------------
    INSTALL(TARGETS ${PLUGIN_NAME}-${TULIP_PLUGIN_VERSION} DESTINATION ${TULIP_PLUGINS_PATH})

     

Log in to post a comment.