1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "customrenderitem_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | CustomRenderItem::CustomRenderItem() |
9 | : AbstractRenderItem(), |
10 | m_texture(0), |
11 | m_positionAbsolute(false), |
12 | m_scalingAbsolute(true), |
13 | m_object(0), |
14 | m_needBlend(true), |
15 | m_visible(true), |
16 | m_valid(true), |
17 | m_index(0), |
18 | m_shadowCasting(false), |
19 | m_isFacingCamera(false), |
20 | m_item(0), |
21 | m_renderer(0), |
22 | m_labelItem(false), |
23 | m_textureWidth(0), |
24 | m_textureHeight(0), |
25 | m_textureDepth(0), |
26 | m_isVolume(false), |
27 | m_textureFormat(QImage::Format_ARGB32), |
28 | m_sliceIndexX(-1), |
29 | m_sliceIndexY(-1), |
30 | m_sliceIndexZ(-1), |
31 | m_alphaMultiplier(1.0f), |
32 | m_preserveOpacity(true), |
33 | m_useHighDefShader(true), |
34 | m_drawSlices(false), |
35 | m_drawSliceFrames(false) |
36 | |
37 | { |
38 | } |
39 | |
40 | CustomRenderItem::~CustomRenderItem() |
41 | { |
42 | ObjectHelper::releaseObjectHelper(cacheId: m_renderer, obj&: m_object); |
43 | } |
44 | |
45 | bool CustomRenderItem::setMesh(const QString &meshFile) |
46 | { |
47 | ObjectHelper::resetObjectHelper(cacheId: m_renderer, obj&: m_object, meshFile); |
48 | return m_object ? true : false; |
49 | } |
50 | |
51 | void CustomRenderItem::setColorTable(const QList<QRgb> &colors) |
52 | { |
53 | m_colorTable.resize(size: 256); |
54 | for (int i = 0; i < 256; i++) { |
55 | if (i < colors.size()) { |
56 | const QRgb &rgb = colors.at(i); |
57 | m_colorTable[i] = QVector4D(float(qRed(rgb)) / 255.0f, |
58 | float(qGreen(rgb)) / 255.0f, |
59 | float(qBlue(rgb)) / 255.0f, |
60 | float(qAlpha(rgb)) / 255.0f); |
61 | } else { |
62 | m_colorTable[i] = QVector4D(0.0f, 0.0f, 0.0f, 0.0f); |
63 | } |
64 | } |
65 | } |
66 | |
67 | void CustomRenderItem::setMinBounds(const QVector3D &bounds) |
68 | { |
69 | m_minBounds = bounds; |
70 | m_minBoundsNormal = m_minBounds; |
71 | m_minBoundsNormal.setY(-m_minBoundsNormal.y()); |
72 | m_minBoundsNormal.setZ(-m_minBoundsNormal.z()); |
73 | m_minBoundsNormal = 0.5f * (m_minBoundsNormal + oneVector); |
74 | } |
75 | |
76 | void CustomRenderItem::setMaxBounds(const QVector3D &bounds) |
77 | { |
78 | m_maxBounds = bounds; |
79 | m_maxBoundsNormal = m_maxBounds; |
80 | m_maxBoundsNormal.setY(-m_maxBoundsNormal.y()); |
81 | m_maxBoundsNormal.setZ(-m_maxBoundsNormal.z()); |
82 | m_maxBoundsNormal = 0.5f * (m_maxBoundsNormal + oneVector); |
83 | } |
84 | |
85 | void CustomRenderItem::setSliceFrameColor(const QColor &color) |
86 | { |
87 | const QRgb &rgb = color.rgba(); |
88 | m_sliceFrameColor = QVector4D(float(qRed(rgb)) / 255.0f, |
89 | float(qGreen(rgb)) / 255.0f, |
90 | float(qBlue(rgb)) / 255.0f, |
91 | float(1.0f)); // Alpha not supported for frames |
92 | } |
93 | |
94 | QT_END_NAMESPACE |
95 | |