diff --git a/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp b/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp index 69f6df356a..61085996b8 100644 --- a/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp +++ b/Core/Code/Testing/mitkPointSetDataInteractorTest.cpp @@ -1,91 +1,91 @@ /*=================================================================== 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(TestAddPointInteraction); CPPUNIT_TEST_SUITE_END(); public: void setUp() { } void TestAddPointInteraction() { //Path to the reference PointSet std::string referencePointSetPath = GetTestDataFilePath("/Users/schroedt/Desktop/pointsetTestRef.mps"); //Path to the interaction xml file std::string interactionXmlPath = "/Users/schroedt/Desktop/pointsetTest.xml"; //execute CPPUNIT_ASSERT(TestPointSetInteraction(interactionXmlPath, referencePointSetPath)); } private: bool TestPointSetInteraction(std::string interactionXmlPath, std::string referencePointSetPath) { //Create DataNode as a container for our PointSet to be tested mitk::DataNode::Pointer testPointSetNode = mitk::DataNode::New(); // Create PointSetData Interactor mitk::PointSetDataInteractor::Pointer dataInteractor = mitk::PointSetDataInteractor::New(); // Load the according state machine for regular point set interaction dataInteractor->LoadStateMachine("PointSet.xml"); // Set the configuration file that defines the triggers for the transitions dataInteractor->SetEventConfig("PointSetConfig.xml"); // set the DataNode (which already is added to the DataStorage) dataInteractor->SetDataNode(testPointSetNode); //Create new PointSet which will receive the interaction input mitk::PointSet::Pointer testPointSet = mitk::PointSet::New(); testPointSetNode->SetData(testPointSet); //Create test helper to initialize all necessary objects for interaction - mitk::InteractionTestHelper interactionTestHelper(640, 480, interactionXmlPath); + mitk::InteractionTestHelper interactionTestHelper(interactionXmlPath); //Add our test node to the DataStorage of our test helper interactionTestHelper.AddNodeToStorage(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 return mitk::Equal(testPointSet.GetPointer(), referencePointSet.GetPointer(), mitk::eps, false); } }; MITK_TEST_SUITE_REGISTRATION(mitkPointSetDataInteractor) diff --git a/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp b/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp index 692d079c61..0a1294d06c 100644 --- a/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp +++ b/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp @@ -1,225 +1,225 @@ /*=================================================================== 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. ===================================================================*/ //VTK #include #include #include #include //MITK #include #include #include #include #include #include #include // include gl to read out properties #include #include #if defined _MSC_VER #if _MSC_VER >= 1700 #define RESIZE_WORKAROUND #endif #endif #ifdef RESIZE_WORKAROUND #include "vtkWin32OpenGLRenderWindow.h" #endif -mitk::InteractionTestHelper::InteractionTestHelper(int width, int height, std::string interactionFilePath) +mitk::InteractionTestHelper::InteractionTestHelper(std::string interactionFilePath) : m_AutomaticallyCloseRenderWindow(true) { - this->Initialize(width, height, interactionFilePath); + this->Initialize(640, 480, interactionFilePath); } void mitk::InteractionTestHelper::Initialize(int width, int height, std::string interactionFilePath) { // Global interaction must(!) be initialized mitk::GlobalInteraction::GetInstance()->Initialize("global"); m_RenderWindow = mitk::RenderWindow::New(); m_DataStorage = mitk::StandaloneDataStorage::New(); m_RenderWindow->GetRenderer()->SetDataStorage(m_DataStorage); this->SetMapperIDToRender2D(); m_RenderWindow->GetVtkRenderWindow()->SetSize( width, height ); #ifdef RESIZE_WORKAROUND HWND hWnd = static_cast(this->GetVtkRenderWindow())->GetWindowId(); RECT r; r.left = 10; r.top = 10; r.right = r.left + width; r.bottom = r.top + height; LONG style = GetWindowLong(hWnd, GWL_STYLE); AdjustWindowRect( &r, style, FALSE ); MITK_INFO << "WANTED:"; MITK_INFO << r.right-r.left; MITK_INFO << r.bottom-r.top; RECT rect; if(GetWindowRect(hWnd, &rect)) { int width = rect.right - rect.left; int height = rect.bottom - rect.top; MITK_INFO << "ACTUAL:"; MITK_INFO << width; MITK_INFO <GetRenderer()->Resize( width, height); //load interaction pattern std::ifstream xmlStream(interactionFilePath.c_str()); mitk::XML2EventParser parser(xmlStream); m_Events = parser.GetInteractions(); xmlStream.close(); } mitk::InteractionTestHelper::~InteractionTestHelper() { } void mitk::InteractionTestHelper::SetMapperID( mitk::BaseRenderer::StandardMapperSlot id) { m_RenderWindow->GetRenderer()->SetMapperID(id); } void mitk::InteractionTestHelper::SetMapperIDToRender3D() { this->SetMapperID(mitk::BaseRenderer::Standard3D); } void mitk::InteractionTestHelper::SetMapperIDToRender2D() { this->SetMapperID(mitk::BaseRenderer::Standard2D); } //void mitk::InteractionTestHelper::Render() //{ // //if the datastorage is initialized and at least 1 image is loaded render it // if(m_DataStorage.IsNotNull() || m_DataStorage->GetAll()->Size() >= 1 ) // { // //Prepare the VTK camera before rendering. // m_RenderWindow->GetRenderer()->PrepareRender(); // this->GetVtkRenderWindow()->Render(); // if(m_AutomaticallyCloseRenderWindow == false) // { // //Use interaction to stop the test // this->GetVtkRenderWindow()->GetInteractor()->Start(); // } // } // else // { // MITK_ERROR << "No images loaded in data storage!"; // } //} mitk::DataStorage::Pointer mitk::InteractionTestHelper::GetDataStorage() { return m_DataStorage; } void mitk::InteractionTestHelper::SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection) { mitk::BaseRenderer::GetInstance(m_RenderWindow->GetVtkRenderWindow())->GetSliceNavigationController()->SetDefaultViewDirection(viewDirection); mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()) ); } mitk::BaseRenderer* mitk::InteractionTestHelper::GetRenderer() { return m_RenderWindow->GetRenderer(); } mitk::RenderWindow* mitk::InteractionTestHelper::GetRenderWindow() { return m_RenderWindow; } void mitk::InteractionTestHelper::SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow) { m_AutomaticallyCloseRenderWindow = automaticallyCloseRenderWindow; } void mitk::InteractionTestHelper::AddToStorage(const std::string &filename) { try { mitk::DataNode::Pointer node = mitk::IOUtil::LoadDataNode(filename); this->AddNodeToStorage(node); } catch ( itk::ExceptionObject & e ) { MITK_ERROR << "Failed loading test data '" << filename << "': " << e.what(); } } void mitk::InteractionTestHelper::AddNodeToStorage(mitk::DataNode::Pointer node) { this->m_DataStorage->Add(node); mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()) ); } void mitk::InteractionTestHelper::PlaybackInteraction() { for (int i=0; i < m_Events.size(); ++i) { m_Events.at(i)->GetSender()->GetDispatcher()->ProcessEvent(m_Events.at(i)); } } diff --git a/Core/Code/TestingHelper/mitkInteractionTestHelper.h b/Core/Code/TestingHelper/mitkInteractionTestHelper.h index 09bd47376c..614749253e 100644 --- a/Core/Code/TestingHelper/mitkInteractionTestHelper.h +++ b/Core/Code/TestingHelper/mitkInteractionTestHelper.h @@ -1,128 +1,140 @@ /*=================================================================== 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 Generate all necessary objects to handle interaction events. - - +/** @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 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. + * + * \sa XML2EventParser + * \sa EventFactory + * \sa EventRecorder */ class MITK_TESTINGHELPER_EXPORT InteractionTestHelper { public: /** @param interactionFilePath Path to xml file containing interaction events. **/ - InteractionTestHelper(int width, int height, std::string interactionFilePath); + InteractionTestHelper(std::string interactionFilePath); /** Default destructor */ ~InteractionTestHelper(); /** @brief Getter for the vtkRenderer. **/ BaseRenderer* GetRenderer(); /** @brief Getter for the vtkRenderWindow which should be used to call vtkRegressionTestImage. **/ RenderWindow* GetRenderWindow(); /** * @brief SetStopRenderWindow Convenience method to make the renderwindow hold after rendering. Usefull for debugging. * @param flag Flag indicating whether the renderwindow should automatically close (false, default) or stay open (true). Usefull for debugging. */ void SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow); /** @brief Set the view direction of the renderwindow (e.g. sagittal, coronal, axial) **/ void SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection); // /** @brief Render everything into an mitkRenderWindow. Call SetViewDirection() and SetProperty() before this method. // **/ // void Render(); /** @brief Returns the datastorage, in order to modify the data inside a rendering test. **/ mitk::DataStorage::Pointer GetDataStorage(); /** * @brief SetMapperID Change between Standard2D and 3D mappers. * @param id Enum mitk::BaseRenderer::StandardMapperSlot which defines the mapper. */ void SetMapperID(mitk::BaseRenderer::StandardMapperSlot id); /** * @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 SetMapperIDToRender3D Convenience method to render in a 3D renderwindow. * @warning Does not add helper objects like the image planes to render images in 3D. */ void SetMapperIDToRender3D(); /** * @brief SetMapperIDToRender2D Convenience method to render in a 2D renderwindow. */ void SetMapperIDToRender2D(); /** * @brief PlaybackInteraction plays loaded interaction by passing events to the dispatcher. */ void PlaybackInteraction(); protected: /** * @brief Initialize Internal method to initialize the renderwindow and set the datastorage. * @param width Height of renderwindow. * @param height Width of renderwindow. * @param interactionFilePath path to xml file containing interaction events. */ void Initialize(int width, int height, std::string interactionFilePath); /** @brief This method tries to load the given file into a member datastorage, in order to render it. @param fileName The filename of the file to be loaded (including path). **/ void AddToStorage(const std::string& filename); mitk::XML2EventParser::EventContainerType m_Events; //<< List with loaded interaction events mitk::RenderWindow::Pointer m_RenderWindow; //<< Contains the mitkRenderWindow into which the test renders the data mitk::DataStorage::Pointer m_DataStorage; //<< Contains the mitkDataStorage which contains the data to be rendered bool m_AutomaticallyCloseRenderWindow; //<< Flag indicating whether the renderwindow should automatically close (true, default) or stay open (false). Usefull for debugging. }; }//namespace mitk #endif