TOC PREV NEXT INDEX

The Graphics Display Kit


5

Interactivity

This chapter describes the Graphics Display Kit's facilities that allow the user to interactively draw and edit 2D objects in a view.

This chapter discusses:

5.1 Introduction

The Graphics Display Kit has a flexible pipeline for constructing and editing 2D objects. This process can be broken down into the following stages:

This chapter provides conceptual material describing this process and a series of examples to illustrate the process.

5.2 Constructing the drawing

The first step in the interactive 2D drawing pipeline is the construction of the drawing in screen space coordinates.

Two modules are provided for construction: GDroi2d_cont and GDroi2d_click. The two modules produce the same end result (that is, a screen space drawing) but use a different method of construction. The major inputs to these modules are a view and screen space XY coordinates. The module obtains an input view by connecting downstream of one of the viewers provided in the Graphics Display Kit. This is done so the modules can draw on top of the existing contents of the view without having to rerender all the objects currently in the view if possible.

Part of the Graphics Display Kit API provides routines that do drawing directly in screen space coordinates. This part of the API is a thin layer built directly on top of the windowing system, so modules built with it are portable between X Windows and Win32. The screen space XY coordinates are typically obtained by connecting to a UI interactor. The UI interactor effectively puts you inside the window system event loop. It also provides you with the ability to easily change the gesture that causes the XY positions to be generated since that specification is part of the UI interactor.

The GDroi2d_cont module generates the drawing with a continuous stream of screen space XY positions typically fed to the module from a UItwoPoint interactor. With this method of interaction, you can generate a drawing with one smooth, continuous motion of the input device. The disadvantage of this method is that it does not allow you a chance to edit the drawing during the construction process. The following V code describes the GDroi2d_cont module.

group GDroi2d_cont_notify_templ {
int+IPort2 state; /* from UItwoPoint */
int+IPort2 clear;
int+IPort2 done;
int+IPort2 redraw;
method+notify_inst init = "GDroi2d_cont_create";
method+notify_del delete = "GDroi2d_cont_delete";
method+notify_val update = "GDroi2d_cont_update";
};
GDroi2d_cont_notify_templ GDroi2d_cont_templ {
GDview_templ+IPort2 &view_in;
int+IPort2 x;
int+IPort2 y;
int draw_mode; /* 0=copy, 1=xor */
int mode; /* 0=clear, 1=append */
int option; /* 0=point, 1=line, 2=box,3=polyline,4=polygon */
int immed; /* 0=confirm, 1=on button up */
float red, green, blue;
GDroi2d_buffer+OPort2 out_buf;
ptr+nonotify+nosave local_ptr;
};

The GDroi2d_click module generates a drawing with screen space XY positions provided one at a time typically from a UIonePoint interactor. With this method of construction, you have the opportunity to more accurately place each point in the drawing and to erase points as needed during the construction process. The add, erase, and close elements are also typically connected to UIonePoint interactors. Included below is the V description of the GDroi2d_click module.

group GDroi2d_click_notify_templ {
int+IPort2 add;
int+IPort2 erase;
int+IPort2 close;
int+IPort2 clear;
int+IPort2 done;
int+IPort2 redraw;
method+notify_inst init = "GDroi2d_click_create";
method+notify_del delete = "GDroi2d_click_delete";
method+notify_val update = "GDroi2d_click_update";
};
GDroi2d_click_notify_templ GDroi2d_click_templ {
GDview_templ+IPort2 &view_in;
int+IPort2 x;
int+IPort2 y;
int mode; /* 0=clear, 1=append */
int option; /* 0=point, 1=line, 2=box, 3=polyline, 4=polygon */
int immed; /* 0=confirm, 1=on button up */
float red, green, blue;
GDroi2d_buffer+OPort2 out_buf;
ptr+nonotify+nosave local_ptr;
};

The output of these modules is a buffer of screen space coordinates - GDroi2d_buffer. It is important to note that the points in the drawing that are generated are kept in the module's internal buffer until you commit to the drawing. This keeps any modules connected to the construction module from running until that time. This provides a tight loop during construction composed of the UIinteractor that is generating the XY screen space coordinates and one of the Graphics Display Kit's construction modules.

There are a number of additional parameters to the modules that control their operation. The value of option determines what type of primitive is built. Supported types of primitives are points, lines, boxes, polylines and polygons. The value of mode determines if the new primitive is appended to the internal buffer or if it replaces whatever primitive(s) might be in the internal buffer. The values of the red, green, and blue parameters are used as the color to draw the primitives during construction. This is termed the "build" color. The value of immed determines if the internal buffer is written to the output buffer when the primitive is completed or if the write to the output buffer happens when the value of done changes. When a change of unset is detected, both the internal local buffer and the output buffer are cleared.

5.3 Mapping the drawing

The second step of the interactive 2D drawing pipeline is the mapping of the screen space coordinates into world space.

