diff --git a/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp b/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp index 0a1294d06c..e47367bca6 100644 --- a/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp +++ b/Core/Code/TestingHelper/mitkInteractionTestHelper.cpp @@ -1,225 +1,83 @@ /*=================================================================== 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(std::string interactionFilePath) - : m_AutomaticallyCloseRenderWindow(true) +mitk::InteractionTestHelper::InteractionTestHelper() { - this->Initialize(640, 480, interactionFilePath); + this->Initialize(); } -void mitk::InteractionTestHelper::Initialize(int width, int height, std::string interactionFilePath) +void mitk::InteractionTestHelper::Initialize() { // Global interaction must(!) be initialized mitk::GlobalInteraction::GetInstance()->Initialize("global"); + //create renderWindow, renderer and dispatcher m_RenderWindow = mitk::RenderWindow::New(); + //create data storage m_DataStorage = mitk::StandaloneDataStorage::New(); - + //set storage of renderer 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(); - } + return m_Renderer; } 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) + for (unsigned long i=0; i < m_Events.size(); ++i) { m_Events.at(i)->GetSender()->GetDispatcher()->ProcessEvent(m_Events.at(i)); } } + + +void mitk::InteractionTestHelper::LoadInteraction(std::string interactionXmlPath) +{ + //load interaction pattern + std::ifstream xmlStream(interactionXmlPath.c_str()); + mitk::XML2EventParser parser(xmlStream); + m_Events = parser.GetInteractions(); + xmlStream.close(); +} diff --git a/Core/Code/TestingHelper/mitkInteractionTestHelper.h b/Core/Code/TestingHelper/mitkInteractionTestHelper.h index 614749253e..0b7cb0f143 100644 --- a/Core/Code/TestingHelper/mitkInteractionTestHelper.h +++ b/Core/Code/TestingHelper/mitkInteractionTestHelper.h @@ -1,140 +1,103 @@ /*=================================================================== 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 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(std::string interactionFilePath); + InteractionTestHelper(); /** Default destructor */ ~InteractionTestHelper(); - /** @brief Getter for the vtkRenderer. + /** @brief Getter for the Renderer. **/ 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(); + /** + * @brief LoadInteraction loads events from xml file. + * @param interactionXmlPath path to xml file with interaction events. + */ + void LoadInteraction(std::string interactionXmlPath); + 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); - + void Initialize(); - /** @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::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. + mitk::VtkPropRenderer::Pointer m_Renderer; + mitk::RenderWindow::Pointer m_RenderWindow; + mitk::DataStorage::Pointer m_DataStorage; }; }//namespace mitk #endif