1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include "customrenderitem_p.h" |
31 | |
32 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
33 | |
34 | CustomRenderItem::CustomRenderItem() |
35 | : AbstractRenderItem(), |
36 | m_texture(0), |
37 | m_positionAbsolute(false), |
38 | m_scalingAbsolute(true), |
39 | m_object(0), |
40 | m_needBlend(true), |
41 | m_visible(true), |
42 | m_valid(true), |
43 | m_index(0), |
44 | m_shadowCasting(false), |
45 | m_isFacingCamera(false), |
46 | m_item(0), |
47 | m_renderer(0), |
48 | m_labelItem(false), |
49 | m_textureWidth(0), |
50 | m_textureHeight(0), |
51 | m_textureDepth(0), |
52 | m_isVolume(false), |
53 | m_textureFormat(QImage::Format_ARGB32), |
54 | m_sliceIndexX(-1), |
55 | m_sliceIndexY(-1), |
56 | m_sliceIndexZ(-1), |
57 | m_alphaMultiplier(1.0f), |
58 | m_preserveOpacity(true), |
59 | m_useHighDefShader(true), |
60 | m_drawSlices(false), |
61 | m_drawSliceFrames(false) |
62 | |
63 | { |
64 | } |
65 | |
66 | CustomRenderItem::~CustomRenderItem() |
67 | { |
68 | ObjectHelper::releaseObjectHelper(cacheId: m_renderer, obj&: m_object); |
69 | } |
70 | |
71 | void CustomRenderItem::setMesh(const QString &meshFile) |
72 | { |
73 | ObjectHelper::resetObjectHelper(cacheId: m_renderer, obj&: m_object, meshFile); |
74 | } |
75 | |
76 | void CustomRenderItem::setColorTable(const QVector<QRgb> &colors) |
77 | { |
78 | m_colorTable.resize(asize: 256); |
79 | for (int i = 0; i < 256; i++) { |
80 | if (i < colors.size()) { |
81 | const QRgb &rgb = colors.at(i); |
82 | m_colorTable[i] = QVector4D(float(qRed(rgb)) / 255.0f, |
83 | float(qGreen(rgb)) / 255.0f, |
84 | float(qBlue(rgb)) / 255.0f, |
85 | float(qAlpha(rgb)) / 255.0f); |
86 | } else { |
87 | m_colorTable[i] = QVector4D(0.0f, 0.0f, 0.0f, 0.0f); |
88 | } |
89 | } |
90 | } |
91 | |
92 | void CustomRenderItem::setMinBounds(const QVector3D &bounds) |
93 | { |
94 | m_minBounds = bounds; |
95 | m_minBoundsNormal = m_minBounds; |
96 | m_minBoundsNormal.setY(-m_minBoundsNormal.y()); |
97 | m_minBoundsNormal.setZ(-m_minBoundsNormal.z()); |
98 | m_minBoundsNormal = 0.5f * (m_minBoundsNormal + oneVector); |
99 | } |
100 | |
101 | void CustomRenderItem::setMaxBounds(const QVector3D &bounds) |
102 | { |
103 | m_maxBounds = bounds; |
104 | m_maxBoundsNormal = m_maxBounds; |
105 | m_maxBoundsNormal.setY(-m_maxBoundsNormal.y()); |
106 | m_maxBoundsNormal.setZ(-m_maxBoundsNormal.z()); |
107 | m_maxBoundsNormal = 0.5f * (m_maxBoundsNormal + oneVector); |
108 | } |
109 | |
110 | void CustomRenderItem::setSliceFrameColor(const QColor &color) |
111 | { |
112 | const QRgb &rgb = color.rgba(); |
113 | m_sliceFrameColor = QVector4D(float(qRed(rgb)) / 255.0f, |
114 | float(qGreen(rgb)) / 255.0f, |
115 | float(qBlue(rgb)) / 255.0f, |
116 | float(1.0f)); // Alpha not supported for frames |
117 | } |
118 | |
119 | QT_END_NAMESPACE_DATAVISUALIZATION |
120 | |