diff --git a/Modules/Segmentation/Interactions/mitkEraseRegionTool.cpp b/Modules/Segmentation/Interactions/mitkEraseRegionTool.cpp index e1d480645d..5d98f23651 100644 --- a/Modules/Segmentation/Interactions/mitkEraseRegionTool.cpp +++ b/Modules/Segmentation/Interactions/mitkEraseRegionTool.cpp @@ -1,59 +1,93 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "mitkEraseRegionTool.h" #include "mitkEraseRegionTool.xpm" +#include +#include +#include // us #include #include #include #include namespace mitk { MITK_TOOL_MACRO(MITKSEGMENTATION_EXPORT, EraseRegionTool, "Erase tool"); } -mitk::EraseRegionTool::EraseRegionTool() : SetRegionTool(0) -{ - FeedbackContourTool::SetFeedbackContourColor(1.0, 1.0, 0.0); -} - -mitk::EraseRegionTool::~EraseRegionTool() -{ -} - const char **mitk::EraseRegionTool::GetXPM() const { return mitkEraseRegionTool_xpm; } us::ModuleResource mitk::EraseRegionTool::GetIconResource() const { us::Module *module = us::GetModuleContext()->GetModule(); us::ModuleResource resource = module->GetResource("Erase_48x48.png"); return resource; } us::ModuleResource mitk::EraseRegionTool::GetCursorIconResource() const { us::Module *module = us::GetModuleContext()->GetModule(); us::ModuleResource resource = module->GetResource("Erase_Cursor_32x32.png"); return resource; } const char *mitk::EraseRegionTool::GetName() const { return "Erase"; } + +template +void DoFillImage(itk::Image* image) +{ + image->FillBuffer(1); +}; + +mitk::Image::Pointer mitk::EraseRegionTool::GenerateFillImage(const Image* workingSlice, Point3D seedPoint) const +{ + auto labelSetImage = dynamic_cast(this->GetWorkingData()); + + itk::Index<2> seedIndex; + workingSlice->GetGeometry()->WorldToIndex(seedPoint, seedIndex); + + using AccessorType = ImagePixelReadAccessor; + AccessorType accessor(workingSlice); + + Image::Pointer fillImage; + + if (accessor.GetPixelByIndex(seedIndex) == labelSetImage->GetExteriorLabel()->GetValue()) + { //clicked on background remove everything which is not locked. + fillImage = workingSlice->Clone(); + AccessByItk(fillImage, DoFillImage); + } + else + { + fillImage = Superclass::GenerateFillImage(workingSlice, seedPoint); + } + + return fillImage; +} + +void mitk::EraseRegionTool::PrepareFilling(const Image* /*workingSlice*/, Point3D /*seedPoint*/) +{ + auto labelSetImage = dynamic_cast(this->GetWorkingData()); + if (nullptr != labelSetImage) + { + m_FillValue = labelSetImage->GetExteriorLabel()->GetValue(); + } +}; diff --git a/Modules/Segmentation/Interactions/mitkEraseRegionTool.h b/Modules/Segmentation/Interactions/mitkEraseRegionTool.h index 5316ce5dc1..7244ebcb1b 100644 --- a/Modules/Segmentation/Interactions/mitkEraseRegionTool.h +++ b/Modules/Segmentation/Interactions/mitkEraseRegionTool.h @@ -1,61 +1,64 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef mitkEraseRegionTool_h_Included #define mitkEraseRegionTool_h_Included -#include "mitkSetRegionTool.h" +#include "mitkFillRegionBaseTool.h" #include namespace us { class ModuleResource; } namespace mitk { /** \brief Erase the inside of a contour by filling the inside of a contour with the background pixel value. \sa SetRegionTool \ingroup Interactions Finds the outer contour of a shape in 2D (possibly including single patches) and sets all the pixels inside to the background pixel value (erasing a segmentation). If clicked on the background, the outer contour might contain the whole image and thus fill the whole image with the background pixel value. \warning Only to be instantiated by mitk::ToolManager. */ - class MITKSEGMENTATION_EXPORT EraseRegionTool : public SetRegionTool + class MITKSEGMENTATION_EXPORT EraseRegionTool : public FillRegionBaseTool { public: - mitkClassMacro(EraseRegionTool, SetRegionTool); + mitkClassMacro(EraseRegionTool, FillRegionBaseTool); itkFactorylessNewMacro(Self); itkCloneMacro(Self); - const char **GetXPM() const override; + const char **GetXPM() const override; us::ModuleResource GetCursorIconResource() const override; us::ModuleResource GetIconResource() const override; const char *GetName() const override; protected: - EraseRegionTool(); // purposely hidden - ~EraseRegionTool() override; + EraseRegionTool() = default; // purposely hidden + ~EraseRegionTool() = default; + + Image::Pointer GenerateFillImage(const Image* workingSlice, Point3D seedPoint) const override; + void PrepareFilling(const Image* workingSlice, Point3D seedPoint) override; }; } // namespace #endif diff --git a/Modules/Segmentation/Interactions/mitkFillRegionTool.cpp b/Modules/Segmentation/Interactions/mitkFillRegionTool.cpp index 1ef851a209..2fba00dbac 100644 --- a/Modules/Segmentation/Interactions/mitkFillRegionTool.cpp +++ b/Modules/Segmentation/Interactions/mitkFillRegionTool.cpp @@ -1,58 +1,59 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "mitkFillRegionTool.h" -#include "mitkFillRegionTool.xpm" - // us #include #include #include #include namespace mitk { MITK_TOOL_MACRO(MITKSEGMENTATION_EXPORT, FillRegionTool, "Fill tool"); } -mitk::FillRegionTool::FillRegionTool() : SetRegionTool(1) -{ -} - -mitk::FillRegionTool::~FillRegionTool() -{ -} - const char **mitk::FillRegionTool::GetXPM() const { - return mitkFillRegionTool_xpm; + return nullptr; } us::ModuleResource mitk::FillRegionTool::GetIconResource() const { us::Module *module = us::GetModuleContext()->GetModule(); us::ModuleResource resource = module->GetResource("Fill_48x48.png"); return resource; } us::ModuleResource mitk::FillRegionTool::GetCursorIconResource() const { us::Module *module = us::GetModuleContext()->GetModule(); us::ModuleResource resource = module->GetResource("Fill_Cursor_32x32.png"); return resource; } const char *mitk::FillRegionTool::GetName() const { return "Fill"; } + +void mitk::FillRegionTool::PrepareFilling(const Image* /*workingSlice*/, Point3D /*seedPoint*/) +{ + auto labelSetImage = dynamic_cast(this->GetWorkingData()); + + if (nullptr == labelSetImage) mitkThrow() << "Invalid state of FillRegionTool. Working image is not of correct type."; + + m_FillValue = labelSetImage->GetActiveLabel()->GetValue(); + m_MergeStyle = MultiLabelSegmentation::MergeStyle::Merge; +}; + diff --git a/Modules/Segmentation/Interactions/mitkFillRegionTool.h b/Modules/Segmentation/Interactions/mitkFillRegionTool.h index 3643b13992..e7a1247858 100644 --- a/Modules/Segmentation/Interactions/mitkFillRegionTool.h +++ b/Modules/Segmentation/Interactions/mitkFillRegionTool.h @@ -1,60 +1,62 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef mitkFillRegionTool_h_Included #define mitkFillRegionTool_h_Included -#include "mitkSetRegionTool.h" +#include "mitkFillRegionBaseTool.h" #include namespace us { class ModuleResource; } namespace mitk { /** \brief Fill the inside of a contour with the foreground pixel value. \sa SetRegionTool \ingroup Interactions Finds the outer contour of a shape in 2D (possibly including holes) and sets all the pixels inside to the foreground pixel value (filling holes in a segmentation). If clicked on the background, the outer contour might contain the whole image and thus fill the whole image with the foreground pixel value. \warning Only to be instantiated by mitk::ToolManager. */ - class MITKSEGMENTATION_EXPORT FillRegionTool : public SetRegionTool + class MITKSEGMENTATION_EXPORT FillRegionTool : public FillRegionBaseTool { public: - mitkClassMacro(FillRegionTool, SetRegionTool); + mitkClassMacro(FillRegionTool, FillRegionBaseTool); itkFactorylessNewMacro(Self); itkCloneMacro(Self); - const char **GetXPM() const override; + const char **GetXPM() const override; us::ModuleResource GetCursorIconResource() const override; us::ModuleResource GetIconResource() const override; const char *GetName() const override; protected: - FillRegionTool(); // purposely hidden - ~FillRegionTool() override; + void PrepareFilling(const Image* workingSlice, Point3D seedPoint) override; + + FillRegionTool() = default; // purposely hidden + ~FillRegionTool() = default; }; } // namespace #endif