Autore Topic: Classi grafiche  (Letto 346 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.305
  • Ne mors quidem nos iunget
    • Mostra profilo
Classi grafiche
« il: 13 Settembre 2014, 17:32:20 »
Vi riporto questa comunicazione:

" Hi list,

with #6468, it is finally possible to use Graphs from gb.data. You have a
base "Graph" class from which all implementations inherit. It also acts
like a driver/dispatcher for implementation functions. (Little) more on
that below.

GraphMatrix is a concrete graph implementation in gb.data based on an
adjacency matrix (a full n*n one at the moment -- I may go for sparse
matrices later). More implementations may follow as I have time.

You can also create your own graph classes in Gambas. It's more
complicated than you might want it to be but you don't invent new graph
classes on a daily basis, right? That's mainly because I made excessive
use of virtual classes to have a nice interface without additional memory
usage.

At least the process of creating your own graph class is convoluted enough
that I cannot explain it now, so either self-study or wait for the tutorial/
GambasMag article (depends on how fast December approaches) :-)

Attached are three projects:

  - ConnectivityMatrix: shows how to use GraphMatrix. It (sort of) computes
    the connected components of a graph, but by taking the sum over powers
    of the adjacency matrix (using gb.gsl).

  - custom-graph: a very quickly written project which implements a
    "DirectoryGraph", i.e. a graph which represents a directory hierarchy
    where "being contained in a directory" and (symbolic) links are edges.

    The class is written in Gambas and rather minimal. The project creates
    a (graphviz) dot file and its png of the graph of /usr/lib/gambas3/*so*.

  - GraphFloodFill: is a more sophisticated project. At its heart it
    interprets an Image object as a graph by implicitly taking the pixels
    as vertices and defining edges between pixels of the same colour (or
    from any colour to white or transparent).

    The BreadthFirstSearch class implements a BFS for a general Graph object.
    ImageGraph contains just enough functionality to allow a BFS on it. This
    together allows to do a flood fill on the backing Image object.

    There is also a neat little colour chooser because the traditional one
    from gb.form was too bulky for the form.

Questions?

Regards,
Tobi
"
« Ultima modifica: 13 Settembre 2014, 18:57:02 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »