Exemple #1
0
class TestSceneWidget(TestCaseQt, ParametricTestCase):
    """Tests SceneWidget picking feature"""
    def setUp(self):
        super(TestSceneWidget, self).setUp()
        self.widget = SceneWidget()
        self.widget.show()
        self.qWaitForWindowExposed(self.widget)

    def tearDown(self):
        self.qapp.processEvents()
        self.widget.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.widget.close()
        del self.widget
        super(TestSceneWidget, self).tearDown()

    def testFogEffect(self):
        """Test fog effect on scene primitive"""
        image = self.widget.addImage(numpy.arange(100).reshape(10, 10))
        scatter = self.widget.add3DScatter(
            *numpy.random.random(4000).reshape(4, -1))
        scatter.setTranslation(10, 10)
        scatter.setScale(10, 10, 10)

        self.widget.resetZoom('front')
        self.qapp.processEvents()

        self.widget.setFogMode(self.widget.FogMode.LINEAR)
        self.qapp.processEvents()

        self.widget.setFogMode(self.widget.FogMode.NONE)
        self.qapp.processEvents()
Exemple #2
0
class TestSceneWidget(TestCaseQt, ParametricTestCase):
    """Tests StatsWidget combined with SceneWidget"""
    def setUp(self):
        super(TestSceneWidget, self).setUp()
        self.sceneWidget = SceneWidget()
        self.sceneWidget.resize(300, 300)
        self.sceneWidget.show()
        self.statsWidget = BasicStatsWidget()
        self.statsWidget.setPlot(self.sceneWidget)
        # self.qWaitForWindowExposed(self.sceneWidget)

    def tearDown(self):
        Stats._getContext.cache_clear()
        self.qapp.processEvents()
        self.sceneWidget.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.sceneWidget.close()
        del self.sceneWidget
        self.statsWidget.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.statsWidget.close()
        del self.statsWidget
        super(TestSceneWidget, self).tearDown()

    def test(self):
        """Test StatsWidget with SceneWidget"""
        # Prepare scene

        # Data image
        image = self.sceneWidget.addImage(numpy.arange(100).reshape(10, 10))
        image.setLabel('Image')
        # RGB image
        imageRGB = self.sceneWidget.addImage(
            numpy.arange(300, dtype=numpy.uint8).reshape(10, 10, 3))
        imageRGB.setLabel('RGB Image')
        # 2D scatter
        data = numpy.arange(100)
        scatter2D = self.sceneWidget.add2DScatter(x=data, y=data, value=data)
        scatter2D.setLabel('2D Scatter')
        # 3D scatter
        scatter3D = self.sceneWidget.add3DScatter(x=data,
                                                  y=data,
                                                  z=data,
                                                  value=data)
        scatter3D.setLabel('3D Scatter')
        # Add a group
        group = items.GroupItem()
        self.sceneWidget.addItem(group)
        # 3D scalar field
        data = numpy.arange(64**3).reshape(64, 64, 64)
        scalarField = items.ScalarField3D()
        scalarField.setData(data, copy=False)
        scalarField.setLabel('3D Scalar field')
        group.addItem(scalarField)

        statsTable = self.statsWidget._getStatsTable()

        # Test selection only
        self.statsWidget.setDisplayOnlyActiveItem(True)
        self.assertEqual(statsTable.rowCount(), 0)

        self.sceneWidget.selection().setCurrentItem(group)
        self.assertEqual(statsTable.rowCount(), 0)

        for item in (image, scatter2D, scatter3D, scalarField):
            with self.subTest('selection only', item=item.getLabel()):
                self.sceneWidget.selection().setCurrentItem(item)
                self.assertEqual(statsTable.rowCount(), 1)
                self._checkItem(item)

        # Test all data
        self.statsWidget.setDisplayOnlyActiveItem(False)
        self.assertEqual(statsTable.rowCount(), 4)

        for item in (image, scatter2D, scatter3D, scalarField):
            with self.subTest('all items', item=item.getLabel()):
                self._checkItem(item)

    def _checkItem(self, item):
        """Check that item is in StatsTable and that stats are OK

        :param silx.gui.plot3d.items.Item3D item:
        """
        if isinstance(item, (items.Scatter2D, items.Scatter3D)):
            data = item.getValueData(copy=False)
        else:
            data = item.getData(copy=False)

        statsTable = self.statsWidget._getStatsTable()
        tableItems = statsTable._itemToTableItems(item)
        self.assertTrue(len(tableItems) > 0)
        self.assertEqual(tableItems['legend'].text(), item.getLabel())
        self.assertEqual(float(tableItems['min'].text()), numpy.min(data))
        self.assertEqual(float(tableItems['max'].text()), numpy.max(data))
