本页内容

QCustom3DVolume Class

QCustom3DVolume 类向图形中添加了一个体积渲染对象。更多内容...

头文件: #include <QCustom3DVolume>
CMake: find_package(Qt6 REQUIRED COMPONENTS Graphs)
target_link_libraries(mytarget PRIVATE Qt6::Graphs)
qmake: QT += graphs
在 QML 中: Custom3DVolume
继承自: QCustom3DItem

属性

公共函数

QCustom3DVolume(QObject *parent = nullptr)
QCustom3DVolume(QVector3D position, QVector3D scaling, const QQuaternion &rotation, int textureWidth, int textureHeight, int textureDepth, QList<uchar> *textureData, QImage::Format textureFormat, const QList<QRgb> &colorTable, QObject *parent = nullptr)
virtual ~QCustom3DVolume() override
float alphaMultiplier() const
QList<QRgb> colorTable() const
QList<uchar> *createTextureData(const QList<QImage *> &images)
bool drawSliceFrames() const
bool drawSlices() const
bool preserveOpacity() const
QImage renderSlice(Qt::Axis axis, int index)
void setAlphaMultiplier(float mult)
void setColorTable(const QList<QRgb> &colors)
void setDrawSliceFrames(bool enable)
void setDrawSlices(bool enable)
void setPreserveOpacity(bool enable)
void setSliceFrameColor(QColor color)
void setSliceFrameGaps(QVector3D values)
void setSliceFrameThicknesses(QVector3D values)
void setSliceFrameWidths(QVector3D values)
void setSliceIndexX(int value)
void setSliceIndexY(int value)
void setSliceIndexZ(int value)
void setSliceIndices(int x, int y, int z)
void setSubTextureData(Qt::Axis axis, int index, const QImage &image)
void setSubTextureData(Qt::Axis axis, int index, const uchar *data)
void setTextureData(QList<uchar> *data)
void setTextureDepth(int value)
void setTextureDimensions(int width, int height, int depth)
void setTextureFormat(QImage::Format format)
void setTextureHeight(int value)
void setTextureWidth(int value)
void setUseHighDefShader(bool enable)
QColor sliceFrameColor() const
QVector3D sliceFrameGaps() const
QVector3D sliceFrameThicknesses() const
QVector3D sliceFrameWidths() const
int sliceIndexX() const
int sliceIndexY() const
int sliceIndexZ() const
QList<uchar> *textureData() const
int textureDataWidth() const
int textureDepth() const
QImage::Format textureFormat() const
int textureHeight() const
int textureWidth() const
bool useHighDefShader() const

信号

void alphaMultiplierChanged(float mult)
void colorTableChanged()
void drawSliceFramesChanged(bool enabled)
void drawSlicesChanged(bool enabled)
void preserveOpacityChanged(bool enabled)
void sliceFrameColorChanged(QColor color)
void sliceFrameGapsChanged(QVector3D values)
void sliceFrameThicknessesChanged(QVector3D values)
void sliceFrameWidthsChanged(QVector3D values)
void sliceIndexXChanged(int value)
void sliceIndexYChanged(int value)
void sliceIndexZChanged(int value)
void textureDataChanged(QList<uchar> *data)
void textureDepthChanged(int value)
void textureFormatChanged(QImage::Format format)
void textureHeightChanged(int value)
void textureWidthChanged(int value)
void useHighDefShaderChanged(bool enabled)

详细说明

体渲染对象是一个带有 3D 纹理的盒子。该体支持三个切片平面,分别沿体的三个主轴方向。

体积对象的渲染非常耗费性能,尤其是当体积大部分透明时,因为体积内容需要通过光线追踪来渲染。性能几乎与体积在屏幕上占用的像素数量成线性关系,因此将体积显示在较小的视图中或限制图形的缩放级别,是提升性能的简便方法。 同样,体积纹理的尺寸也会对性能产生重大影响。如果帧率比体积内容的像素级精确渲染更为重要,请考虑通过将useHighDefShader 属性设置为false 来关闭高清着色器。