The GDmap2d_ss module performs the mapping from screen space to world space. This module accepts a GDroi2d_buffer as input. As described previously, this buffer contains the screen points that represent the drawing that you have generated and committed to. The other required inputs for the module are a view and a camera. The view and camera are needed to be able to determine the mapping from screen space to world space. An object is an optional input to the module. When the module executes, if an object does not exist, the screen points are mapped into the coordinate system of the camera. If the object does exist, the points are mapped into the same coordinate system as the object.

Included below is the V description of the GDmap2d_ss module.

group GDmap2d_ss_notify_templ {
GDroi2d_buffer+IPort2 &in_buf;
int clear;
method+notify_val update = "GDmap2d_ss_update";
};

GDmap2d_ss_notify_templ GDmap2d_ss_templ {
GDview_templ+IPort2 &view_in;
GDcamera_templ+IPort2 &cam_in;
GDobject_templ+IPort2 &obj_in;
int mode /* 0 = clear, 1 = append */
string name;
int color; /* 0=no cell data, 1=cell data colors */
float red, green, blue;
Mesh+Cell_Data+OPort2 out_mesh {
&xform => obj_in.xform;
};
};

The output of the GDmap2d_ss module is an AVS/Express field (that is, Mesh) that contains the drawing. This field can now be input to a GDobject that in turn can be input to a viewer to be rendered as part of the normal rendering pipeline.

Once the drawing is converted into an AVS/Express field, it can be picked with the normal picking process, zoomed and panned, have its attributes changed and so on. It should be noted that all the attributes (for example, line width and line style) at this point are on a per field basis. This means that if a field has multiple primitives, the attributes cannot be changed individually.

There are a number of additional parameters to the module that control its operation. The value of mode determines if the output mesh is either replaced or appended to. The value of color determines if the red, green, and blue values are written to the output mesh as cell colors. This color is termed the "map" color. A name, if provided, is written as the cell set name in the output mesh. This name can be used by other modules as a filter. Two of the existing AVS/Express modules that can use this name are select cells and vector2raster.

There is a tremendous amount of flexibility due to the number of combinations that are available.A good example of how the field is used by modules that take it as input is in the construction of region of interests (ROIs) in a medical imaging application. The user can have a name attached to each ROI or set of ROIs. This is possible to do by using the proper combinations of modes. The various combinations and their effect on the output mesh are outlined below.

In this case, each setting of done in the construct module causes a mesh of one cell set with one cell to be written. The cell can be either a point, line, box, or polyline/polygon. The new mesh overwrites any existing mesh.

In this case, each setting of done in the construct module causes a mesh of up to four cell sets - each with n cells to be written. There is one cell set for each different type of cell - point, line, box, or polyline/polygon. The new mesh overwrites any existing mesh.

In this case, each setting of done in the construct module causes one cell set with one cell to be appended to any existing mesh. The cell can be either a point, line, box, or polyline/polygon.

In this case, each setting of done in the construct module causes up to four cell sets - each with n cells to be appended to any existing mesh. There is one cell set for each different type of cell - point, line, box, or polyline/polygon.

5.4 Editing the drawing

The third step of the interactive 2D drawing pipeline is the highlighting and editing of the world space coordinates. This is a two stage process. First, you must select the object to edit using the normal pick process. When the selection occurs, all or part of the object is highlighted. Then, you can move the highlighted section of the object around. The edit is committed to the AVS/Express field under your control. Much like the construction process, the edit takes place locally. This allows the drawing in response to the edits to be done directly in screen space coordinates. The changes are then mapped back into world space coordinates when you commit to the edit.

The GDedit_mesh module performs the editing. This module accepts as input an object to edit. Typically, this module connects to the picked object output port from one of the standard viewers in the Graphics Display Kit. In this way, when an object is picked, the edit mesh module runs and gets an opportunity to highlight the item that was picked. The field that is attached to the object is what is edited. The other inputs to the module are screen space XY coordinates that are used to move the selected object. These values are normally attached to a UItwoPoint interactor. The other required inputs to the module are a view and camera. As in the mapping stage, these are used by the module to map screen space coordinates into world space.

Included below is the V description of the GDedit_mesh module.

group GDedit_mesh_notify_templ {
int+IPort2 state;
int+IPort2 done;
int+IPort2 remove;
GDobject_templ+IPort2 *picked_obj;
method+notify_inst init = "GDedit_mesh_create";
method+notify_del delete = "GDedit_mesh_delete";
method+notify_val update = "GDedit_mesh_update";
};

GDedit_mesh_notify_templ GDedit_mesh_templ {
int+IPort2 x;
int+IPort2 y;
int mode; /* 0=edit point, 1=edit prim 2=edit cell */
int immed; /* 0=confirm, 1=on button up */
float red, green, blue;
GDview_templ+IPort2 &view_in;
GDcamera_templ+IPort2 &cam_in;
ptr+nonotify+nosave local_ptr;
};

