XY reading is being wrote.
authorhegyi
Wed, 30 Mar 2005 14:29:55 +0000
changeset 1277e4cc8e996912
parent 1276 b143e42c44de
child 1278 4abea330614d
XY reading is being wrote.
src/work/peter/Makefile
src/work/peter/canvas-test.cc
src/work/peter/xy-reader.cc
     1.1 --- a/src/work/peter/Makefile	Wed Mar 30 14:29:11 2005 +0000
     1.2 +++ b/src/work/peter/Makefile	Wed Mar 30 14:29:55 2005 +0000
     1.3 @@ -1,7 +1,10 @@
     1.4 -triangle: canvas-test.cc
     1.5 -	g++ canvas-test.cc -W -Wall -ansi -pedantic -o triangle `pkg-config libgnomecanvasmm-2.6 --cflags --libs`
     1.6 +gd: graph-displayer.cc
     1.7 +	g++ graph-displayer.cc -W -Wall -ansi -pedantic -o gd `pkg-config libgnomecanvasmm-2.6 --cflags --libs` -I../..
     1.8  
     1.9 -run: triangle
    1.10 -	./triangle 100 100 -100 100 0 -100
    1.11 +xyr: xy-reader.cc
    1.12 +	g++ xy-reader.cc -W -Wall -ansi -pedantic -o xyr -I../..
    1.13 +
    1.14 +run: gd
    1.15 +	./gd
    1.16  
    1.17  .PHONY: run
     2.1 --- a/src/work/peter/canvas-test.cc	Wed Mar 30 14:29:11 2005 +0000
     2.2 +++ b/src/work/peter/canvas-test.cc	Wed Mar 30 14:29:55 2005 +0000
     2.3 @@ -6,6 +6,7 @@
     2.4  #include <libgnomecanvasmm.h>
     2.5  #include <libgnomecanvasmm/polygon.h>
     2.6  #include <iostream>
     2.7 +#include <lemon/list_graph.h>
     2.8  
     2.9  class CanvasExample : public Gnome::Canvas::CanvasAA
    2.10  {
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/work/peter/xy-reader.cc	Wed Mar 30 14:29:55 2005 +0000
     3.3 @@ -0,0 +1,69 @@
     3.4 +#include <fstream>
     3.5 +#include <iostream>
     3.6 +
     3.7 +#include <lemon/xy.h>
     3.8 +#include <lemon/concept/maps.h>
     3.9 +#include <lemon/error.h>
    3.10 +#include <lemon/list_graph.h>
    3.11 +#include <lemon/graph_reader.h>
    3.12 +#include <lemon/graph_utils.h>
    3.13 +
    3.14 +using namespace lemon;
    3.15 +
    3.16 +typedef ListGraph Graph;
    3.17 +typedef xy<double> Coordinates;
    3.18 +typedef Graph::NodeMap<Coordinates> CoordinatesMap;
    3.19 +typedef Graph::Node Node;
    3.20 +
    3.21 +class CoordReaderMap: public concept::WriteMap<Node, double>
    3.22 +{
    3.23 +    CoordinatesMap * cm;
    3.24 +    char xoy;
    3.25 +
    3.26 +public:
    3.27 +    CoordReaderMap(char xory, CoordinatesMap * coordmap): concept::WriteMap<Node, double>() ,cm(coordmap)
    3.28 +    {
    3.29 +	switch(xory)
    3.30 +	{
    3.31 +	    case 'x':
    3.32 +	    case 'y':
    3.33 +		xoy=xory;
    3.34 +		break;
    3.35 +	    default:
    3.36 +		throw UninitializedParameter() ;
    3.37 +	}
    3.38 +    }
    3.39 +
    3.40 +    void set(Node node, double coord)
    3.41 +    {
    3.42 +	switch(xoy)
    3.43 +	{
    3.44 +	    case 'x':
    3.45 +		(*cm)[node].x=coord;
    3.46 +		break;
    3.47 +	    case 'y':
    3.48 +		(*cm)[node].y=coord;
    3.49 +		break;
    3.50 +	    default:
    3.51 +		throw UninitializedParameter() ;
    3.52 +	}
    3.53 +    }
    3.54 +};
    3.55 +
    3.56 +int main(void)
    3.57 +{
    3.58 +    Graph g;
    3.59 +    CoordinatesMap cm(g);
    3.60 +
    3.61 +    CoordReaderMap xreader('x',&cm);
    3.62 +    CoordReaderMap yreader('y',&cm);
    3.63 +
    3.64 +    std::ifstream is("dijkstra_test.lemon");
    3.65 +    
    3.66 +    GraphReader<Graph> reader(is, g);
    3.67 +    reader.addNodeMap("coordinates_x", xreader);
    3.68 +    reader.addNodeMap("coordinates_y", yreader);
    3.69 +    reader.run();
    3.70 +    
    3.71 +    return 0;
    3.72 +}