SoScriptOverlay¶
- InventorModule¶
genre
author
Michael Schmidt
package
dll
definition
see also
RunPythonScript,SoRenderArea,SoView2DOverlay,OrthoViewOverlay,SoView2DShaderOverlaykeywords
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.
The following table lists all ScriptPainter slots:
Slot |
Description |
|---|---|
|
Calculates a fitting font pixel size for the given text rectangle. |
|
Returns the target image height in pixels. |
|
Returns the target image width in pixels. |
|
Returns the supersampling factor. |
|
Draws an arc using Qt angle units (1/16 degree). |
|
Draws a chord using Qt angle units (1/16 degree). |
|
Draws an ellipse in the given rectangle. |
|
Draws a line segment. |
|
Draws a pie segment using Qt angle units (1/16 degree). |
|
Draws a single point. |
|
Draws a polygon from a flat coordinate list |
|
Draws a polyline from a flat coordinate list |
|
Draws a rectangle. |
|
Draws a rounded rectangle. |
|
Draws centered, word-wrapped text in a rectangle. |
|
Draws text in a rectangle using explicit Qt text flags. |
|
Draws an image aligned within the target image. |
|
Returns the underlying QImage for advanced use. |
|
Returns the wrapped QPainter for advanced operations. |
|
Sets the current brush. |
|
Sets brush color with 8-bit RGBA values. |
|
Sets brush color with normalized RGBA values in [0.0, 1.0]. |
|
Sets the brush fill style. |
|
Sets the current font. |
|
Enables or disables bold font rendering. |
|
Sets the font family. |
|
Enables or disables italic font rendering. |
|
Sets the font pixel size. |
|
Enables or disables underlined font rendering. |
|
Sets the current pen. |
|
Sets the pen cap style. |
|
Sets pen color with 8-bit RGBA values. |
|
Sets pen color with normalized RGBA values in [0.0, 1.0]. |
|
Sets the pen dash offset. |
|
Sets the pen dash pattern. |
|
Sets the pen join style. |
|
Sets the pen miter limit. |
|
Sets the pen style. |
|
Sets pen width in pixels (integer overload). |
|
Sets pen width as floating-point value. |
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¶
|
|
|
|
|
|
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. |