The output of this module is changes to the mesh that are attached to the picked object.

There are a number of additional parameters to the module that control its operation. The value of mode determines if a point, primitive, or cell is highlighted and then edited. The value of immed determines if the field is updated immediately when the user interface gesture is completed or if an explicit confirmation is required. A change to the done value provides the explicit confirmation. A change to the remove value causes the currently highlighted point, primitive, or cell to be removed from the output field. The red, green, and blue values are the colors used to perform the highlight.

5.5 Converting vector data to raster data

The final step in the ROI pipeline, after construction, mapping, and editing is the conversion of the vector information into raster information for use by subsequent image processing routines.

The GDvector2raster module performs this conversion. The input to this module is an AVS/Express field, typically output from either the GDmap2d_ss or GDedit_mesh modules. The output of the module is a byte image that contains either the value 0 or 255 at each point in the image. A value of 255 indicates to the image processing routine that the pixel is to be processed.

The inside element controls if the image generated is either inside or outside the vector ROIs provided. A value of 0 means generate the image outside the ROIs provided, a value of 1 means generate the image inside the ROIs provided.

A name element is provided to allow the input vector ROIs to be filtered based on a name. If the name is the empty string, all ROIs are processed. If a name is provided, only those ROIs that have a name that matches are processed.

The V code for the GDvector2raster module is as follows:

group GDvector2raster_notify_templ {
Mesh+Iparam &input;
int inside;
string name;
Field_Unif+Dim2+Space2+Oparam output;
method+notify_val upd_func = "GDvector2raster_update";
};
GDvector2raster_notify_templ GDvector2raster_templ {
GDobject_templ+IPort2 &obj_in;
};
5.6 Components

There are several higher-level macros that bundle sets of modules and user interfaces that aid in the process of drawing ROIs. They are as follows:

5.7 Examples

The remainder of this chapter contains examples of the use of the Graphics Display Kit's a flexible pipeline for constructing and editing 2D objects. These show you how to:

5.8 Sketch in a 2D view, display in a 3D view

The following example illustrates how to use the ClickSketch module to draw on top of a slice from a volume. The drawing that is produced from the ClickSketch module is subsequently displayed in both a 2D and 3D view.

5.8.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.8.2 Instance the example
2. Instance ClickSketch into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. Upon being instanced, the example renders a slice from hydrogen in both viewer's windows. In the 2D view, the slice, rendered as a image, appears normalized in the view. In the 3D view, the slice, rendered as a mesh, appears normalized in the view.

5.8.3 Construct the drawing

We are now ready to construct a drawing in the 2D view.

3. Select Editors->Modules to make the modules user interface panel visible. Select ClickSketch from the Modules option menu. This causes the user interface for the ClickSketch module to appear.

By default, the ClickSketch module is set up to draw a polyline. Other primitives that are available are point, line, box, and polygon.

4. Choose the primitive that you want to generate from the radio box options at the top of the ClickSketch user interface.
5. Begin building a drawing, using the add point operation.

The mouse operations that control the drawing in the ClickSketch module are:

Mouse-controlled operations
Gesture
Add point
Press the right button.
Erase point
Hold down the Shift key and press the right button.
Close region
Hold down the Control key and press the right button. This completes the primitive that is in progress. This operation applies only to the polyline and polygon primitives.

If you have chosen:

6. Conversion of screen space primitives into an AVS/Express field.

This example has the ClickSketch module configured so that upon completion of a primitive it is immediately converted into an AVS/Express field. When this happens, the color of the primitives you have drawn on the slice changes from the build color to either the map color, if the Use Map Color toggle is set, or the primary color as specified by the Graphics Display Kit object's properties.

This example touches on only a small portion of the functionality in the ClickSketch module. For more information on the construction and mapping phases of the Graphics Display Kit's interactive 2D drawing capabilities, see

Section 5.2, Constructing the drawing  [page 5-3]
Section 5.3, Mapping the drawing  [page 5-7]
5.8.4 View the drawing in the 3D view

Once the drawing is converted into an AVS/Express field, you can also view it in the 3D view.

5.8.5 Cleanup

This completes the example.

7. Delete the ClickSketch application.
5.9 Sketch and edit in a 2D view

The following example illustrates how to use the EditMesh module to edit a drawing that has been built using the ClickSketch module on top of a slice from a volume.

5.9.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.9.2 Instance the example
2. Instance EditMesh into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. Upon being instanced, the example renders a slice from hydrogen.fld in the viewer's window.

5.9.3 Construct the drawing

We are now ready to construct a drawing in the view.

3. Select Editors->Modules to make the modules user interface panel visible. Select ClickSketch from the Modules option menu. This causes the user interface for the ClickSketch module to appear.

