diff --git a/Modules/PlanarFigure/Testing/files.cmake b/Modules/PlanarFigure/Testing/files.cmake index ab1838d181..5c683c9c48 100644 --- a/Modules/PlanarFigure/Testing/files.cmake +++ b/Modules/PlanarFigure/Testing/files.cmake @@ -1,19 +1,19 @@ set(MODULE_TESTS mitkPlanarCrossTest.cpp mitkPlanarPolygonTest.cpp mitkPlanarSubdivisionPolygonTest.cpp mitkPlanarFigureIOTest.cpp mitkPlanarFigureObjectFactoryTest.cpp mitkPlanarArrowTest.cpp ) set(MODULE_CUSTOM_TESTS mitkViewportRenderingTest.cpp ) if(MITK_ENABLE_RENDERING_TESTING) #since mitkInteractionTestHelper is currently creating a vtkRenderWindow set(MODULE_TESTS ${MODULE_TESTS} - mitkPlanarFigureMeasurementTest.cpp + mitkPlanarFigureInteractionTest.cpp ) endif() diff --git a/Modules/PlanarFigure/Testing/mitkPlanarFigureInteractionTest.cpp b/Modules/PlanarFigure/Testing/mitkPlanarFigureInteractionTest.cpp new file mode 100644 index 0000000000..54df7ffddf --- /dev/null +++ b/Modules/PlanarFigure/Testing/mitkPlanarFigureInteractionTest.cpp @@ -0,0 +1,115 @@ +/*=================================================================== + +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 "usModuleRegistry.h" +#include "mitkPlanarFigureReader.h" +#include "mitkPlanarFigureWriter.h" + + + +class mitkPlanarFigureInteractionTestSuite : public mitk::TestFixture +{ + + CPPUNIT_TEST_SUITE(mitkPlanarFigureInteractionTestSuite); + MITK_TEST(RectangleInteraction); + MITK_TEST(CircleInteraction); + CPPUNIT_TEST_SUITE_END(); + + +public: + + void setUp() + { + } + + 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 = mitk::IOUtil::LoadImage(GetTestDataFilePath("Pic3D.nrrd")); + 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 RectangleInteraction() + { + mitk::PlanarFigure::Pointer figure; + figure = mitk::PlanarRectangle::New(); + RunTest(figure, "InteractionTestData/Interactions/PlanarFigureInteractor_PlanarRectangle_Create.xml", "InteractionTestData/ReferenceData/PlanarFigureInteractor_PlanarRectangle_Create.pf"); + } + + void CircleInteraction() + { + mitk::PlanarFigure::Pointer figure; + figure = mitk::PlanarCircle::New(); + RunTest(figure, "InteractionTestData/Interactions/PlanarFigureInteractor_PlanarCircle_Create.xml", "InteractionTestData/ReferenceData/PlanarFigureInteractor_PlanarCircle_Create.pf"); + } + +}; + +MITK_TEST_SUITE_REGISTRATION(mitkPlanarFigureInteraction) diff --git a/Modules/PlanarFigure/Testing/mitkPlanarFigureMeasurementTest.cpp b/Modules/PlanarFigure/Testing/mitkPlanarFigureMeasurementTest.cpp deleted file mode 100644 index b5d8f1f423..0000000000 --- a/Modules/PlanarFigure/Testing/mitkPlanarFigureMeasurementTest.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/*=================================================================== - -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 "usModuleRegistry.h" -#include "mitkPlanarFigureReader.h" -#include "mitkPlanarFigureWriter.h" - - - -class mitkPlanarFigureMeasurementTestSuite : public mitk::TestFixture -{ - - CPPUNIT_TEST_SUITE(mitkPlanarFigureMeasurementTestSuite); - MITK_TEST(MeasurePixelSquare); - CPPUNIT_TEST_SUITE_END(); - - -private: - mitk::DataNode::Pointer m_Node; - mitk::PlanarFigure::Pointer m_Figure; - mitk::PlanarFigureInteractor::Pointer m_FigureInteractor; - - -public: - - void setUp() - { - //Add our test node to the DataStorage of our test helper - - //Create test helper to initialize all necessary objects for interaction - } - - void tearDown() - { - m_Node = NULL; - m_Figure = NULL; - m_FigureInteractor = NULL; - } - - void MeasurePixelSquare() - { - - //Create DataNode as a container for our Planar Figure to be tested - m_Node = mitk::DataNode::New(); - m_Figure = mitk::PlanarRectangle::New(); - m_Node->SetData(m_Figure); - - std::string interactionXmlPath = "C:\\tmp\\interaction.xml"; - - mitk::InteractionTestHelper interactionTestHelper(interactionXmlPath); - - std::string dicomPath = "C:\\tmp\\toy.nrrd"; - //Load the reference PointSet - mitk::Image::Pointer testImage = mitk::IOUtil::LoadImage(dicomPath); - mitk::DataNode::Pointer dn = mitk::DataNode::New(); - dn->SetData(testImage); - interactionTestHelper.AddNodeToStorage(dn); - interactionTestHelper.GetDataStorage()->Add(m_Node, dn); - - - m_Node->SetName("PLANAR FIGURE"); - // set as selected - m_Node->SetSelected( true ); - m_Node->AddProperty( "selected", mitk::BoolProperty::New(true) ); - - m_FigureInteractor = mitk::PlanarFigureInteractor::New(); - - us::Module* planarFigureModule = us::ModuleRegistry::GetModule( "MitkPlanarFigure" ); - m_FigureInteractor->LoadStateMachine("PlanarFigureInteraction.xml", planarFigureModule ); - m_FigureInteractor->SetEventConfig( "PlanarFigureConfig.xml", planarFigureModule ); - m_FigureInteractor->SetDataNode( m_Node ); - - - //Start Interaction - interactionTestHelper.PlaybackInteraction(); - - mitk::PlanarFigureWriter::Pointer writer = mitk::PlanarFigureWriter::New(); - writer->SetFileName("C:\\tmp\\result.pf"); - writer->SetInput(m_Figure); - writer->Update(); - - mitk::PlanarFigureReader::Pointer reader = mitk::PlanarFigureReader::New(); - reader->SetFileName("C:\\tmp\\ref.pf"); - reader->Update(); - mitk::PlanarFigure::Pointer reference = reader->GetOutput(0); - MITK_ASSERT_EQUAL(m_Figure, reference, "Compare figure with reference"); - - } - -}; - -MITK_TEST_SUITE_REGISTRATION(mitkPlanarFigureMeasurement)