public class SoTransferFunction extends SoNode
SoTransferFunction
has no effect on rendering an RGBA volume (SoVolumeData.dataRGBA
field contains true). In this case the voxel values are explicitly color values already.
Data range
The range of scalar values is specified by an SoDataRange
node. If the application does not provide an SoDataRange
node, then the full range of the volume's data type is mapped into the color map. This can be appropriate and convenient for 8-bit (byte) data, but is usually incorrect for larger data types, especially float values. For example, DICOM data is normally stored in 16-bit voxels, which would have a default data range of 0..65535 (or -32767..32767 if signed). To get the correct image in this case the application should create an an SoDataRange
node and set the data range to the actual range of data values, for example 0..4095. If the actual range is not known, the min and max values can be queried using the SoVolumeData
getMinMax methods. Note that the minValue and maxValue fields of this node have a different meaning that is described later. An example data-to-color-mapping looks like this:
Color maps
If no transfer function has been specified, VolumeViz rendering nodes automatically use the predefined GRAY color map. In this color map all the color values are 1,1,1 (full white) and the alpha values are a linear ramp from 0 to 1. This can be a useful starting point for volume rendering.
To use one of the predefined color maps, set the predefColorMap
to a valid value other than NONE, for example INTENSITY. In this color map the color values are a linear ramp from 0 to 1 and all alpha values are 1 (full opaque). This can be a useful starting point for slice rendering.
To create a custom color map, set the predefColorMap
field to NONE, set the colorMapType
field to the appropriate type (RGBA is the default and most commonly used), then set the color map values in the colorMap
field. The colorMap
field contains an array of float values in the range [0,1]. The number of float values needed depends on the colorMapType. It is equal to the number of colors in the color map multiplied by the number of components in each color. An ALPHA color map has one component per color, a LUM_ALPHA (Luminance plus Alpha) color map has two components per color and an RGBA color map has four components per color. For example, for an RGBA color map of length N, there must be 4*N float values in the field.
As usual with SoMF fields, memory is automatically allocated as needed if you set the values one at a time using the set1Value() method. This is convenient, but very inefficient. If you must set values one at a time, use the setNum() method to pre-allocate enough memory for all the float values. There is another reason not to set values one at a time. Changing a value in the colorMap field automatically updates the Note that the meaning of the min and max fields in To modify an existing color map, use the setValues() method (as discussed above) or use the start/finish editing methods. For example: The transfer function is associated with the rendering node(s), not the volume data node. So for example it is possible to use one transfer function for volume rendering ( When rendering a single volume, there is only one transfer function active at a time and each rendering node uses the current (i.e. last traversed) transfer function in the traversal state, similar to the way materials apply to polygonal geometry.
The application may switch from one transfer function to a different one. For example, by putting multiple transfer functions under an When combining multiple volumes using When using volume masks ( It can be convenient to use the same color map for volume rendering and for slice rendering. But typically the volume rendering color map should have transparency (alpha values less than one) and the slice rendering color map should be opaque. It's not actually necessary to create two separate color maps. Set the
alphaUse field in the slice node to ALPHA_OPAQUE and the slice will ignore the transparency values in the color map.
Applications are not limited to using an More about data mapping
We have discussed above the basic concept of mapping scalar values to color values. Here we present more details, which may be important in some cases, for example when rendering a label volume. The way scalar values are mapped to indices in the color map depends on:
We have discussed all of these previously except for texture precision. The texturePrecision field of The data values may also be explicitly rescaled before mapping onto the color map, using the Label volumes
A label volume, also known as a label field, is usually the result of doing some sort of segmentation on a data volume. Each voxel value is an integer label (id) identifying which material, object, etc. that the voxel belongs to. There could be 100's or 1000's of labels, but there might be as few as 8 label values. For example, a simple label volume might have 7 opaque materials plus plus an "exterior" material that is completely transparent. Conceptually, there is one big difference between a (typical) data volume and a label volume. A data volume is conceptually a set of discrete samples taken from a continuous scalar field. So we know the exact value at the center of each voxel and interpolate between those values to get the value at any position in between voxels. In a label volume we normally consider each voxel to belong completely to one material, so the value is constant until we cross the boundary into the next voxel. Therefore we do not want to interpolate the label values. When rendering a label volume with volume rendering, set the shape node's
interpolation field to NEAREST and leave the
preintegrated field set to false ( It is also important to set the data range, texture precision and color map size carefully. In particular, take care that the number of values in the data range and the number of entries in the color map are exactly equal and a "power
of 2" (8, 16, 32, ...). For example, if you have 6 label values, you might (logically) set the data range to 0..5 (min = 0 and max = 5) and create a label color map with 6 color values. That will work most of the time, but in a some cases (that are difficult to predict), loss of precision in the mapping arithmetic can cause a data value to map to the wrong color. In the previous example, with 6 label values, we recommend setting the data range to 0..7 and creating a color map with 8 color values (the last two values can be anything since they will not be used).
If you need more than 256 label values (this is not common, but it is possible), follow the above recommendation and also set the texturePrecision field to 16 (the default is 8). This ensures that each label value maps to a unique GPU data value. For example, if you have 1000 labels, we recommond setting the data range to 0..1024, setting texturePrecision to 16 and creating a color map with 1024 color values.
Finally, if you're rendering a label volume and you want to "remove" one of the materials (i.e. make it invisible), you cannot do this in the usual data volume way by modifying the data range in the Faux shading
This node also supports a "faux shading" technique that can produce results somewhat similar to surface shading without the performance penalty for computing lighting. Faux shading modifies the lower portion of the color map so that color and opacity ramp down to zero. Faux shading is controlled by the The LIMITATIONS
File format/default:
TransferFunction {
Action behavior:
See also:
actualColorMap
field on each change. To avoid performance problems, we recommend using the setValues() or setValuesBuffer() method to create the color map.
It is also possible to load a color map from a file using the loadColormap()
method. Currently the only supported file format is Avizo color map (.am or .col).
SoDataRange
is quite different than the meaning of the minValue
and maxValue
fields in SoTransferFunction
. The fields in SoDataRange
specify the range of voxel values that will be mapped into the full color map. But changing the minValue and maxValue fields in SoTransferFunction
"remaps" the color map, compressing the original list of color values into the specified range of entries. Entries outside this range are set to full transparent black (all components zero). This does not affect the mapping of scalar values to the color map, it just modifies the color map. Scalar values in the current data range are still mapped to the full range of color map entries. This is mainly useful if you are using one of the predefined color maps and want to quickly remove low value voxels that represent "noise" in the data or to use the first or last entry in the color map for "undefined" values. Visually the effect can be similar to changing the data range using SoDataRange
, and it is generally faster, but note that remapping effectively reduces the resolution of the color map. In general it's better to change the range of data values mapped into the color map using SoDataRange
.
Rendering
SoVolumeRender
) and a different transfer function for slices (e.g. SoOrthoSlice
).
SoSwitch
node. The application may also dynamically modify the contents of a transfer function, even if using a predefined color map. See the colorMap
and actualColorMap
fields.
SoMultiDataSeparator
and SoVolumeShader
it is possible to specify multiple transfer functions. All the transfer functions under the SoMultiDataSeparator
will be available to the shader program based on their transferFunctionId
. The application should assign a unique id to each transfer function. See the description of the transferFunctionId
field for more details.
SoVolumeMask
and SoVolumeMaskGroup
), the transferFunctionId
is also very important. In this case multiple transfer functions, with different id values, may exist in the traversal state simultaneously. Each mask region is only visible if there exists a transfer function with the same id as that region. Traversal order of the transfer functions is not important. Each region, including the original (unmasked) volume, is colored using the transfer function (if any) that has the same id value. See SoVolumeMask
for more details.
SoTransferFunction
node to specify the data to color mapping. The application can implement its own data to color mapping function in GLSL (OpenGL shader language). Use an SoVolumeShader
node and replace the VVizComputeFragmentColor function. In this case SoTransferFunction
can still be used to load a color map (or maps) on the GPU, if desired, but the actual assignment of a color is done by the application's shader function.
SoVolumeData
),
SoDataRange
),
SoVolumeData
), and
SoTransferFunction
).
SoVolumeData
effectively specifies the GPU data type, in other words the size (in bits) of the data values stored on the GPU. The default is 8 (1 byte), but VolumeViz also supports 16. Effectively a volume data value is normalized in the specified data range (SoDataRange
) then converted to a GPU data value in the range of values supported by the GPU data type (default 0..255). For 8-bit (byte) volume data this is a one-to-one mapping. For larger data types it is possible that more than one volume data value will map to the same GPU data value (value aliasing). During rendering the GPU data value is normalized to the number of entries in the color map then converted to an index into the list of colors. For 8-bit (byte) data, if the color map contains 256 entries, this is also a one-to-one mapping. But note that the GPU data values are usually interpolated before this step (see the interpolation field in, for example, SoVolumeRender
).
shift
and offset
fields.
SoVolumeRenderingQuality
). If rendering isosurfaces, set the
segmentedInterpolation field to true (SoVolumeRenderingQuality
).
SoDataRange
node or changing the min/max values in the SoTransferFunction
node. Doing either of those change will cause label values to map to different colors. Instead you should directly modify the values in the color map. In other words, for the color entry corresponding to the material id, change the Alpha value to zero.
fauxShadingLength
, fauxShadingStrength
, and fauxShadingDarkenThreshold
fields.
No Faux Shading Faux Shading
actualColorMap
field always contains the actual color values (after remapping, faux shading, etc have been applied) that will be used for rendering.
In the most common case the volume contains scalar data values, scalar values are loaded on the GPU and the color map is applied on the GPU. In this case the color map size (number of colors) cannot be larger than the OpenGL maximum texture size. (Because the color map is stored in an OpenGL texture.) This value is generally 16384 on modern GPUs. Use the OpenGL function glGetIntegerv(GL_MAX_TEXTURE_SIZE) to get this value if necessary.
If it is necessary to use a larger color map, set the usePalettedTexture field to false in the SoVolumeData
node. In this case the color map is applied on the CPU and RGBA values are loaded on the GPU. The color map can be any size. However rendering may be different because the GPU will interpolate between color values rather than data values and modifying the color map will be much slower because data must be reloaded on the GPU.
When using an SoVolumeGroup
, the SoTransferFunction
node must be inserted after the SoVolumeData
, not before.
This node only affects VolumeViz shape nodes (SoVolumeRender
, SoOrthoSlice
, SoObliqueSlice
, SoVolumeSkin
, etc). For Open Inventor nodes see SoColorMap
.
When using SoMultiDataSeparator
, all transfer functions must have the same 'colorMapType' and must have the same number of entries.
On very old graphics boards, modifying the color map when using RGBA (not paletted) textures will usually force the textures to be recreated, which may be slow. See the SoVolumeData.usePalettedTexture
field of SoVolumeData
.
}
shift 0
offset 0
predefColorMap NONE
colorMapType RGBA
colorMap 0
actualColorMap 0
transferFunctionId 0
minValue 0
maxValue 255
fauxShadingStrength 1
fauxShadingLength 0
fauxShadingDarkenThreshold 1
SoCallbackAction
, SoGLRenderAction
Sets transfer function parameters in the traversal state.
Modifier and Type | Class and Description |
---|---|
static class |
SoTransferFunction.ColorMapTypes
Available color map type.
|
static class |
SoTransferFunction.PredefColorMaps
Predefined color maps.
|
Inventor.ConstructorCommand
Modifier and Type | Field and Description |
---|---|
SoMFFloat |
actualColorMap
This field contains the actual color map used.
|
static int |
AIRWAY
Deprecated.
Use
SoTransferFunction.PredefColorMaps.AIRWAY instead. |
static int |
AIRWAY_SURFACES
Deprecated.
Use
SoTransferFunction.PredefColorMaps.AIRWAY_SURFACES instead. |
static int |
ALPHA
Deprecated.
Use
SoTransferFunction.ColorMapTypes.ALPHA instead. |
static int |
BLUE_RED
Deprecated.
Use
SoTransferFunction.PredefColorMaps.BLUE_RED instead. |
static int |
BLUE_WHITE_RED
Deprecated.
Use
SoTransferFunction.PredefColorMaps.BLUE_WHITE_RED instead. |
SoMFFloat |
colorMap
Array of floats in the range [0,1] defining a color map.
|
SoSFEnum<SoTransferFunction.ColorMapTypes> |
colorMapType
ColorMap type (number of color components).
|
SoSFFloat |
fauxShadingDarkenThreshold
Opacity threshold for darkening edges.
|
SoSFFloat |
fauxShadingLength
Controls how many color values will be affected by faux shading.
|
SoSFFloat |
fauxShadingStrength
Controls how much faux shading will darken the color values of the transfer function.
|
static int |
GLOW
Deprecated.
Use
SoTransferFunction.PredefColorMaps.GLOW instead. |
static int |
GRAY
Deprecated.
Use
SoTransferFunction.PredefColorMaps.GRAY instead. |
static int |
GREY
Deprecated.
Use
SoTransferFunction.PredefColorMaps.GREY instead. |
static int |
INTENSITY
Deprecated.
Use
SoTransferFunction.PredefColorMaps.INTENSITY instead. |
static int |
INTENSITY_REVERSED
Deprecated.
|
static int |
LABEL_256
Deprecated.
Use
SoTransferFunction.PredefColorMaps.LABEL_256 instead. |
static int |
LUM_ALPHA
Deprecated.
Use
SoTransferFunction.ColorMapTypes.LUM_ALPHA instead. |
SoSFInt32 |
maxValue
See
minValue field. |
SoSFInt32 |
minValue
Remaps the defined color map between minValue and maxValue indices.
|
static int |
NONE
Deprecated.
Use
SoTransferFunction.PredefColorMaps.NONE instead. |
SoSFInt32 |
offset
Used for rescaling the input data values.
|
static int |
PHYSICS
Deprecated.
Use
SoTransferFunction.PredefColorMaps.PHYSICS instead. |
SoSFEnum<SoTransferFunction.PredefColorMaps> |
predefColorMap
Predefined color map to use.
|
static int |
RGBA
Deprecated.
Use
SoTransferFunction.ColorMapTypes.RGBA instead. |
static int |
SEISMIC
Deprecated.
Use
SoTransferFunction.PredefColorMaps.SEISMIC instead. |
SoSFInt32 |
shift
Used for rescaling the input data values.
|
static int |
STANDARD
Deprecated.
Use
SoTransferFunction.PredefColorMaps.STANDARD instead. |
static int |
TEMPERATURE
Deprecated.
Use
SoTransferFunction.PredefColorMaps.TEMPERATURE instead. |
SoSFInt32 |
transferFunctionId
This field allows the use of multiple transfer functions.
|
static int |
VOLREN_GREEN
Deprecated.
Use
SoTransferFunction.PredefColorMaps.VOLREN_GREEN instead. |
static int |
VOLREN_RED
Deprecated.
Use
SoTransferFunction.PredefColorMaps.VOLREN_RED instead. |
VERBOSE_LEVEL, ZeroHandle
Constructor and Description |
---|
SoTransferFunction()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.nio.ByteBuffer |
getPackedColorMap(int alphaUsage)
Returns the current internal color map corresponding to this transfer
function.
|
boolean |
hasTransparency()
Returns true if the current color map contains alpha values less than 1.
|
boolean |
loadColormap(java.lang.String filename)
Loads a colormap from a file.
|
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
dispose, getEXTERNPROTO, getName, getPROTO, isDisposable, isSynchronizable, setName, setSynchronizable
getAddress, getNativeResourceHandle, startInternalThreads, stopInternalThreads
@Deprecated public static final int NONE
SoTransferFunction.PredefColorMaps.NONE
instead.@Deprecated public static final int GREY
SoTransferFunction.PredefColorMaps.GREY
instead.@Deprecated public static final int GRAY
SoTransferFunction.PredefColorMaps.GRAY
instead.@Deprecated public static final int TEMPERATURE
SoTransferFunction.PredefColorMaps.TEMPERATURE
instead.@Deprecated public static final int PHYSICS
SoTransferFunction.PredefColorMaps.PHYSICS
instead.@Deprecated public static final int STANDARD
SoTransferFunction.PredefColorMaps.STANDARD
instead.@Deprecated public static final int GLOW
SoTransferFunction.PredefColorMaps.GLOW
instead.@Deprecated public static final int BLUE_RED
SoTransferFunction.PredefColorMaps.BLUE_RED
instead.@Deprecated public static final int SEISMIC
SoTransferFunction.PredefColorMaps.SEISMIC
instead.@Deprecated public static final int BLUE_WHITE_RED
SoTransferFunction.PredefColorMaps.BLUE_WHITE_RED
instead.@Deprecated public static final int INTENSITY
SoTransferFunction.PredefColorMaps.INTENSITY
instead.@Deprecated public static final int LABEL_256
SoTransferFunction.PredefColorMaps.LABEL_256
instead.@Deprecated public static final int VOLREN_RED
SoTransferFunction.PredefColorMaps.VOLREN_RED
instead.@Deprecated public static final int VOLREN_GREEN
SoTransferFunction.PredefColorMaps.VOLREN_GREEN
instead.@Deprecated public static final int AIRWAY
SoTransferFunction.PredefColorMaps.AIRWAY
instead.@Deprecated public static final int AIRWAY_SURFACES
SoTransferFunction.PredefColorMaps.AIRWAY_SURFACES
instead.@Deprecated public static final int INTENSITY_REVERSED
SoTransferFunction.PredefColorMaps.INTENSITY_REVERSED
instead.@Deprecated public static final int ALPHA
SoTransferFunction.ColorMapTypes.ALPHA
instead.@Deprecated public static final int LUM_ALPHA
SoTransferFunction.ColorMapTypes.LUM_ALPHA
instead.@Deprecated public static final int RGBA
SoTransferFunction.ColorMapTypes.RGBA
instead.public final SoSFInt32 transferFunctionId
SoVolumeShader
) to access one of multiple transfer funcions and can also be used to associate a transfer function with a volume mask (see SoVolumeMask
). Note that, unlike SoDataSet/SoVolumeData, this value is NOT a GL texture unit number. Therefore it is possible (but not recommended) to use id values starting at 0. The SoVolumeData
dataSetId values should start at 1, so generally it's best to be consistent and use the same value as the data set that this TF corresponds to, which usually means starting the numbering at 1. Note that whatever values you assign, if you create a custom GLSL shader function, you
must use the same values when you call VVizTransferFunction() in your shader function.
All active transfer functions are combined into a single 2D texture by "stacking" them in order according to their ids. By default this texture is bound to OpenGL texture unit 0. It is possible to change the texture unit used for transfer functions by setting the preferences variable IVVR_TF_TEX_UNIT (see SoPreferences
).
Since Open Inventor 8.1, functions are provided which allow convenient access to a specific transfer function in a GLSL fragment shader. Although direct access is still possible, we strongly recommend using the GLSL convenience functions provided by VolumeViz to ensure compatibility with future rendering features:
For direct access, the texture S coordinate specifies the entry in the color map and the texture T coordinate specifies which color map to use. If N is the number of color maps used, the rules are:
public final SoSFInt32 shift
public final SoSFInt32 minValue
Setting minValue to 64 and maxValue to 192 while the predefined STANDARD color map is selected makes the color map as shown:
public final SoSFInt32 maxValue
minValue
field.
The value is automatically set to the number of colors in colorMap minus 1 as long an explicit value is not specified.
public final SoSFFloat fauxShadingLength
public final SoSFFloat fauxShadingStrength
public final SoSFFloat fauxShadingDarkenThreshold
public final SoSFEnum<SoTransferFunction.PredefColorMaps> predefColorMap
colorMap
field). All predefined color maps have 256 entries.
GREY or GRAY | ![]() |
TEMPERATURE | ![]() |
PHYSICS | ![]() |
STANDARD | ![]() |
GLOW | ![]() |
BLUE_RED | ![]() |
SEISMIC | ![]() |
BLUE_WHITE_RED | ![]() |
INTENSITY | ![]() |
INTENSITY_REVERSED | ![]() |
LABEL_256 | ![]() |
VOLREN_RED | ![]() |
VOLREN_GREEN | ![]() |
AIRWAY | ![]() |
AIRWAY_SURFACES | ![]() |
NOTE: The checkerboard pattern shows through where the color map alpha (opacity) value is less than 1.0.
If this field is explicitly set to NONE, then the colorMap
and colorMapType
fields should be set.
public final SoSFEnum<SoTransferFunction.ColorMapTypes> colorMapType
ALPHA means one alpha component per color.
LUM_ALPHA means two components per color, luminance and alpha. In such a case the colorMap float array contains a list of two floats. Index 0 is luminance, index 1 is alpha, index 2 is luminance, index 3 is alpha and so on.
RGBA means four components per color, ordered red, green, blue, then alpha.
An alpha value equal to zero means "fully transparent", an alpha value equal to one means "completely opaque" (exactly the inverse of transparency in SoMaterial
).
public final SoMFFloat colorMap
colorMapType
. It is equal to the number of colors defined multiplied by the number of components per color. For example, for an RGBA color map of length n, there should be 4*n float values in the field.
Note that changing a value in the colorMap field automatically updates the actualColorMap
field. Thus it can be very inefficient to set the color map entries one at a time. To avoid a performance decrease we recommend using one of the following techniques, particularly when changing many values:
See the examples in the class description.
public final SoMFFloat actualColorMap
public java.nio.ByteBuffer getPackedColorMap(int alphaUsage)
alphaUsage
- 0 : as is (alpha unchanged), 1 : opaque (alpha always 1), 2 :
binary (alpha is either 0 or 1)public boolean hasTransparency()
public boolean loadColormap(java.lang.String filename)
Note: This method loads RGBA values into the colorMap field, but the application must still set the predefColorMap field to NONE for the custom colormap values to be used.
Supported formats:
Generated on January 23, 2025, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com