By default, the ClickSketch module is set up to draw a polyline. Other primitives that are available are point, line, box, and polygon.

4. Choose the type of primitive that you want to generate from the radio box options at the top of the ClickSketch user interface.
5. Begin building a drawing, using the add point operation.

The mouse operations that control the drawing in the ClickSketch module are:

Mouse-controlled operations
Gesture
Add point
Press the right button.
Erase point
Hold down the Shift key and press the right button.
Close region
Hold down the Control key and press the right button. This completes the primitive that is in progress. This operation applies only to the polyline and polygon primitives.

If you have chosen:

6. Conversion of screen space primitives into an AVS/Express field.

This example has the ClickSketch module configured so that upon completion of a primitive it is immediately converted into an AVS/Express field. When this happens, the color of the primitives you have drawn on the slice changes from the build color to either the map color, if the Use Map Color toggle is set, or the primary color as specified by the Graphics Display Kit object's properties.

This touches on only a small portion of the capabilities in the ClickSketch module. For more information on the construction and mapping phases of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.2, Constructing the drawing  [page 5-3]
Section 5.3, Mapping the drawing  [page 5-7]
5.9.4 Edit the drawing

We are now ready to edit the drawing in the view.

7. Select EditMesh from the Modules option menu. This causes the user interface for the EditMesh module to appear.

By default, the EditMesh is set up to edit a primitive. Points or cells can also be edited.

8. Select to edit either a point, primitive or cell from the radio box options at the top of the EditMesh user interface.
9. Edit the drawing by performing a select/move primitive operation.

The mouse operations that control editing in the EditMesh module are:

Mouse-controlled operations
Gesture
Select
Press Control left button while the mouse is over a point or line in the drawing.
Move primitive
Hold down the Control key and drag the primitive while depressing the middle button.

When the select operation takes place, the point, primitive or cell selected is drawn in the highlight color. The highlight of the point is done with a small rectangle.

When the move primitive operation is in progress, the current position of the updated primitive is echoed in the highlight color. By default, the EditMesh module is configured so when the move primitive operation is completed, the field is updated. This causes the drawing to be rerendered to reflect its new contents.

Points, primitives, and cells may also deleted by clicking on the Delete button after a select operation is done.

For more information on the edit phase of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.4, Editing the drawing  [page 5-10]
5.9.5 Cleanup

This completes the example.

10. Delete the EditMesh application.
5.10 Draw a region of interest (ROI)

The following example illustrates how to use ClickSketch in a network to draw an ROI on top of an image. The vector ROI that is produced from the ClickSketch module can subsequently be edited with the EditMesh module. The vector ROI is also converted to a raster mask by the Vector2Raster module and then displayed in another view. Typically, this mask would be an input to various image processing routines.

5.10.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.10.2 Instance the example
2. Instance ROIdraw into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. Upon instancing, the example renders an image of the mandrill in one of the viewer's window. The other view has nothing rendered in it initially.

5.10.3 Construct the drawing

We are now ready to construct a drawing in the view.

3. Select Editors->Modules to make the modules user interface panel visible. Select ClickSketch from the Modules option menu. This causes the user interface for the ClickSketch module to appear.

By default, the ClickSketch module is set up to draw a polygon. Other primitives that are available are point, line, box, and polygon. In this example, we must use either the box or the polygon primitive since we are drawing a region and it must be closed for proper operation.

4. Begin building a polygon, using the add point operation.

The mouse operations that control the drawing in the ClickSketch module are:

Mouse-controlled operations
Gesture
Add point
Press the right button.
Erase point
Hold down the Shift key and press the right button.
Close region
Hold down the Control key and press the right button. This completes the primitive that is in progress. This operation applies only to the polyline and polygon primitives.

Since you have chosen the polygon primitive, each add point operation adds another point to the polygon. The polygon is terminated and automatically closed with the close operation.

5. Conversion of screen space primitives into an AVS/Express field.

This example has the ClickSketch module configured so that upon completion of a polygon it is immediately converted into an AVS/Express field. When this happens, the color of the primitives you have drawn on the slice changes from the build color to either the map color, if the Use Map Color toggle is set, or the primary color as specified by the Graphics Display Kit object's properties.

This touches on only a small portion of the capabilities in the ClickSketch module. For more information on the construction and mapping phases of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.2, Constructing the drawing  [page 5-3]
Section 5.3, Mapping the drawing  [page 5-7]
5.10.4 Convert the polygons to a raster mask

We can now see the raster mask that has been created from the polygon(s) that have been output from the ClickSketch module in the second view. This mask has been rendered as an image that has two different values, 0 meaning outside and 255 meaning inside. A value of 0 is rendered as blue and a value of 255 is rendered as red.

6. Select Vector2Raster from the Modules option menu. This causes the user interface for the Vector2Raster module to appear.
7. Toggle Inside in the Vector2Raster user interface.

