Line Object


Introduction

Line objects are created using function
XintView3DCreateLine. Two types of lines are supported, XintOBJECT_LINE_SEGMENT and XintOBJECT_LINE_POLYLINE. Set the line type to XintOBJECT_LINE_SEGMENT to create one or more discontinuous line segments. Set the line type to XintOBJECT_LINE_POLYLINE to create a polyline.

Function XintView3DCreateLine lets the application specify a list of indices using arguments vertices/num_vertices. This list specifies how to traverse the list of vertices when drawing the lines. In most cases argument indices should be set to NULL so that the list of indices is automatically generated by the line creation function (set to 0,1,2... num_verts-1). Only in special circumstances will you need to specify your own list of indices. An example would be a case where you need to draw a pattern requiring you to traverse some points multiple times. In this case it may be more efficient to specify an index list rather than having to duplicate the points in the list of vertices.

The example below illustrates how to specify the arguments vertices and indices to draw the pattern shown below.





Material Types

The line object supports all material types. In most cases, you will use material types XintMATERIAL_SINGLE_COLOR or XintMATERIAL_COLOR_INDEX to specify a single color for the entire line. Material types XintMATERIAL_COLOR_RANGE and XintMATERIAL_COLOR_SCALE can be used to specify a color range or color scale. Finally, material types XintMATERIAL_COLOR_INDEX or XintMATERIAL_COLOR_MULTI can be used to specify a different color at each of the line vertices.

Some material attributes are ignored for Line objects. In particular, Line objects do not support lighting, and the material draw mode XintFILL is equivalent to XintLINE. The attribute specifying whether or not to draw grid lines is also ignored.


Example

The following code sample illustrates how to create a polyline object with varying line color as a function of the Z value.

    #include <stdio.h>
    #include <Xint/View3D.h>

    #define NV 100

    main(int argc, char **argv) 
    {
       int i;
       XtAppContext                 app_context;
       Widget                       top_level, view3d;
       XintVector3                  *vertices;
       XintView3DObject             *line;
       XintView3DMaterial           *material;
       XintView3DMaterialColor      color_range;
       XintView3DMaterialAttributes attributes;

       /* Initialize the application */
       top_level = XtVaAppInitialize(&app_context, "line_1",
                                     NULL, 0, &argc, argv, NULL, NULL);

       /* Create a View3D widget */
       view3d = XtVaCreateManagedWidget("Viewer3D", xintView3DWidgetClass, 
                                        top_level, 
                                        XmNwidth, 400, 
                                        XmNheight, 400, 
                                        NULL);

       /* Create a color range material */
       color_range.range.range_direction = XintINTERPOLATE_Z;
       color_range.range.interp_method = XintINTERPOLATE_LINEAR;
       color_range.range.across_object = False;
       color_range.range.color_model = XintCOLOR_MODEL_HSV;

       color_range.range.min_color[0] = 1.0;
       color_range.range.min_color[1] = 0.0;
       color_range.range.min_color[2] = 0.0;
       color_range.range.min_color[3] = 1.0;

       color_range.range.max_color[0] = 0.0;
       color_range.range.max_color[1] = 0.0;
       color_range.range.max_color[2] = 1.0;
       color_range.range.max_color[3] = 1.0;

       attributes.light = False;
       attributes.draw_mode = XintDRAW_LINE;
       material = XintView3DCreateMaterial(NULL, XintMATERIAL_RANGE_COLOR, 
                                           &color_range,
                                           XintMA_LIGHT | XintMA_DRAW_MODE,
                                           &attributes);

       /* Generate line points */
       vertices = (XintVector3 *) XtMalloc(sizeof(XintVector3) * NV);

       for (i=0; i < NV; i++) {
            vertices[i][0] = sin((double) i/10.);
            vertices[i][1] = cos((double) i/10.);
            vertices[i][2] = cos((double) i/7.);
       }

       /* Create line object */
       line = XintView3DCreateLine("line", XintOBJECT_LINE_POLYLINE,
                                   2.0, NV, vertices, 0, 
                                   NULL, True, NULL, NULL);

       /* Free the vertices */
       XtFree((char *) vertices);

       /* Add object to display */
       XintView3DAddObjectAndMaterial(view3d, line, material, NULL);
  
       XtRealizeWidget(top_level);
       XtAppMainLoop(app_context);
    }

The output of this code example is shown below:


Figure 16: Line with color varying along the Z value