| 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 | // |
| 31 | // W A R N I N G |
| 32 | // ------------- |
| 33 | // |
| 34 | // This file is not part of the QtDataVisualization API. It exists purely as an |
| 35 | // implementation detail. This header file may change from version to |
| 36 | // version without notice, or even be removed. |
| 37 | // |
| 38 | // We mean it. |
| 39 | |
| 40 | #ifndef CUSTOMRENDERITEM_P_H |
| 41 | #define CUSTOMRENDERITEM_P_H |
| 42 | |
| 43 | #include "abstractrenderitem_p.h" |
| 44 | #include "objecthelper_p.h" |
| 45 | #include <QtGui/QRgb> |
| 46 | #include <QtGui/QImage> |
| 47 | #include <QtGui/QColor> |
| 48 | |
| 49 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
| 50 | |
| 51 | class QCustom3DItem; |
| 52 | class Abstract3DRenderer; |
| 53 | |
| 54 | class CustomRenderItem : public AbstractRenderItem |
| 55 | { |
| 56 | public: |
| 57 | CustomRenderItem(); |
| 58 | virtual ~CustomRenderItem(); |
| 59 | |
| 60 | inline void setTexture(GLuint texture) { m_texture = texture; } |
| 61 | inline GLuint texture() const { return m_texture; } |
| 62 | void setMesh(const QString &meshFile); |
| 63 | inline ObjectHelper *mesh() const { return m_object; } |
| 64 | inline void setScaling(const QVector3D &scaling) { m_scaling = scaling; } |
| 65 | inline const QVector3D &scaling() const { return m_scaling; } |
| 66 | inline void setOrigScaling(const QVector3D &scaling) { m_origScaling = scaling; } |
| 67 | inline const QVector3D &origScaling() const { return m_origScaling; } |
| 68 | inline void setPosition(const QVector3D &position) { m_position = position; } |
| 69 | inline const QVector3D &position() const { return m_position; } |
| 70 | inline void setOrigPosition(const QVector3D &position) { m_origPosition = position; } |
| 71 | inline const QVector3D &origPosition() const { return m_origPosition; } |
| 72 | inline void setPositionAbsolute(bool absolute) { m_positionAbsolute = absolute; } |
| 73 | inline bool isPositionAbsolute() const { return m_positionAbsolute; } |
| 74 | inline void setScalingAbsolute(bool absolute) { m_scalingAbsolute = absolute; } |
| 75 | inline bool isScalingAbsolute() const { return m_scalingAbsolute; } |
| 76 | inline void setBlendNeeded(bool blend) { m_needBlend = blend; } |
| 77 | inline bool isBlendNeeded() const { return m_needBlend; } |
| 78 | inline void setVisible(bool visible) { m_visible = visible; } |
| 79 | inline bool isVisible() const { return m_visible; } |
| 80 | inline void setItemPointer(QCustom3DItem *item) { m_item = item; } |
| 81 | inline QCustom3DItem *itemPointer() const { return m_item; } |
| 82 | inline void setValid(bool valid) { m_valid = valid; } |
| 83 | inline bool isValid() const { return m_valid; } |
| 84 | inline void setIndex(int index) { m_index = index; } |
| 85 | inline int index() const { return m_index; } |
| 86 | inline void setShadowCasting(bool shadowCasting) { m_shadowCasting = shadowCasting; } |
| 87 | inline bool isShadowCasting() const { return m_shadowCasting; } |
| 88 | inline void setFacingCamera(bool facing) { m_isFacingCamera = facing; } |
| 89 | inline bool isFacingCamera() const { return m_isFacingCamera; } |
| 90 | inline void setRenderer(Abstract3DRenderer *renderer) { m_renderer = renderer; } |
| 91 | inline void setLabelItem(bool isLabel) { m_labelItem = isLabel; } |
| 92 | inline bool isLabel() const { return m_labelItem; } |
| 93 | |
| 94 | // Volume specific |
| 95 | inline void setTextureWidth(int width) { m_textureWidth = width; setSliceIndexX(m_sliceIndexX); } |
| 96 | inline int textureWidth() const { return m_textureWidth; } |
| 97 | inline void setTextureHeight(int height) { m_textureHeight = height; setSliceIndexY(m_sliceIndexY); } |
| 98 | inline int textureHeight() const { return m_textureHeight; } |
| 99 | inline void setTextureDepth(int depth) { m_textureDepth = depth; setSliceIndexZ(m_sliceIndexZ); } |
| 100 | inline int textureDepth() const { return m_textureDepth; } |
| 101 | inline int textureSize() const { return m_textureWidth * m_textureHeight * m_textureDepth; } |
| 102 | inline void setColorTable(const QVector<QVector4D> &colors) { m_colorTable = colors; } |
| 103 | void setColorTable(const QVector<QRgb> &colors); |
| 104 | inline const QVector<QVector4D> &colorTable() const { return m_colorTable; } |
| 105 | inline void setVolume(bool volume) { m_isVolume = volume; } |
| 106 | inline bool isVolume() const { return m_isVolume; } |
| 107 | inline void setTextureFormat(QImage::Format format) { m_textureFormat = format; } |
| 108 | inline QImage::Format textureFormat() const { return m_textureFormat; } |
| 109 | inline void setSliceIndexX(int index) |
| 110 | { |
| 111 | m_sliceIndexX = index; |
| 112 | m_sliceFractions.setX((float(index) + 0.5f) / float(m_textureWidth) * 2.0 - 1.0); |
| 113 | } |
| 114 | inline void setSliceIndexY(int index) |
| 115 | { |
| 116 | m_sliceIndexY = index; |
| 117 | m_sliceFractions.setY((float(index) + 0.5f) / float(m_textureHeight) * 2.0 - 1.0); |
| 118 | } |
| 119 | inline void setSliceIndexZ(int index) |
| 120 | { |
| 121 | m_sliceIndexZ = index; |
| 122 | m_sliceFractions.setZ((float(index) + 0.5f) / float(m_textureDepth) * 2.0 - 1.0); |
| 123 | } |
| 124 | inline const QVector3D &sliceFractions() const { return m_sliceFractions; } |
| 125 | inline int sliceIndexX() const { return m_sliceIndexX; } |
| 126 | inline int sliceIndexY() const { return m_sliceIndexY; } |
| 127 | inline int sliceIndexZ() const { return m_sliceIndexZ; } |
| 128 | inline void setAlphaMultiplier(float mult) { m_alphaMultiplier = mult; } |
| 129 | inline float alphaMultiplier() const { return m_alphaMultiplier; } |
| 130 | inline void setPreserveOpacity(bool enable) { m_preserveOpacity = enable; } |
| 131 | inline bool preserveOpacity() const { return m_preserveOpacity; } |
| 132 | inline void setUseHighDefShader(bool enable) { m_useHighDefShader = enable; } |
| 133 | inline bool useHighDefShader() const {return m_useHighDefShader; } |
| 134 | void setMinBounds(const QVector3D &bounds); |
| 135 | inline const QVector3D &minBounds() const { return m_minBounds; } |
| 136 | void setMaxBounds(const QVector3D &bounds); |
| 137 | inline const QVector3D &maxBounds() const { return m_maxBounds; } |
| 138 | inline const QVector3D &minBoundsNormal() const { return m_minBoundsNormal; } |
| 139 | inline const QVector3D &maxBoundsNormal() const { return m_maxBoundsNormal; } |
| 140 | inline void setDrawSlices(bool enable) { m_drawSlices = enable; } |
| 141 | inline bool drawSlices() const {return m_drawSlices; } |
| 142 | inline void setDrawSliceFrames(bool enable) { m_drawSliceFrames = enable; } |
| 143 | inline bool drawSliceFrames() const {return m_drawSliceFrames; } |
| 144 | void setSliceFrameColor(const QColor &color); |
| 145 | inline const QVector4D &sliceFrameColor() const { return m_sliceFrameColor; } |
| 146 | inline void setSliceFrameWidths(const QVector3D &widths) { m_sliceFrameWidths = widths * 2.0f; } |
| 147 | inline const QVector3D &sliceFrameWidths() const { return m_sliceFrameWidths; } |
| 148 | inline void setSliceFrameGaps(const QVector3D &gaps) { m_sliceFrameGaps = gaps * 2.0f; } |
| 149 | inline const QVector3D &sliceFrameGaps() const { return m_sliceFrameGaps; } |
| 150 | inline void setSliceFrameThicknesses(const QVector3D &thicknesses) { m_sliceFrameThicknesses = thicknesses; } |
| 151 | inline const QVector3D &sliceFrameThicknesses() const { return m_sliceFrameThicknesses; } |
| 152 | |
| 153 | private: |
| 154 | Q_DISABLE_COPY(CustomRenderItem) |
| 155 | |
| 156 | GLuint m_texture; |
| 157 | QVector3D m_scaling; |
| 158 | QVector3D m_origScaling; |
| 159 | QVector3D m_position; |
| 160 | QVector3D m_origPosition; |
| 161 | bool m_positionAbsolute; |
| 162 | bool m_scalingAbsolute; |
| 163 | ObjectHelper *m_object; // shared reference |
| 164 | bool m_needBlend; |
| 165 | bool m_visible; |
| 166 | bool m_valid; |
| 167 | int m_index; |
| 168 | bool m_shadowCasting; |
| 169 | bool m_isFacingCamera; |
| 170 | QCustom3DItem *m_item; |
| 171 | Abstract3DRenderer *m_renderer; |
| 172 | bool m_labelItem; |
| 173 | |
| 174 | // Volume specific |
| 175 | int m_textureWidth; |
| 176 | int m_textureHeight; |
| 177 | int m_textureDepth; |
| 178 | QVector<QVector4D> m_colorTable; |
| 179 | bool m_isVolume; |
| 180 | QImage::Format m_textureFormat; |
| 181 | int m_sliceIndexX; |
| 182 | int m_sliceIndexY; |
| 183 | int m_sliceIndexZ; |
| 184 | QVector3D m_sliceFractions; |
| 185 | float m_alphaMultiplier; |
| 186 | bool m_preserveOpacity; |
| 187 | bool m_useHighDefShader; |
| 188 | QVector3D m_minBounds; |
| 189 | QVector3D m_maxBounds; |
| 190 | QVector3D m_minBoundsNormal; |
| 191 | QVector3D m_maxBoundsNormal; |
| 192 | bool m_drawSlices; |
| 193 | bool m_drawSliceFrames; |
| 194 | QVector4D m_sliceFrameColor; |
| 195 | QVector3D m_sliceFrameWidths; |
| 196 | QVector3D m_sliceFrameGaps; |
| 197 | QVector3D m_sliceFrameThicknesses; |
| 198 | }; |
| 199 | typedef QHash<QCustom3DItem *, CustomRenderItem *> CustomRenderItemArray; |
| 200 | |
| 201 | QT_END_NAMESPACE_DATAVISUALIZATION |
| 202 | |
| 203 | #endif |
| 204 |