By default, Inside was set. This caused the Vector2Raster module to set any pixels inside the polygons to 255 and any values outside the polygons to 0. By toggling Inside, the Vector2Raster module now sets any pixels inside the polygons to 0 and any pixels outside the polygons to 255.

The field that represents this image can be used as input to many of the image processing routines to control which pixels in the image are actually processed.

For more information on the vector-to-raster phase of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.5, Converting vector data to raster data  [page 5-13]
5.10.5 Edit the drawing

We are now ready to edit the drawing in the view and observe the effect that the edit has on the raster mask.

8. Select EditMesh from the Modules option menu. This causes the user interface for the EditMesh module to appear.

By default, the EditMesh is set up to edit a primitive. Points or cells can also be edited.

9. Select either a point, primitive, or cell to edit from the radio box options at the top of the EditMesh user interface.
10. Edit the drawing by performing a select/move primitive operation.

The mouse operations that control editing in the EditMesh module are:

Mouse-controlled operations
Gesture
Select
Press Control left button while the mouse is over a point or line in the drawing.
Move primitive
Hold down the Control key and drag the primitive while depressing the middle button.

When the select operation takes place, the point, primitive or cell selected is drawn in the highlight color. The highlight of the point is done with a small rectangle.

When the move primitive operation is in progress, the current position of the updated primitive is echoed in the highlight color. By default, the EditMesh module is configured so when the move primitive operation is completed, the field is updated. This causes the drawing to be rerendered to reflect its new contents.

Points, primitives, and cells may also deleted by clicking on the Delete button after a select operation is done.

Notice that any edit that is performed is immediately reflected in the appearance of the raster mask in the other view.

For more information on the edit phase of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.4, Editing the drawing  [page 5-10]
5.10.6 Cleanup

This completes the example.

11. Delete the ROIdraw application.
5.11 Crop a 3D region

Another example that involves some of the interactive 2D drawing modules is to select a region within an image in a 2D view using the ContinuousSketch module. The selected region is then displayed as a surface in a 3D view.

5.11.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.11.2 Instance the example
2. Instance RegionCrop3D into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. The example renders the image of Mount St. Helens in the 2D viewer's window. The image appears normalized in the view. The 3D view has nothing rendered in it initially.

5.11.3 Select a region from the image

We are now ready to select a region in the image to be displayed as a surface in the 3D view.

3. Select Editors->Modules to make the modules user interface panel visible. Select ContinuousSketch from the Modules option menu. This causes the user interface for the ContinuousSketch module to appear.
4. Begin drawing a box, using the draw primitive operation.

The mouse operations that control the drawing in the ContinuousSketch module are:

Mouse-controlled operations
Gesture
Draw primitive
Hold down the right button, and drag the mouse.

In this example, the ContinuousSketch module is set up to draw a box in XOR mode. Once the operation is complete (that is, the right mouse button is released), the box is converted into a field since the Immediate toggle is set.

The extents of this field are used as input parameters by the region crop module to select the region to display in the 3D view. Note that region crop is a macro that was built for this example. The V code for it can be found in v/gd_examp/GDinter5.v.

This touches on only a small portion of the capabilities in the ContinuousSketch module. For more information on the construction and mapping phases of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.2, Constructing the drawing  [page 5-3]
Section 5.3, Mapping the drawing  [page 5-7]
5.11.4 View the region in the 3D view

Once a region is selected in the image, you can also view it as a surface in the 3D view.

5. Look at the selected region in the 3D view.

A completely new region can be selected by repeating the same process that was used to generate the initial region.

5.11.5 Edit the region

Alternatively, we can edit the region in the 2D view and observe the effect that it has on the surface in the 3D view.

6. Select EditMesh from the Modules option menu. This causes the user interface for the EditMesh module to appear in the ModuleStack window.

In this example, the EditMesh is set up to edit a cell.

7. Edit the drawing by performing a select/move primitive operation.

The mouse operations that control editing in the EditMesh module are:

Mouse-controlled operations
Gesture
Select
Press Control left button while the mouse is over a point or line in the drawing.
Move primitive
Hold down the Control key and drag the primitive while depressing the middle button.

When the select operation takes place, the region is drawn in the highlight color.

When the move primitive operation is in progress, the current position of the updated region is echoed in the highlight color. By default, the EditMesh module is configured so when the move primitive operation is completed, the field is updated. This causes a new region to be cropped from the image and rendered in the 3D view as a surface.

For more information on the edit phase of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.4, Editing the drawing  [page 5-10]
5.11.6 Cleanup

This completes the example.

8. Delete the RegionCrop3D application.
5.12 Cropping a 2D region

Another useful example is when one view displays a filtered down version of a large image and the second view displays a section of the image at full resolution. This uses the ContinuousSketch to select a region within an image.

