diff --git a/Modules/Core/test/mitkPointSetDataInteractorTest.cpp b/Modules/Core/test/mitkPointSetDataInteractorTest.cpp index 5d2360d54b..f335a9501f 100644 --- a/Modules/Core/test/mitkPointSetDataInteractorTest.cpp +++ b/Modules/Core/test/mitkPointSetDataInteractorTest.cpp @@ -1,202 +1,207 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" #include #include #include "mitkInteractionTestHelper.h" #include #include #include #include #include class mitkPointSetDataInteractorTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPointSetDataInteractorTestSuite); /// \todo Fix VTK memory leaks. Bug 18144. vtkDebugLeaks::SetExitError(0); MITK_TEST(AddPointInteraction); MITK_TEST(MoveDeletePointInteraction); // MITK_TEST(RotatedPlanesInteraction); CPPUNIT_TEST_SUITE_END(); private: mitk::DataNode::Pointer m_TestPointSetNode; mitk::PointSetDataInteractor::Pointer m_DataInteractor; mitk::PointSet::Pointer m_TestPointSet; public: void setUp() { - // check whether sufficient openGL is available - mitk::RenderingTestHelper openGlTest(640, 480); - // Create DataNode as a container for our PointSet to be tested m_TestPointSetNode = mitk::DataNode::New(); // Create PointSetData Interactor m_DataInteractor = mitk::PointSetDataInteractor::New(); // Load the according state machine for regular point set interaction m_DataInteractor->LoadStateMachine("PointSet.xml"); // Set the configuration file that defines the triggers for the transitions m_DataInteractor->SetEventConfig("PointSetConfig.xml"); // Create new PointSet which will receive the interaction input m_TestPointSet = mitk::PointSet::New(); m_TestPointSetNode->SetData(m_TestPointSet); // set the DataNode (which already is added to the DataStorage) m_DataInteractor->SetDataNode(m_TestPointSetNode); } void tearDown() { // destroy all objects - m_TestPointSetNode->SetDataInteractor(nullptr); + if (m_TestPointSetNode != nullptr) + { + m_TestPointSetNode->SetDataInteractor(nullptr); + } m_TestPointSetNode = nullptr; m_TestPointSet = nullptr; m_DataInteractor = nullptr; } void AddPointInteraction() { // Path to the reference PointSet std::string referencePointSetPath = GetTestDataFilePath("InteractionTestData/ReferenceData/TestAddPoints.mps"); // Path to the interaction xml file std::string interactionXmlPath = GetTestDataFilePath("InteractionTestData/Interactions/TestAddPoints.xml"); std::string pic3D = GetTestDataFilePath("Pic3D.nrrd"); mitk::Image::Pointer referenceImage = dynamic_cast(mitk::IOUtil::Load(pic3D)[0].GetPointer()); mitk::DataNode::Pointer refDN = mitk::DataNode::New(); refDN->SetData(referenceImage); // Create test helper to initialize all necessary objects for interaction mitk::InteractionTestHelper interactionTestHelper(interactionXmlPath); // Add our test node to the DataStorage of our test helper interactionTestHelper.AddNodeToStorage(m_TestPointSetNode); interactionTestHelper.AddNodeToStorage(refDN); // Start Interaction interactionTestHelper.PlaybackInteraction(); // Load the reference PointSet mitk::PointSet::Pointer referencePointSet = dynamic_cast(mitk::IOUtil::Load(referencePointSetPath)[0].GetPointer()); // Compare reference with the result of the interaction. Last parameter (false) is set to ignore the geometries. // They are not stored in a file and therefore not equal. CPPUNIT_ASSERT_MESSAGE("", mitk::Equal(referencePointSet, m_TestPointSet, .001, true, false)); } void RotatedPlanesInteraction() { // Path to the reference PointSet std::string referencePointSetPath = GetTestDataFilePath("InteractionTestData/ReferenceData/PointSetDataInteractor_PointsAdd2d3d.mps"); // Path to the interaction xml file std::string interactionXmlPath = GetTestDataFilePath("InteractionTestData/Interactions/PointSetDataInteractor_PointsAdd2d3d.xml"); std::string pic3D = GetTestDataFilePath("Pic3D.nrrd"); mitk::Image::Pointer referenceImage = dynamic_cast(mitk::IOUtil::Load(pic3D)[0].GetPointer()); mitk::DataNode::Pointer refDN = mitk::DataNode::New(); refDN->SetData(referenceImage); // Create test helper to initialize all necessary objects for interaction mitk::InteractionTestHelper interactionTestHelper(interactionXmlPath); // Add our test node to the DataStorage of our test helper interactionTestHelper.AddNodeToStorage(m_TestPointSetNode); interactionTestHelper.AddNodeToStorage(refDN); // Start Interaction interactionTestHelper.PlaybackInteraction(); // Load the reference PointSet mitk::PointSet::Pointer referencePointSet = dynamic_cast(mitk::IOUtil::Load(referencePointSetPath)[0].GetPointer()); // Compare reference with the result of the interaction. Last parameter (false) is set to ignore the geometries. // They are not stored in a file and therefore not equal. CPPUNIT_ASSERT_MESSAGE("", mitk::Equal(referencePointSet, m_TestPointSet, .001, true, false)); } void PlayInteraction(std::string &xmlFile, mitk::DataNode *node) { mitk::InteractionTestHelper interactionTestHelper(xmlFile); interactionTestHelper.AddNodeToStorage(node); interactionTestHelper.PlaybackInteraction(); } void EvaluateState(std::string &refPsFile, mitk::PointSet::Pointer ps, int selected) { mitk::PointSet::Pointer refPs = dynamic_cast(mitk::IOUtil::Load(refPsFile)[0].GetPointer()); refPs->UpdateOutputInformation(); ps->UpdateOutputInformation(); MITK_ASSERT_EQUAL(ps, refPs, ""); MITK_TEST_CONDITION_REQUIRED(true, "Test against reference point set."); MITK_TEST_CONDITION_REQUIRED(ps->GetNumberOfSelected() == 1, "One selected point."); MITK_TEST_CONDITION_REQUIRED(ps->GetSelectInfo(selected), "Testing if proper point is selected."); } void SetupInteractor(mitk::PointSetDataInteractor *dataInteractor, mitk::DataNode *node) { dataInteractor->LoadStateMachine("PointSet.xml"); dataInteractor->SetEventConfig("PointSetConfig.xml"); dataInteractor->SetDataNode(node); } void MoveDeletePointInteraction() { // Path to the reference PointSet std::string referencePointSetPath = GetTestDataFilePath("InteractionTestData/ReferenceData/TestMoveRemovePoints.mps"); // Path to the interaction xml file std::string interactionXmlPath = GetTestDataFilePath("InteractionTestData/Interactions/TestMoveRemovePoints.xml"); std::string pic3D = GetTestDataFilePath("Pic3D.nrrd"); mitk::Image::Pointer referenceImage = dynamic_cast(mitk::IOUtil::Load(pic3D)[0].GetPointer()); mitk::DataNode::Pointer refDN = mitk::DataNode::New(); refDN->SetData(referenceImage); // Create test helper to initialize all necessary objects for interaction mitk::InteractionTestHelper interactionTestHelper(interactionXmlPath); // Add our test node to the DataStorage of our test helper interactionTestHelper.AddNodeToStorage(m_TestPointSetNode); interactionTestHelper.AddNodeToStorage(refDN); // Start Interaction interactionTestHelper.PlaybackInteraction(); // Load the reference PointSet mitk::PointSet::Pointer referencePointSet = dynamic_cast(mitk::IOUtil::Load(referencePointSetPath)[0].GetPointer()); // Compare reference with the result of the interaction. Last parameter (false) is set to ignore the geometries. // They are not stored in a file and therefore not equal. CPPUNIT_ASSERT_MESSAGE("", mitk::Equal(referencePointSet, m_TestPointSet, .001, true, false)); } + + // this is only for the OpenGL check + mitkPointSetDataInteractorTestSuite() : m_RenderingTestHelper(300, 300) {} + private: + mitk::RenderingTestHelper m_RenderingTestHelper; }; MITK_TEST_SUITE_REGISTRATION(mitkPointSetDataInteractor) diff --git a/Modules/PlanarFigure/test/mitkPlanarFigureInteractionTest.cpp b/Modules/PlanarFigure/test/mitkPlanarFigureInteractionTest.cpp index 2a4280c926..25812d1845 100644 --- a/Modules/PlanarFigure/test/mitkPlanarFigureInteractionTest.cpp +++ b/Modules/PlanarFigure/test/mitkPlanarFigureInteractionTest.cpp @@ -1,203 +1,206 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "usModuleRegistry.h" class mitkPlanarFigureInteractionTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPlanarFigureInteractionTestSuite); MITK_TEST(AngleInteractionCreate); MITK_TEST(Angle2InteractionCreate); MITK_TEST(BezierCurveInteractionCreate); MITK_TEST(CircleInteractionCreate); MITK_TEST(DoubleEllipseInteractionCreate); MITK_TEST(PlanarFourPointAngleInteractionCreate); MITK_TEST(PlanarLineInteractionCreate); MITK_TEST(PlanarPolygonInteractionCreate); MITK_TEST(NonClosedPlanarPolygonInteractionCreate); MITK_TEST(RectangleInteractionCreate); // BUG 19304 // MITK_TEST(PlanarSubdivisionInteractionCreate); CPPUNIT_TEST_SUITE_END(); public: void setUp() { - // check whether sufficient openGL is available - mitk::RenderingTestHelper openGlTest(640, 480); /// \todo Fix leaks of vtkObjects. Bug 18095. vtkDebugLeaks::SetExitError(0); } void tearDown() {} void RunTest(mitk::PlanarFigure::Pointer figure, std::string interactionXmlPath, std::string referenceFigurePath) { mitk::DataNode::Pointer node; mitk::PlanarFigureInteractor::Pointer figureInteractor; // Create DataNode as a container for our PlanarFigure node = mitk::DataNode::New(); node->SetData(figure); mitk::InteractionTestHelper interactionTestHelper(GetTestDataFilePath(interactionXmlPath)); // Load a bounding image mitk::Image::Pointer testImage = dynamic_cast(mitk::IOUtil::Load(GetTestDataFilePath("Pic3D.nrrd"))[0].GetPointer()); figure->SetGeometry(testImage->GetGeometry()); mitk::DataNode::Pointer dn = mitk::DataNode::New(); dn->SetData(testImage); interactionTestHelper.AddNodeToStorage(dn); interactionTestHelper.GetDataStorage()->Add(node, dn); node->SetName("PLANAR FIGURE"); // set as selected node->SetSelected(true); node->AddProperty("selected", mitk::BoolProperty::New(true)); // Load state machine figureInteractor = mitk::PlanarFigureInteractor::New(); us::Module *planarFigureModule = us::ModuleRegistry::GetModule("MitkPlanarFigure"); figureInteractor->LoadStateMachine("PlanarFigureInteraction.xml", planarFigureModule); figureInteractor->SetEventConfig("PlanarFigureConfig.xml", planarFigureModule); figureInteractor->SetDataNode(node); // Start Interaction interactionTestHelper.PlaybackInteraction(); // Load reference PlanarFigure mitk::PlanarFigureReader::Pointer reader = mitk::PlanarFigureReader::New(); reader->SetFileName(GetTestDataFilePath(referenceFigurePath)); reader->Update(); mitk::PlanarFigure::Pointer reference = reader->GetOutput(0); // Compare figures MITK_ASSERT_EQUAL(figure, reference, "Compare figure with reference"); } void AngleInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarAngle::New(); RunTest(figure, "InteractionTestData/Interactions/Angle1.xml", "InteractionTestData/ReferenceData/Angle1.pf"); } void Angle2InteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarAngle::New(); RunTest(figure, "InteractionTestData/Interactions/Angle2.xml", "InteractionTestData/ReferenceData/Angle2.pf"); } void BezierCurveInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarBezierCurve::New(); RunTest(figure, "InteractionTestData/Interactions/Bezier.xml", "InteractionTestData/ReferenceData/Bezier.pf"); } void CircleInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarCircle::New(); RunTest(figure, "InteractionTestData/Interactions/Circle.xml", "InteractionTestData/ReferenceData/Circle.pf"); } void DoubleEllipseInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarDoubleEllipse::New(); RunTest(figure, "InteractionTestData/Interactions/DoubleEllipse.xml", "InteractionTestData/ReferenceData/DoubleEllipse.pf"); } void PlanarSubdivisionInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarSubdivisionPolygon::New(); RunTest(figure, "InteractionTestData/Interactions/SubdivisionPolygon.xml", "InteractionTestData/ReferenceData/SubDivision.pf"); } void PlanarFourPointAngleInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarFourPointAngle::New(); RunTest(figure, "InteractionTestData/Interactions/Planar4PointAngle.xml", "InteractionTestData/ReferenceData/Planar4PointAngle.pf"); } void PlanarLineInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarLine::New(); RunTest(figure, "InteractionTestData/Interactions/Line.xml", "InteractionTestData/ReferenceData/Line.pf"); } void PlanarPolygonInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarPolygon::New(); RunTest(figure, "InteractionTestData/Interactions/Polygon.xml", "InteractionTestData/ReferenceData/Polygon.pf"); } void NonClosedPlanarPolygonInteractionCreate() { mitk::PlanarPolygon::Pointer figure; figure = mitk::PlanarPolygon::New(); figure->ClosedOff(); RunTest( figure.GetPointer(), "InteractionTestData/Interactions/Path.xml", "InteractionTestData/ReferenceData/Path.pf"); } void RectangleInteractionCreate() { mitk::PlanarFigure::Pointer figure; figure = mitk::PlanarRectangle::New(); RunTest(figure, "InteractionTestData/Interactions/Rectangle.xml", "InteractionTestData/ReferenceData/Rectangle.pf"); } + + // this is only for the OpenGL check + mitkPlanarFigureInteractionTestSuite() : m_RenderingTestHelper(300, 300) {} + private: + mitk::RenderingTestHelper m_RenderingTestHelper; }; MITK_TEST_SUITE_REGISTRATION(mitkPlanarFigureInteraction)