注意:体积 对象使用 3D 纹理,而 OpenGL ES2 环境不支持 3D 纹理。

注意:仅 支持两种格式:QImage::Format_Indexed8 和QImage::Format_ARGB32 。如果指定了索引格式,则必须同时设置colorTable 。默认值为QImage::Format_ARGB32 。

另请参阅 Q3DGraphsWidgetItem::addCustomItem() 和useHighDefShader 。

属性文档

alphaMultiplier : float

该属性存储的值将在渲染时与体积纹理中每个纹素的透明度值相乘。

该属性可用于为体积引入均匀的透明度。如果preserveOpacity 的值为true ,则仅受影响的纹素是那些最初就具有一定透明度的纹素,而完全不透明的纹素不受影响。该值不得为负数。默认值为1.0f 。

访问函数:

float alphaMultiplier() const
void setAlphaMultiplier(float mult)

通知信号:

void alphaMultiplierChanged(float mult)

另请参阅 preserveOpacity 和textureData 。

colorTable : QList<QRgb>

该属性保存了一个数组,其中包含索引纹理格式的颜色。

如果纹理格式不是索引式,则不会使用此数组,且该数组可以为空。

默认值为0 。

访问函数:

QList<QRgb> colorTable() const
void setColorTable(const QList<QRgb> &colors)

通知信号:

void colorTableChanged()

另请参阅 textureData 、setTextureFormat() 以及QImage::colorTable()。

drawSliceFrames : bool

该属性控制是否在体积周围绘制切片边框。

如果该属性值为true ,则会沿体积周围绘制由切片索引属性指定的切片边框;如果该属性值为false ,则不会绘制任何切片边框。

绘制切片边框与绘制切片是相互独立的,因此您可以显示整个体积,同时仍在其周围绘制切片边框。当使用renderSlice() 将切片显示在图表本身之外时,此功能非常有用。

默认值为false 。

访问函数:

bool drawSliceFrames() const
void setDrawSliceFrames(bool enable)

通知信号:

void drawSliceFramesChanged(bool enabled)

另请参阅 sliceIndexX 、sliceIndexY 、sliceIndexZ 、drawSlices 以及renderSlice()。

drawSlices : bool

该属性用于控制是否绘制指定的切片,而非整个体积。

如果该属性值为true ,则将绘制由切片索引属性指定的切片,而非整个体积。如果该属性值为false ,则始终绘制整个体积。默认值为false 。

注意: 切片始终沿项目轴线绘制,因此如果项目被旋转,切片也会随之旋转。

访问函数:

bool drawSlices() const
void setDrawSlices(bool enable)

通知信号:

void drawSlicesChanged(bool enabled)

另请参阅 sliceIndexX 、sliceIndexY 以及sliceIndexZ 。

preserveOpacity : bool

该属性用于指定是否将透明度乘数应用于所有纹素。

如果该属性值为true ,则alphaMultiplier 仅应用于已经具有一定透明度的纹理像素。如果为false ,则该乘数将应用于所有纹理像素的alpha值。默认值为true 。

访问函数:

bool preserveOpacity() const
void setPreserveOpacity(bool enable)

通知信号:

void preserveOpacityChanged(bool enabled)

另请参阅 alphaMultiplier 。

sliceFrameColor : QColor

此属性用于指定切片边框的颜色。

不支持透明的切片边框颜色。

默认颜色为黑色。

访问函数:

QColor sliceFrameColor() const
void setSliceFrameColor(QColor color)

通知信号:

void sliceFrameColorChanged(QColor color)

另请参阅 drawSliceFrames 。

sliceFrameGaps : QVector3D

该属性指定了在每个维度上,体块本身与框架之间留出的气隙大小。

不同方向上的间隙可能不同。这些值是该方向上体块厚度的分数。这些值不能为负。