5.12.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.12.2 Instance the example
2. Instance RegionCrop2D into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. Upon being instanced, the example renders an image of Mount St. Helens in the 2D viewer's window. The second 2D view has nothing rendered in it initially.

5.12.3 Select a region from the image

We are now ready to select a region in the image to be displayed in the second 2D view.

3. Select Editors->Modules to make the modules user interface panel visible. Select ContinuousSketch from the Modules option menu. This causes the user interface for the ContinuousSketch module to appear.
4. Begin drawing a box, using the draw primitive operation.

The mouse operations that control the drawing in the ContinuousSketch module are:

Mouse-controlled operations
Gesture
Draw primitive
Hold down the right button, and drag the mouse.

In this example, the ContinuousSketch module is set up to draw a box in XOR mode. Once the operation is complete (that is, the right mouse button is released), the box is converted into a field since the Immediate toggle is set.

The extents of this field are used as input parameters by the region crop module to select the region to display in the second 2D view. Note that region crop is a macro that was built for this example. The V code for it can be found in v/gd_examp/GDinter6.v.

This touches on only a small portion of the capabilities in the ContinuousSketch module. For more information on the construction and mapping phases of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.2, Constructing the drawing  [page 5-3]
Section 5.3, Mapping the drawing  [page 5-7]
5.12.4 View the region in the second 2D view

Once a region is selected in the image, you can also view it in the second 2D view.

5. Look at the selected region in the second 2D view.

You can select a completely new region by repeating the same process that was used to generate the initial region.

5.12.5 Edit the region

Alternatively, we can edit the region in the initial 2D view and observe the effect that it has in the second 2D view.

6. Select EditMesh in the Modules option menu. This causes the user interface for the EditMesh module to appear.

In this example, the EditMesh is set up to edit a cell.

7. Edit the drawing by performing a select/move primitive operation.

The mouse operations that control editing in the EditMesh module are:

Mouse-controlled operations
Gesture
Select
Press Control left button while the mouse is over a point or line in the drawing.
Move primitive
Hold down the Control key and drag the primitive while depressing the middle button.

When the select operation takes place, the region is drawn in the highlight color.

When the move primitive operation is in progress, the current position of the updated region is echoed in the highlight color. By default, the EditMesh module is configured so when the move primitive operation is completed, the field is updated. This causes a new region to be cropped from the image and rendered in the second 2D view.

For more information on the edit phase of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.4, Editing the drawing  [page 5-10]
5.12.6 Cleanup

This completes the example.

8. Delete the RegionCrop2D application.
5.13 Probe a location in a 2D view

The following example illustrates how to use the DrawCursor2D module to probe a location in a 2D view. DrawCursor2D is a general module that, given a screen space XY coordinate, translates that position into the coordinate system of any Graphics Display Kit object. A cursor is displayed at the current screen space XY position.

5.13.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.13.2 Instance the example
2. Instance DrawCursor2D into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. The example renders the image avs.x in the viewer's window.

5.13.3 Probe the image

We are now ready to probe positions in the image.

3. Select Editors->Modules to make the modules user interface panel visible. Select DrawCursor2D from the Modules option menu. This causes the user interface for the DrawCursor2D module to appear.
4. Begin probing the view using the cursor.

The mouse operations that control the drawing of the cursor are:

Mouse-controlled operations
Gesture
Probe position
Hold down the right button, and drag the mouse.

The DrawCursor2D module displays the XY position it is probing in its user interface. By default, the module updates the XY position every time it gets a new screen space input.

5. Toggle Immediate.

This causes the XY position to be updated only when the right mouse button has been released (that is, at the end of the gesture).

The avs.x image has dimensions of 628 by 184. Notice that when the cursor is inside the extents of the image, the values displayed in the DrawCursor2D user interface for X are in the range 0 to 627 and for Y in the range of 0 to 183.

6. In the application workspace, disconnect Read_Image.image and DrawCursor2D.obj_in.
7. Begin probing the view using the cursor.

Notice that the values displayed in the DrawCursor2D user interface now range from -5 in the lower left to 5 in the upper right. This is the default coordinate system of the camera. When there is no object as input to DrawCursor2D, the screen space positions are translated into the camera's coordinate system.

8. Toggle Cross

This causes a cross of the specified size and thickness to be displayed when probing instead of a full-screen cross hair cursor.

5.13.4 Cleanup

This completes the example.

9. Delete the DrawCursor2D application.
5.14 Probe a value in a 2D view

The DrawCursor2D module can be used to probe locations in a 2D view. DrawCursor2D is a general module that, given a screen space XY coordinate, translates that position into the coordinate system of any Graphics Display Kit object.

The following example shows how to extend the DrawCursor2D module to also return the value of the image at the XY position.

5.14.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.14.2 Instance the example
2. Instance ImageProbe into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. The example renders the image mandrill.x in the viewer's window.

5.14.3 Probe the image

We are now ready to probe values in the image.

