diff options
author | Mike Krus <mike.krus@kdab.com> | 2017-02-10 22:08:28 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-02-12 13:12:15 +0000 |
commit | be8099cd83a9fedf84508538ab49a86a41fc61d6 (patch) | |
tree | 7104a0fdbd8c4a81c50ac76bb5173ab9c2b46d69 | |
parent | 5c5d0d11127e52f1d1b49fda7b9e72cd3a84bdd5 (diff) |
Unit test for bounding spheres
Change-Id: Iee1e7aeaf43a4b783a914d808e2e7ac1e215b263
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | tests/auto/render/boundingsphere/boundingsphere.pro | 17 | ||||
-rw-r--r-- | tests/auto/render/boundingsphere/boundingsphere.qrc | 6 | ||||
-rw-r--r-- | tests/auto/render/boundingsphere/cube.qml | 69 | ||||
-rw-r--r-- | tests/auto/render/boundingsphere/sphere.qml | 69 | ||||
-rw-r--r-- | tests/auto/render/boundingsphere/tst_boundingsphere.cpp | 201 | ||||
-rw-r--r-- | tests/auto/render/render.pro | 1 |
6 files changed, 363 insertions, 0 deletions
diff --git a/tests/auto/render/boundingsphere/boundingsphere.pro b/tests/auto/render/boundingsphere/boundingsphere.pro new file mode 100644 index 000000000..cebba17e7 --- /dev/null +++ b/tests/auto/render/boundingsphere/boundingsphere.pro @@ -0,0 +1,17 @@ +TEMPLATE = app + +TARGET = tst_boundingsphere +QT += core-private 3dcore 3dcore-private 3drender 3drender-private 3dextras testlib + +CONFIG += testcase + +SOURCES += tst_boundingsphere.cpp + +include(../commons/commons.pri) +include(../../core/common/common.pri) +include(../qmlscenereader/qmlscenereader.pri) +# Extra dependencies to build test scenes needed by the tests +QT += quick 3dquick 3dquick-private 3dextras 3dquickextras + +RESOURCES += \ + boundingsphere.qrc diff --git a/tests/auto/render/boundingsphere/boundingsphere.qrc b/tests/auto/render/boundingsphere/boundingsphere.qrc new file mode 100644 index 000000000..5ea2cb958 --- /dev/null +++ b/tests/auto/render/boundingsphere/boundingsphere.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file>sphere.qml</file> + <file>cube.qml</file> + </qresource> +</RCC> diff --git a/tests/auto/render/boundingsphere/cube.qml b/tests/auto/render/boundingsphere/cube.qml new file mode 100644 index 000000000..11d6d4db1 --- /dev/null +++ b/tests/auto/render/boundingsphere/cube.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Extras 2.0 + +Entity { + id: sceneRoot + + components: [ ] + + // Parent Entity + Entity { + + components: [ + CuboidMesh { id: testMesh; objectName: "testMesh" }, + PhongMaterial { id: material } + ] + } + +} diff --git a/tests/auto/render/boundingsphere/sphere.qml b/tests/auto/render/boundingsphere/sphere.qml new file mode 100644 index 000000000..1f0e2245a --- /dev/null +++ b/tests/auto/render/boundingsphere/sphere.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Extras 2.0 + +Entity { + id: sceneRoot + + components: [ ] + + // Parent Entity + Entity { + + components: [ + SphereMesh { id: testMesh; objectName: "testMesh" }, + PhongMaterial { id: material } + ] + } + +} diff --git a/tests/auto/render/boundingsphere/tst_boundingsphere.cpp b/tests/auto/render/boundingsphere/tst_boundingsphere.cpp new file mode 100644 index 000000000..fcbfaf6ba --- /dev/null +++ b/tests/auto/render/boundingsphere/tst_boundingsphere.cpp @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlscenereader.h" +#include "testpostmanarbiter.h" + +#include <QUrl> + +#include <QtTest/QTest> +#include <Qt3DCore/qentity.h> +#include <Qt3DCore/qtransform.h> +#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> +#include <Qt3DCore/private/qaspectjobmanager_p.h> +#include <QtQuick/qquickwindow.h> + +#include <Qt3DRender/QCamera> +#include <Qt3DRender/QObjectPicker> +#include <Qt3DRender/QPickEvent> +#include <Qt3DRender/QPickTriangleEvent> +#include <Qt3DRender/private/nodemanagers_p.h> +#include <Qt3DRender/private/managers_p.h> +#include <Qt3DRender/private/entity_p.h> +#include <Qt3DRender/qrenderaspect.h> +#include <Qt3DRender/private/qrenderaspect_p.h> +#include <Qt3DRender/private/pickboundingvolumejob_p.h> +#include <Qt3DRender/private/updatemeshtrianglelistjob_p.h> +#include <Qt3DRender/private/updateworldboundingvolumejob_p.h> +#include <Qt3DRender/private/updateworldtransformjob_p.h> +#include <Qt3DRender/private/expandboundingvolumejob_p.h> +#include <Qt3DRender/private/calcboundingvolumejob_p.h> +#include <Qt3DRender/private/calcgeometrytrianglevolumes_p.h> +#include <Qt3DRender/private/loadbufferjob_p.h> +#include <Qt3DRender/private/buffermanager_p.h> +#include <Qt3DRender/private/geometryrenderermanager_p.h> +#include <Qt3DRender/private/sphere_p.h> + +#include <Qt3DExtras/qspheremesh.h> +#include <Qt3DExtras/qcylindermesh.h> +#include <Qt3DExtras/qtorusmesh.h> +#include <Qt3DExtras/qcuboidmesh.h> +#include <Qt3DExtras/qplanemesh.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class TestAspect : public Qt3DRender::QRenderAspect +{ +public: + TestAspect(Qt3DCore::QNode *root) + : Qt3DRender::QRenderAspect(Qt3DRender::QRenderAspect::Synchronous) + , m_sceneRoot(nullptr) + { + QRenderAspect::onRegistered(); + + const Qt3DCore::QNodeCreatedChangeGenerator generator(root); + const QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = generator.creationChanges(); + + d_func()->setRootAndCreateNodes(qobject_cast<Qt3DCore::QEntity *>(root), creationChanges); + + Render::Entity *rootEntity = nodeManagers()->lookupResource<Render::Entity, Render::EntityManager>(rootEntityId()); + Q_ASSERT(rootEntity); + m_sceneRoot = rootEntity; + } + + ~TestAspect() + { + QRenderAspect::onUnregistered(); + } + + void onRegistered() { QRenderAspect::onRegistered(); } + void onUnregistered() { QRenderAspect::onUnregistered(); } + + Qt3DRender::Render::NodeManagers *nodeManagers() const { return d_func()->m_renderer->nodeManagers(); } + Qt3DRender::Render::FrameGraphNode *frameGraphRoot() const { return d_func()->m_renderer->frameGraphRoot(); } + Qt3DRender::Render::RenderSettings *renderSettings() const { return d_func()->m_renderer->settings(); } + Qt3DRender::Render::Entity *sceneRoot() const { return m_sceneRoot; } + +private: + Render::Entity *m_sceneRoot; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +namespace { + +void runRequiredJobs(Qt3DRender::TestAspect *test) +{ + Qt3DRender::Render::UpdateWorldTransformJob updateWorldTransform; + updateWorldTransform.setRoot(test->sceneRoot()); + updateWorldTransform.run(); + + // For each buffer + QVector<Qt3DRender::Render::HBuffer> bufferHandles = test->nodeManagers()->bufferManager()->activeHandles(); + for (auto bufferHandle : bufferHandles) { + Qt3DRender::Render::LoadBufferJob loadBuffer(bufferHandle); + loadBuffer.setNodeManager(test->nodeManagers()); + loadBuffer.run(); + } + + Qt3DRender::Render::CalculateBoundingVolumeJob calcBVolume; + calcBVolume.setManagers(test->nodeManagers()); + calcBVolume.setRoot(test->sceneRoot()); + calcBVolume.run(); + + Qt3DRender::Render::UpdateWorldBoundingVolumeJob updateWorldBVolume; + updateWorldBVolume.setManager(test->nodeManagers()->renderNodesManager()); + updateWorldBVolume.run(); + + Qt3DRender::Render::ExpandBoundingVolumeJob expandBVolume; + expandBVolume.setRoot(test->sceneRoot()); + expandBVolume.run(); + + Qt3DRender::Render::UpdateMeshTriangleListJob updateTriangleList; + updateTriangleList.setManagers(test->nodeManagers()); + updateTriangleList.run(); + + // For each geometry id + QVector<Qt3DRender::Render::HGeometryRenderer> geometryRenderHandles = test->nodeManagers()->geometryRendererManager()->activeHandles(); + for (auto geometryRenderHandle : geometryRenderHandles) { + Qt3DCore::QNodeId geometryRendererId = test->nodeManagers()->geometryRendererManager()->data(geometryRenderHandle)->peerId(); + Qt3DRender::Render::CalcGeometryTriangleVolumes calcGeometryTriangles(geometryRendererId, test->nodeManagers()); + calcGeometryTriangles.run(); + } +} + +} // anonymous + +class tst_BoundingSphere : public QObject +{ + Q_OBJECT +private: + +private Q_SLOTS: + void checkExtraGeometries_data() + { + QTest::addColumn<QString>("qmlFile"); + QTest::addColumn<QVector3D>("sphereCenter"); + QTest::addColumn<float>("sphereRadius"); + QTest::newRow("SphereMesh") << "qrc:/sphere.qml" << QVector3D(0.f, 0.f, 0.f) << 1.f; + QTest::newRow("CubeMesh") << "qrc:/cube.qml" << QVector3D(0.0928356f, -0.212021f, -0.0467958f) << 1.07583f; // weird! + } + + void checkExtraGeometries() + { + // GIVEN + QFETCH(QString, qmlFile); + QFETCH(QVector3D, sphereCenter); + QFETCH(float, sphereRadius); + + QUrl qmlUrl(qmlFile); + QmlSceneReader sceneReader(qmlUrl); + QScopedPointer<Qt3DCore::QNode> root(qobject_cast<Qt3DCore::QNode *>(sceneReader.root())); + QVERIFY(root); + + QScopedPointer<Qt3DRender::TestAspect> test(new Qt3DRender::TestAspect(root.data())); + + // Runs Required jobs + runRequiredJobs(test.data()); + + // THEN + QVERIFY(test->sceneRoot()->worldBoundingVolumeWithChildren()); + const auto boundingSphere = test->sceneRoot()->worldBoundingVolumeWithChildren(); + qDebug() << qmlFile << boundingSphere->radius() << boundingSphere->center(); + QCOMPARE(boundingSphere->radius(), sphereRadius); + QVERIFY(qAbs(boundingSphere->center().x() - sphereCenter.x()) < 0.000001f); // qFuzzyCompare hates 0s + QVERIFY(qAbs(boundingSphere->center().y() - sphereCenter.y()) < 0.000001f); + QVERIFY(qAbs(boundingSphere->center().z() - sphereCenter.z()) < 0.000001f); + } +}; + +QTEST_MAIN(tst_BoundingSphere) + +#include "tst_boundingsphere.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index 4f536d3f4..052b19dd3 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -45,6 +45,7 @@ qtConfig(private_tests) { picking \ # qboundingvolumedebug \ # boundingvolumedebug \ + boundingsphere \ qdefaultmeshes \ trianglesextractor \ triangleboundingvolume \ |