diff --git a/Core/Code/Interactions/mitkXML2EventParser.h b/Core/Code/Interactions/mitkXML2EventParser.h index 9ef98d375f..30ad4e4dbf 100755 --- a/Core/Code/Interactions/mitkXML2EventParser.h +++ b/Core/Code/Interactions/mitkXML2EventParser.h @@ -1,104 +1,105 @@ /*=================================================================== 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. ===================================================================*/ #ifndef mitkXML2EventParser_h #define mitkXML2EventParser_h #include #include "mitkPropertyList.h" #include #include "mitkInteractionEvent.h" namespace us { class Module; } namespace mitk { /** * \class InteractionEventList * \brief Generates a list of InteractionEvents based on an XML file- * + * @sa EventRecorder * @ingroup Interaction **/ class XML2EventParser : public vtkXMLParser { public: /** * @brief Construct an InteractionEventList object based on a XML configuration file. * * Uses the specified resource file containing an XML event configuration to * construct an EventConfig object. If the resource is invalid, the created * EventConfig object will also be invalid. * * @param filename The resource name relative to the Interactions resource folder. * @param module */ XML2EventParser(const std::string& filename, const us::Module* module = NULL); /** * @brief Construct an InteractionEventList object based on a XML configuration file. * * Uses the specified istream refering to a file containing an XML event configuration to * construct an EventConfig object. If the resource is invalid, the created * EventConfig object will also be invalid. * * @param inputStream std::ifstream to XML configuration file */ XML2EventParser(std::istream &inputStream); typedef std::vector EventContainerType; EventContainerType GetInteractions() { return m_InteractionList; } ~XML2EventParser(){}; protected: /** * @brief Derived from XMLReader **/ void StartElement(const char* elementName, const char **atts); /** * @brief Derived from XMLReader **/ void EndElement(const char* elementName); std::string ReadXMLStringAttribute(const std::string& name, const char** atts); bool ReadXMLBooleanAttribute(const std::string& name, const char** atts); private: PropertyList::Pointer m_EventPropertyList; EventContainerType m_InteractionList; }; } // namespace mitk #endif /* mitkStateMachineConfig_h */ diff --git a/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp b/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp index 1eef99461b..e0caca8a00 100644 --- a/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp +++ b/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp @@ -1,98 +1,95 @@ /*=================================================================== 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 class mitkPointSetDataInteractorTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkPointSetDataInteractorTestSuite); MITK_TEST(AddPointInteraction); CPPUNIT_TEST_SUITE_END(); private: mitk::DataNode::Pointer m_TestPointSetNode; mitk::PointSetDataInteractor::Pointer m_DataInteractor; mitk::PointSet::Pointer m_TestPointSet; - mitk::InteractionTestHelper::Pointer m_InteractionTestHelper; public: void setUp() { //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"); // set the DataNode (which already is added to the DataStorage) m_DataInteractor->SetDataNode(m_TestPointSetNode); //Create new PointSet which will receive the interaction input m_TestPointSet = mitk::PointSet::New(); m_TestPointSetNode->SetData(m_TestPointSet); } void tearDown() { //destroy all objects m_TestPointSetNode = NULL; m_TestPointSet = NULL; m_DataInteractor = NULL; - //make sure to destroy the test helper object after each test - m_InteractionTestHelper = NULL; } void AddPointInteraction() { //Path to the reference PointSet std::string referencePointSetPath = "/Users/schroedt/Desktop/pointsetTestRef.mps"; //Path to the interaction xml file std::string interactionXmlPath = "/Users/schroedt/Desktop/pointsetTest.xml"; //Create test helper to initialize all necessary objects for interaction - m_InteractionTestHelper = mitk::InteractionTestHelper::New(interactionXmlPath); + mitk::InteractionTestHelper m_InteractionTestHelper(interactionXmlPath); //Add our test node to the DataStorage of our test helper - m_InteractionTestHelper->AddNodeToStorage(m_TestPointSetNode); + m_InteractionTestHelper.AddNodeToStorage(m_TestPointSetNode); //Start Interaction - m_InteractionTestHelper->PlaybackInteraction(); + m_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.GetPointer(), referencePointSet.GetPointer(), ""); } }; MITK_TEST_SUITE_REGISTRATION(mitkPointSetDataInteractor) diff --git a/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp b/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp index cec5607166..9e97533485 100644 --- a/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp +++ b/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp @@ -1,157 +1,155 @@ /*=================================================================== 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. ===================================================================*/ //MITK #include #include #include #include #include //us #include #include mitk::InteractionTestHelper::InteractionTestHelper(const std::string &interactionXmlFilePath) : m_InteractionFilePath(interactionXmlFilePath) { this->Initialize(interactionXmlFilePath); } void mitk::InteractionTestHelper::Initialize(const std::string &interactionXmlFilePath) { //TiXmlDocument document(interactionXmlPath.c_str()); TiXmlDocument document(interactionXmlFilePath); bool loadOkay = document.LoadFile(); if (loadOkay) { // Global interaction must(!) be initialized if(! mitk::GlobalInteraction::GetInstance()->IsInitialized()) mitk::GlobalInteraction::GetInstance()->Initialize("global"); //get RenderingManager instance mitk::RenderingManager* rm = mitk::RenderingManager::GetInstance(); //create data storage m_DataStorage = mitk::StandaloneDataStorage::New(); //for each renderer found create a render window and configure for( TiXmlElement* element = document.FirstChildElement(mitk::InteractionEventConst::xmlTagInteractions())->FirstChildElement(mitk::InteractionEventConst::xmlTagConfigRoot())->FirstChildElement(mitk::InteractionEventConst::xmlTagRenderer()); element != NULL; element = element->NextSiblingElement(mitk::InteractionEventConst::xmlTagRenderer()) ) { //get name of renderer const char* rendererName = element->Attribute(mitk::InteractionEventConst::xmlEventPropertyRendererName().c_str()); //get view direction int viewDirectionNum = std::atoi(element->Attribute(mitk::InteractionEventConst::xmlEventPropertyViewDirection())->c_str()); mitk::SliceNavigationController::ViewDirection viewDirection = static_cast(viewDirectionNum); //create renderWindow, renderer and dispatcher mitk::RenderWindow::Pointer rw = mitk::RenderWindow::New(NULL, rendererName, rm); //VtkRenderWindow is created within constructor if NULL //set storage of renderer rw->GetRenderer()->SetDataStorage(m_DataStorage); //set view direction to axial rw->GetSliceNavigationController()->SetDefaultViewDirection( viewDirection ); //set renderer to render 2D rw->GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard2D); //connect SliceNavigationControllers to timestep changed event of TimeNavigationController rw->GetSliceNavigationController()->ConnectGeometryTimeEvent(rm->GetTimeNavigationController(), false); //add to list of kown render windows m_RenderWindowList.push_back(rw); } //########### register display interactor to handle scroll events ################## //use MouseModeSwitcher to ensure that the statemachine of DisplayInteractor is loaded correctly m_MouseModeSwitcher = mitk::MouseModeSwitcher::New(); } else { mitkThrow() << "Can not load interaction xml file <" << m_InteractionFilePath << ">"; } } mitk::InteractionTestHelper::~InteractionTestHelper() { //unregister renderers InteractionTestHelper::RenderWindowListType::iterator it = m_RenderWindowList.begin(); InteractionTestHelper::RenderWindowListType::iterator end = m_RenderWindowList.end(); for(; it != end; it++) { mitk::BaseRenderer::RemoveInstance((*it)->GetVtkRenderWindow()); } } mitk::DataStorage::Pointer mitk::InteractionTestHelper::GetDataStorage() { return m_DataStorage; } - - void mitk::InteractionTestHelper::AddNodeToStorage(mitk::DataNode::Pointer node) { this->m_DataStorage->Add(node); mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(m_DataStorage); } void mitk::InteractionTestHelper::PlaybackInteraction() { //load events if not loaded yet if(m_Events.empty()) this->LoadInteraction(); //playback all events in queue for (unsigned long i=0; i < m_Events.size(); ++i) { //let dispatcher of sending renderer process the event m_Events.at(i)->GetSender()->GetDispatcher()->ProcessEvent(m_Events.at(i)); } } void mitk::InteractionTestHelper::LoadInteraction() { //load interaction pattern from xml file std::ifstream xmlStream(m_InteractionFilePath.c_str()); mitk::XML2EventParser parser(xmlStream); m_Events = parser.GetInteractions(); xmlStream.close(); } void mitk::InteractionTestHelper::SetTimeStep(int newTimeStep) { bool timeStepIsvalid = mitk::RenderingManager::GetInstance()->GetTimeNavigationController()->GetCreatedWorldGeometry()->IsValidTimeStep(newTimeStep); if(timeStepIsvalid) { mitk::RenderingManager::GetInstance()->GetTimeNavigationController()->GetTime()->SetPos(newTimeStep); } } diff --git a/Core/Code/TestingHelper/mitkInteractionTestHelper.h b/Core/Code/TestingHelper/mitkInteractionTestHelper.h index 3211dba169..6094d6f149 100644 --- a/Core/Code/TestingHelper/mitkInteractionTestHelper.h +++ b/Core/Code/TestingHelper/mitkInteractionTestHelper.h @@ -1,120 +1,117 @@ /*=================================================================== 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. ===================================================================*/ #ifndef mitkInteractionTestHelper_h #define mitkInteractionTestHelper_h #include #include #include #include #include #include class vtkRenderWindow; class vtkRenderer; namespace mitk { /** @brief Creates everything needed to load and playback interaction events. * * The interaction is loaded from an xml file and the event are created. This file is * usually a recorded user interaction with the GUI. This can be done with InteractionEventRecorder * plugin. Also all necessary objects to handle interaction events are generated. * The user of this class is responsible to add the data object to interact with to the data storage * of InteractionTestHelper. And must also make sure that a proper data interactor is associated with the data object. * * To test a PointSet interaction for instance make sure you have a PointSet node and a PointSetDataInteractor. * Then just add the node to the storage of the your InteractionTestHelper by calling InteractionTestHelper::AddNodeToStorage. * Use InteractionTestHelper::PlaybackInteraction to execute. The result can afterwards be compared to a reference object. * * Make sure to destroy the test helper instance after each test, since all render windows and its renderers have to be unregistered. * * \sa XML2EventParser * \sa EventFactory * \sa EventRecorder */ -class MITK_TESTINGHELPER_EXPORT InteractionTestHelper : public itk::LightObject +class MITK_TESTINGHELPER_EXPORT InteractionTestHelper { public: - mitkClassMacro(InteractionTestHelper, LightObject); - mitkNewMacro1Param(InteractionTestHelper, const std::string &); + /** + * @brief InteractionTestHelper set up all neseccary objects by calling Initialize. + * @param interactionXmlFilePath path to xml file containing events and configuration information for the render windows. + */ + InteractionTestHelper(const std::string &interactionXmlFilePath); + //unregisters all render windows and its renderers. + virtual ~InteractionTestHelper(); /** @brief Returns the datastorage, in order to modify the data inside a rendering test. **/ mitk::DataStorage::Pointer GetDataStorage(); /** * @brief AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering. * @param node The data you want to add. */ void AddNodeToStorage(mitk::DataNode::Pointer node); /** * @brief PlaybackInteraction playback loaded interaction by passing events to the dispatcher. */ void PlaybackInteraction(); /** * @brief SetTimeStep Sets timesteps of all SliceNavigationControllers to given timestep. * @param newTimeStep new timestep * * Does the same as using ImageNavigators Time slider. Use this if your data was modified in a timestep other than 0. */ void SetTimeStep(int newTimeStep); typedef std::vector RenderWindowListType; protected: - /** - * @brief InteractionTestHelper set up all neseccary objects by calling Initialize. - * @param interactionXmlFilePath path to xml file containing events and configuration information for the render windows. - */ - InteractionTestHelper(const std::string &interactionXmlFilePath); - - //unregisters all render windows and its renderers. - virtual ~InteractionTestHelper(); /** * @brief Initialize Internal method to initialize the renderwindow and set the datastorage. * @throws mitk::Exception if interaction xml file can not be loaded. */ void Initialize(const std::string &interactionXmlFilePath); /** * @brief LoadInteraction loads events from xml file. * @param interactionXmlPath path to xml file with interaction events. */ void LoadInteraction(); mitk::XML2EventParser::EventContainerType m_Events; // List with loaded interaction events std::string m_InteractionFilePath; RenderWindowListType m_RenderWindowList; mitk::DataStorage::Pointer m_DataStorage; mitk::MouseModeSwitcher::Pointer m_MouseModeSwitcher; }; }//namespace mitk #endif