默认值为QVector3D(0.01, 0.01, 0.01) 。

访问函数:

QVector3D sliceFrameGaps() const
void setSliceFrameGaps(QVector3D values)

通知信号:

void sliceFrameGapsChanged(QVector3D values)

另请参阅 drawSliceFrames 。

sliceFrameThicknesses : QVector3D

该属性存储了各维度切片框的厚度。

这些值是同一维度下体积厚度的分数。这些值不能为负数。

默认值为QVector3D(0.01, 0.01, 0.01) 。

访问函数:

QVector3D sliceFrameThicknesses() const
void setSliceFrameThicknesses(QVector3D values)

通知信号:

void sliceFrameThicknessesChanged(QVector3D values)

另请参阅 drawSliceFrames 。

sliceFrameWidths : QVector3D

该属性用于指定切片边框的宽度。

不同方向上的宽度可能不同,因此您可以通过将某个方向的数值设为零,来省略该方向上体积的边框绘制。这些数值是该方向上体积厚度的分数值。数值不能为负。

默认值为QVector3D(0.01, 0.01, 0.01) 。

访问函数:

QVector3D sliceFrameWidths() const
void setSliceFrameWidths(QVector3D values)

通知信号:

void sliceFrameWidthsChanged(QVector3D values)

另请参阅 drawSliceFrames 。

sliceIndexX : int

该属性存储纹理数据中的 x 方向索引,用于指定要显示的垂直切片。

将任何维度设置为负值,表示不绘制该维度的切片或切片边框。如果所有维度均为负值,则不绘制任何切片或切片边框,体积将按常规方式绘制。

默认值为-1 。

访问函数:

int sliceIndexX() const
void setSliceIndexX(int value)

通知信号:

void sliceIndexXChanged(int value)

另请参阅 textureData 、drawSlices 和drawSliceFrames 。

sliceIndexY : int

该属性存储纹理数据中的 y 维索引,用于指定要显示的水平切片。

将任何维度设置为负值,表示不绘制该维度的切片或切片边框。如果所有维度均为负值,则不绘制任何切片或切片边框,体积将按常规方式绘制。

默认值为-1 。

访问函数:

int sliceIndexY() const
void setSliceIndexY(int value)

通知信号:

void sliceIndexYChanged(int value)

另请参阅 textureData 、drawSlices 和drawSliceFrames 。

sliceIndexZ : int

该属性存储纹理数据中的 z 维度索引,用于指示应显示哪个垂直切片。

将任何维度设置为负值,表示不绘制该维度的切片或切片框。如果所有维度均为负值,则不绘制任何切片或切片框,体积将按常规方式绘制。

默认值为-1 。

访问函数:

int sliceIndexZ() const
void setSliceIndexZ(int value)

通知信号:

void sliceIndexZChanged(int value)

另请参阅 textureData 、drawSlices 和drawSliceFrames 。

textureData : QList<uchar>*

该属性存储了一个数组,其中包含以textureFormat 中指定的格式存储的纹理数据。

该数组的大小必须至少为 (textureDataWidth * textureHeight * textureDepth * texture format color depth in bytes)。

3D 纹理由一组 2D 子纹理堆叠而成。 每个子纹理的大小必须相同(textureDataWidth * textureHeight ),而堆栈的深度由textureDepth 属性定义。每个2D纹理中的数据与具有相同格式的QImage 数据完全相同,因此可以使用QImage::bits()为每个子纹理提供数据。

新数组的所有权将转移至QCustom3DVolume 实例。若设置了另一个数组,则先前数组将被删除。若再次设置相同的数组,则系统会认为数组内容已发生变化,并触发图形渲染。

注意: 数据的每一行 (x 维度)都需要进行 32 位对齐。如果textureFormat 为QImage::Format_Indexed8 ,且textureWidth 的值不能被 4 整除,则可能需要在data 的每一行(x 维度)中添加填充字节。textureDataWidth() 函数会返回填充的字节数。 填充字节应指定为完全透明的颜色,以避免渲染异常。

