diff --git a/CMakeExternals/MITKData.cmake b/CMakeExternals/MITKData.cmake index 71a0996f06..1f74c21d84 100644 --- a/CMakeExternals/MITKData.cmake +++ b/CMakeExternals/MITKData.cmake @@ -1,39 +1,39 @@ #----------------------------------------------------------------------------- # MITK Data #----------------------------------------------------------------------------- # Sanity checks if(DEFINED MITK_DATA_DIR AND NOT EXISTS ${MITK_DATA_DIR}) message(FATAL_ERROR "MITK_DATA_DIR variable is defined but corresponds to non-existing directory") endif() set(proj MITK-Data) set(proj_DEPENDENCIES) set(MITK-Data_DEPENDS ${proj}) if(BUILD_TESTING) - set(revision_tag 91a6bd5e) # first 8 characters of hash-tag + set(revision_tag 6001ab9c) # first 8 characters of hash-tag # ^^^^^^^^ these are just to check correct length of hash part ExternalProject_Add(${proj} SOURCE_DIR ${proj} # GIT_REPOSITORY https://phabricator.mitk.org/diffusion/MD/mitk-data.git # GIT_TAG ${revision_tag} URL ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/mitk-data_${revision_tag}.tar.gz UPDATE_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" DEPENDS ${proj_DEPENDENCIES} ) set(MITK_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${proj}) else() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") endif(BUILD_TESTING) diff --git a/Modules/Annotation/include/mitkLogoAnnotation.h b/Modules/Annotation/include/mitkLogoAnnotation.h index a065cb0725..53d2042983 100644 --- a/Modules/Annotation/include/mitkLogoAnnotation.h +++ b/Modules/Annotation/include/mitkLogoAnnotation.h @@ -1,103 +1,104 @@ /*=================================================================== 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 LOGOAnnotation_H #define LOGOAnnotation_H #include "MitkAnnotationExports.h" #include #include #include class mitkVtkLogoRepresentation; class vtkImageData; class vtkImageReader2Factory; class vtkImageImport; namespace mitk { /** \brief Displays a logo on the renderwindow */ class MITKANNOTATION_EXPORT LogoAnnotation : public mitk::VtkAnnotation { public: class LocalStorage : public mitk::Annotation::BaseLocalStorage { public: /** \brief Actor of a 2D render window. */ vtkSmartPointer m_LogoImage; vtkSmartPointer m_LogoRep; /** \brief Timestamp of last update of stored data. */ itk::TimeStamp m_LastUpdateTime; /** \brief Default constructor of the local storage. */ LocalStorage(); /** \brief Default deconstructor of the local storage. */ ~LocalStorage(); }; mitkClassMacro(LogoAnnotation, mitk::VtkAnnotation); itkFactorylessNewMacro(Self) itkCloneMacro(Self) vtkSmartPointer m_readerFactory; void SetLogoImage(vtkSmartPointer logo); void SetLogoImagePath(std::string text); std::string GetLogoImagePath() const; + void LoadLogoImageFromPath(); /** \brief The relative offset to the corner position */ void SetOffsetVector(const Point2D &OffsetVector); Point2D GetOffsetVector() const; /** \brief The corner where the logo is displayed. 0 = Bottom left 1 = Bottom right 2 = Top right 3 = Top left 4 = Center*/ void SetCornerPosition(const int &corner); int GetCornerPosition() const; void SetRelativeSize(const float &size); float GetRelativeSize() const; protected: /** \brief The LocalStorageHandler holds all LocalStorages for the render windows. */ mutable mitk::LocalStorageHandler m_LSH; vtkProp *GetVtkProp(BaseRenderer *renderer) const override; void UpdateVtkAnnotation(mitk::BaseRenderer *renderer) override; /** \brief explicit constructor which disallows implicit conversions */ explicit LogoAnnotation(); /** \brief virtual destructor in order to derive from this class */ ~LogoAnnotation() override; private: vtkSmartPointer m_UpdatedLogoImage; vtkSmartPointer m_VtkImageImport; /** \brief copy constructor */ LogoAnnotation(const LogoAnnotation &); /** \brief assignment operator */ LogoAnnotation &operator=(const LogoAnnotation &); }; } // namespace mitk #endif // LOGOAnnotation_H diff --git a/Modules/Annotation/src/mitkLogoAnnotation.cpp b/Modules/Annotation/src/mitkLogoAnnotation.cpp index 1b6a161cbd..13e615ec88 100644 --- a/Modules/Annotation/src/mitkLogoAnnotation.cpp +++ b/Modules/Annotation/src/mitkLogoAnnotation.cpp @@ -1,158 +1,181 @@ /*=================================================================== 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 "mitkLogoAnnotation.h" +#include #include "vtkUnicodeString.h" #include #include #include #include #include #include #include #include #include #include #include #include #include +#include +#include mitk::LogoAnnotation::LogoAnnotation() { m_readerFactory = vtkSmartPointer::New(); mitk::Point2D offset; offset.Fill(0.03); SetOffsetVector(offset); SetRelativeSize(0.2); SetLogoImagePath("mbiLogo"); SetCornerPosition(3); m_VtkImageImport = vtkSmartPointer::New(); m_UpdatedLogoImage = vtkSmartPointer::New(); } mitk::LogoAnnotation::~LogoAnnotation() { for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer()) { if (renderer) { this->RemoveFromBaseRenderer(renderer); } } } mitk::LogoAnnotation::LocalStorage::~LocalStorage() { } mitk::LogoAnnotation::LocalStorage::LocalStorage() { m_LogoRep = vtkSmartPointer::New(); } void mitk::LogoAnnotation::UpdateVtkAnnotation(mitk::BaseRenderer *renderer) { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); if (ls->IsGenerateDataRequired(renderer, this)) { ls->m_LogoImage = m_UpdatedLogoImage; ls->m_LogoRep->SetImage(ls->m_LogoImage); ls->m_LogoRep->SetDragable(false); ls->m_LogoRep->SetMoving(false); ls->m_LogoRep->SetPickable(false); ls->m_LogoRep->SetShowBorder(true); ls->m_LogoRep->SetRenderer(renderer->GetVtkRenderer()); float size = GetRelativeSize(); ls->m_LogoRep->SetPosition2(size, size); int corner = GetCornerPosition(); ls->m_LogoRep->SetCornerPosition(corner); mitk::Point2D offset = GetOffsetVector(); ls->m_LogoRep->SetPosition(offset[0], offset[1]); float opacity = 1.0; GetOpacity(opacity); ls->m_LogoRep->GetImageProperty()->SetOpacity(opacity); ls->m_LogoRep->BuildRepresentation(); ls->UpdateGenerateDataTime(); } } void mitk::LogoAnnotation::SetLogoImagePath(std::string path) { SetStringProperty("Annotation.LogoImagePath", path.c_str()); Modified(); } +void mitk::LogoAnnotation::LoadLogoImageFromPath() +{ + auto imageNodeVector = mitk::IOUtil::Load(this->GetLogoImagePath()); + + if (imageNodeVector.size() == 1) + { + mitk::Image::Pointer image = dynamic_cast(imageNodeVector.front().GetPointer()); + + if (image.IsNotNull()) + { + vtkNew flip; + flip->SetInputData(image->GetVtkImageData()); + flip->SetFilteredAxis(1); + flip->Update(); + m_UpdatedLogoImage->DeepCopy(flip->GetOutput()); + Modified(); + } + } +} + void mitk::LogoAnnotation::SetLogoImage(vtkSmartPointer logo) { m_UpdatedLogoImage = logo; Modified(); } std::string mitk::LogoAnnotation::GetLogoImagePath() const { std::string path; GetPropertyList()->GetStringProperty("Annotation.LogoImagePath", path); return path; } void mitk::LogoAnnotation::SetOffsetVector(const Point2D &OffsetVector) { mitk::Point2dProperty::Pointer OffsetVectorProperty = mitk::Point2dProperty::New(OffsetVector); SetProperty("Annotation.OffsetVector", OffsetVectorProperty.GetPointer()); Modified(); } mitk::Point2D mitk::LogoAnnotation::GetOffsetVector() const { mitk::Point2D OffsetVector; OffsetVector.Fill(0); GetPropertyValue("Annotation.OffsetVector", OffsetVector); return OffsetVector; } void mitk::LogoAnnotation::SetCornerPosition(const int &corner) { SetIntProperty("Annotation.CornerPosition", corner); Modified(); } int mitk::LogoAnnotation::GetCornerPosition() const { int corner = 0; GetIntProperty("Annotation.CornerPosition", corner); return corner; } void mitk::LogoAnnotation::SetRelativeSize(const float &size) { SetFloatProperty("Annotation.RelativeSize", size); Modified(); } float mitk::LogoAnnotation::GetRelativeSize() const { float size = 0; GetFloatProperty("Annotation.RelativeSize", size); return size; } vtkProp *mitk::LogoAnnotation::GetVtkProp(BaseRenderer *renderer) const { LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_LogoRep; } diff --git a/Modules/Annotation/test/mitkLogoAnnotationTest.cpp b/Modules/Annotation/test/mitkLogoAnnotationTest.cpp index 51f541c416..9c6bd4bbc1 100644 --- a/Modules/Annotation/test/mitkLogoAnnotationTest.cpp +++ b/Modules/Annotation/test/mitkLogoAnnotationTest.cpp @@ -1,138 +1,146 @@ /*=================================================================== 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 #include class mitkLogoAnnotationTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkLogoAnnotationTestSuite); MITK_TEST(RenderMbiLogo); MITK_TEST(RenderLogo); CPPUNIT_TEST_SUITE_END(); private: /** Members used inside the different test methods. All members are initialized via setUp().*/ mitk::RenderingTestHelper m_RenderingTestHelper; std::vector m_CommandlineArgs; std::string m_PathToBall; std::string m_PathToImage; std::string m_PathToLogo; std::string m_PathToMitkLogo; std::string m_ReferenceImagePath; public: /** * @brief mitkManualPlacementAnnotationRendererTestSuite Because the RenderingTestHelper does not have an * empty default constructor, we need this constructor to initialize the helper with a * resolution. */ mitkLogoAnnotationTestSuite() : m_RenderingTestHelper(300, 300) {} /** * @brief Setup Initialize a fresh rendering test helper and a vector of strings * to simulate commandline arguments for vtkTesting::Test. */ void setUp() { m_RenderingTestHelper = mitk::RenderingTestHelper(300, 300); m_PathToBall = GetTestDataFilePath("ball.stl"); m_PathToImage = GetTestDataFilePath("Pic3D.nrrd"); m_PathToLogo = GetTestDataFilePath("RenderingTestData/texture.jpg"); m_PathToMitkLogo = GetTestDataFilePath("RenderingTestData/defaultWatermark.png"); m_ReferenceImagePath = "RenderingTestData/ReferenceScreenshots/Annotation/"; // Build a command line for the vtkTesting::Test method. // See VTK documentation and RenderingTestHelper for more information. // Use the following command line option to save the difference image // and the test image in some tmp folder // m_CommandlineArgs.push_back("-T"); // m_CommandlineArgs.push_back("/path/to/save/tmp/difference/images/"); m_CommandlineArgs.push_back("-V"); } void tearDown() {} void RenderMbiLogo() { mitk::DataNode::Pointer ballnode = mitk::DataNode::New(); ballnode->SetData(mitk::IOUtil::Load(m_PathToBall)[0]); m_RenderingTestHelper.AddNodeToStorage(ballnode); mitk::DataNode::Pointer imagenode = mitk::DataNode::New(); imagenode->SetData(mitk::IOUtil::Load(m_PathToImage)[0]); m_RenderingTestHelper.AddNodeToStorage(imagenode); std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "LogoAnnotation_mitkLogo.png"); // reference screenshot for this test m_CommandlineArgs.push_back(refImagePath); // Convert vector of strings to argc/argv mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs); m_RenderingTestHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); mitk::LogoAnnotation::Pointer logoAnnotation = mitk::LogoAnnotation::New(); logoAnnotation->SetLogoImagePath(m_PathToMitkLogo); + logoAnnotation->LoadLogoImageFromPath(); + logoAnnotation->SetOpacity(0.5); + mitk::Point2D offset; + offset.Fill(0.03); + logoAnnotation->SetOffsetVector(offset); + logoAnnotation->SetRelativeSize(0.5); + logoAnnotation->SetCornerPosition(1); mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow()); mitk::ManualPlacementAnnotationRenderer::AddAnnotation(logoAnnotation.GetPointer(), renderer); m_RenderingTestHelper.Render(); // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath); m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true); CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true); } void RenderLogo() { mitk::DataNode::Pointer ballnode = mitk::DataNode::New(); ballnode->SetData(mitk::IOUtil::Load(m_PathToBall)[0]); m_RenderingTestHelper.AddNodeToStorage(ballnode); mitk::DataNode::Pointer imagenode = mitk::DataNode::New(); imagenode->SetData(mitk::IOUtil::Load(m_PathToImage)[0]); m_RenderingTestHelper.AddNodeToStorage(imagenode); std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "LogoAnnotation.png"); // reference screenshot for this test m_CommandlineArgs.push_back(refImagePath); // Convert vector of strings to argc/argv mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs); m_RenderingTestHelper.SetViewDirection(mitk::SliceNavigationController::Sagittal); mitk::LogoAnnotation::Pointer logoAnnotation = mitk::LogoAnnotation::New(); logoAnnotation->SetLogoImagePath(m_PathToLogo); + logoAnnotation->LoadLogoImageFromPath(); mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow()); mitk::ManualPlacementAnnotationRenderer::AddAnnotation(logoAnnotation.GetPointer(), renderer); m_RenderingTestHelper.Render(); // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath); m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true); CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true); } }; MITK_TEST_SUITE_REGISTRATION(mitkLogoAnnotation)