Visualization Functions

The following functions does nothing in the command line interpreter.

The visualization painting expects that all registered vertices contatin __x, __y and __z properties for their positioning in 3D space. The center of the whole graph should be at (0, 0, 0) location to guarantee the proper rotations. Vertices and edges can contatin __r, __g and __b color specification, the value ranges are from 0 to 255. The edges can also set their __w property; if visUseWeightWhenPaintingEdges() flag is set, the weight will be added to the Z position coordinate.

Register graph or set for painting. String parameter will be used in the application menu to enable/disable when painting. Three numbers are RGB color components, they can be locally redefined in any vertex or edge.

visRegister(graph|set, string, number, number, number) : null

Set a vertex position in 3D space. Actually set __x, __y and __z properties.

visSetPos(vertex, number, number, number) : null

Set vertex or edge color. Actually set __r, __g and __b properties.

visSetColor(vertex|edge, number, number, number) : null

Set position of camera using X, Y and Z coordinates together with X and Y rotations. The camera will be initialized using the OpenGL code below.

visSetView(number, number, number, number, number) : null
glLoadIdentity();
glTranslatef(m_currentView.getPosX(), m_currentView.getPosY(), m_currentView.getPosZ() - 10.0f);
glRotatef(m_currentView.getRotX(), 1.0f, 0.0f, 0.0f);
glRotatef(m_currentView.getRotY(), 0.0f, 1.0f, 0.0f);

If the flag is set, the edge weight (__w property) will be added to the Z position coordinate.

visUseWeightWhenPaintingEdges(bool) : null

Take a screenshot of the visualization window and save the image to the specified file.

visScreenshot(string) : null

Get the graph specified in the Graphal GUI application. You should always check the returned value for null.

visGetGraph() : graph|null

Examples

Load a graph from a file and register the vertices and edges to be painted with different colors.

g = graph();
assert(g.loadFromFile("../graphs/01_house.txt"));
breakpoint(true);
visRegister(g.getVertices(), "vertices", 255, 0, 0);
visRegister(g.getEdges(), "edges", 0, 255, 0);

Paint a house graph edge by edge.

define("ZPOS", "0.0");

g = graph();
g.setDirected(true);

v0 = g.generateVertex(); v0.visSetPos(-1,  1, ZPOS);
v1 = g.generateVertex(); v1.visSetPos( 1,  1, ZPOS);
v2 = g.generateVertex(); v2.visSetPos( 1, -1, ZPOS);
v3 = g.generateVertex(); v3.visSetPos(-1, -1, ZPOS);
v4 = g.generateVertex(); v4.visSetPos( 0,  2, ZPOS);

// Use "step over" debugging now
breakpoint(true);
visRegister(g, "graph", 0, 255, 0);
e0 = g.generateEdge(v3, v0);
e1 = g.generateEdge(v0, v1);
e2 = g.generateEdge(v1, v3);
e3 = g.generateEdge(v3, v2);
e4 = g.generateEdge(v2, v0);
e5 = g.generateEdge(v0, v4);
e6 = g.generateEdge(v4, v1);
e7 = g.generateEdge(v1, v2);
g.setDirected(false);

Load a graph specified in Graphal GUI application and fallback to the default one if no one is set.

if((g = visGetGraph()) == null)
{
	echo("No graph was set in GUI, using predefined one in the script.\n");
	g = graph();
	assert(g.loadFromFile("../graphs/00_simple.txt"));
}