diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2017-08-18 12:21:55 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-08-18 19:45:48 +0000 |
commit | 78569895236c4f82dba212d49ab57373682be4d5 (patch) | |
tree | 5e893995ec2737db96b86a2dd46883ac7995ec88 /tests | |
parent | 0ebfeccafe2ae87dbc10da25a34afdccc7e55124 (diff) |
FilterProximityDistanceJob added
Filters entity based on distance between an entity and another target
entity.
Properly unit tested
Change-Id: I776c634dee2d4fd94c40cb5720cc5588daa1b741
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/render/proximityfiltering/proximityfiltering.pro | 13 | ||||
-rw-r--r-- | tests/auto/render/proximityfiltering/tst_proximityfiltering.cpp | 287 | ||||
-rw-r--r-- | tests/auto/render/render.pro | 3 |
3 files changed, 302 insertions, 1 deletions
diff --git a/tests/auto/render/proximityfiltering/proximityfiltering.pro b/tests/auto/render/proximityfiltering/proximityfiltering.pro new file mode 100644 index 000000000..68b709ec5 --- /dev/null +++ b/tests/auto/render/proximityfiltering/proximityfiltering.pro @@ -0,0 +1,13 @@ +TEMPLATE = app + +TARGET = tst_proximityfiltering + +QT += core-private 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_proximityfiltering.cpp + +CONFIG += useCommonTestAspect + +include(../commons/commons.pri) diff --git a/tests/auto/render/proximityfiltering/tst_proximityfiltering.cpp b/tests/auto/render/proximityfiltering/tst_proximityfiltering.cpp new file mode 100644 index 000000000..7a5648271 --- /dev/null +++ b/tests/auto/render/proximityfiltering/tst_proximityfiltering.cpp @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Paul Lemire +** 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 <QtTest/QTest> +#include <Qt3DCore/qentity.h> +#include <Qt3DCore/qtransform.h> +#include <Qt3DRender/private/nodemanagers_p.h> +#include <Qt3DRender/private/managers_p.h> +#include <Qt3DRender/private/entity_p.h> +#include <Qt3DRender/private/filterproximitydistancejob_p.h> +#include <Qt3DRender/private/updatetreeenabledjob_p.h> +#include <Qt3DRender/qproximityfilter.h> + +#include "testaspect.h" + +namespace { + +Qt3DCore::QEntity *buildEntityAtDistance(float distance, Qt3DCore::QEntity *parent) +{ + Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(parent); + Qt3DCore::QTransform *transform = new Qt3DCore::QTransform(parent); + const QVector3D t = QVector3D(1.0f, 0.0f, 0.0f) * distance; + + transform->setTranslation(t); + entity->addComponent(transform); + + return entity; +} + +} // anonymous + +class tst_ProximityFiltering : public QObject +{ + Q_OBJECT +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DRender::Render::FilterProximityDistanceJob filterJob; + + // THEN + QCOMPARE(filterJob.hasProximityFilter(), false); + QCOMPARE(filterJob.filteredEntities().size(), 0); + QCOMPARE(filterJob.proximityFilterIds().size(), 0); + QVERIFY(filterJob.manager() == nullptr); + } + + void filterEntities_data() + { + QTest::addColumn<Qt3DCore::QEntity *>("entitySubtree"); + QTest::addColumn<Qt3DCore::QNodeIdVector>("proximityFilterIds"); + QTest::addColumn<Qt3DCore::QNodeIdVector>("expectedSelectedEntities"); + + { + Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); + Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); + Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); + Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); + + QTest::newRow("ShouldSelectAll") << rootEntity + << Qt3DCore::QNodeIdVector() + << (Qt3DCore::QNodeIdVector() + << rootEntity->id() + << childEntity1->id() + << childEntity2->id() + << childEntity3->id() + ); + } + + { + Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); + Qt3DCore::QEntity *childEntity1 = new Qt3DCore::QEntity(rootEntity); + Qt3DCore::QEntity *childEntity2 = new Qt3DCore::QEntity(rootEntity); + Qt3DCore::QEntity *childEntity3 = new Qt3DCore::QEntity(rootEntity); + Q_UNUSED(childEntity1); + Q_UNUSED(childEntity2); + Q_UNUSED(childEntity3); + + Qt3DRender::QProximityFilter *proximityFilter = new Qt3DRender::QProximityFilter(rootEntity); + + QTest::newRow("ShouldSelectNone") << rootEntity + << (Qt3DCore::QNodeIdVector() << proximityFilter->id()) + << (Qt3DCore::QNodeIdVector()); + } + + { + Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); + Qt3DCore::QEntity *targetEntity = new Qt3DCore::QEntity(rootEntity); + Qt3DCore::QEntity *childEntity1 = buildEntityAtDistance(50.0f, rootEntity); + Qt3DCore::QEntity *childEntity2 = buildEntityAtDistance(25.0f, rootEntity); + Qt3DCore::QEntity *childEntity3 = buildEntityAtDistance(75.0f, rootEntity); + Qt3DRender::QProximityFilter *proximityFilter = new Qt3DRender::QProximityFilter(rootEntity); + proximityFilter->setDistanceThreshold(30.0f); + + // Note: rootEntity BoundingSphere will be centered in vec3(75.0f / 2.0, 0.0f 0.0f); + + // Note: we cannot set rootEntity here as that would mean + // that the parent of the root would then be the proximity filter + // (since rootEntity has no parent) but this isn't valid in the way + // we have build the test + // Also rootEntity is centered based on the size of the child it contains + proximityFilter->setEntity(targetEntity); + + Q_UNUSED(childEntity1); + Q_UNUSED(childEntity3); + + QTest::newRow("ShouldSelectChild2") << rootEntity + << (Qt3DCore::QNodeIdVector() << proximityFilter->id()) + << (Qt3DCore::QNodeIdVector() + << targetEntity->id() + << childEntity2->id() + ); + } + + { + Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); + Qt3DCore::QEntity *targetEntity = new Qt3DCore::QEntity(rootEntity); + Qt3DCore::QEntity *childEntity1 = buildEntityAtDistance(50.0f, rootEntity); + Qt3DCore::QEntity *childEntity2 = buildEntityAtDistance(25.0f, rootEntity); + Qt3DCore::QEntity *childEntity3 = buildEntityAtDistance(49.9f, rootEntity); + Qt3DRender::QProximityFilter *proximityFilter = new Qt3DRender::QProximityFilter(rootEntity); + proximityFilter->setDistanceThreshold(50.0f); + + // Note: rootEntity BoundingSphere will be centered in vec3(50.0f / 2.0, 0.0f 0.0f); + + // Note: we cannot set rootEntity here as that would mean + // that the parent of the root would then be the proximity filter + // (since rootEntity has no parent) but this isn't valid in the way + // we have build the test + // Also rootEntity is centered based on the size of the child it contains + proximityFilter->setEntity(targetEntity); + + QTest::newRow("ShouldSelectRootChild123") << rootEntity + << (Qt3DCore::QNodeIdVector() << proximityFilter->id()) + << (Qt3DCore::QNodeIdVector() + << rootEntity->id() + << targetEntity->id() + << childEntity1->id() + << childEntity2->id() + << childEntity3->id() + ); + } + + { + Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); + Qt3DCore::QEntity *targetEntity = new Qt3DCore::QEntity(rootEntity); + Qt3DCore::QEntity *childEntity1 = buildEntityAtDistance(51.0f, rootEntity); + Qt3DCore::QEntity *childEntity2 = buildEntityAtDistance(75.0f, rootEntity); + Qt3DCore::QEntity *childEntity3 = buildEntityAtDistance(883.0f, rootEntity); + Qt3DRender::QProximityFilter *proximityFilter = new Qt3DRender::QProximityFilter(rootEntity); + proximityFilter->setDistanceThreshold(50.0f); + + // Note: rootEntity BoundingSphere will be centered in vec3(883.0f / 2.0, 0.0f 0.0f); + + // Note: we cannot set rootEntity here as that would mean + // that the parent of the root would then be the proximity filter + // (since rootEntity has no parent) but this isn't valid in the way + // we have build the test + // Also rootEntity is centered based on the size of the child it contains + proximityFilter->setEntity(targetEntity); + + Q_UNUSED(childEntity1); + Q_UNUSED(childEntity2); + Q_UNUSED(childEntity3); + + QTest::newRow("ShouldSelectNoneButTarget") << rootEntity + << (Qt3DCore::QNodeIdVector() << proximityFilter->id()) + << (Qt3DCore::QNodeIdVector() << targetEntity->id()); + } + + { + Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); + Qt3DCore::QEntity *targetEntity = new Qt3DCore::QEntity(rootEntity); + Qt3DCore::QEntity *childEntity1 = buildEntityAtDistance(50.0f, rootEntity); + Qt3DCore::QEntity *childEntity2 = buildEntityAtDistance(150.0f, rootEntity); + Qt3DCore::QEntity *childEntity3 = buildEntityAtDistance(25.0f, rootEntity); + + Qt3DRender::QProximityFilter *proximityFilter = new Qt3DRender::QProximityFilter(rootEntity); + proximityFilter->setDistanceThreshold(50.0f); + + Qt3DRender::QProximityFilter *proximityFilter2 = new Qt3DRender::QProximityFilter(rootEntity); + proximityFilter2->setDistanceThreshold(30.0f); + + // Note: rootEntity BoundingSphere will be centered in vec3(150.0f / 2.0, 0.0f 0.0f); + + // Note: we cannot set rootEntity here as that would mean + // that the parent of the root would then be the proximity filter + // (since rootEntity has no parent) but this isn't valid in the way + // we have build the test + // Also rootEntity is centered based on the size of the child it contains + proximityFilter->setEntity(targetEntity); + proximityFilter2->setEntity(targetEntity); + + Q_UNUSED(childEntity2); + + QTest::newRow("Nested-Step1") << rootEntity + << (Qt3DCore::QNodeIdVector() << proximityFilter->id()) + << (Qt3DCore::QNodeIdVector() + << targetEntity->id() + << childEntity1->id() + << childEntity3->id() + ); + QTest::newRow("Nested-Step2") << rootEntity + << (Qt3DCore::QNodeIdVector() << proximityFilter->id() << proximityFilter2->id()) + << (Qt3DCore::QNodeIdVector() + << targetEntity->id() + << childEntity3->id() + ); + } + } + + void filterEntities() + { + QFETCH(Qt3DCore::QEntity *, entitySubtree); + QFETCH(Qt3DCore::QNodeIdVector, proximityFilterIds); + QFETCH(Qt3DCore::QNodeIdVector, expectedSelectedEntities); + + // GIVEN + QScopedPointer<Qt3DRender::TestAspect> aspect(new Qt3DRender::TestAspect(entitySubtree)); + + // WHEN + Qt3DRender::Render::Entity *backendRoot = aspect->nodeManagers()->renderNodesManager()->getOrCreateResource(entitySubtree->id()); + Qt3DRender::Render::UpdateTreeEnabledJob updateTreeEnabledJob; + updateTreeEnabledJob.setRoot(backendRoot); + updateTreeEnabledJob.run(); + + Qt3DRender::Render::UpdateWorldTransformJob updateWorldTransform; + updateWorldTransform.setRoot(backendRoot); + updateWorldTransform.run(); + + Qt3DRender::Render::CalculateBoundingVolumeJob calcBVolume; + calcBVolume.setManagers(aspect->nodeManagers()); + calcBVolume.setRoot(backendRoot); + calcBVolume.run(); + + Qt3DRender::Render::UpdateWorldBoundingVolumeJob updateWorldBVolume; + updateWorldBVolume.setManager(aspect->nodeManagers()->renderNodesManager()); + updateWorldBVolume.run(); + + Qt3DRender::Render::ExpandBoundingVolumeJob expandBVolume; + expandBVolume.setRoot(backendRoot); + expandBVolume.run(); + + // WHEN + Qt3DRender::Render::FilterProximityDistanceJob filterJob; + filterJob.setProximityFilterIds(proximityFilterIds); + filterJob.setManager(aspect->nodeManagers()); + filterJob.run(); + + // THEN + const QVector<Qt3DRender::Render::Entity *> filterEntities = filterJob.filteredEntities(); + QCOMPARE(filterEntities.size(), expectedSelectedEntities.size()); + + for (auto i = 0, m = expectedSelectedEntities.size(); i < m; ++i) + QCOMPARE(filterEntities.at(i)->peerId(), expectedSelectedEntities.at(i)); + } +}; + +QTEST_MAIN(tst_ProximityFiltering) + +#include "tst_proximityfiltering.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index 8e9a5441f..0af4a7b3a 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -105,7 +105,8 @@ qtConfig(private_tests) { skeleton \ joint \ qproximityfilter \ - proximityfilter + proximityfilter \ + proximityfiltering QT_FOR_CONFIG = 3dcore-private qtConfig(qt3d-extras) { |