QCustom3DVolume Class

QCustom3DVolume 类可将体积渲染对象添加到图形中。更多

Header: #include <QCustom3DVolume>
CMake: find_package(Qt6 REQUIRED COMPONENTS DataVisualization)
target_link_libraries(mytarget PRIVATE Qt6::DataVisualization)
qmake: QT += datavisualization
QtDataVisualization 1.2
在 QML 中: Custom3DVolume
继承: QCustom3DItem

属性

公共功能

QCustom3DVolume(QObject *parent = nullptr)
QCustom3DVolume(const QVector3D &position, const 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()
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(const QColor &color)
void setSliceFrameGaps(const QVector3D &values)
void setSliceFrameThicknesses(const QVector3D &values)
void setSliceFrameWidths(const 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(const QColor &color)
void sliceFrameGapsChanged(const QVector3D &values)
void sliceFrameThicknessesChanged(const QVector3D &values)
void sliceFrameWidthsChanged(const 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)

详细说明

体积渲染对象是一个带有三维纹理的盒子。体支持三个切平面,沿体的每个主轴各一个。

渲染体积对象需要非常高的性能,尤其是当体积基本透明时,因为体积的内容是通过光线追踪的。性能与体积在屏幕上所占的像素数量几乎成线性关系,因此以较小的视图显示体积或限制图形的缩放级别是提高性能的简单方法。同样,体积纹理尺寸对性能也有很大影响。如果帧频比完美渲染体积内容的像素更重要,可以考虑关闭高清着色器,方法是将useHighDefShader 属性设置为false

注: 体积对象仅支持正投影。

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

另请参阅 QAbstract3DGraph::addCustomItem(),QAbstract3DGraph::orthoProjection, 和useHighDefShader

属性文档

alphaMultiplier : float

该属性用于保存渲染时体积纹理每个像素的 alpha 值乘以的值。

该属性可用于为 volume 引入统一的透明度。如果preserveOpacitytrue ,则只有至少具有一定透明度的纹理会受到影响,完全不透明的纹理不会受到影响。该值不能为负。默认值为1.0f

访问功能:

float alphaMultiplier() const
void setAlphaMultiplier(float mult)

Notifier 信号:

void alphaMultiplierChanged(float mult)

另请参见 preserveOpacitytextureData

colorTable : QList<QRgb>

此属性保存包含索引纹理格式颜色的数组。

如果纹理格式没有索引,则不使用此数组,数组可以为空。

默认为0

访问功能:

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

Notifier 信号:

void colorTableChanged()

另请参阅 textureData,setTextureFormat() 和QImage::colorTable() 。

drawSliceFrames : bool

此属性用于确定是否在体积周围绘制切片框架。

如果该属性值为true ,则将在体积周围绘制切片索引属性所指示的切片框架。如果该属性值为false ,则不会绘制切片框架。

绘制切片框架与绘制切片无关,因此可以在显示完整体积的同时绘制其周围的切片框架。这在使用renderSlice() 在图形外显示切片时非常有用。

默认为false

访问功能:

bool drawSliceFrames() const
void setDrawSliceFrames(bool enable)

Notifier 信号:

void drawSliceFramesChanged(bool enabled)

另请参阅 sliceIndexX,sliceIndexY,sliceIndexZ,drawSlicesrenderSlice() 。

drawSlices : bool

此属性表示是否绘制指定的切片而不是整个体积。

如果此属性值为true ,则将绘制切片索引属性所指示的切片,而不是整个体积。如果该属性值为false ,则将始终绘制全卷。默认值为false

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

访问功能:

bool drawSlices() const
void setDrawSlices(bool enable)

通知信号:

void drawSlicesChanged(bool enabled)

另请参阅 sliceIndexX,sliceIndexY, 和sliceIndexZ

preserveOpacity : bool

此属性表示 Alpha 倍增器是否应用于所有像素。

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

访问功能:

bool preserveOpacity() const
void setPreserveOpacity(bool enable)

Notifier 信号:

void preserveOpacityChanged(bool enabled)

另请参阅 alphaMultiplier

sliceFrameColor : QColor

该属性用于保存切片边框的颜色。

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

默认为黑色。

访问功能:

QColor sliceFrameColor() const
void setSliceFrameColor(const QColor &color)

Notifier 信号:

void sliceFrameColorChanged(const QColor &color)

另请参见 drawSliceFrames

sliceFrameGaps : QVector3D

该属性表示在每个维度上,体积本身与边框之间的气隙大小。

不同尺寸的间隙可能不同。数值为同一尺寸内体积厚度的分数。数值不能为负。

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

访问功能:

QVector3D sliceFrameGaps() const
void setSliceFrameGaps(const QVector3D &values)

通知信号:

void sliceFrameGapsChanged(const QVector3D &values)

另请参阅 drawSliceFrames

sliceFrameThicknesses : QVector3D

此属性保存每个维度的切片框架厚度。

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

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

访问功能:

QVector3D sliceFrameThicknesses() const
void setSliceFrameThicknesses(const QVector3D &values)

Notifier 信号:

void sliceFrameThicknessesChanged(const QVector3D &values)

另请参阅 drawSliceFrames

sliceFrameWidths : QVector3D

此属性表示切片边框的宽度。

宽度可以在不同的维度上有所不同,因此您可以通过将该维度的值设置为零来省略绘制体积某些边上的边框。该值是同一维度上体积厚度的分数。数值不能为负数。

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

访问功能:

QVector3D sliceFrameWidths() const
void setSliceFrameWidths(const QVector3D &values)

通知信号:

void sliceFrameWidthsChanged(const QVector3D &values)

另请参阅 drawSliceFrames

sliceIndexX : int

此属性包含纹理数据中的 x 维度索引,表示要显示的垂直切片。

将任何维度设置为负数都表示不绘制该维度的切片或切片框架。如果所有维度都为负数,则不绘制切片或切片框架,正常绘制体积。

默认值为-1

访问功能:

int sliceIndexX() const
void setSliceIndexX(int value)

Notifier 信号:

void sliceIndexXChanged(int value)

另请参阅 textureData,drawSlices, 和drawSliceFrames

sliceIndexY : int

此属性包含纹理数据中的 y 维度索引,表示要显示的水平切片。

将任何维度设置为负数都表示不绘制该维度的切片或切片框架。如果所有维度都为负数,则不绘制切片或切片框架,正常绘制体积。

默认值为-1

访问功能:

int sliceIndexY() const
void setSliceIndexY(int value)

Notifier 信号:

void sliceIndexYChanged(int value)

另请参阅 textureData,drawSlices, 和drawSliceFrames

sliceIndexZ : int

此属性保存纹理数据中的 Z 维度索引,用于显示垂直切片。

将任何维度设置为负数都表示不绘制该维度的切片或切片框架。如果所有维度都为负数,则不会绘制任何切片或切片框架,体积将正常绘制。

默认值为-1

访问功能:

int sliceIndexZ() const
void setSliceIndexZ(int value)

Notifier 信号:

void sliceIndexZChanged(int value)

另请参阅 textureData,drawSlices, 和drawSliceFrames

textureData : QList<uchar>*

该属性保存包含纹理数据的数组,数据格式由textureFormat 指定。

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

三维纹理由二维子纹理堆栈定义。每个子纹理的大小必须相同 (textureDataWidth * textureHeight) ,堆栈的深度由textureDepth 属性定义。每个 2D 纹理中的数据与QImage 数据格式相同,因此可以使用QImage::bits() 为每个子纹理提供数据。

新数组的所有权将转移到QCustom3DVolume 实例。如果设置了另一个数组,先前的数组将被删除。如果再次设置同一数组,则假定数组内容已更改,并触发图形渲染。

注意: 数据的每个 x 维行都需要 32 位对齐。如果textureFormatQImage::Format_Indexed8 ,而textureWidth 的值不能被四整除,则可能需要在data 的每个 x 维数据行添加填充字节。函数textureDataWidth() 返回填充字节数。填充字节应显示完全透明的颜色,以避免出现渲染伪影。

默认值为0

访问函数:

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

Notifier 信号:

void textureDataChanged(QList<uchar> *data)

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

textureDepth : int

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

默认值为0

注: 如果更改此值,可能需要调整textureData 的大小或重新创建。默认为0

访问功能:

int textureDepth() const
void setTextureDepth(int value)

Notifier 信号:

void textureDepthChanged(int value)

另请参阅 textureData,textureWidth,textureHeightsetTextureFormat() 。

textureHeight : int

此属性用于保存定义体积内容的 3D 纹理的高度(单位:像素)。

默认值为0

注: 如果更改此值,可能需要调整textureData 的大小或重新创建。默认为0

访问功能:

int textureHeight() const
void setTextureHeight(int value)

Notifier 信号:

void textureHeightChanged(int value)

另请参阅 textureData,textureWidth,textureDepthsetTextureFormat() 。

textureWidth : int

此属性表示定义体积内容的 3D 纹理的宽度(像素)。

默认值为0

注: 如果更改此值,可能需要调整textureData 的大小或重新创建。默认为0

访问功能:

int textureWidth() const
void setTextureWidth(int value)

Notifier 信号:

void textureWidthChanged(int value)

另请参阅 textureData,textureHeight,textureDepth,setTextureFormat() 和textureDataWidth() 。

useHighDefShader : bool

此属性表示使用高清晰度还是低清晰度着色器来渲染体积。

如果此属性值为true ,则使用高清着色器。如果该属性值为false ,则使用低清晰度着色器。

高清着色器可确保在渲染体积时,对体积纹理的每个可见像素都进行采样。低清晰度着色器只能渲染体积内容的大致近似值,但帧频要高得多。低清晰度着色器不能保证对体积纹理的每个像素都进行采样,因此如果体积包含明显的细小特征,可能会出现闪烁。

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

默认值为true

访问功能:

bool useHighDefShader() const
void setUseHighDefShader(bool enable)

Notifier 信号:

void useHighDefShaderChanged(bool enabled)

另请参阅 renderSlice().

成员函数文档

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

用给定的parent 构建自定义三维体。

[explicit] QCustom3DVolume::QCustom3DVolume(const QVector3D &position, const 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 构建自定义三维体。

另请参阅 textureData,setTextureFormat() 和colorTable

[virtual noexcept] QCustom3DVolume::~QCustom3DVolume()

删除自定义 3D 卷。

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

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

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

另请参阅 textureData,textureWidth,textureHeight,textureDepthsetTextureFormat() 。

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 设置三维纹理的单个二维子纹理。index 参数指定要设置的子纹理。如果textureFormat 是索引,源image 必须是textureFormat 属性指定的格式。如果textureFormatQImage::Format_ARGB32 ,图像将转换为该格式。图像的大小必须与体积纹理沿指定轴线的横截面相同。图像的方向应与renderSlice() 方法沿同一轴线生成的切片图像的方向一致。

注意: 当以 y 轴或 z 轴为目标时,数据的每条 x 维线都需要 32 位对齐。如果textureFormatQImage::Format_Indexed8 ,而textureWidth 的值不能被四整除,则可能需要在图像的每个 x 维线上添加填充字节,以便正确对齐。填充字节应显示完全透明的颜色,以避免出现渲染伪影。QImage 并不保证会自动这样做。

另请参阅 textureDatarenderSlice()。

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

沿指定的axis 设置三维纹理的单个二维子纹理。index 参数指定了要设置的子纹理。纹理data 必须是textureFormat 属性指定的格式,其大小为沿指定轴的体纹理截面乘以纹理格式颜色深度(以字节为单位)。data 的排序方式应与renderSlice() 方法沿同一轴线生成的图像数据类似。

注意: 当以 Y 轴或 Z 轴为目标时,数据的每条 x 维线都需要 32 位对齐。如果textureFormatQImage::Format_Indexed8 ,而textureWidth 的值不能被四整除,则可能需要在data 的每条 x 维线上添加填充字节,以便正确对齐。填充字节应显示完全透明的颜色,以避免出现渲染假象。

另请参阅 textureDatarenderSlice()。

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

一个方便的函数,用于一次性设置所有三个纹理维度 (width,height, 和depth)。

另请参见 textureData

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

textureData 属性的格式设置为format 。目前只支持两种格式:QImage::Format_Indexed8QImage::Format_ARGB32 。如果指定了索引格式,则colorTable 也必须设置。默认为QImage::Format_ARGB32

另请参阅 textureFormat(),colorTable, 和textureData

int QCustom3DVolume::textureDataWidth() const

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

QImage::Format QCustom3DVolume::textureFormat() const

返回textureData 属性值的格式。

另请参阅 setTextureFormat().

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

formattextureData 值发生变化时会发出该信号。

另请参阅 setTextureFormat() 。

© 2025 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.