Defining and using glyphs
A glyph is a defined symbol used to represent a marker, a shell vertex, an element in a line pattern, or a line endpoint such as an arrowhead.
Each Visualize segment has its own attribute setting for the current marker symbol. As glyphs are used as marker symbols, it follows that in order to use different glyphs as markers, you must use different segments. Visualize comes with a number of glyphs predefined and ready to use. A list of these glyphs can be found in the appendix. Before using a pre-defined glyph, you must import it into the active portfolio. The code sample below demonstrates how to set a glyph as the current marker symbol and insert the marker at the origin:
Custom glyphs
If the set of predefined glyphs is not sufficient, you can create a custom glyph. The following section demonstrates how to do that.
Glyphs are composed of one or more HPS::GlyphElement objects which are used to draw the lines, dots, and curves of the glyph. These elements can be any of the following:
Geometry type | Associated class |
---|---|
circular arcs | HPS::CircularArcGlyphElement |
ellipses | HPS::EllipseGlyphElement |
lines | HPS::LineGlyphElement |
infinite lines | HPS::InfiniteLineGlyphElement |
individual pixels | HPS::DotGlyphElement |
Attribute settings for glyphs include color and fill and are set at the attribute level. Glyphs are programmatically defined as shown in the following steps:
Step 1: Segment structure
As glyph settings affect glyphs at the segment-level, it is important to arrange the scene hierarchy to achieve the desired result. For this example, a new segment is created in order to make a glyph in the shape of a modified X. A new HPS::GlyphKit is also initialized.
Step 2: Set the glyph canvas
All glyphs have an associated drawing canvas, the maximum size of which is 256 x 256 units. Although glyphs are rectangular in shape, each one has a "radius" which sets the drawable area. The glyph offset must also be set. This locates the origin of the glyph coordinate system relative to the center of the glyph. For example, the following code sets a drawable area of -100 to 100 in both x and y directions, and additionally creates an offset of zero, leaving the origin in the center of the glyph.
Step 3: Set the glyph geometry
This glyph will be drawn using lines, so the HPS::LineGlyphElement will be used. This class requires a series of HPS::GlyphPoint objects to build the line. There can be any number of line glyph elements in a single glyph, but for this example, only one is needed. The result is a sort of polyline. Note that the color is set at the element level using SetExplicitColor.
Step 4: Assemble the GlyphElements into an array
For a glyph that is composed of multiple elements, assembling the glyph elements into a collection seems more natural. However, regardless of the number of elements, the HPS::GlyphElementArray is necessary, even for a single element:
Step 5: Define the glyph in a portfolio
All glyphs must be associated with a portfolio, and this portfolio must be made active for the segment that will display the glyph. Give your glyph a descriptive name if there is any possibility of ambiguity. Portfolios are discussed in detail in here.
Step 6: Custom glyph is ready to use
At this point, the glyph is imported into Visualize and is ready to use. To insert it as a marker, be sure to make it the active marker symbol:
Images as glyphs
HOOPS Visualize also allows you to create a glyph from a defined image. The process is similar to creating a custom glyph as described in the previous section, except you would use the defined image as the source of a glyph element. When you define an image as a glyph element, it can be combined with other types of glyph elements to create complex glyphs.
One important difference when using image glyphs is setting the glyph radius. Normally, this value is used as the size of the "canvas" on which the glyph is drawn. With image glyphs, the radius is internally computed based on the image size. However, you must still call SetRadius(0) to initialize the glyph element properly.
The code below shows how to create a glyph from an image: