diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d68700c --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2003-2019, German Cancer Research Center (DKFZ) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 7b17319..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,36 +0,0 @@ -Copyright (c) 2003-2019 German Cancer Research Center, -Division of Medical and Biological Informatics -All rights reserved. - -Redistribution and use in source and binary forms, with or -without modification, are permitted provided that the -following conditions are met: - - * Redistributions of source code must retain the above - copyright notice, this list of conditions and the - following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - - * Neither the name of the German Cancer Research Center, - nor the names of its contributors may be used to endorse - or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. diff --git a/Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp b/Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp index bbc9cf0..a0fb949 100644 --- a/Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp +++ b/Modules/ExampleModule/cmdapps/ExampleCmdApp.cpp @@ -1,149 +1,145 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include #include #include #include #include /** \brief Example command-line app that demonstrates the example image filter * * This command-line app will take the first given image and add the * provided offset to each voxel. */ int main(int argc, char* argv[]) { mitkCommandLineParser parser; // Set general information about your command-line app parser.setCategory("Example Cmd App Category"); parser.setTitle("Example Cmd App"); parser.setContributor("CAMIC"); parser.setDescription( "This command-line app takes the given image and adds the provided offset to each voxel."); // How should arguments be prefixed parser.setArgumentPrefix("--", "-"); // Add arguments. Unless specified otherwise, each argument is optional. // See mitkCommandLineParser::addArgument() for more information. parser.addArgument( "input", "i", mitkCommandLineParser::InputFile, "Input Image", "Any image format known to MITK.", us::Any(), false); parser.addArgument( "output", "o", mitkCommandLineParser::OutputFile, "Output file", "Where to save the output.", us::Any(), false); parser.addArgument( "offset", "f", mitkCommandLineParser::Int, "Offset", "the offset integer to add to each voxel.", us::Any(), false); parser.addArgument( // optional "verbose", "v", mitkCommandLineParser::Bool, "Verbose Output", "Whether to produce verbose output"); // Parse arguments. This method returns a mapping of long argument names to // their values. auto parsedArgs = parser.parseArguments(argc, argv); if (parsedArgs.empty()) return EXIT_FAILURE; // Just exit, usage information was already printed. if (parsedArgs["input"].Empty() || parsedArgs["output"].Empty() || parsedArgs["offset"].Empty()) { MITK_INFO << parser.helpText(); return EXIT_FAILURE; } // Parse, cast and set required arguments auto inFilename = us::any_cast(parsedArgs["input"]); auto outFilename = us::any_cast(parsedArgs["output"]); auto offset = us::any_cast(parsedArgs["offset"]); // Default values for optional arguments auto verbose = false; // Parse, cast and set optional arguments if (parsedArgs.end() != parsedArgs.find("verbose")) verbose = us::any_cast(parsedArgs["verbose"]); try { if (verbose) MITK_INFO << "Read input file"; auto inImage = mitk::IOUtil::Load(inFilename); if (inImage.IsNull()) { MITK_ERROR << "Could not read \"" << inFilename << "\"!"; return EXIT_FAILURE; } if (verbose) MITK_INFO << "Add offset to image"; auto exampleFilter = ExampleImageFilter::New(); exampleFilter->SetInput(inImage); exampleFilter->SetOffset(offset); exampleFilter->Update(); auto outImage = exampleFilter->GetOutput(); if (nullptr == outImage) { MITK_ERROR << "Image processing failed!"; return EXIT_FAILURE; } if (verbose) MITK_INFO << "Write output file"; mitk::IOUtil::Save(outImage, outFilename); return EXIT_SUCCESS; } catch (const std::exception &e) { MITK_ERROR << e.what(); return EXIT_FAILURE; } catch (...) { MITK_ERROR << "Unexpected error!"; return EXIT_FAILURE; } } diff --git a/Modules/ExampleModule/include/ExampleImageFilter.h b/Modules/ExampleModule/include/ExampleImageFilter.h index 8bbf100..be07e96 100644 --- a/Modules/ExampleModule/include/ExampleImageFilter.h +++ b/Modules/ExampleModule/include/ExampleImageFilter.h @@ -1,52 +1,48 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #ifndef ExampleImageFilter_h #define ExampleImageFilter_h #include // The following header file is generated by CMake and thus it's located in // the build directory. It provides an export macro for classes and functions // that you want to be part of the public interface of your module. #include // While you are free to derive directly from ITK filter base classes, // MITK filter base classes provide typed accessor methods for the inputs // and outputs, which will save you and your clients lots of manual casting. class MITKEXAMPLEMODULE_EXPORT ExampleImageFilter final : public mitk::ImageToImageFilter { public: // All classes that derive from an ITK-based MITK class need at least the // following two macros. Make sure you don't declare the constructor public // to force clients of your class to follow the ITK convention for // instantiating classes via the static New() method. mitkClassMacro(ExampleImageFilter, mitk::ImageToImageFilter) itkFactorylessNewMacro(Self) itkSetMacro(Offset, int) itkGetMacro(Offset, int) private: ExampleImageFilter(); ~ExampleImageFilter(); void GenerateData() override; int m_Offset; }; #endif diff --git a/Modules/ExampleModule/include/ExampleImageInteractor.h b/Modules/ExampleModule/include/ExampleImageInteractor.h index 379463d..1b9e03c 100644 --- a/Modules/ExampleModule/include/ExampleImageInteractor.h +++ b/Modules/ExampleModule/include/ExampleImageInteractor.h @@ -1,47 +1,43 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #ifndef ExampleImageInteractor_h #define ExampleImageInteractor_h #include #include #include // See ExampleImageFilter.h for details on typical class declarations // in MITK. The actual functionality of this class is commented in its // implementation file. class MITKEXAMPLEMODULE_EXPORT ExampleImageInteractor final : public mitk::DataInteractor { public: mitkClassMacro(ExampleImageInteractor, DataInteractor) itkFactorylessNewMacro(Self) private: ExampleImageInteractor(); ~ExampleImageInteractor(); void ConnectActionsAndFunctions() override; void DataNodeChanged() override; void Paint(mitk::StateMachineAction* action, mitk::InteractionEvent* event); itk::Index<3> m_LastPixelIndex; }; #endif diff --git a/Modules/ExampleModule/include/ExampleModule.h b/Modules/ExampleModule/include/ExampleModule.h index 93d008d..1b71e38 100644 --- a/Modules/ExampleModule/include/ExampleModule.h +++ b/Modules/ExampleModule/include/ExampleModule.h @@ -1,27 +1,23 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #ifndef ExampleModule_h #define ExampleModule_h #include namespace ExampleModule { MITKEXAMPLEMODULE_EXPORT void ForceLinkage(); } #endif diff --git a/Modules/ExampleModule/include/ExampleSegTool2D.h b/Modules/ExampleModule/include/ExampleSegTool2D.h index 7362c78..eca6e13 100644 --- a/Modules/ExampleModule/include/ExampleSegTool2D.h +++ b/Modules/ExampleModule/include/ExampleSegTool2D.h @@ -1,80 +1,76 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #ifndef ExampleSegTool2D_h #define ExampleSegTool2D_h #include #include namespace us { class ModuleResource; } // This is an example on how to add a segmentation tool to the standard // MITK Segmentation Views. Here's the crucial points to make it work: // // * The name of the class MUST end in either SegTool2D or SegTool3D // // * Derive directly or indirectly from mitk::Tool, for example // mitk::SegTool2D is a typical choice for 2d tools and // mitk::AutoSegmentationTool is a typical choice for 3d tools. // // * Don't forget the MITK_TOOL_MACRO in the implementation file // // * You don't have to provide your own state machine if the state // machines of the MitkSegmentation module are sufficient, but if // you do, you MUST provide both, the state machine and an event // config file, for example Paint.xml and PaintConfig.xml. The // file name of the event config file MUST be "equal" to the file // name of the state machine, suffixed by Config.xml instead of // .xml. The file name is passed to the base class constructor // without any extension, for example simply "Paint". // // * Look into ExampleSegTool2DGUI.h for an example of how to provide // a custom tool GUI. The naming is important and basically "equals" // the class name of the tool class, suffixed by GUI. Don't forget // the MITK_TOOL_GUI_MACRO in the implementation file of the tool GUI. // // * Ensure that the module containing your tool is loaded at runtime // before the MITK Segmentation Views are opened. Otherwise it cannot // be found. One way is to call anything from that module in a plugin // with eager activation policy. Such plugins are loaded very early // in MITK. For an example of how this works, look into ExampleModule.h // and the org_mitk_exampleplugin_eageractivation plugin. class MITKEXAMPLEMODULE_EXPORT ExampleSegTool2D : public mitk::SegTool2D { public: mitkClassMacro(ExampleSegTool2D, SegTool2D) itkFactorylessNewMacro(Self) us::ModuleResource GetIconResource() const override; const char *GetName() const override; const char **GetXPM() const override; protected: ExampleSegTool2D(); ~ExampleSegTool2D() override; virtual void Paint(mitk::StateMachineAction* action, mitk::InteractionEvent* event); private: void ConnectActionsAndFunctions() override; }; #endif diff --git a/Modules/ExampleModule/include/ExampleSegTool2DGUI.h b/Modules/ExampleModule/include/ExampleSegTool2DGUI.h index 747334e..832c393 100644 --- a/Modules/ExampleModule/include/ExampleSegTool2DGUI.h +++ b/Modules/ExampleModule/include/ExampleSegTool2DGUI.h @@ -1,47 +1,43 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #ifndef ExampleSegTool2DGUI_h #define ExampleSegTool2DGUI_h #include #include #include namespace Ui { class ExampleSegTool2DGUI; } // Look into ExampleSegTool2D.h for more information. class MITKEXAMPLEMODULE_EXPORT ExampleSegTool2DGUI : public QmitkToolGUI { Q_OBJECT public: mitkClassMacro(ExampleSegTool2DGUI, QmitkToolGUI) itkFactorylessNewMacro(Self) protected: ExampleSegTool2DGUI(); ~ExampleSegTool2DGUI() override; private: QScopedPointer m_Ui; }; #endif diff --git a/Modules/ExampleModule/src/ExampleImageFilter.cpp b/Modules/ExampleModule/src/ExampleImageFilter.cpp index 3dcd9da..86cb0c5 100644 --- a/Modules/ExampleModule/src/ExampleImageFilter.cpp +++ b/Modules/ExampleModule/src/ExampleImageFilter.cpp @@ -1,100 +1,96 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include #include #include #include // See definition of ExampleImageFilter::GenerateData() further below for // a rationale behind this function template. template static void AddOffset(const itk::Image* inputImage, int offset, mitk::Image::Pointer outputImage) { typedef itk::Image ImageType; typedef itk::ShiftScaleImageFilter FilterType; auto filter = FilterType::New(); filter->SetInput(inputImage); filter->SetShift(offset); filter->Update(); // This is the tricky part that is done wrong very often. As the image data // of ITK images and MITK images are binary compatible, we don't need to // cast or copy the ITK output image. Instead, we just want to reference // the image data and tell ITK that we took the ownership. mitk::GrabItkImageMemory(filter->GetOutput(), outputImage); } ExampleImageFilter::ExampleImageFilter() : m_Offset(0) { this->SetNumberOfRequiredInputs(1); this->SetNumberOfRequiredOutputs(1); } ExampleImageFilter::~ExampleImageFilter() { } void ExampleImageFilter::GenerateData() { mitk::Image::Pointer inputImage = this->GetInput(0); if (m_Offset == 0) { // Nothing to calculate in this case, just copy the input image. this->SetPrimaryOutput(inputImage->Clone().GetPointer()); } else { mitk::Image::Pointer outputImage = this->GetOutput(); try { // We want to apply an ITK filter to the MITK input image. While MITK // images are not templated, ITK images are templated by both pixel type // and image dimension. The actual image data is binary compatible, though. // MITK provides ITK access macros that enable you to directly operate // on MITK images without any superfluous copying. // To allow ITK filters to work with different image types at runtime you // would be required to instantiate your function templates for each and // every expected combination of pixel type and image dimension. Luckily, // MITK provides a whole bunch of multiplexer macros to save you doing this // manually (see mitkImageAccessByItk.h). // These macros range from being completely generic to partly constrained // variants. For example, you may want to constrain the image dimension or // the pixel type. As your function template is compiled for each allowed // combination, compile time and code size may increase dramatically. // As a rule of thumb, use a suitable multiplexer macro that is as // constrained as possible and yet as generic as necessary. // To prevent a combinatorial explosion, image dimension is restricted to // 2 and 3 even for the dimension-variable multiplexer macros. // Thus, the following multiplexer macro allows for 2-dimensional and // 3-dimensional images with an integer pixel type, for example, // (un)signed char, short, and int, resulting in a total of 12 distinct // combinations. AccessIntegralPixelTypeByItk_n(inputImage, AddOffset, (m_Offset, outputImage)); } catch (const mitk::AccessByItkException& e) { MITK_ERROR << "Unsupported pixel type or image dimension: " << e.what(); } } } diff --git a/Modules/ExampleModule/src/ExampleImageInteractor.cpp b/Modules/ExampleModule/src/ExampleImageInteractor.cpp index 6f85f61..93b3b11 100644 --- a/Modules/ExampleModule/src/ExampleImageInteractor.cpp +++ b/Modules/ExampleModule/src/ExampleImageInteractor.cpp @@ -1,186 +1,182 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include #include #include #include #include namespace { // Helper function to get an image from a data node. mitk::Image::Pointer GetImage(mitk::DataNode::Pointer dataNode) { if (dataNode.IsNull()) mitkThrow(); mitk::Image::Pointer image = dynamic_cast(dataNode->GetData()); - + if (image.IsNull()) mitkThrow(); return image; } // Helper function to get a geometry of an image for a specific time step. mitk::BaseGeometry::Pointer GetGeometry(mitk::Image::Pointer image, unsigned int timeStep) { mitk::TimeGeometry::Pointer timeGeometry = image->GetTimeGeometry(); if (timeGeometry.IsNull()) mitkThrow(); auto geometry = timeGeometry->GetGeometryForTimeStep(timeStep); if (geometry.IsNull()) mitkThrow(); return geometry; } } // The actual painting happens here. We're using a write accessor to gain safe // write access to our image. The whole image volume for a given time step is // locked. However, it's also possible - and preferable - to lock the slice of // interest only. template static void Paint(mitk::Image::Pointer image, itk::Index<3> index, unsigned int timeStep) { // As soon as the ImagePixelWriteAccessor object goes out of scope at the // end of this function, the image will be unlocked again (RAII). mitk::ImagePixelWriteAccessor writeAccessor(image, image->GetVolumeData(timeStep)); writeAccessor.SetPixelByIndex(index, std::numeric_limits::min()); // Don't forget to update the modified time stamp of the image. Otherwise, // everything downstream wouldn't recognize that the image changed, // including the rendering system. image->Modified(); } // Helper function to multiplex the actual Paint function call for different // pixel types. As it's cumbersome and ugly, you may want to avoid such // functions by using ITK for the actual painting and use the ITK access // macros like we did for the AwesomeImageFilter. static void Paint(mitk::Image::Pointer image, itk::Index<3> index, unsigned int timeStep) { switch (image->GetPixelType().GetComponentType()) { case itk::ImageIOBase::CHAR: Paint(image, index, timeStep); break; case itk::ImageIOBase::UCHAR: Paint(image, index, timeStep); break; case itk::ImageIOBase::SHORT: Paint(image, index, timeStep); break; case itk::ImageIOBase::USHORT: Paint(image, index, timeStep); break; case itk::ImageIOBase::INT: Paint(image, index, timeStep); break; case itk::ImageIOBase::UINT: Paint(image, index, timeStep); break; default: mitkThrow(); } } ExampleImageInteractor::ExampleImageInteractor() { } ExampleImageInteractor::~ExampleImageInteractor() { } void ExampleImageInteractor::ConnectActionsAndFunctions() { // Wire up this interactor with the state machine that is described by // resource/Interactions/Paint.xml. CONNECT_FUNCTION("paint", Paint) } void ExampleImageInteractor::DataNodeChanged() { // You almost always want to reset the state machine when the interactor // has been attached to another data node. this->ResetToStartState(); } // The state machine is wired up with this Paint method. We wrote a few helper // functions at the top of this files to keep this method clear and easy to // read. void ExampleImageInteractor::Paint(mitk::StateMachineAction*, mitk::InteractionEvent* event) { try { auto renderer = event->GetSender(); auto image = GetImage(this->GetDataNode()); auto timeStep = renderer->GetTimeStep(); auto geometry = GetGeometry(image, timeStep); // This method is wired up to mouse events. Thus, we can safely assume // that the following cast will succeed and we have access to the mouse // position and the first intersection point of a ray originating at the // mouse position and shot into the scene. Convenient, isn't it? :-) auto positionEvent = dynamic_cast(event); auto position = positionEvent->GetPositionInWorld(); if (!geometry->IsInside(position)) return; // Nothing to paint, as we're not inside the image bounds. // Okay, we're safe. Convert the mouse position to the index of the pixel // we're pointing at. itk::Index<3> index; geometry->WorldToIndex<3>(position, index); // We don't need to paint over and over again while moving the mouse // pointer inside the same pixel. That's especially relevant when operating // on zoomed images. if (index != m_LastPixelIndex) { // And finally... ::Paint(image, index, timeStep); // Nearly done. We request the renderer to update the render window in // order to see the result immediately. Actually, we should update all // of the render windows by caling RequestUpdateAll() instead, as the // painted pixels are possibly visible in other render windows, too. // However, we decided to prefer performance here. mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow()); MITK_INFO << index[0] << " " << index[1] << " " << index[2]; m_LastPixelIndex = index; } } catch (...) { return; } } diff --git a/Modules/ExampleModule/src/ExampleModule.cpp b/Modules/ExampleModule/src/ExampleModule.cpp index eeb9723..f607c9c 100644 --- a/Modules/ExampleModule/src/ExampleModule.cpp +++ b/Modules/ExampleModule/src/ExampleModule.cpp @@ -1,21 +1,17 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include void ExampleModule::ForceLinkage() { } diff --git a/Modules/ExampleModule/src/ExampleSegTool2D.cpp b/Modules/ExampleModule/src/ExampleSegTool2D.cpp index 1687470..acf81de 100644 --- a/Modules/ExampleModule/src/ExampleSegTool2D.cpp +++ b/Modules/ExampleModule/src/ExampleSegTool2D.cpp @@ -1,59 +1,55 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include #include #include MITK_TOOL_MACRO(MITKEXAMPLEMODULE_EXPORT, ExampleSegTool2D, "Example tool"); ExampleSegTool2D::ExampleSegTool2D() : SegTool2D("Paint", us::GetModuleContext()->GetModule()) { } ExampleSegTool2D::~ExampleSegTool2D() { } void ExampleSegTool2D::ConnectActionsAndFunctions() { CONNECT_FUNCTION("paint", Paint) } void ExampleSegTool2D::Paint(mitk::StateMachineAction*, mitk::InteractionEvent*) { MITK_INFO << "Hello from the other side!"; } us::ModuleResource ExampleSegTool2D::GetIconResource() const { auto moduleContext = us::GetModuleContext(); auto module = moduleContext->GetModule(); auto resource = module->GetResource("ExampleIcon.svg"); return resource; } const char *ExampleSegTool2D::GetName() const { return "Example"; } const char **ExampleSegTool2D::GetXPM() const { return nullptr; } diff --git a/Modules/ExampleModule/src/ExampleSegTool2DGUI.cpp b/Modules/ExampleModule/src/ExampleSegTool2DGUI.cpp index 2b9940a..1ca34b6 100644 --- a/Modules/ExampleModule/src/ExampleSegTool2DGUI.cpp +++ b/Modules/ExampleModule/src/ExampleSegTool2DGUI.cpp @@ -1,30 +1,26 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include #include MITK_TOOL_GUI_MACRO(MITKEXAMPLEMODULE_EXPORT, ExampleSegTool2DGUI, "") ExampleSegTool2DGUI::ExampleSegTool2DGUI() : m_Ui(new Ui::ExampleSegTool2DGUI) { m_Ui->setupUi(this); } ExampleSegTool2DGUI::~ExampleSegTool2DGUI() { } diff --git a/Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.cpp b/Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.cpp index feb721b..4705033 100644 --- a/Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.cpp +++ b/Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.cpp @@ -1,27 +1,23 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include "PluginActivator.h" #include void PluginActivator::start(ctkPluginContext*) { ExampleModule::ForceLinkage(); } void PluginActivator::stop(ctkPluginContext*) { } diff --git a/Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.h b/Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.h index 5530fce..d1380c7 100644 --- a/Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.h +++ b/Plugins/org.mitk.exampleplugin.eageractivation/src/internal/PluginActivator.h @@ -1,33 +1,29 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #ifndef PluginActivator_h #define PluginActivator_h #include class PluginActivator : public QObject, public ctkPluginActivator { Q_OBJECT Q_PLUGIN_METADATA(IID "org_mitk_exampleplugin_eageractivation") Q_INTERFACES(ctkPluginActivator) public: void start(ctkPluginContext* context); void stop(ctkPluginContext* context); }; #endif diff --git a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.cpp b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.cpp index 7a4f4e9..0f711fa 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.cpp +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.cpp @@ -1,27 +1,23 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include "PluginActivator.h" #include "QmitkExampleView.h" void PluginActivator::start(ctkPluginContext* context) { BERRY_REGISTER_EXTENSION_CLASS(QmitkExampleView, context) } void PluginActivator::stop(ctkPluginContext*) { } diff --git a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.h b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.h index 4a8cacf..79dd854 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.h +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/PluginActivator.h @@ -1,33 +1,29 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #ifndef PluginActivator_h #define PluginActivator_h #include class PluginActivator : public QObject, public ctkPluginActivator { Q_OBJECT Q_PLUGIN_METADATA(IID "org_mitk_gui_qt_exampleplugin") Q_INTERFACES(ctkPluginActivator) public: void start(ctkPluginContext* context); void stop(ctkPluginContext* context); }; #endif diff --git a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.cpp b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.cpp index 8bf2b22..9c2fcbe 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.cpp +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.cpp @@ -1,180 +1,176 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #include #include #include #include #include #include #include "QmitkExampleView.h" namespace { // Helper function to create a fully set up instance of our // ExampleImageInteractor, based on the state machine specified in Paint.xml // as well as its configuration in PaintConfig.xml. Both files are compiled // into ExtExampleModule as resources. static ExampleImageInteractor::Pointer CreateExampleImageInteractor() { auto exampleModule = us::ModuleRegistry::GetModule("MitkExampleModule"); if (nullptr != exampleModule) { auto interactor = ExampleImageInteractor::New(); interactor->LoadStateMachine("Paint.xml", exampleModule); interactor->SetEventConfig("PaintConfig.xml", exampleModule); return interactor; } return nullptr; } } // Don't forget to initialize the VIEW_ID. const std::string QmitkExampleView::VIEW_ID = "org.mitk.views.exampleview"; void QmitkExampleView::CreateQtPartControl(QWidget* parent) { // Setting up the UI is a true pleasure when using .ui files, isn't it? m_Controls.setupUi(parent); // Wire up the UI widgets with our functionality. connect(m_Controls.processImageButton, SIGNAL(clicked()), this, SLOT(ProcessSelectedImage())); } void QmitkExampleView::SetFocus() { m_Controls.processImageButton->setFocus(); } void QmitkExampleView::OnSelectionChanged(berry::IWorkbenchPart::Pointer, const QList& dataNodes) { for (const auto& dataNode : dataNodes) { // Write robust code. Always check pointers before using them. If the // data node pointer is null, the second half of our condition isn't // even evaluated and we're safe (C++ short-circuit evaluation). if (dataNode.IsNotNull() && nullptr != dynamic_cast(dataNode->GetData())) { m_Controls.selectImageLabel->setVisible(false); return; } } // Nothing is selected or the selection doesn't contain an image. m_Controls.selectImageLabel->setVisible(true); } void QmitkExampleView::ProcessSelectedImage() { // Before we even think about processing something, we need to make sure // that we have valid input. Don't be sloppy, this is a main reason // for application crashes if neglected. auto selectedDataNodes = this->GetDataManagerSelection(); if (selectedDataNodes.empty()) return; auto firstSelectedDataNode = selectedDataNodes.front(); if (firstSelectedDataNode.IsNull()) { QMessageBox::information(nullptr, "Example View", "Please load and select an image before starting image processing."); return; } auto data = firstSelectedDataNode->GetData(); // Something is selected, but does it contain data? if (data != nullptr) { // We don't use the auto keyword here, which would evaluate to a native // image pointer. Instead, we want a smart pointer in order to ensure that // the image isn't deleted somewhere else while we're using it. mitk::Image::Pointer image = dynamic_cast(data); // Something is selected and it contains data, but is it an image? if (image.IsNotNull()) { auto imageName = firstSelectedDataNode->GetName(); auto offset = m_Controls.offsetSpinBox->value(); MITK_INFO << "Process image \"" << imageName << "\" ..."; // We're finally using the ExampleImageFilter from ExtExampleModule. auto filter = ExampleImageFilter::New(); filter->SetInput(image); filter->SetOffset(offset); filter->Update(); mitk::Image::Pointer processedImage = filter->GetOutput(); if (processedImage.IsNull() || !processedImage->IsInitialized()) return; MITK_INFO << " done"; // Stuff the resulting image into a data node, set some properties, // and add it to the data storage, which will eventually display the // image in the application. auto processedImageDataNode = mitk::DataNode::New(); processedImageDataNode->SetData(processedImage); QString name = QString("%1 (Offset: %2)").arg(imageName.c_str()).arg(offset); processedImageDataNode->SetName(name.toStdString()); // We don't really need to copy the level window, but if we wouldn't // do it, the new level window would be initialized to display the image // with optimal contrast in order to capture the whole range of pixel // values. This is also true for the input image as long as one didn't // modify its level window manually. Thus, the images would appear // identical unless you compare the level window widget for both images. mitk::LevelWindow levelWindow; if (firstSelectedDataNode->GetLevelWindow(levelWindow)) processedImageDataNode->SetLevelWindow(levelWindow); // We also attach our ExampleImageInteractor, which allows us to paint // on the resulting images by using the mouse as long as the CTRL key // is pressed. auto interactor = CreateExampleImageInteractor(); if (interactor.IsNotNull()) interactor->SetDataNode(processedImageDataNode); this->GetDataStorage()->Add(processedImageDataNode); } } // Now it's your turn. This class/method has lots of room for improvements, // for example: // // - What happens when multiple items are selected but the first one isn't // an image? - There isn't any feedback for the user at all. // - What's the front item of a selection? Does it depend on the order // of selection or the position in the Data Manager? - Isn't it // better to process all selected images? Don't forget to adjust the // titles of the UI widgets. // - In addition to the the displayed label, it's probably a good idea to // enable or disable the button depending on the selection. } diff --git a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.h b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.h index e429b0c..f84d5df 100644 --- a/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.h +++ b/Plugins/org.mitk.gui.qt.exampleplugin/src/internal/QmitkExampleView.h @@ -1,69 +1,65 @@ -/*=================================================================== +/*============================================================================ The Medical Imaging Interaction Toolkit (MITK) -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. +Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ +============================================================================*/ #ifndef QmitkExampleView_h #define QmitkExampleView_h #include #include // There's an item "ExampleViewControls.ui" in the UI_FILES list in // files.cmake. The Qt UI Compiler will parse this file and generate a // header file prefixed with "ui_", which is located in the build directory. // Use Qt Creator to view and edit .ui files. The generated header file // provides a class that contains all of the UI widgets. #include // All views in MITK derive from QmitkAbstractView. You have to override // at least the two methods CreateQtPartControl() and SetFocus(). class QmitkExampleView : public QmitkAbstractView { // As ExampleView derives from QObject and we want to use the Qt // signal and slot mechanism, we must not forget the Q_OBJECT macro. // This header file also has to be listed in MOC_H_FILES in files.cmake // so that the Qt Meta-Object compiler can find and process this // class declaration. Q_OBJECT - + public: // This is a tricky one and will give you some headache later on in // your debug sessions if it has been forgotten. Also, don't forget // to initialize it in the implementation file. static const std::string VIEW_ID; // In this method we initialize the GUI components and connect the // associated signals and slots. void CreateQtPartControl(QWidget* parent) override; private slots: void ProcessSelectedImage(); private: // Typically a one-liner. Set the focus to the default widget. void SetFocus() override; // This method is conveniently called whenever the selection of Data Manager // items changes. void OnSelectionChanged( berry::IWorkbenchPart::Pointer source, const QList& dataNodes) override; // Generated from the associated UI file, it encapsulates all the widgets // of our view. Ui::ExampleViewControls m_Controls; }; #endif diff --git a/README.md b/README.md index 055b65e..c731fa9 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,43 @@ The MITK Project Template ========================= -This project provides a complete CMake-based set-up to get started with [MITK](http://mitk.org). +This project provides a complete CMake-based set-up to get started with [MITK](https://github.com/MITK/MITK). Features -------- - Example module - ITK-based image filter - Interactor to paint in images - Example command-line app - Uses the image filter of the example module - Example plugin - GUI for the image filter and interactor of the example module - Example external project - Microsoft's Guidelines Support Library (GSL) What's new in v2018.04 ---------------------- The project template was completely restructured to fit the new extension mechanism of MITK v2018.04. Here's how it basically works: 1. Clone the latest stable branch `releases/2018-04` of MITK from https://phabricator.mitk.org/source/mitk.git (not yet available on GitHub) 2. Clone MITK-ProjectTemplate 3. Configure the MITK superbuild and set the CMake cache variable `MITK_EXTENSION_DIRS` to your working copy of the project template 4. Generate and build the MITK superbuild The project template is integrated right into the MITK superbuild and MITK build. Thus you can extend MITK with your own modules, plugins, command-line apps, and external projects without touching the MITK source code. There is no need for a super-superbuild anymore as compared to earlier versions of the project template. Supported platforms and other requirements ------------------------------------------ See the [MITK documentation](http://docs.mitk.org/2018.04/). + +License +------- + +Copyright (c) [German Cancer Research Center (DKFZ)](https://www.dkfz.de)
+All rights reserved. + +The MITK-ProjectTemplate is part of [MITK](https://github.com/MITK/MITK) and as such available as free open-source software under a [3-clause BSD license](https://github.com/MITK/MITK-ProjectTemplate/blob/master/LICENSE).