默认值为0 。

访问函数:

QList<uchar> *textureData() const
void setTextureData(QList<uchar> *data)

通知信号:

void textureDataChanged(QList<uchar> *data)

另请参阅 colorTable 、setTextureFormat()、setSubTextureData() 和textureDataWidth()。

textureDepth : int

该属性以像素为单位存储定义体积内容的3D纹理的深度。

默认值为0 。

注意: 如果更改此值,可能需要调整textureData 的尺寸 或重新创建该纹理 。默认值为0 。

访问函数:

int textureDepth() const
void setTextureDepth(int value)

通知信号:

void textureDepthChanged(int value)

另请参见 textureData 、textureWidth 、textureHeight 以及setTextureFormat()。

textureHeight : int

该属性存储定义体积内容的 3D 纹理的高度(以像素为单位)。

默认值为0 。

注意: 如果更改此值,可能需要调整textureData 的尺寸 或重新创建该纹理 。默认值为0 。

访问函数:

int textureHeight() const
void setTextureHeight(int value)

通知信号:

void textureHeightChanged(int value)

另请参阅 textureData 、textureWidth 、textureDepth 以及setTextureFormat()。

textureWidth : int

该属性存储定义体积内容的 3D 纹理的宽度(以像素为单位)。

默认值为0 。

注意: 如果更改此值,可能需要调整textureData 的尺寸 或重新创建该纹理 。默认值为0 。

访问函数:

int textureWidth() const
void setTextureWidth(int value)

通知信号:

void textureWidthChanged(int value)

另请参阅 textureData 、textureHeight 、textureDepth 、setTextureFormat() 以及textureDataWidth()。

useHighDefShader : bool

该属性决定渲染体积时使用的是高分辨率着色器还是低分辨率着色器。

如果该属性值为true ,则使用高分辨率着色器;如果为false ,则使用低分辨率着色器。

高分辨率着色器可确保在渲染体积时,对体积纹理的每个可见纹素都进行采样。 低分辨率着色器仅渲染体积内容的粗略近似,但帧率要高得多。低分辨率着色器不能保证对体积纹理的每个纹素都进行采样,因此如果体积包含明显的细微特征,可能会出现闪烁。

注意:此值 不会影响渲染体积切片时的细节级别。

默认值为true 。

访问函数:

bool useHighDefShader() const
void setUseHighDefShader(bool enable)

通知信号:

void useHighDefShaderChanged(bool enabled)

另请参阅 renderSlice()。

成员函数文档

[explicit] QCustom3DVolume::QCustom3DVolume(QObject *parent = nullptr)

根据给定的parent 构建一个自定义的3D体积。

[explicit] QCustom3DVolume::QCustom3DVolume(QVector3D position, QVector3D scaling, const QQuaternion &rotation, int textureWidth, int textureHeight, int textureDepth, QList<uchar> *textureData, QImage::Format textureFormat, const QList<QRgb> &colorTable, QObject *parent = nullptr)

根据给定的position 、scaling 、rotation 、textureWidth 、textureHeight 、textureDepth 、textureData 、textureFormat 、colorTable 以及可选的parent ,构建一个自定义的3D体。

另请参阅 textureData 、setTextureFormat() 以及colorTable 。

[override virtual noexcept] QCustom3DVolume::~QCustom3DVolume()

删除自定义 3D 体素。

QList<uchar> *QCustom3DVolume::createTextureData(const QList<QImage *> &images)

根据images 数组创建一个新的纹理数据数组,并将其设置为该体积对象的textureData 。纹理尺寸也会根据图像和数组的尺寸进行设置。 数组中的所有图像必须具有相同大小。如果图像并非全部采用QImage::Format_Indexed8 格式,则所有纹理数据都将被转换为QImage::Format_ARGB32 格式。如果图像采用QImage::Format_Indexed8 格式,则整个体积的colorTable 值将取自第一张图像。

