SoScriptOverlay

InventorModule
author Michael Schmidt
package FMEwork/ReleaseMeVis
dll SoScriptOverlay
definition SoScriptOverlay.def
keywords scripting, rendering, PythonQt

Purpose

This module offers a scripting interface to python render scripted graphics into a viewer.

Details

The script-interface of this module allows to register a python-function as callback for drawing overlays on the inventor scene. The following happens a Scene containing an instance of SoScriptOverlay is rendered:

  • A QImage with the same extent as the configured viewport area is created. The image is an RGBA image and initially fully transparent.
  • A ScriptPainter is instantiated.
  • The registered python-function is called and the wrapped ScriptPainter is passed as the only argument.
  • When the callback returns, the QImage is uploaded as a texture and a textured Quad covering the active viewport region is rendered.

The ScriptPainter provides a more python-friendly interface to a subset of the QPainter class. If you need more sophisticated functions, you can get access to the underlying QImage and a QPainter using the getQImage()- and getQPainter()-slots of the wrapped ScriptPainter. Furthermore, the ScriptPainter is likely to get augmented with some utility functions over the time. For now, it features a method to determine the maximum possible font-size for rendering a user-provided string within a region of a given width and height.

Since the module only works on the active viewport regions, you can use the SoViewportRegion module for sophisticated control of where to place and how to size the overlay area.

Since drawing in python is not the fastest thing on earth, the module provides mechanisms for caching the overlays. Your python function is called when you invalidate the cache by calling refresh() on the script-interface of the module. Furthermore, it is called if Fixed Texture Size is false and the viewport dimensions change. Since the module might be shown in different viewers with different viewport settings, the module currently caches up to 10 different resolutions of the overlay. This will probably be changed to some more clever and/or resource friendly caching strategy when the need arises. If Fixed Texture Size is true, only one texture of the given size (Texture Size) is cached and reused the whole time. This configuration makes sense in scenarios where interactive resizing might be carried out. However, some tuning of the resolution and the anti-aliasing settings of the SoRenderArea might be necessary for a nice rendering. Furthermore, the displayed content may be stretched depending on the viewport size. Use SoViewportRegion to display the overlay in a viewport region of the same aspect ratio as the Texture Size!

Using a Supersampling value greater than 1 leads to a higher internal resolution and therefore might slow rendering down. However, rendering quality might improve significantly. Best results might be achieved if no downsampling is used (which would scale the image back to the output screen size and can introduce bluring).

To find out how to use the module just have a look at its example network.

Windows

Default Panel

Contains all relevant settings.

Output Fields

self

name: self, type: SoNode

The output inventor node.

Parameter Fields

Field Index

Downsampling: Enum
Fixed Texture Size: Bool
Mag Filter: Enum
Min Filter: Enum
Supersampling: Integer
Texture Size: IntVector2

Visible Fields

Supersampling

name: supersampling, type: Integer, default: 1, minimum: 1, maximum: 8

Sets the super-sampling value for anti-aliasing.

Fixed Texture Size

name: fixedTextureSize, type: Bool, default: FALSE

If true, a fixed internal texture size is used.

Texture Size

name: textureSize, type: IntVector2, default: 512 512

Fixed texture Size.

Downsampling

name: downsampling, type: Enum, default: SMOOTH

Mode for downsamling of the supersampled texture to the original size

Values:

Title Name Description
None NONE No downsampling. The supersampled texture is rendered
Fast FAST Simple nearest neighbor downsampling (see Qt::FastTransformation)
Smooth SMOOTH Bilinear downsampling (see Qt::SmoothTransformation)

Min Filter

name: minFilter, type: Enum, default: LINEAR

Defines the function that is used whenever one screen pixel maps to an area greater than one texture pixel.

Values:

Title Name Description
Nearest NEAREST Uses closest texture sample (Manhattan distance).
Linear LINEAR Uses the weighted average of the four texture elements that are closest to the center of the screen pixel
Nearest Mipmap Nearest NEAREST_MIPMAP_NEAREST Chooses the closest mipmap and uses nearest filtering.
Nearest Mipmap Linear NEAREST_MIPMAP_LINEAR Chooses the closest mipmap and uses linear filtering.
Linear Mipmap Nearest LINEAR_MIPMAP_NEAREST Linearly blends the two closest mipmaps and uses nearest filtering on the result.
Linear Mipmap Linear LINEAR_MIPMAP_LINEAR Linearly blends the two closest mipmaps and uses linear filtering on the result.

Mag Filter

name: magFilter, type: Enum, default: LINEAR

Defines the function that is used whenever one screen pixel maps to an area less than or equal one texture pixel.

Values:

Title Name Description
Nearest NEAREST Uses closest texture sample (Manhattan distance).
Linear LINEAR Uses the weighted average of the four texture elements that are closest to the center of the screen pixel
Nearest Mipmap Nearest NEAREST_MIPMAP_NEAREST Chooses the closest mipmap and uses nearest filtering.
Nearest Mipmap Linear NEAREST_MIPMAP_LINEAR Chooses the closest mipmap and uses linear filtering.
Linear Mipmap Nearest LINEAR_MIPMAP_NEAREST Linearly blends the two closest mipmaps and uses nearest filtering on the result.
Linear Mipmap Linear LINEAR_MIPMAP_LINEAR Linearly blends the two closest mipmaps and uses linear filtering on the result.