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::Image*>(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::PointSet*>(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 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")); 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 AddPointInteraction() { //Path to the reference PointSet std::string referencePointSetPath = GetTestDataFilePath("InteractionTestData/ReferenceData/PointSetDataInteractor_add_points_in_2D_ref.mps"); //Path to the interaction xml file std::string interactionXmlPath = GetTestDataFilePath("InteractionTestData/Interactions/PointSetDataInteractor_add_points_in_2D.xml"); //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); //Start Interaction interactionTestHelper.PlaybackInteraction(); //Load the reference PointSet mitk::PointSet::Pointer referencePointSet = mitk::IOUtil::LoadPointSet(referencePointSetPath); //Compare reference with the result of the interaction MITK_ASSERT_EQUAL(m_TestPointSet, referencePointSet, ""); }
void PlayInteraction(std::string &xmlFile, mitk::DataNode *node) { mitk::InteractionTestHelper interactionTestHelper(xmlFile); interactionTestHelper.AddNodeToStorage(node); interactionTestHelper.PlaybackInteraction(); }
void RunTestWithParameters(const std::string& patientImagePath, const std::string& referenceSegmentationImage, const std::string& toolName, const std::string& interactionPattern, unsigned int timestep=0, const std::string& preSegmentationImagePath = std::string()) { //Create test helper to initialize all necessary objects for interaction mitk::InteractionTestHelper interactionTestHelper(GetTestDataFilePath(interactionPattern)); //Use data storage of test helper m_DataStorage = interactionTestHelper.GetDataStorage().GetPointer(); //create ToolManager m_ToolManager = mitk::ToolManager::New(m_DataStorage); m_ToolManager->InitializeTools(); m_ToolManager->RegisterClient();//This is needed because there must be at least one registered. Otherwise tools can't be activated. //Load patient image mitk::Image::Pointer patientImage = mitk::IOUtil::LoadImage(GetTestDataFilePath(patientImagePath)); CPPUNIT_ASSERT(patientImage.IsNotNull()); mitk::DataNode::Pointer patientImageNode = mitk::DataNode::New(); patientImageNode->SetData(patientImage); //Activate tool to work with int toolID = GetToolIdByToolName(toolName); mitk::Tool* tool = m_ToolManager->GetToolById(toolID); CPPUNIT_ASSERT(tool != NULL); //Create empty segmentation working image mitk::DataNode::Pointer workingImageNode = mitk::DataNode::New(); const std::string organName = "test"; mitk::Color color;//actually it dosn't matter which color we are using color.SetRed(1); //but CreateEmptySegmentationNode expects a color parameter color.SetGreen(0); color.SetBlue(0); if(preSegmentationImagePath.empty()) { workingImageNode = tool->CreateEmptySegmentationNode(patientImage, organName, color); } else { mitk::Image::Pointer preSegmentation = mitk::IOUtil::LoadImage(GetTestDataFilePath(preSegmentationImagePath)); workingImageNode = tool->CreateSegmentationNode(preSegmentation, organName, color); } CPPUNIT_ASSERT(workingImageNode.IsNotNull()); CPPUNIT_ASSERT(workingImageNode->GetData() != NULL); //add images to datastorage interactionTestHelper.AddNodeToStorage(patientImageNode); interactionTestHelper.AddNodeToStorage(workingImageNode); //set reference and working image m_ToolManager->SetWorkingData(workingImageNode); m_ToolManager->SetReferenceData(patientImageNode); //set time step interactionTestHelper.SetTimeStep(timestep); //load interaction events m_ToolManager->ActivateTool(toolID); CPPUNIT_ASSERT(m_ToolManager->GetActiveTool() != NULL); //Start Interaction interactionTestHelper.PlaybackInteraction(); //load reference segmentation image mitk::Image::Pointer segmentationReferenceImage = mitk::IOUtil::LoadImage(GetTestDataFilePath(referenceSegmentationImage)); mitk::Image::Pointer currentSegmentationImage = mitk::Image::New(); currentSegmentationImage = dynamic_cast<mitk::Image*>(workingImageNode->GetData()); //compare reference with interaction result MITK_ASSERT_EQUAL(segmentationReferenceImage, currentSegmentationImage, "Reference equals interaction result." ); }