返回指向新创建数组的指针。

另请参阅 textureData 、textureWidth 、textureHeight 、textureDepth 以及setTextureFormat()。

QImage QCustom3DVolume::renderSlice(Qt::Axis axis, int index)

将由index 指定的切片沿axis 指定的轴渲染为图像。使用该对象的纹理格式。

返回该切片的渲染图像;若指定了无效索引,则返回空图像。

另请参阅 setTextureFormat()。

void QCustom3DVolume::setSliceIndices(int x, int y, int z)

一个便捷函数,用于同时设置三个切片索引(x 、y 和z )。

另请参阅 textureData 。

void QCustom3DVolume::setSubTextureData(Qt::Axis axis, int index, const QImage &image)

沿体积的指定axis 设置3D纹理中的单个2D子纹理。index 参数指定要设置的子纹理。 如果textureFormat 采用索引方式,则源image 必须符合textureFormat 属性指定的格式。如果textureFormat 的值是QImage::Format_ARGB32 ,则图像将转换为该格式。图像的大小必须与体积纹理沿指定轴的横截面尺寸一致。图像的方向应与renderSlice()方法沿同一轴生成的切片图像的方向相对应。

注意: 当目标轴为 y 轴或 z 轴时,数据的每条 x 维度行都需要进行 32 位对齐。如果textureFormat 的值为QImage::Format_Indexed8 ,且textureWidth 的值不能被 4 整除,则可能需要在图像的每条 x 维度行中添加填充字节,以实现正确的对齐。 填充字节应设置为完全透明的颜色,以避免渲染异常。不能保证QImage 会自动执行此操作。

另请参阅 textureData 和renderSlice()。

void QCustom3DVolume::setSubTextureData(Qt::Axis axis, int index, const uchar *data)

沿体积的指定axis ,设置3D纹理中的单个2D子纹理。index 参数指定要设置的子纹理。 纹理data 必须符合textureFormat 属性指定的格式,且其大小应为体积纹理沿指定轴方向的横截面尺寸乘以纹理格式色深(单位为字节)。data 的排列顺序应与renderSlice()方法沿同一轴生成的图像中的数据顺序一致。

注意: 当目标轴为 y 轴或 z 轴时,数据的每行 x 维度数据都需要进行 32 位对齐。如果 `textureFormat ` 为 `QImage::Format_Indexed8 `,且 `textureWidth ` 的值不能被 4 整除,则可能需要向 `data ` 的每行 x 维度数据中添加填充字节,以实现正确的对齐。 填充字节应指定完全透明的颜色,以避免渲染异常。

另请参阅 textureData 和renderSlice()。

void QCustom3DVolume::setTextureDimensions(int width, int height, int depth)

一个用于同时设置三个纹理维度(width 、height 和depth )的便捷函数。

另请参阅 textureData 。

void QCustom3DVolume::setTextureFormat(QImage::Format format)

将textureData 属性的格式设置为format 。目前仅支持两种格式:QImage::Format_Indexed8 和QImage::Format_ARGB32 。如果指定了索引格式,则还必须设置colorTable 。默认值为QImage::Format_ARGB32 。

另请参阅 textureFormat()、colorTable 以及textureData 。

int QCustom3DVolume::textureDataWidth() const

返回实际纹理数据的宽度。当纹理格式为QImage::Format_Indexed8 时,该值等于textureWidth (对齐到32位边界)。否则,该值等于textureWidth 的四倍。

QImage::Format QCustom3DVolume::textureFormat() const

返回textureData 属性值的格式。

另请参阅 setTextureFormat()。

[signal] void QCustom3DVolume::textureFormatChanged(QImage::Format format)

当textureData 的format 值发生变化时,会触发此信号。

另请参阅 setTextureFormat()。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.