3. Select Editors->Modules to make the modules user interface panel visible. Select DrawCursor2D from the Modules option menu. This causes the user interface for the DrawCursor2D module to appear.
4. Toggle Immediate.

This causes the XY position to be updated only when the right mouse button has been released (that is, at the end of the gesture).

5. Begin probing the view using the cursor.

The mouse operations that control the drawing of the cursor are:

Mouse-controlled operations
Gesture
Probe position
Hold down the right button, and drag the mouse.

The mandrill.x image has dimensions of 500 by 480. Note that when the cursor is inside the extents of the image, the values displayed in the DrawCursor2D user interface for X are in the range 0 to 499 and for Y in the range of 0 to 479.

6. In the application workspace, look at the image values.
a. Maximize interp_data.
b. Open DVinterpolate_data.
c. Open out_nd.
d. Open the node_data array. It should look like "node_data[1]".
e. Scroll up to find the node_data array. It should have two arrows on it to indicate that it is an array. Press the right arrow once to access the first (and only) entry of the array.
f. Open the values array. It should look like "values[1][4]".
g. Resize DVinterpolate_data so you can easily see all four entries in the array.

The entries in the array are in order alpha, red, green, and blue. The range for the values is 0 to 255. Notice that if you probe the mandrill's nose which is a shade of red that the red value is dominate. Note that if you probe the mandrill's cheeks which are a shade of blue that the blue value is dominate.

5.14.4 Cleanup

This completes the example.

7. Delete the ImageProbe application.
5.15 Probe locations on a 2D line

The following example illustrates how to use the DrawLine2D module to probe the locations on a line in a 2D view. DrawLine2D is a general module that, given a screen space line represented by two endpoints, translates those endpoints into the coordinate system of any Graphics Display Kit object.

5.15.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.15.2 Instance the example
2. Instance DrawLine2D into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. Upon being instanced, the example renders a slice from hydrogen.fld in the viewer's window.

5.15.3 Probe the slice

We are now ready to probe positions in the view.

3. Select Editors->Modules to make the modules user interface panel visible. Select DrawLine2D from the Modules option menu. This causes the user interface for the DrawLine2D module to appear.
4. Begin probing the view by drawing a line.

The mouse operations that control the line drawing are:

Mouse-controlled operations
Gesture
Draw line.
Hold down the right button, and drag the mouse.

The DrawLine2D module draws a line from the start position to the end position. As long as the right button is held down the a line is drawn from the start position to the current end position. When the right button is released, the line is converted into a field.

Note: If you are using the OpenGL renderer, you may notice that the image of the line flashes as it is drawn.This is because OpenGL only supports single-buffering of 2D primitives. You can reduce the flashing by selecting Xor instead of Copy mode in the DrawLine2D module interface.

The start and end points of the line are then displayed in the user interface for the DrawLine2D module. By default, the module updates the XY position immediately when the right button is released.

5. Toggle Immediate.

This causes the XY position to be updated only when the Measure button is clicked.

The slice of hydrogen has dimensions of 64 by 64. Notice that when the line is inside the extents of the slice, the values displayed in the DrawLine2D user interface for X and Y are in the range 0 to 64.

6. In the Network Editor workspace, disconnect reset_xform.out_obj from DrawLine2D. This port on DrawLine2D is a connection to the obj_in subobject.
7. Begin probing the view by drawing a line.

When you click the Measure button, notice that the line is drawn in the lower left, and the values displayed in the DrawLine2D user interface now range from -5 in the lower left to 5 in the upper right. This is the default coordinate system of the camera. Because you are no longer passing the object from reset_xform as input to DrawLine2D, the screen space positions are translated into the Uviewer camera's coordinate system.

5.15.4 Cleanup

This completes the example.

8. Delete the DrawLine2D application.
5.16 Measure images

One use of the DrawLine2D module is for probing and measuring images. The output of the DrawLine2D module, two XY positions, can be used in a number of different ways:

5.16.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.16.2 Instance the example
2. Instance ImageMeasure into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. Upon being instanced, the example renders a slice from wind.fld in the viewer's window.

5.16.3 Probe the slice

We are now ready to probe values in the slice.

3. Select Editors->Modules to make the modules user interface panel visible. Select DrawLine2D from the Modules option menu. This causes the user interface for the DrawLine2D module to appear.
4. Begin probing the view by drawing a line.

The mouse operations that control the line drawing are:

Mouse-controlled operations
Gesture
Draw line.
Hold down right button, and drag the mouse.

The DrawLine2D module draws a line from the start position to the end position As long as the right button is held down the a line is drawn from the start position to the current end position. When the right button is released, the line is converted into a field.

The start and end points of the line are then displayed in the user interface for the DrawLine2D module. By default, the module updates the XY position immediately when the right button is released.

