13.4. Generating HTML


From a given scene graph containing a camera, this action generates an image file (an off-screen rendering of the scene graph) and an HTML file. The HTML file contains a reference to the image file (<IMG>) and the image map (<MAP>). Each region of the image map will have a URL associated with it.

With HTML, image maps allow you to specify regions of an image and assign a specific action to each region (a link can be associated with each map). When the region is clicked by the user, the action is executed.

Each region of the image is determined by a subgraph which is under an SoWWWAnchor( C++ | Java | .NET ) group node.

The generated HTML file contains, in the following order:

  1. An image map tag that defines the region corresponding to each subgraph that is under an SoWWWAnchor( C++ | Java | .NET ) group node. For each region, the associated link is the URL defined either by the SoWWWAnchor( C++ | Java | .NET ) node.

  2. An image tag that references the image generated by SoToHTMLAction( C++ | Java | .NET ) .

You can specify the format used to generate the image:


C++
myAction->setImageFormat(SoToHTMLAction::JPEG_FORMAT);
  

.NET
myAction.SetImageFormat(SoToHTMLAction.ImageFormats.JPEG_FORMAT);
  

Java
myAction.setImageFormat(SoToHTMLAction.ImageFormats.JPEG_FORMAT);
  

To specify the quality of the output, from 0.0 (worst) to 1.0 (best):


C++
float quality;
quality = 0.75;
myAction->setImageQuality(quality);
  

.NET
float quality;
quality = 0.75f;
myAction.SetImageQuality(quality);
  

Java
float quality;
quality = 0.75f;
myAction.setImageQuality(quality);
  

For JPEG output this specifies the amount of compression used to generate/store the JPEG image.

Next, specify the components used to describe the image pixels:


C++
myAction->setImageComponents(SoToHTMLAction::RGB);
  

.NET
myAction.SetImageComponents(SoToHTMLAction.Components.RGB);
  

Java
myAction.setImageComponents(SoToHTMLAction.Components.RGB);
  

You can chose from:

  • LUMINANCE

  • LUMINANCE_TRANSPARENCY

  • RGB

  • RGB_TRANSPARENCY

By default, the image component is RGB.

To specify the background color to be used for the image:


C++
// Specify a RED background.
myAction->setImageBackgroundColor(SbColor(1,0,0));
  

.NET
// Specify a RED background.
myAction.SetImageBackgroundColor(new SbColor(1, 0, 0));
  

Java
// Specify a RED background.
myAction.setImageBackgroundColor(new SbColor(1, 0, 0));
  

To specify the size of the image:


C++
// This will create a 200x200 image.
myAction->setViewportRegion(SbViewportRegion(200,200));
  

.NET
// This will create a 200x200 image.
myAction.SetViewportRegion(new SbViewportRegion(200, 200));
 

Java
// This will create a 200x200 image.
myAction.setViewportRegion(new SbViewportRegion((short)200, (short)200));

The image format, image quality, image component, background color, and size can be retrieved by:


C++
SoToHTMLAction::ImageFormat format = myAction->getImageFormat();
float quality = myAction->getImageQuality();
SoToHTMLAction::Component components = myAction->getImageComponents();
const SbColor backColor = myAction-> getImageBackgroundColor();
const SbViewportRegion size = myAction->getViewportRegion();
  

.NET
SoToHTMLAction.ImageFormats format = myAction.GetImageFormat();
float quality = myAction.GetImageQuality();
SoToHTMLAction.Components components = myAction.GetImageComponents();
SbColor backColor = myAction.GetImageBackgroundColor();
SbViewportRegion size = myAction.GetViewportRegion();

Java
SoToHTMLAction.ImageFormats format = myAction.getImageFormat();
float quality = myAction.getImageQuality();
SoToHTMLAction.Components components = myAction.getImageComponents();
SbColor backColor = myAction.getImageBackgroundColor();
SbViewportRegion size = myAction.getViewportRegion();