Images

An image is a 2D array of pixels. Images are like markers and annotation text in that they are always drawn in screen space (if you want to see an image rotate in 3D, you would apply it as a texture to a 3d object by using HOOPS/3dGS' Texture Mapping support.) The following program creates and display a simple image: a set of eight color bars.

struct Color
{
unsigned char r, g, b;
};
const unsigned char on = 0xff;
const unsigned char off = 0x00;
Color colors[8] =
{
{ on, off, off }, // red
{ off, on, off }, // green
{ off, off, on }, // blue
{ off, on, on }, // cyan
{ on, off, on }, // magenta
{ on, on, off }, // yellow
{ on, on, on }, // white
{ off, off, off } // black
};
const int width = 25; // width of each color bar
const int height = 200; // height of each color bar
unsigned char image[3 * 8 * width * height];
unsigned char *p = image;
// create the image
for (int h = 0; h < height; h++)
{
for (int bar = 0; bar < 8; bar++)
{
for (int w = 0; w < width; w++)
{
*p++ = colors[bar].r;
*p++ = colors[bar].g;
*p++ = colors[bar].b;
}
}
}
// insert the image
HC_Open_Segment("?Picture");
HC_Insert_Image(0.0, 0.0, 0.0, "RGB", width * 8, height, image);
HC_Close_Segment();
Color bars created with an RGB image.

In the code above, each pixel was defined as an RGB value, with 3 bytes taken up in the image array for each pixel. An alternative way to define an image is to use color indices into a color map. Below, each pixel only needs 1 byte in the image array. Each byte in the image array is an index into the local color map. The local color map is set on line 8. Note that a color map is an attribute in HOOPS, so different segments can have different color maps.

const int width = 25; // width of each color bar
const int height = 200; // height of each color bar
unsigned char image[8 * width * height];
unsigned char *p = image;
// create the color map
HC_Set_Color_Map("red, green, blue, cyan, magenta, yellow, white, black");
// create the image
for (int h = 0; h < height; h++)
{
for (unsigned char bar = 0; bar < 8; bar++)
{
for (int w = 0; w < width; w++)
*p++ = bar;
}
}
// insert the image
HC_Open_Segment("?Picture");
HC_Insert_Image(0.0, 0.0, 0.0, "mapped", width * 8, height, image);
HC_Close_Segment();
Program Color bars created with a mapped image.

Of course, color bars are not a particularly interesting image. In fact, it probably would be better for us to define color bars using a mesh, or at least as eight polygons. The problem with using an image is that the appearance of an image is platform dependent, because images are defined in screen space (one image pixel per screen pixel). An image will appear larger or smaller depending on the resolution of the display. On a device with a very high resolution, such as a printer, an image will appear very small.

You can retrieve the data from an image using the Show_Image command. You can also determine the size, format, and location of an image using the Show_Image_Size command. You can edit the individual pixels in an image using the Edit_Image command. See the HOOPS/3dGS Reference Manual for more information. To update an image's name, size as well as other options specified in the format parameter of Insert_Image, you can use Edit_Image_Options.

HOOPS also supports the importation of compressed images via the Insert_Compressed_Image function. The following compressed image formats are supported:

  • JPEG
  • TGA
  • DXT1
  • DXT3
  • DXT5

A more common use of HOOPS images is to display externally generated images. HOOPS can display images that either are in raw bitmap form, or use indices into a color map. Most externally generated images, however, use some sort of compression to reduce storage requirements. For example, images are often stored in GIF or JPEG format. The HOOPS/MVO classes provide several built-in image conversion functions, and also provide comprehensive image I/O support via the integration with the LeadTools image conversion toolkit.

Images as attributes

An image is normally considered to be geometry, but an image can be also used as an attribute. For example, an image can be used as the basis for a texture to modify the appearance of the faces of shells or meshes. Section 5.2 contains information on how to use an image as a color or as a texture map.

Scalable Images

HOOPS/3dGS supports scaling of images. There are 2 ways to use this feature:

A. A linear image scaling factor can be set which will inherit down the tree like any attribute. This is set by using the image scale Rendering_Option:

HC_Set_Rendering_Options("image scale = (.1, .1)");

B. An image can be scaled on an individual basis by using the "size" format option of Insert_Image. This option can be set in two ways. You can independently set the width/height components:

HC_Insert_Image(0.0, 0.0, 0.0, "size = (.1 oru, .1 oru)", width, height, image);

If the image is 100x200 pixels and 0.1 oru happens to be 50 pixels, then the above setting will produce an image size of 50x50 pixels. (Aspect ratio is not maintained.)

Or, you can just set the "size" option alone:

HC_Insert_Image(0.0, 0.0, 0.0, "size = 0.1 oru", width, height, image);

If the image is 100x200 pixels and 0.1 oru happens to be 50 pixels, then the above setting will produce an image size of 25x50 pixels. (Aspect ratio is maintained.)

top_level:2 prog_guide:0 prog_guide/3DGS:1