next up previous contents index
Next: Low Level Drawing Up: 3D-Display Implementation Previous: Global Data Types

Drawing the Network in 3D

   

This section describes the functions that are called to draw the network. Most of the routines are located in the module main.c. In other cases, the name of the module is given in parentheses without the prefix d3_. The functions are explained "top-down". Figure gif shows the hierarchy of the calls.

 
Figure:  Function calls of drawNet

  d3_drawNet:The routine is called by the function ui_net_updateWhole in the module ui_netUpdate.c as well as by all routines which make a redraw of the network necessary.(e.g.\ upon changing from wire to solid model). When the display is frozen or not opened, the routine is left immediately. In the case of solid representation, the z-buffer is cleared. Then the units are drawn by draw_units. If links are to be displayed, draw_links calls the appropriate functions.

  draw_units: This function draws all units in a network. First, the maximal dimensions of the net are calculated by get_net_extrema, then the center of rotation is computed from there. Afterwards the matrices for the global translation, scaling, and rotation are determined. The corners for labeling are determined next by get_label_vert_indices. Now the net is traversed unit by unit. For each unit its location in space (in get_unit_pos_vector) and the corresponding matrix is computed. If a value is to be displayed by the size of the unit, the value is first changed to a vector in get_size_vector and then to a matrix. The matrices are multiplied with each other by calc_transformed_cube. With this new matrix, the vectors of the standard cube are transformed to picture space. The center of the transformed unit is stored by insert_center_vector, to speed up the subsequent drawing of links. Depending upon the representation mode the unit is drawn with d3_drawWireframeCube or d3_drawSolidCube in the module draw.c. If the units are to be labeled, d3_labelUnit puts the value at the appropriate place.

  get_net_extrema: This routine determines the extension of the network in x-, y-, and z-direction. For each unit position it is checked whether one of its components is a maximum. The results are two vectors enclosing the net.

  get_label_vert_indices: The indices to the unit vectors for labeling are computed in this function. This can be done at a single unit, since all units are rotated by the same angle and the alignment doesn't change. The routine calls the actual computing function get_vert_index once for the upper and once for the lower label.

  get_unit_pos_vector: This function contains the 2D 3D transformation. Input parameter is the unit number, output value the 3D--vector. All functions which require 3D--coordinates have to call this routine.

The position of the unit is read by krui_getUnitPosition. This value contains the x and y coordinate in the 2D--display as well as the z-value assigned to the unit. The displacement of the unit against the 2d--display in x and y direction is computed by the 2D 3D translation table d3_xyTransTable. The z-coordinate is used to index the table.

  get_size_vector: In this routine the activation, the initial activation, the output, or the threshold is translated into a vector for the unit size. All components of the vector contain the same value. Values bigger than 1 are clipped. This guarantees that the unit can not grow arbitrarily and cover other units. For negative values and values around zero, a flag is returned that keeps the unit from being drawn. This is necessary, since the unit would otherwise be drawn as a point.

  calc_transformed_cube: This subprogram has to calculate the transformed unit coordinates. Therefore the following matrices have to be multiplied: matrix for 3D--position, for centering the unit in space, for the base values of the unit, for the size of the unit representing a value, for the scaling of the net, for a displacement of the net, and the matrix for rotation of the net. The resulting matrix transforms the vectors of the standard cube by unit_transformation. Finally a central projection is performed by d3_projection if that option was selected.

  unit_transformation: In this routine, the vectors of the standard cube are multiplied by the transformation matrix.

  insert_center_vector: The transformed center of the unit is written to the unit structure of the kernel by krui_setUnitCenters.

  d3_drawWireframeCube: This function draws a ``transparent'' unit. The eight transformed vectors of the unit corners are connected with each other according to the entries in the d3_cube_lines array. The drawing is performed by the low level routine d3_drawLine ( graph.c)

  d3_drawSolidCube: This subprogram draws a ``massive`` unit. The corner points of the planes are defined by the array d3_vertex_index in global.c. If no value is to be displayed by the color of the unit, the brightness is computed for all six planes of the cube. For this purpose, d3_normalVector ( anageo.c) computes a vector perpendicular to the plane. d3_shadeIntens in module shade.c takes the position of the light source, the normal vector of the plane, and a vector on the plane and computes the intensity value for the plane. This is converted to a palette index by d3_intens_to_grayval and activated by d3_setColor ( draw.c). If a value is to be displayed by the color, d3_getColorValue determines the appropriate color value and d3_value_to_color the palette index. Then d3_drawPoly ( graph.c) draws the plane.

  d3_shadeIntens: Here the intensity of the light source is computed. The value varies between -1 and 1.

  d3_getColorValue: This function returns a value in the range . The value may represent the activation, initial activation, output, or threshold of the unit.

  d3_labelUnit: To label a unit, the appropriate value is converted to a string. Then, the position for the string is computed. The function get_label_vert_indices did already compute the index of the corner. If the label is to be put at the upper corner, the y-coordinate has to be adjusted by the font height. The string is drawn by a call to d3_draw_string in module fonts.c.

  draw_links: This function draws the links in a network. For each unit the numbers of all units connected with the current one are obtained by krui_getFirstPredUnit and krui_getNextPredUnit. Additionally the weight of the connection is stored. The coordinates of the units to be connected are determined by krui_getUnitCenters. A link is either black, or gets a color assigned by d3_setLinkColor which corresponds to its weight. The drawing is performed by the functions d3_drawWireframeLine or d3_drawSolidLine in module draw.c. An optional labeling with the weight is performed by a call to d3_labelLink.

  d3_setLinkColor: The color of a link is determined by its weight. For this purpose the weight is converted to the interval with the scale factor d3_state.link_scale. Bigger weights get the value 1, smaller ones -1. The implementation is analogous to the 2D--display.

  d3_drawWireframeLine: To draw a link in the wire frame model, the vector is rounded and drawn by the function d3_drawLine ( graph.c).

  d3_drawSolidLine: The points of a link in solid model display are computed from the line equation and drawn with d3_putPixel.

  d3_labelLink: This routine writes the weight of a link at the center of the link. The center between head and tail is given by the line equation with = 0.5. The value is put at this position with d3_draw_string.



next up previous contents index
Next: Low Level Drawing Up: 3D-Display Implementation Previous: Global Data Types



Niels Mache
Wed May 17 11:23:58 MET DST 1995