Exemple #3
0
class TestSceneWidget(TestCaseQt, ParametricTestCase):
    """Tests StatsWidget combined with SceneWidget"""

    def setUp(self):
        super(TestSceneWidget, self).setUp()
        self.sceneWidget = SceneWidget()
        self.sceneWidget.resize(300, 300)
        self.sceneWidget.show()
        self.statsWidget = BasicStatsWidget()
        self.statsWidget.setPlot(self.sceneWidget)
        # self.qWaitForWindowExposed(self.sceneWidget)

    def tearDown(self):
        self.qapp.processEvents()
        self.sceneWidget.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.sceneWidget.close()
        del self.sceneWidget
        self.statsWidget.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.statsWidget.close()
        del self.statsWidget
        super(TestSceneWidget, self).tearDown()

    def test(self):
        """Test StatsWidget with SceneWidget"""
        # Prepare scene

        # Data image
        image = self.sceneWidget.addImage(numpy.arange(100).reshape(10, 10))
        image.setLabel('Image')
        # RGB image
        imageRGB = self.sceneWidget.addImage(
            numpy.arange(300, dtype=numpy.uint8).reshape(10, 10, 3))
        imageRGB.setLabel('RGB Image')
        # 2D scatter
        data = numpy.arange(100)
        scatter2D = self.sceneWidget.add2DScatter(x=data, y=data, value=data)
        scatter2D.setLabel('2D Scatter')
        # 3D scatter
        scatter3D = self.sceneWidget.add3DScatter(x=data, y=data, z=data, value=data)
        scatter3D.setLabel('3D Scatter')
        # Add a group
        group = items.GroupItem()
        self.sceneWidget.addItem(group)
        # 3D scalar field
        data = numpy.arange(64**3).reshape(64, 64, 64)
        scalarField = items.ScalarField3D()
        scalarField.setData(data, copy=False)
        scalarField.setLabel('3D Scalar field')
        group.addItem(scalarField)

        statsTable = self.statsWidget._getStatsTable()

        # Test selection only
        self.statsWidget.setDisplayOnlyActiveItem(True)
        self.assertEqual(statsTable.rowCount(), 0)

        self.sceneWidget.selection().setCurrentItem(group)
        self.assertEqual(statsTable.rowCount(), 0)

        for item in (image, scatter2D, scatter3D, scalarField):
            with self.subTest('selection only', item=item.getLabel()):
                self.sceneWidget.selection().setCurrentItem(item)
                self.assertEqual(statsTable.rowCount(), 1)
                self._checkItem(item)

        # Test all data
        self.statsWidget.setDisplayOnlyActiveItem(False)
        self.assertEqual(statsTable.rowCount(), 4)

        for item in (image, scatter2D, scatter3D, scalarField):
            with self.subTest('all items', item=item.getLabel()):
                self._checkItem(item)

    def _checkItem(self, item):
        """Check that item is in StatsTable and that stats are OK

        :param silx.gui.plot3d.items.Item3D item:
        """
        if isinstance(item, (items.Scatter2D, items.Scatter3D)):
            data = item.getValueData(copy=False)
        else:
            data = item.getData(copy=False)

        statsTable = self.statsWidget._getStatsTable()
        tableItems = statsTable._itemToTableItems(item)
        self.assertTrue(len(tableItems) > 0)
        self.assertEqual(tableItems['legend'].text(), item.getLabel())
        self.assertEqual(float(tableItems['min'].text()), numpy.min(data))
        self.assertEqual(float(tableItems['max'].text()), numpy.max(data))