The slice of wind.fld has dimensions of 25 by 32. Notice that when the line is inside the extents of the slice, the values displayed in the DrawLine2D user interface for X and Y are in that range.

5. In the ModuleStack workspace, look at the slice values.
a. Maximize interp_data.
b. Open DVinterpolate_data.
c. Open out_nd.
d. Open the node_data array. It should look like "node_data[1]".
e. Scroll up to find the node_data array. It should have two arrows on it to indicate that it is an array. Press the right arrow once to access the first (and only) entry of the array.
f. Open the values array. It should look like "values[2][1]".
g. Resize DVinterpolate_data so you can easily see both entries in the array.

The entries in the array are in order the scalar value at the start point and the scalar value at the end point. In this case, the scalars are of type float.

5.16.4 Cleanup

This completes the example.

6. Delete the ImageMeasure application.
5.17 Place annotation interactively

The drawing modules can be used to place annotation interactively. This example uses the ClickSketch and text_glyph modules to do this. A text string is rendered at each coordinate in the field created by the drawing module.

5.17.1 Starting up
1. Start AVS/Express and choose None from the startup dialog, or if you have an existing AVS/Express session, delete or close any existing application workspaces that you have open.
5.17.2 Instance the example
2. Instance ImageAnno into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. Upon being instanced, the he example renders the image avs.x in the viewer's window.

5.17.3 Annotate the image

We are now ready to annotate the image.

3. Select Editors->Modules to make the modules user interface panel visible. Select ClickSketch from the Modules option menu. This causes the user interface for the ClickSketch module to appear.

In this example, the ClickSketch module is set up to draw a polyline. Other primitives that are available are point, line, box, and polygon.

4. Begin drawing a polyline, using the add point operation.

The mouse operations that control the drawing in the ClickSketch module are:

Mouse-controlled operations
Gesture
Add point
Press the right button.
Erase point
Hold down the Shift key and press the right button.
Close region
Hold down the Control key and press the right button. This completes the primitive that is in progress. This operation applies only to the polyline and polygon primitives.

Since you have chosen the polyline primitive, each add point operation adds another point to the polyline. The polyline is terminated and automatically closed with the close operation.

Since the immediate toggle is set in this example, the ClickSketch module converts the polyline to a field as soon as the close region operation is performed.

This touches on only a small portion of the capabilities in the ClickSketch module. For more information on the construction and mapping phases of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.2, Constructing the drawing  [page 5-3]
Section 5.3, Mapping the drawing  [page 5-7]
5. Observe the text strings that have appeared.

As soon as a field is created by the ClickSketch module, text strings appear at each point in the field. The text_glyph module does this by taking a field and an array of strings as input.

5.17.4 Cleanup

This completes the example.

6. Delete the ImageAnno application.
5.18 Calculating Image Statistics

Another example that involves some of the interactive 2D drawing modules is to select a region within an image in a 2D view using the ContinuousSketch module and calculate some simple statistics on the values within that region.


5.18.1 Starting up
1. Start AVS/Express or load a new application with None as the application type, as necessary.
5.18.2 Instance the example
2. Instance ImageStats into the empty NE workspace.

This example is found in Libraries.Examples.Graphics_Display. The example renders the image avs.x into the viewer's window.

5.18.3 Select a region from the image

We are now ready to select a region in the image to calculate statistics.

3. Select Editors->Modules to make the modules user interface panel visible. Select ContinuousSketch from the Modules option menu. This causes the user interface for the ContinuousSketch module to appear.
4. Begin drawing a polygon, using the draw primitive operation.

The mouse operations that control the drawing in the ContinuousSketch module are:

Mouse-controlled operations
Gesture
Draw primitive
Hold down the right button, and drag the mouse.

In this example, the ContinuousSketch module is set up to draw a polygon in COPY mode. Once the operation is complete (that is, the right mouse button is released), the polygon is converted into a field since the Immediate toggle is set.

The polygon converted into a raster mask by the Vector2Raster module. The raster mask is then used by the StatROI macro to calculate some statistics on the pixel values inside the polygon. Note that StatROI is a macro that was built for this example. The V code for it can be found in v/gd_examp/GDinter11.v.

This touches on only a small portion of the capabilities in the ContinuousSketch module. For more information on the construction and mapping phases of the Graphics Display Kit's interactive 2D drawing capability, see

Section 5.2, Constructing the drawing  [page 5-3]
Section 5.3, Mapping the drawing  [page 5-7]
5.18.4 Examining the image statistics

Once a region is selected in the image, you can also view the statistics on the values in that region.

5. Select Statistics from the Modules option menu to make the user interface for this module visible.

This module calculates the mean, minimum, maximum, total, average and standard deviation of the values in the selected region of the image.

5.18.5 Cleanup

This completes the example.

6. Delete the ImageStats application.


TOC PREV NEXT INDEX

Copyright © 2001 Advanced Visual Systems Inc.
All rights reserved.