Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/3dview/linemeshgeometry.cpp
Show All 15 Lines | 1 | /* Atelier KDE Printer Host for 3D Printing | |||
---|---|---|---|---|---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | GNU General Public License for more details. | 17 | GNU General Public License for more details. | ||
18 | 18 | | |||
19 | You should have received a copy of the GNU General Public License | 19 | You should have received a copy of the GNU General Public License | ||
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include <QVector> | 23 | #include <QVector> | ||
24 | #include <QVector3D> | | |||
25 | #include "linemeshgeometry.h" | 24 | #include "linemeshgeometry.h" | ||
26 | 25 | | |||
27 | LineMeshGeometry::LineMeshGeometry(const QVector<QVector3D> &vertices, Qt3DCore::QNode *parent) : | 26 | LineMeshGeometry::LineMeshGeometry(const QVector<QVector3D> &vertices, Qt3DCore::QNode *parent) : | ||
28 | Qt3DRender::QGeometry(parent) | 27 | Qt3DRender::QGeometry(parent) | ||
29 | , _positionAttribute(new Qt3DRender::QAttribute(this)) | 28 | , _positionAttribute(new Qt3DRender::QAttribute(this)) | ||
30 | , _vertexBuffer(new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, this)) | 29 | , _vertexBuffer(new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, this)) | ||
31 | { | 30 | { | ||
32 | QByteArray vertexBufferData; | 31 | QByteArray vertexBufferData; | ||
33 | vertexBufferData.resize(vertices.size() * static_cast<int>(sizeof(QVector3D))); | 32 | vertexBufferData.resize(vertices.size() * static_cast<int>(sizeof(QVector3D))); | ||
34 | memcpy(vertexBufferData.data(), vertices.constData(), static_cast<size_t>(vertexBufferData.size())); | 33 | memcpy(vertexBufferData.data(), vertices.constData(), static_cast<size_t>(vertexBufferData.size())); | ||
35 | _vertexBuffer->setData(vertexBufferData); | 34 | _vertexBuffer->setData(vertexBufferData); | ||
36 | 35 | | |||
37 | _positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); | 36 | _positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); | ||
38 | _positionAttribute->setBuffer(_vertexBuffer); | 37 | _positionAttribute->setBuffer(_vertexBuffer); | ||
39 | _positionAttribute->setDataType(Qt3DRender::QAttribute::Float); | 38 | _positionAttribute->setDataType(Qt3DRender::QAttribute::Float); | ||
40 | _positionAttribute->setDataSize(3); | 39 | _positionAttribute->setDataSize(3); | ||
41 | _positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); | 40 | _positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); | ||
42 | 41 | | |||
43 | addAttribute(_positionAttribute); | 42 | addAttribute(_positionAttribute); | ||
43 | | ||||
44 | if (vertices.isEmpty()) { | ||||
patrickelectric: We are fan of hugs ;) (one line brackets)
Please use our style script, under scripts/style.sh | |||||
45 | return; | ||||
46 | } | ||||
47 | | ||||
48 | float minX = vertices.first().x(); | ||||
49 | float maxX = vertices.first().x(); | ||||
50 | float minY = vertices.first().y(); | ||||
51 | float maxY = vertices.first().y(); | ||||
52 | float minZ = vertices.first().z(); | ||||
53 | float maxZ = vertices.first().z(); | ||||
54 | for (const auto &position : vertices) { | ||||
55 | if (position.x() < minX) { | ||||
56 | minX = position.x(); | ||||
57 | } | ||||
58 | if (position.x() > maxX) { | ||||
59 | maxX = position.x(); | ||||
60 | } | ||||
61 | if (position.y() < minY) { | ||||
62 | minY = position.y(); | ||||
63 | } | ||||
64 | if (position.y() > maxY) { | ||||
65 | maxY = position.y(); | ||||
66 | } | ||||
67 | if (position.z() < minZ) { | ||||
68 | minZ = position.z(); | ||||
69 | } | ||||
70 | if (position.z() > maxZ) { | ||||
71 | maxZ = position.z(); | ||||
72 | } | ||||
73 | } | ||||
74 | _center = QVector3D((minX + maxX) / 2.0f, | ||||
75 | (minY + maxY) / 2.0f, | ||||
76 | (minZ + maxZ) / 2.0f); | ||||
44 | } | 77 | } | ||
45 | 78 | | |||
46 | LineMeshGeometry::~LineMeshGeometry() | 79 | LineMeshGeometry::~LineMeshGeometry() | ||
47 | { | 80 | { | ||
48 | } | 81 | } | ||
49 | 82 | | |||
50 | int LineMeshGeometry::vertexCount() | 83 | int LineMeshGeometry::vertexCount() | ||
51 | { | 84 | { | ||
52 | return _vertexBuffer->data().size() / static_cast<int>(sizeof(QVector3D)); | 85 | return _vertexBuffer->data().size() / static_cast<int>(sizeof(QVector3D)); | ||
53 | } | 86 | } | ||
87 | | ||||
88 | QVector3D LineMeshGeometry::center() | ||||
89 | { | ||||
90 | return _center; | ||||
91 | } |
We are fan of hugs ;) (one line brackets)
Please use our style script, under scripts/style.sh