diff --git a/Modules/Core/include/mitkLookupTable.h b/Modules/Core/include/mitkLookupTable.h index 0b8034b1fa..547abd4fa5 100644 --- a/Modules/Core/include/mitkLookupTable.h +++ b/Modules/Core/include/mitkLookupTable.h @@ -1,273 +1,273 @@ /*=================================================================== 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 mitkLookupTable_h #define mitkLookupTable_h #include "mitkCommon.h" #include #include #include #include #include class vtkColorTransferFunction; class vtkPiecewiseFunction; namespace mitk { /** * @brief The LookupTable class mitk wrapper for a vtkLookupTable * @ingroup DataManagement * * This class can be used to color images with a LookupTable, such as the * vtkLookupTable. * @note If you want to use this as a property for an mitk::Image, make sure * to use the mitk::LookupTableProperty and set the mitk::RenderingModeProperty * to a mode which supports lookup tables (e.g. LOOKUPTABLE_COLOR). Make * sure to check the documentation of the mitk::RenderingModeProperty. For a * code example how to use the mitk::LookupTable check the * mitkImageVtkMapper2DLookupTableTest.cpp in Core\Code\Testing. */ class MITKCORE_EXPORT LookupTable : public itk::DataObject { public: /** * @brief RawLookupTableType raw lookuptable typedef for convenience. */ typedef unsigned char RawLookupTableType; mitkClassMacroItkParent(LookupTable, itk::DataObject); itkFactorylessNewMacro(Self) itkCloneMacro(Self) - /** - * @brief GetVtkLookupTable Getter for the internally wrapped vtkLookupTable. - */ - virtual vtkSmartPointer GetVtkLookupTable() const; + /** + * @brief GetVtkLookupTable Getter for the internally wrapped vtkLookupTable. + */ + virtual vtkSmartPointer GetVtkLookupTable() const; /** * @brief GetRawLookupTable Getter for the raw lookuptable array. */ virtual RawLookupTableType *GetRawLookupTable() const; /** * @brief SetVtkLookupTable Setter for the internal lookuptable. * @param lut The lookuptable. */ virtual void SetVtkLookupTable(vtkSmartPointer lut); /** * @brief ChangeOpacityForAll Set the opacity for all table values. * @param opacity Opacity between 0.0 and 1.0. */ virtual void ChangeOpacityForAll(float opacity); /** * @brief ChangeOpacity Set the opacity for a specific table index. * @param index The lookuptable index. * @param opacity Opacity between 0.0 and 1.0. */ virtual void ChangeOpacity(int index, float opacity); /** * @brief GetColor convenience method wrapping the vtkLookupTable::GetColor() method. * * Map one value through the lookup table and return the color as an RGB array of doubles between 0 and 1. * @param value The value you want to map. * @param rgb RGB values between 0 and 1. */ virtual void GetColor(double value, double rgb[3]); /** * @brief GetTableValue convenience method wrapping the vtkLookupTable::GetTableValue() method. * @param index The index you want to get. * @param rgba RGB values between 0 and 1. */ virtual void GetTableValue(int index, double rgba[4]); /** * @brief SetTableValue convenience method wrapping the vtkLookupTable::SetTableValue() method. * @param index The index you want to set. * @param rgba RGB values between 0 and 1. */ virtual void SetTableValue(int index, double rgba[4]); itkSetMacro(Window, float); itkSetMacro(Level, float); itkSetMacro(Opacity, float); /*! * \brief equality operator implementation */ virtual bool operator==(const mitk::LookupTable &LookupTable) const; /*! * \brief non equality operator implementation */ virtual bool operator!=(const LookupTable &LookupTable) const; /*! * \brief implementation necessary because operator made * private in itk::Object */ virtual LookupTable &operator=(const LookupTable &LookupTable); /** * Updates the output information of the current object by calling * updateOutputInformation of the data objects source object. */ void UpdateOutputInformation() override; /** * Sets the requested Region to the largest possible region. * This method is not implemented, since this is the default * behaviour of the itk pipeline and we do not support the * requested-region mechanism for lookup-tables */ void SetRequestedRegionToLargestPossibleRegion() override; /** * Checks, if the requested region lies outside of the buffered region by * calling verifyRequestedRegion(). */ bool RequestedRegionIsOutsideOfTheBufferedRegion() override; /** * Checks if the requested region is completely contained in * the buffered region. Since we always want to process the lookup * table as a whole, this method always returns true */ bool VerifyRequestedRegion() override; /** * This method has no effect for lookup tables, since we do * not support the region-mechanism */ void SetRequestedRegion(const itk::DataObject *data) override; LookupTable(); ~LookupTable() override; /** * \deprecatedSince{2014_03} Please use CreateColorTransferFunction() instead */ DEPRECATED(void CreateColorTransferFunction(vtkColorTransferFunction *&colorFunction)); /** * \deprecatedSince{2014_03} Please use CreateOpacityTransferFunction() instead */ DEPRECATED(void CreateOpacityTransferFunction(vtkPiecewiseFunction *&opacityFunction)); /** * \deprecatedSince{2014_03} Please use CreateGradientTransferFunction() instead */ DEPRECATED(void CreateGradientTransferFunction(vtkPiecewiseFunction *&gradientFunction)); vtkSmartPointer CreateColorTransferFunction(); vtkSmartPointer CreateOpacityTransferFunction(); vtkSmartPointer CreateGradientTransferFunction(); /** * @brief The LookupTableType enum for different predefined lookup tables. * * \li GRAYSCALE Our default level-window (sometimes referred to as window-level by other sources) setup for a test * image looks like this: * \image html ExampleLevelWindowColor.png * \li INVERSE_GRAYSCALE Inverse LookupTable of GRAYSCALE. * \li HOT_IRON A LookupTable for red colors. * \li JET A LookupTable for JET color rendering. * \li LEGACY_BINARY A LookupTable for binary images. * \li LEGACY_RAINBOW_COLOR A rainbow-like LookupTable. * \li MULTILABEL A LookupTable for multilabel images. * \li PET_COLOR A LookupTable for PET color rendering. * \li PET_20 A LookupTable for PET_20 color rendering. * * The different LookupTableTypes can be applied in the MitkWorkbench via right-clicking * on an image and choosing a color map. */ enum LookupTableType { GRAYSCALE, INVERSE_GRAYSCALE, HOT_IRON, JET, JET_TRANSPARENT, PLASMA, INFERNO, VIRIDIS, MAGMA, LEGACY_BINARY, LEGACY_RAINBOW_COLOR, MULTILABEL, PET_COLOR, PET_20 }; - static const char *const typenameList[]; + static std::vector typenameList; /*! * \brief Set the look-up table type by enum (or integer). * \details Returns if the given type doesn't exist. Only changes the type if it is different * from the current one. */ virtual void SetType(const LookupTableType type); /*! * \brief Set the look-up table type by string. * \details Returns if the given type doesn't exist. Only changes the type if it is different * from the current one. */ virtual void SetType(const std::string &typeName); /*! * \brief Return the current look-up table type as a string. */ virtual const std::string GetActiveTypeAsString(); protected: void PrintSelf(std::ostream &os, itk::Indent indent) const override; LookupTable(const LookupTable &other); virtual void BuildGrayScaleLookupTable(); virtual void BuildLegacyBinaryLookupTable(); virtual void BuildLegacyRainbowColorLookupTable(); virtual void BuildInverseGrayScaleLookupTable(); virtual void BuildHotIronLookupTable(); virtual void BuildPlasmaLookupTable(); virtual void BuildInfernoLookupTable(); virtual void BuildViridisLookupTable(); virtual void BuildMagmaLookupTable(); virtual void BuildJetLookupTable(bool transparent = false); virtual void BuildPETColorLookupTable(); virtual void BuildPET20LookupTable(); virtual void BuildMultiLabelLookupTable(); vtkSmartPointer m_LookupTable; float m_Window; float m_Level; float m_Opacity; - LookupTableType m_type; + LookupTableType m_Type; private: itk::LightObject::Pointer InternalClone() const override; }; } // namespace mitk #endif /* mitkLookupTable_h */ diff --git a/Modules/Core/src/DataManagement/mitkLookupTable.cpp b/Modules/Core/src/DataManagement/mitkLookupTable.cpp index 06b80b1ed7..9374110007 100644 --- a/Modules/Core/src/DataManagement/mitkLookupTable.cpp +++ b/Modules/Core/src/DataManagement/mitkLookupTable.cpp @@ -1,666 +1,666 @@ /*=================================================================== 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 "mitkLookupTable.h" #include #include #include #include #include #include #include #include #include #include #include #include -const char *const mitk::LookupTable::typenameList[] = { +std::vector mitk::LookupTable::typenameList = { "Grayscale", "Inverse Grayscale", "Hot Iron", "Jet", "Jet Transparent", "Plasma", "Inferno", "Viridis", "Magma", "Legacy Binary", "Legacy Rainbow Color", "Multilabel", "PET Color", - "PET 20", - "END_OF_ARRAY" // Do not add typenames after this entry (see QmitkDataManagerView::ColormapMenuAboutToShow()) + "PET 20" }; -mitk::LookupTable::LookupTable() : m_Window(0.0), m_Level(0.0), m_Opacity(1.0), m_type(mitk::LookupTable::GRAYSCALE) +mitk::LookupTable::LookupTable() : m_Window(0.0), m_Level(0.0), m_Opacity(1.0), m_Type(mitk::LookupTable::GRAYSCALE) { m_LookupTable = vtkSmartPointer::New(); this->BuildGrayScaleLookupTable(); } mitk::LookupTable::LookupTable(const LookupTable &other) : itk::DataObject(), m_LookupTable(vtkSmartPointer::New()) { m_LookupTable->DeepCopy(other.m_LookupTable); } mitk::LookupTable::~LookupTable() { } void mitk::LookupTable::SetVtkLookupTable(vtkSmartPointer lut) { if ((!lut) || (m_LookupTable == lut)) { return; } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::SetType(const mitk::LookupTable::LookupTableType type) { - if (m_type == type) + if (m_Type == type) return; switch (type) { case (mitk::LookupTable::GRAYSCALE): this->BuildGrayScaleLookupTable(); break; case (mitk::LookupTable::INVERSE_GRAYSCALE): this->BuildInverseGrayScaleLookupTable(); break; case (mitk::LookupTable::HOT_IRON): this->BuildHotIronLookupTable(); break; case (mitk::LookupTable::JET): this->BuildJetLookupTable(); break; case (mitk::LookupTable::JET_TRANSPARENT): this->BuildJetLookupTable(true); break; case (mitk::LookupTable::PLASMA): this->BuildPlasmaLookupTable(); break; case (mitk::LookupTable::INFERNO): this->BuildInfernoLookupTable(); break; case (mitk::LookupTable::VIRIDIS): this->BuildViridisLookupTable(); break; case (mitk::LookupTable::MAGMA): this->BuildMagmaLookupTable(); break; case (mitk::LookupTable::LEGACY_BINARY): this->BuildLegacyBinaryLookupTable(); break; case (mitk::LookupTable::MULTILABEL): this->BuildMultiLabelLookupTable(); break; case (mitk::LookupTable::PET_COLOR): this->BuildPETColorLookupTable(); break; case (mitk::LookupTable::PET_20): this->BuildPET20LookupTable(); break; case (mitk::LookupTable::LEGACY_RAINBOW_COLOR): this->BuildLegacyRainbowColorLookupTable(); break; default: MITK_ERROR << "non-existing colormap"; return; } - m_type = type; + m_Type = type; } void mitk::LookupTable::SetType(const std::string &typeName) { - int i = 0; - std::string lutType = this->typenameList[i]; - - while (lutType != "END_OF_ARRAY") + for (int i = 0; i < typenameList.size(); ++i) { - if (lutType == typeName) + if (typenameList.at(i) == typeName) { this->SetType(static_cast(i)); } - lutType = this->typenameList[++i]; } } const std::string mitk::LookupTable::GetActiveTypeAsString() { - return std::string(typenameList[(int)m_type]); + if (static_cast(m_Type) < typenameList.size()) + { + return typenameList.at(m_Type); + } + + return ""; } void mitk::LookupTable::ChangeOpacityForAll(float opacity) { int noValues = m_LookupTable->GetNumberOfTableValues(); double rgba[4]; for (int i = 0; i < noValues; i++) { m_LookupTable->GetTableValue(i, rgba); rgba[3] = opacity; m_LookupTable->SetTableValue(i, rgba); } this->Modified(); // need to call modified, since LookupTableProperty seems to be unchanged so no widget-update is // executed } void mitk::LookupTable::ChangeOpacity(int index, float opacity) { int noValues = m_LookupTable->GetNumberOfTableValues(); if (index > noValues) { MITK_INFO << "could not change opacity. index exceed size of lut ... " << std::endl; return; } double rgba[4]; m_LookupTable->GetTableValue(index, rgba); rgba[3] = opacity; m_LookupTable->SetTableValue(index, rgba); this->Modified(); // need to call modified, since LookupTableProperty seems to be unchanged so no widget-update is // executed } void mitk::LookupTable::GetColor(double value, double rgb[3]) { this->GetVtkLookupTable()->GetColor(value, rgb); } void mitk::LookupTable::GetTableValue(int index, double rgba[4]) { this->GetVtkLookupTable()->GetTableValue(index, rgba); } void mitk::LookupTable::SetTableValue(int index, double rgba[4]) { this->GetVtkLookupTable()->SetTableValue(index, rgba); } vtkSmartPointer mitk::LookupTable::GetVtkLookupTable() const { return m_LookupTable; } mitk::LookupTable::RawLookupTableType *mitk::LookupTable::GetRawLookupTable() const { return m_LookupTable->GetPointer(0); } /*! * \brief equality operator inplementation */ bool mitk::LookupTable::operator==(const mitk::LookupTable &other) const { if (m_LookupTable == other.GetVtkLookupTable()) return true; vtkLookupTable *olut = other.GetVtkLookupTable(); if (olut == nullptr) return false; bool equal = (m_LookupTable->GetNumberOfColors() == olut->GetNumberOfColors()) && (m_LookupTable->GetTableRange()[0] == olut->GetTableRange()[0]) && (m_LookupTable->GetTableRange()[1] == olut->GetTableRange()[1]) && (m_LookupTable->GetHueRange()[0] == olut->GetHueRange()[0]) && (m_LookupTable->GetHueRange()[1] == olut->GetHueRange()[1]) && (m_LookupTable->GetSaturationRange()[0] == olut->GetSaturationRange()[0]) && (m_LookupTable->GetSaturationRange()[1] == olut->GetSaturationRange()[1]) && (m_LookupTable->GetValueRange()[0] == olut->GetValueRange()[0]) && (m_LookupTable->GetValueRange()[1] == olut->GetValueRange()[1]) && (m_LookupTable->GetAlphaRange()[0] == olut->GetAlphaRange()[0]) && (m_LookupTable->GetAlphaRange()[1] == olut->GetAlphaRange()[1]) && (m_LookupTable->GetRamp() == olut->GetRamp()) && (m_LookupTable->GetScale() == olut->GetScale()) && (m_LookupTable->GetAlpha() == olut->GetAlpha()) && (m_LookupTable->GetTable()->GetNumberOfTuples() == olut->GetTable()->GetNumberOfTuples()); if (equal == false) return false; for (vtkIdType i = 0; i < m_LookupTable->GetNumberOfTableValues(); i++) { bool tvequal = (m_LookupTable->GetTableValue(i)[0] == olut->GetTableValue(i)[0]) && (m_LookupTable->GetTableValue(i)[1] == olut->GetTableValue(i)[1]) && (m_LookupTable->GetTableValue(i)[2] == olut->GetTableValue(i)[2]) && (m_LookupTable->GetTableValue(i)[3] == olut->GetTableValue(i)[3]); if (tvequal == false) return false; } return true; } /*! * \brief un-equality operator implementation */ bool mitk::LookupTable::operator!=(const mitk::LookupTable &other) const { return !(*this == other); } /*! * \brief assignment operator implementation */ mitk::LookupTable &mitk::LookupTable::operator=(const mitk::LookupTable &LookupTable) { if (this == &LookupTable) { return *this; } else { m_LookupTable = LookupTable.GetVtkLookupTable(); return *this; } } void mitk::LookupTable::UpdateOutputInformation() { if (this->GetSource()) { this->GetSource()->UpdateOutputInformation(); } } void mitk::LookupTable::SetRequestedRegionToLargestPossibleRegion() { } bool mitk::LookupTable::RequestedRegionIsOutsideOfTheBufferedRegion() { return false; } bool mitk::LookupTable::VerifyRequestedRegion() { // normally we should check if the requested region lies within the // largest possible region. Since for lookup-tables we assume, that the // requested region is always the largest possible region, we can always // return true! return true; } void mitk::LookupTable::SetRequestedRegion(const itk::DataObject *) { // not implemented, since we always want to have the RequestedRegion // to be set to LargestPossibleRegion } vtkSmartPointer mitk::LookupTable::CreateColorTransferFunction() { vtkSmartPointer colorFunction = vtkSmartPointer::New(); mitk::LookupTable::RawLookupTableType *rawLookupTable = this->GetRawLookupTable(); int num_of_values = m_LookupTable->GetNumberOfTableValues(); auto cols = new double[3 * num_of_values]; double *colsHead = cols; for (int i = 0; i < num_of_values; ++i) { *cols = static_cast(*rawLookupTable) / 255.0; ++cols; ++rawLookupTable; *cols = static_cast(*rawLookupTable) / 255.0; ++cols; ++rawLookupTable; *cols = static_cast(*rawLookupTable) / 255.0; ++cols; ++rawLookupTable; ++rawLookupTable; } colorFunction->BuildFunctionFromTable( m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values, colsHead); return colorFunction; } void mitk::LookupTable::CreateColorTransferFunction(vtkColorTransferFunction *&colorFunction) { colorFunction = this->CreateColorTransferFunction(); } vtkSmartPointer mitk::LookupTable::CreateOpacityTransferFunction() { vtkSmartPointer opacityFunction = vtkSmartPointer::New(); mitk::LookupTable::RawLookupTableType *rgba = this->GetRawLookupTable(); int num_of_values = m_LookupTable->GetNumberOfTableValues(); auto alphas = new double[num_of_values]; double *alphasHead = alphas; rgba += 3; for (int i = 0; i < num_of_values; ++i) { *alphas = static_cast(*rgba) / 255.0; ++alphas; rgba += 4; } opacityFunction->BuildFunctionFromTable( m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values, alphasHead); return opacityFunction; } void mitk::LookupTable::CreateOpacityTransferFunction(vtkPiecewiseFunction *&opacityFunction) { opacityFunction = this->CreateOpacityTransferFunction(); } vtkSmartPointer mitk::LookupTable::CreateGradientTransferFunction() { vtkSmartPointer gradientFunction = vtkSmartPointer::New(); mitk::LookupTable::RawLookupTableType *rgba = this->GetRawLookupTable(); int num_of_values = m_LookupTable->GetNumberOfTableValues(); auto alphas = new double[num_of_values]; double *alphasHead = alphas; rgba += 3; for (int i = 0; i < num_of_values; ++i) { *alphas = static_cast(*rgba) / 255.0; ++alphas; rgba += 4; } gradientFunction->BuildFunctionFromTable( m_LookupTable->GetTableRange()[0], m_LookupTable->GetTableRange()[1], num_of_values, alphasHead); return gradientFunction; } void mitk::LookupTable::CreateGradientTransferFunction(vtkPiecewiseFunction *&gradientFunction) { gradientFunction = this->CreateGradientTransferFunction(); } void mitk::LookupTable::PrintSelf(std::ostream &os, itk::Indent indent) const { os << indent; m_LookupTable->PrintHeader(os, vtkIndent()); } itk::LightObject::Pointer mitk::LookupTable::InternalClone() const { itk::LightObject::Pointer result(new Self(*this)); result->UnRegister(); return result; } void mitk::LookupTable::BuildGrayScaleLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetRampToLinear(); lut->SetSaturationRange(0.0, 0.0); lut->SetHueRange(0.0, 0.0); lut->SetValueRange(0.0, 1.0); lut->Build(); m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildLegacyBinaryLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetRampToLinear(); lut->SetSaturationRange(0.0, 0.0); lut->SetHueRange(0.0, 0.0); lut->SetValueRange(0.0, 1.0); lut->Build(); lut->SetTableValue(0, 0.0, 0.0, 0.0, 0.0); m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildInverseGrayScaleLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetTableRange(0, 1); lut->SetSaturationRange(0, 0); lut->SetHueRange(0, 0); lut->SetValueRange(1, 0); lut->SetAlphaRange(1, 0); lut->Build(); m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildHotIronLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(256); lut->Build(); for (int i = 0; i < 256; i++) { lut->SetTableValue( i, (double)HotIron[i][0] / 255.0, (double)HotIron[i][1] / 255.0, (double)HotIron[i][2] / 255.0, 1.0); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildJetLookupTable(bool transparent) { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(256); lut->Build(); int i = 0; if (transparent) { // Lowest intensity is transparent lut->SetTableValue(0, (double)Jet[0][0] / 255.0, (double)Jet[0][1] / 255.0, (double)Jet[0][2] / 255.0, 0.0); i = 1; } for (; i < 256; i++) { lut->SetTableValue(i, (double)Jet[i][0] / 255.0, (double)Jet[i][1] / 255.0, (double)Jet[i][2] / 255.0, 1.0); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildPETColorLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(256); lut->SetTableRange((m_Level - m_Window / 2.0), (m_Level + m_Window / 2.0)); lut->Build(); for (int i = 0; i < 256; i++) { lut->SetTableValue( i, (double)PETColor[i][0] / 255.0, (double)PETColor[i][1] / 255.0, (double)PETColor[i][2] / 255.0, 1.0); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildPET20LookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(256); lut->SetTableRange((m_Level - m_Window / 2.0), (m_Level + m_Window / 2.0)); lut->Build(); for (int i = 0; i < 256; i++) { lut->SetTableValue(i, (double)PET20[i][0] / 255.0, (double)PET20[i][1] / 255.0, (double)PET20[i][2] / 255.0, 1.0); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildMultiLabelLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(65536); lut->SetTableRange(0, 65536); lut->SetTableValue(0, 0.0, 0.0, 0.0, 0.0); // background lut->SetTableValue(1, 1.0, 1.0, 0.0, 0.4); lut->SetTableValue(2, 0.0, 1.0, 0.0, 0.4); lut->SetTableValue(3, 0.0, 0.0, 1.0, 0.4); lut->SetTableValue(4, 1.0, 1.0, 0.4, 0.4); lut->SetTableValue(5, 0.0, 0.4, 0.7, 0.4); lut->SetTableValue(6, 1.0, 0.0, 1.0, 0.4); lut->SetTableValue(7, 1.0, 0.5, 0.0, 0.4); lut->SetTableValue(8, 0.0, 1.0, 0.5, 0.4); lut->SetTableValue(9, 0.5, 0.0, 1.0, 0.4); lut->SetTableValue(10, 1.0, 1.0, 0.5, 0.4); lut->SetTableValue(11, 0.5, 1.0, 1.0, 0.4); lut->SetTableValue(12, 1.0, 0.5, 0.6, 0.4); lut->SetTableValue(13, 1.0, 0.3, 0.3, 0.4); lut->SetTableValue(14, 0.4, 0.7, 1.0, 0.4); lut->SetTableValue(15, 0.4, 0.5, 1.0, 0.4); lut->SetTableValue(16, 0.8, 0.5, 1.0, 0.4); lut->SetTableValue(17, 1.0, 0.3, 1.0, 0.4); lut->SetTableValue(18, 1.0, 0.5, 0.6, 0.4); lut->SetTableValue(19, 1.0, 0.5, 0.4, 0.4); lut->SetTableValue(20, 0.4, 0.5, 0.4, 0.4); lut->SetTableValue(21, 1.0, 0.5, 0.76, 0.4); lut->SetTableValue(22, 0.76, 0.4, 0.4, 0.4); lut->SetTableValue(23, 1.0, 0.5, 0.4, 0.4); lut->SetTableValue(24, 0.76, 0.3, 0.4, 0.4); lut->SetTableValue(25, 1.0, 0.3, 0.4, 0.4); for (int i = 26; i < 65536; i++) { if (i % 12 == 0) lut->SetTableValue(i, 1.0, 0.0, 0.0, 0.4); else if (i % 12 == 1) lut->SetTableValue(i, 0.0, 1.0, 0.0, 0.4); else if (i % 12 == 2) lut->SetTableValue(i, 0.0, 0.0, 1.0, 0.4); else if (i % 12 == 3) lut->SetTableValue(i, 1.0, 1.0, 0.0, 0.4); else if (i % 12 == 4) lut->SetTableValue(i, 0.0, 1.0, 1.0, 0.4); else if (i % 12 == 5) lut->SetTableValue(i, 1.0, 0.0, 1.0, 0.4); else if (i % 12 == 6) lut->SetTableValue(i, 1.0, 0.5, 0.0, 0.4); else if (i % 12 == 7) lut->SetTableValue(i, 0.0, 1.0, 0.5, 0.4); else if (i % 12 == 8) lut->SetTableValue(i, 0.5, 0.0, 1.0, 0.4); else if (i % 12 == 9) lut->SetTableValue(i, 1.0, 1.0, 0.5, 0.4); else if (i % 12 == 10) lut->SetTableValue(i, 0.5, 1.0, 1.0, 0.4); else if (i % 12 == 11) lut->SetTableValue(i, 1.0, 0.5, 1.0, 0.4); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildLegacyRainbowColorLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetRampToLinear(); lut->SetHueRange(0.6667, 0.0); lut->SetTableRange(0.0, 20.0); lut->Build(); m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildPlasmaLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(256); lut->Build(); for (int i = 0; i < 256; i++) { lut->SetTableValue( i, (double)Plasma[i][0] / 255.0, (double)Plasma[i][1] / 255.0, (double)Plasma[i][2] / 255.0, 1.0); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildInfernoLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(256); lut->Build(); for (int i = 0; i < 256; i++) { lut->SetTableValue( i, (double)Inferno[i][0] / 255.0, (double)Inferno[i][1] / 255.0, (double)Inferno[i][2] / 255.0, 1.0); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildViridisLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(256); lut->Build(); for (int i = 0; i < 256; i++) { lut->SetTableValue( i, (double)Viridis[i][0] / 255.0, (double)Viridis[i][1] / 255.0, (double)Viridis[i][2] / 255.0, 1.0); } m_LookupTable = lut; this->Modified(); } void mitk::LookupTable::BuildMagmaLookupTable() { vtkSmartPointer lut = vtkSmartPointer::New(); lut->SetNumberOfTableValues(256); lut->Build(); for (int i = 0; i < 256; i++) { lut->SetTableValue( i, (double)Magma[i][0] / 255.0, (double)Magma[i][1] / 255.0, (double)Magma[i][2] / 255.0, 1.0); } m_LookupTable = lut; this->Modified(); } diff --git a/Modules/Core/src/Rendering/mitkImageVtkMapper2D.cpp b/Modules/Core/src/Rendering/mitkImageVtkMapper2D.cpp index bf8dae62d6..af882dd13b 100644 --- a/Modules/Core/src/Rendering/mitkImageVtkMapper2D.cpp +++ b/Modules/Core/src/Rendering/mitkImageVtkMapper2D.cpp @@ -1,1124 +1,1124 @@ /*=================================================================== 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 #include #include #include #include #include //#include #include "mitkImageStatisticsHolder.h" #include "mitkPlaneClipping.h" #include // MITK Rendering #include "mitkImageVtkMapper2D.h" #include "vtkMitkLevelWindowFilter.h" #include "vtkMitkThickSlicesFilter.h" #include "vtkNeverTranslucentTexture.h" // VTK #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // ITK #include #include mitk::ImageVtkMapper2D::ImageVtkMapper2D() { } mitk::ImageVtkMapper2D::~ImageVtkMapper2D() { // The 3D RW Mapper (PlaneGeometryDataVtkMapper3D) is listening to this event, // in order to delete the images from the 3D RW. this->InvokeEvent(itk::DeleteEvent()); } // set the two points defining the textured plane according to the dimension and spacing void mitk::ImageVtkMapper2D::GeneratePlane(mitk::BaseRenderer *renderer, double planeBounds[6]) { LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); float depth = this->CalculateLayerDepth(renderer); // Set the origin to (xMin; yMin; depth) of the plane. This is necessary for obtaining the correct // plane size in crosshair rotation and swivel mode. localStorage->m_Plane->SetOrigin(planeBounds[0], planeBounds[2], depth); // These two points define the axes of the plane in combination with the origin. // Point 1 is the x-axis and point 2 the y-axis. // Each plane is transformed according to the view (axial, coronal and saggital) afterwards. localStorage->m_Plane->SetPoint1(planeBounds[1], planeBounds[2], depth); // P1: (xMax, yMin, depth) localStorage->m_Plane->SetPoint2(planeBounds[0], planeBounds[3], depth); // P2: (xMin, yMax, depth) } float mitk::ImageVtkMapper2D::CalculateLayerDepth(mitk::BaseRenderer *renderer) { // get the clipping range to check how deep into z direction we can render images double maxRange = renderer->GetVtkRenderer()->GetActiveCamera()->GetClippingRange()[1]; // Due to a VTK bug, we cannot use the whole clipping range. /100 is empirically determined float depth = -maxRange * 0.01; // divide by 100 int layer = 0; GetDataNode()->GetIntProperty("layer", layer, renderer); // add the layer property for each image to render images with a higher layer on top of the others depth += layer * 10; //*10: keep some room for each image (e.g. for ODFs in between) if (depth > 0.0f) { depth = 0.0f; MITK_WARN << "Layer value exceeds clipping range. Set to minimum instead."; } return depth; } const mitk::Image *mitk::ImageVtkMapper2D::GetInput(void) { return static_cast(GetDataNode()->GetData()); } vtkProp *mitk::ImageVtkMapper2D::GetVtkProp(mitk::BaseRenderer *renderer) { // return the actor corresponding to the renderer return m_LSH.GetLocalStorage(renderer)->m_Actors; } void mitk::ImageVtkMapper2D::GenerateDataForRenderer(mitk::BaseRenderer *renderer) { LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); auto *image = const_cast(this->GetInput()); mitk::DataNode *datanode = this->GetDataNode(); if (nullptr == image || !image->IsInitialized()) { return; } // check if there is a valid worldGeometry const PlaneGeometry *worldGeometry = renderer->GetCurrentWorldPlaneGeometry(); if (nullptr == worldGeometry || !worldGeometry->IsValid() || !worldGeometry->HasReferenceGeometry()) { return; } image->Update(); // early out if there is no intersection of the current rendering geometry // and the geometry of the image that is to be rendered. if (!RenderingGeometryIntersectsImage(worldGeometry, image->GetSlicedGeometry())) { // set image to nullptr, to clear the texture in 3D, because // the latest image is used there if the plane is out of the geometry // see bug-13275 localStorage->m_ReslicedImage = nullptr; localStorage->m_Mapper->SetInputData(localStorage->m_EmptyPolyData); return; } // set main input for ExtractSliceFilter localStorage->m_Reslicer->SetInput(image); localStorage->m_Reslicer->SetWorldGeometry(worldGeometry); localStorage->m_Reslicer->SetTimeStep(this->GetTimestep()); // set the transformation of the image to adapt reslice axis localStorage->m_Reslicer->SetResliceTransformByGeometry( image->GetTimeGeometry()->GetGeometryForTimeStep(this->GetTimestep())); // is the geometry of the slice based on the input image or the worldgeometry? bool inPlaneResampleExtentByGeometry = false; datanode->GetBoolProperty("in plane resample extent by geometry", inPlaneResampleExtentByGeometry, renderer); localStorage->m_Reslicer->SetInPlaneResampleExtentByGeometry(inPlaneResampleExtentByGeometry); // Initialize the interpolation mode for resampling; switch to nearest // neighbor if the input image is too small. if ((image->GetDimension() >= 3) && (image->GetDimension(2) > 1)) { VtkResliceInterpolationProperty *resliceInterpolationProperty; datanode->GetProperty(resliceInterpolationProperty, "reslice interpolation", renderer); int interpolationMode = VTK_RESLICE_NEAREST; if (resliceInterpolationProperty != nullptr) { interpolationMode = resliceInterpolationProperty->GetInterpolation(); } switch (interpolationMode) { case VTK_RESLICE_NEAREST: localStorage->m_Reslicer->SetInterpolationMode(ExtractSliceFilter::RESLICE_NEAREST); break; case VTK_RESLICE_LINEAR: localStorage->m_Reslicer->SetInterpolationMode(ExtractSliceFilter::RESLICE_LINEAR); break; case VTK_RESLICE_CUBIC: localStorage->m_Reslicer->SetInterpolationMode(ExtractSliceFilter::RESLICE_CUBIC); break; } } else { localStorage->m_Reslicer->SetInterpolationMode(ExtractSliceFilter::RESLICE_NEAREST); } // set the vtk output property to true, makes sure that no unneeded mitk image convertion // is done. localStorage->m_Reslicer->SetVtkOutputRequest(true); // Thickslicing int thickSlicesMode = 0; int thickSlicesNum = 1; // Thick slices parameters if (image->GetPixelType().GetNumberOfComponents() == 1) // for now only single component are allowed { DataNode *dn = renderer->GetCurrentWorldPlaneGeometryNode(); if (dn) { ResliceMethodProperty *resliceMethodEnumProperty = nullptr; if (dn->GetProperty(resliceMethodEnumProperty, "reslice.thickslices", renderer) && resliceMethodEnumProperty) thickSlicesMode = resliceMethodEnumProperty->GetValueAsId(); IntProperty *intProperty = nullptr; if (dn->GetProperty(intProperty, "reslice.thickslices.num", renderer) && intProperty) { thickSlicesNum = intProperty->GetValue(); if (thickSlicesNum < 1) thickSlicesNum = 1; } } else { MITK_WARN << "no associated widget plane data tree node found"; } } const auto *planeGeometry = dynamic_cast(worldGeometry); if (thickSlicesMode > 0) { double dataZSpacing = 1.0; Vector3D normInIndex, normal; const auto *abstractGeometry = dynamic_cast(worldGeometry); if (abstractGeometry != nullptr) normal = abstractGeometry->GetPlane()->GetNormal(); else { if (planeGeometry != nullptr) { normal = planeGeometry->GetNormal(); } else return; // no fitting geometry set } normal.Normalize(); image->GetTimeGeometry()->GetGeometryForTimeStep(this->GetTimestep())->WorldToIndex(normal, normInIndex); dataZSpacing = 1.0 / normInIndex.GetNorm(); localStorage->m_Reslicer->SetOutputDimensionality(3); localStorage->m_Reslicer->SetOutputSpacingZDirection(dataZSpacing); localStorage->m_Reslicer->SetOutputExtentZDirection(-thickSlicesNum, 0 + thickSlicesNum); // Do the reslicing. Modified() is called to make sure that the reslicer is // executed even though the input geometry information did not change; this // is necessary when the input /em data, but not the /em geometry changes. localStorage->m_TSFilter->SetThickSliceMode(thickSlicesMode - 1); localStorage->m_TSFilter->SetInputData(localStorage->m_Reslicer->GetVtkOutput()); // vtkFilter=>mitkFilter=>vtkFilter update mechanism will fail without calling manually localStorage->m_Reslicer->Modified(); localStorage->m_Reslicer->Update(); localStorage->m_TSFilter->Modified(); localStorage->m_TSFilter->Update(); localStorage->m_ReslicedImage = localStorage->m_TSFilter->GetOutput(); } else { // this is needed when thick mode was enable bevore. These variable have to be reset to default values localStorage->m_Reslicer->SetOutputDimensionality(2); localStorage->m_Reslicer->SetOutputSpacingZDirection(1.0); localStorage->m_Reslicer->SetOutputExtentZDirection(0, 0); localStorage->m_Reslicer->Modified(); // start the pipeline with updating the largest possible, needed if the geometry of the input has changed localStorage->m_Reslicer->UpdateLargestPossibleRegion(); localStorage->m_ReslicedImage = localStorage->m_Reslicer->GetVtkOutput(); } // Bounds information for reslicing (only reuqired if reference geometry // is present) // this used for generating a vtkPLaneSource with the right size double sliceBounds[6]; for (auto &sliceBound : sliceBounds) { sliceBound = 0.0; } localStorage->m_Reslicer->GetClippedPlaneBounds(sliceBounds); // get the spacing of the slice localStorage->m_mmPerPixel = localStorage->m_Reslicer->GetOutputSpacing(); // calculate minimum bounding rect of IMAGE in texture { double textureClippingBounds[6]; for (auto &textureClippingBound : textureClippingBounds) { textureClippingBound = 0.0; } // Calculate the actual bounds of the transformed plane clipped by the // dataset bounding box; this is required for drawing the texture at the // correct position during 3D mapping. mitk::PlaneClipping::CalculateClippedPlaneBounds(image->GetGeometry(), planeGeometry, textureClippingBounds); textureClippingBounds[0] = static_cast(textureClippingBounds[0] / localStorage->m_mmPerPixel[0] + 0.5); textureClippingBounds[1] = static_cast(textureClippingBounds[1] / localStorage->m_mmPerPixel[0] + 0.5); textureClippingBounds[2] = static_cast(textureClippingBounds[2] / localStorage->m_mmPerPixel[1] + 0.5); textureClippingBounds[3] = static_cast(textureClippingBounds[3] / localStorage->m_mmPerPixel[1] + 0.5); // clipping bounds for cutting the image localStorage->m_LevelWindowFilter->SetClippingBounds(textureClippingBounds); } // get the number of scalar components to distinguish between different image types int numberOfComponents = localStorage->m_ReslicedImage->GetNumberOfScalarComponents(); // get the binary property bool binary = false; bool binaryOutline = false; datanode->GetBoolProperty("binary", binary, renderer); if (binary) // binary image { datanode->GetBoolProperty("outline binary", binaryOutline, renderer); if (binaryOutline) // contour rendering { // get pixel type of vtk image itk::ImageIOBase::IOComponentType componentType = static_cast(image->GetPixelType().GetComponentType()); switch (componentType) { case itk::ImageIOBase::UCHAR: // generate contours/outlines localStorage->m_OutlinePolyData = CreateOutlinePolyData(renderer); break; case itk::ImageIOBase::USHORT: // generate contours/outlines localStorage->m_OutlinePolyData = CreateOutlinePolyData(renderer); break; default: binaryOutline = false; this->ApplyLookuptable(renderer); MITK_WARN << "Type of all binary images should be unsigned char or unsigned short. Outline does not work on other pixel types!"; } if (binaryOutline) // binary outline is still true --> add outline { float binaryOutlineWidth = 1.0; if (datanode->GetFloatProperty("outline width", binaryOutlineWidth, renderer)) { if (localStorage->m_Actors->GetNumberOfPaths() > 1) { float binaryOutlineShadowWidth = 1.5; datanode->GetFloatProperty("outline shadow width", binaryOutlineShadowWidth, renderer); dynamic_cast(localStorage->m_Actors->GetParts()->GetItemAsObject(0)) ->GetProperty() ->SetLineWidth(binaryOutlineWidth * binaryOutlineShadowWidth); } localStorage->m_Actor->GetProperty()->SetLineWidth(binaryOutlineWidth); } } } else // standard binary image { if (numberOfComponents != 1) { MITK_ERROR << "Rendering Error: Binary Images with more then 1 component are not supported!"; } } } this->ApplyOpacity(renderer); this->ApplyRenderingMode(renderer); // do not use a VTK lookup table (we do that ourselves in m_LevelWindowFilter) localStorage->m_Texture->SetColorModeToDirectScalars(); int displayedComponent = 0; if (datanode->GetIntProperty("Image.Displayed Component", displayedComponent, renderer) && numberOfComponents > 1) { localStorage->m_VectorComponentExtractor->SetComponents(displayedComponent); localStorage->m_VectorComponentExtractor->SetInputData(localStorage->m_ReslicedImage); localStorage->m_LevelWindowFilter->SetInputConnection(localStorage->m_VectorComponentExtractor->GetOutputPort(0)); } else { // connect the input with the levelwindow filter localStorage->m_LevelWindowFilter->SetInputData(localStorage->m_ReslicedImage); } // check for texture interpolation property bool textureInterpolation = false; GetDataNode()->GetBoolProperty("texture interpolation", textureInterpolation, renderer); // set the interpolation modus according to the property localStorage->m_Texture->SetInterpolate(textureInterpolation); // connect the texture with the output of the levelwindow filter localStorage->m_Texture->SetInputConnection(localStorage->m_LevelWindowFilter->GetOutputPort()); this->TransformActor(renderer); auto *contourShadowActor = dynamic_cast(localStorage->m_Actors->GetParts()->GetItemAsObject(0)); if (binary && binaryOutline) // connect the mapper with the polyData which contains the lines { // We need the contour for the binary outline property as actor localStorage->m_Mapper->SetInputData(localStorage->m_OutlinePolyData); localStorage->m_Actor->SetTexture(nullptr); // no texture for contours bool binaryOutlineShadow = false; datanode->GetBoolProperty("outline binary shadow", binaryOutlineShadow, renderer); if (binaryOutlineShadow) { contourShadowActor->SetVisibility(true); } else { contourShadowActor->SetVisibility(false); } } else { // Connect the mapper with the input texture. This is the standard case. // setup the textured plane this->GeneratePlane(renderer, sliceBounds); // set the plane as input for the mapper localStorage->m_Mapper->SetInputConnection(localStorage->m_Plane->GetOutputPort()); // set the texture for the actor localStorage->m_Actor->SetTexture(localStorage->m_Texture); contourShadowActor->SetVisibility(false); } // We have been modified => save this for next Update() localStorage->m_LastUpdateTime.Modified(); } void mitk::ImageVtkMapper2D::ApplyLevelWindow(mitk::BaseRenderer *renderer) { LocalStorage *localStorage = this->GetLocalStorage(renderer); LevelWindow levelWindow; this->GetDataNode()->GetLevelWindow(levelWindow, renderer, "levelwindow"); localStorage->m_LevelWindowFilter->GetLookupTable()->SetRange(levelWindow.GetLowerWindowBound(), levelWindow.GetUpperWindowBound()); mitk::LevelWindow opacLevelWindow; if (this->GetDataNode()->GetLevelWindow(opacLevelWindow, renderer, "opaclevelwindow")) { // pass the opaque level window to the filter localStorage->m_LevelWindowFilter->SetMinOpacity(opacLevelWindow.GetLowerWindowBound()); localStorage->m_LevelWindowFilter->SetMaxOpacity(opacLevelWindow.GetUpperWindowBound()); } else { // no opaque level window localStorage->m_LevelWindowFilter->SetMinOpacity(0.0); localStorage->m_LevelWindowFilter->SetMaxOpacity(255.0); } } void mitk::ImageVtkMapper2D::ApplyColor(mitk::BaseRenderer *renderer) { LocalStorage *localStorage = this->GetLocalStorage(renderer); float rgb[3] = {1.0f, 1.0f, 1.0f}; // check for color prop and use it for rendering if it exists // binary image hovering & binary image selection bool hover = false; bool selected = false; bool binary = false; GetDataNode()->GetBoolProperty("binaryimage.ishovering", hover, renderer); GetDataNode()->GetBoolProperty("selected", selected, renderer); GetDataNode()->GetBoolProperty("binary", binary, renderer); if (binary && hover && !selected) { mitk::ColorProperty::Pointer colorprop = dynamic_cast(GetDataNode()->GetProperty("binaryimage.hoveringcolor", renderer)); if (colorprop.IsNotNull()) { memcpy(rgb, colorprop->GetColor().GetDataPointer(), 3 * sizeof(float)); } else { GetDataNode()->GetColor(rgb, renderer, "color"); } } if (binary && selected) { mitk::ColorProperty::Pointer colorprop = dynamic_cast(GetDataNode()->GetProperty("binaryimage.selectedcolor", renderer)); if (colorprop.IsNotNull()) { memcpy(rgb, colorprop->GetColor().GetDataPointer(), 3 * sizeof(float)); } else { GetDataNode()->GetColor(rgb, renderer, "color"); } } if (!binary || (!hover && !selected)) { GetDataNode()->GetColor(rgb, renderer, "color"); } double rgbConv[3] = {(double)rgb[0], (double)rgb[1], (double)rgb[2]}; // conversion to double for VTK dynamic_cast(localStorage->m_Actors->GetParts()->GetItemAsObject(0))->GetProperty()->SetColor(rgbConv); localStorage->m_Actor->GetProperty()->SetColor(rgbConv); if (localStorage->m_Actors->GetParts()->GetNumberOfItems() > 1) { float rgb[3] = {1.0f, 1.0f, 1.0f}; mitk::ColorProperty::Pointer colorprop = dynamic_cast(GetDataNode()->GetProperty("outline binary shadow color", renderer)); if (colorprop.IsNotNull()) { memcpy(rgb, colorprop->GetColor().GetDataPointer(), 3 * sizeof(float)); } double rgbConv[3] = {(double)rgb[0], (double)rgb[1], (double)rgb[2]}; // conversion to double for VTK dynamic_cast(localStorage->m_Actors->GetParts()->GetItemAsObject(0))->GetProperty()->SetColor(rgbConv); } } void mitk::ImageVtkMapper2D::ApplyOpacity(mitk::BaseRenderer *renderer) { LocalStorage *localStorage = this->GetLocalStorage(renderer); float opacity = 1.0f; // check for opacity prop and use it for rendering if it exists GetDataNode()->GetOpacity(opacity, renderer, "opacity"); // set the opacity according to the properties localStorage->m_Actor->GetProperty()->SetOpacity(opacity); if (localStorage->m_Actors->GetParts()->GetNumberOfItems() > 1) { dynamic_cast(localStorage->m_Actors->GetParts()->GetItemAsObject(0)) ->GetProperty() ->SetOpacity(opacity); } } void mitk::ImageVtkMapper2D::ApplyRenderingMode(mitk::BaseRenderer *renderer) { LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); bool binary = false; this->GetDataNode()->GetBoolProperty("binary", binary, renderer); if (binary) // is it a binary image? { // for binary images, we always use our default LuT and map every value to (0,1) // the opacity of 0 will always be 0.0. We never a apply a LuT/TfF nor a level window. localStorage->m_LevelWindowFilter->SetLookupTable(localStorage->m_BinaryLookupTable); } else { // all other image types can make use of the rendering mode int renderingMode = mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR; mitk::RenderingModeProperty::Pointer mode = dynamic_cast(this->GetDataNode()->GetProperty("Image Rendering.Mode", renderer)); if (mode.IsNotNull()) { renderingMode = mode->GetRenderingMode(); } switch (renderingMode) { case mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR: MITK_DEBUG << "'Image Rendering.Mode' = LevelWindow_LookupTable_Color"; this->ApplyLookuptable(renderer); this->ApplyLevelWindow(renderer); break; case mitk::RenderingModeProperty::COLORTRANSFERFUNCTION_LEVELWINDOW_COLOR: MITK_DEBUG << "'Image Rendering.Mode' = LevelWindow_ColorTransferFunction_Color"; this->ApplyColorTransferFunction(renderer); this->ApplyLevelWindow(renderer); break; case mitk::RenderingModeProperty::LOOKUPTABLE_COLOR: MITK_DEBUG << "'Image Rendering.Mode' = LookupTable_Color"; this->ApplyLookuptable(renderer); break; case mitk::RenderingModeProperty::COLORTRANSFERFUNCTION_COLOR: MITK_DEBUG << "'Image Rendering.Mode' = ColorTransferFunction_Color"; this->ApplyColorTransferFunction(renderer); break; default: MITK_ERROR << "No valid 'Image Rendering.Mode' set. Using LOOKUPTABLE_LEVELWINDOW_COLOR instead."; this->ApplyLookuptable(renderer); this->ApplyLevelWindow(renderer); break; } } // we apply color for all images (including binaries). this->ApplyColor(renderer); } void mitk::ImageVtkMapper2D::ApplyLookuptable(mitk::BaseRenderer *renderer) { LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); vtkLookupTable *usedLookupTable = localStorage->m_ColorLookupTable; // If lookup table or transferfunction use is requested... mitk::LookupTableProperty::Pointer lookupTableProp = - dynamic_cast(this->GetDataNode()->GetProperty("LookupTable")); + dynamic_cast(this->GetDataNode()->GetProperty("LookupTable", renderer)); if (lookupTableProp.IsNotNull()) // is a lookuptable set? { usedLookupTable = lookupTableProp->GetLookupTable()->GetVtkLookupTable(); } else { //"Image Rendering.Mode was set to use a lookup table but there is no property 'LookupTable'. // A default (rainbow) lookup table will be used. // Here have to do nothing. Warning for the user has been removed, due to unwanted console output // in every interation of the rendering. } localStorage->m_LevelWindowFilter->SetLookupTable(usedLookupTable); } void mitk::ImageVtkMapper2D::ApplyColorTransferFunction(mitk::BaseRenderer *renderer) { mitk::TransferFunctionProperty::Pointer transferFunctionProp = dynamic_cast( this->GetDataNode()->GetProperty("Image Rendering.Transfer Function", renderer)); if (transferFunctionProp.IsNull()) { MITK_ERROR << "'Image Rendering.Mode'' was set to use a color transfer function but there is no property 'Image " "Rendering.Transfer Function'. Nothing will be done."; return; } LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); // pass the transfer function to our level window filter localStorage->m_LevelWindowFilter->SetLookupTable(transferFunctionProp->GetValue()->GetColorTransferFunction()); localStorage->m_LevelWindowFilter->SetOpacityPiecewiseFunction( transferFunctionProp->GetValue()->GetScalarOpacityFunction()); } void mitk::ImageVtkMapper2D::Update(mitk::BaseRenderer *renderer) { bool visible = true; GetDataNode()->GetVisibility(visible, renderer, "visible"); if (!visible) { return; } auto *data = const_cast(this->GetInput()); if (data == nullptr) { return; } // Calculate time step of the input data for the specified renderer (integer value) this->CalculateTimeStep(renderer); // Check if time step is valid const TimeGeometry *dataTimeGeometry = data->GetTimeGeometry(); if ((dataTimeGeometry == nullptr) || (dataTimeGeometry->CountTimeSteps() == 0) || (!dataTimeGeometry->IsValidTimeStep(this->GetTimestep()))) { return; } const DataNode *node = this->GetDataNode(); data->UpdateOutputInformation(); LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); // check if something important has changed and we need to rerender if ((localStorage->m_LastUpdateTime < node->GetMTime()) || (localStorage->m_LastUpdateTime < data->GetPipelineMTime()) || (localStorage->m_LastUpdateTime < renderer->GetCurrentWorldPlaneGeometryUpdateTime()) || (localStorage->m_LastUpdateTime < renderer->GetCurrentWorldPlaneGeometry()->GetMTime()) || (localStorage->m_LastUpdateTime < node->GetPropertyList()->GetMTime()) || (localStorage->m_LastUpdateTime < node->GetPropertyList(renderer)->GetMTime()) || (localStorage->m_LastUpdateTime < data->GetPropertyList()->GetMTime())) { this->GenerateDataForRenderer(renderer); } // since we have checked that nothing important has changed, we can set // m_LastUpdateTime to the current time localStorage->m_LastUpdateTime.Modified(); } void mitk::ImageVtkMapper2D::SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer, bool overwrite) { mitk::Image::Pointer image = dynamic_cast(node->GetData()); // Properties common for both images and segmentations node->AddProperty("depthOffset", mitk::FloatProperty::New(0.0), renderer, overwrite); node->AddProperty("outline binary", mitk::BoolProperty::New(false), renderer, overwrite); node->AddProperty("outline width", mitk::FloatProperty::New(1.0), renderer, overwrite); node->AddProperty("outline binary shadow", mitk::BoolProperty::New(false), renderer, overwrite); node->AddProperty("outline binary shadow color", ColorProperty::New(0.0, 0.0, 0.0), renderer, overwrite); node->AddProperty("outline shadow width", mitk::FloatProperty::New(1.5), renderer, overwrite); if (image->IsRotated()) node->AddProperty("reslice interpolation", mitk::VtkResliceInterpolationProperty::New(VTK_RESLICE_CUBIC)); else node->AddProperty("reslice interpolation", mitk::VtkResliceInterpolationProperty::New()); node->AddProperty("texture interpolation", mitk::BoolProperty::New(false)); node->AddProperty("in plane resample extent by geometry", mitk::BoolProperty::New(false)); node->AddProperty("bounding box", mitk::BoolProperty::New(false)); mitk::RenderingModeProperty::Pointer renderingModeProperty = mitk::RenderingModeProperty::New(); node->AddProperty("Image Rendering.Mode", renderingModeProperty); // Set default grayscale look-up table mitk::LookupTable::Pointer mitkLut = mitk::LookupTable::New(); mitkLut->SetType(mitk::LookupTable::GRAYSCALE); mitk::LookupTableProperty::Pointer mitkLutProp = mitk::LookupTableProperty::New(); mitkLutProp->SetLookupTable(mitkLut); - node->SetProperty("LookupTable", mitkLutProp); + node->SetProperty("LookupTable", mitkLutProp, renderer); std::string photometricInterpretation; // DICOM tag telling us how pixel values should be displayed if (node->GetStringProperty("dicom.pixel.PhotometricInterpretation", photometricInterpretation)) { // modality provided by DICOM or other reader if (photometricInterpretation.find("MONOCHROME1") != std::string::npos) // meaning: display MINIMUM pixels as WHITE { // Set inverse grayscale look-up table mitkLut->SetType(mitk::LookupTable::INVERSE_GRAYSCALE); mitkLutProp->SetLookupTable(mitkLut); - node->SetProperty("LookupTable", mitkLutProp); + node->SetProperty("LookupTable", mitkLutProp, renderer); renderingModeProperty->SetValue(mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR); // USE lookuptable } // Otherwise do nothing - the default grayscale look-up table has already been set } bool isBinaryImage(false); if (!node->GetBoolProperty("binary", isBinaryImage) && image->GetPixelType().GetNumberOfComponents() == 1) { // ok, property is not set, use heuristic to determine if this // is a binary image mitk::Image::Pointer centralSliceImage; ScalarType minValue = 0.0; ScalarType maxValue = 0.0; ScalarType min2ndValue = 0.0; ScalarType max2ndValue = 0.0; mitk::ImageSliceSelector::Pointer sliceSelector = mitk::ImageSliceSelector::New(); sliceSelector->SetInput(image); sliceSelector->SetSliceNr(image->GetDimension(2) / 2); sliceSelector->SetTimeNr(image->GetDimension(3) / 2); sliceSelector->SetChannelNr(image->GetDimension(4) / 2); sliceSelector->Update(); centralSliceImage = sliceSelector->GetOutput(); if (centralSliceImage.IsNotNull() && centralSliceImage->IsInitialized()) { minValue = centralSliceImage->GetStatistics()->GetScalarValueMin(); maxValue = centralSliceImage->GetStatistics()->GetScalarValueMax(); min2ndValue = centralSliceImage->GetStatistics()->GetScalarValue2ndMin(); max2ndValue = centralSliceImage->GetStatistics()->GetScalarValue2ndMax(); } if ((maxValue == min2ndValue && minValue == max2ndValue) || minValue == maxValue) { // centralSlice is strange, lets look at all data minValue = image->GetStatistics()->GetScalarValueMin(); maxValue = image->GetStatistics()->GetScalarValueMaxNoRecompute(); min2ndValue = image->GetStatistics()->GetScalarValue2ndMinNoRecompute(); max2ndValue = image->GetStatistics()->GetScalarValue2ndMaxNoRecompute(); } isBinaryImage = (maxValue == min2ndValue && minValue == max2ndValue); } std::string className = image->GetNameOfClass(); if (className != "TensorImage" && className != "OdfImage" && className != "ShImage") { PixelType pixelType = image->GetPixelType(); size_t numComponents = pixelType.GetNumberOfComponents(); if ((pixelType.GetPixelType() == itk::ImageIOBase::VECTOR && numComponents > 1) || numComponents == 2 || numComponents > 4) { node->AddProperty("Image.Displayed Component", mitk::IntProperty::New(0), renderer, overwrite); } } // some more properties specific for a binary... if (isBinaryImage) { node->AddProperty("opacity", mitk::FloatProperty::New(0.3f), renderer, overwrite); node->AddProperty("color", ColorProperty::New(1.0, 0.0, 0.0), renderer, overwrite); node->AddProperty("binaryimage.selectedcolor", ColorProperty::New(1.0, 0.0, 0.0), renderer, overwrite); node->AddProperty("binaryimage.selectedannotationcolor", ColorProperty::New(1.0, 0.0, 0.0), renderer, overwrite); node->AddProperty("binaryimage.hoveringcolor", ColorProperty::New(1.0, 0.0, 0.0), renderer, overwrite); node->AddProperty("binaryimage.hoveringannotationcolor", ColorProperty::New(1.0, 0.0, 0.0), renderer, overwrite); node->AddProperty("binary", mitk::BoolProperty::New(true), renderer, overwrite); node->AddProperty("layer", mitk::IntProperty::New(10), renderer, overwrite); } else //...or image type object { node->AddProperty("opacity", mitk::FloatProperty::New(1.0f), renderer, overwrite); node->AddProperty("color", ColorProperty::New(1.0, 1.0, 1.0), renderer, overwrite); node->AddProperty("binary", mitk::BoolProperty::New(false), renderer, overwrite); node->AddProperty("layer", mitk::IntProperty::New(0), renderer, overwrite); } if (image.IsNotNull() && image->IsInitialized()) { if ((overwrite) || (node->GetProperty("levelwindow", renderer) == nullptr)) { /* initialize level/window from DICOM tags */ std::string sLevel = ""; std::string sWindow = ""; if (GetBackwardsCompatibleDICOMProperty( 0x0028, 0x1050, "dicom.voilut.WindowCenter", image->GetPropertyList(), sLevel) && GetBackwardsCompatibleDICOMProperty( 0x0028, 0x1051, "dicom.voilut.WindowWidth", image->GetPropertyList(), sWindow)) { float level = atof(sLevel.c_str()); float window = atof(sWindow.c_str()); mitk::LevelWindow contrast; std::string sSmallestPixelValueInSeries; std::string sLargestPixelValueInSeries; if (GetBackwardsCompatibleDICOMProperty(0x0028, 0x0108, "dicom.series.SmallestPixelValueInSeries", image->GetPropertyList(), sSmallestPixelValueInSeries) && GetBackwardsCompatibleDICOMProperty(0x0028, 0x0109, "dicom.series.LargestPixelValueInSeries", image->GetPropertyList(), sLargestPixelValueInSeries)) { float smallestPixelValueInSeries = atof(sSmallestPixelValueInSeries.c_str()); float largestPixelValueInSeries = atof(sLargestPixelValueInSeries.c_str()); contrast.SetRangeMinMax(smallestPixelValueInSeries - 1, largestPixelValueInSeries + 1); // why not a little buffer? // might remedy some l/w widget challenges } else { contrast.SetAuto(static_cast(node->GetData()), false, true); // we need this as a fallback } contrast.SetLevelWindow(level, window, true); node->SetProperty("levelwindow", LevelWindowProperty::New(contrast), renderer); } } if (((overwrite) || (node->GetProperty("opaclevelwindow", renderer) == nullptr)) && (image->GetPixelType().GetPixelType() == itk::ImageIOBase::RGBA) && (image->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR)) { mitk::LevelWindow opaclevwin; opaclevwin.SetRangeMinMax(0, 255); opaclevwin.SetWindowBounds(0, 255); mitk::LevelWindowProperty::Pointer prop = mitk::LevelWindowProperty::New(opaclevwin); node->SetProperty("opaclevelwindow", prop, renderer); } } Superclass::SetDefaultProperties(node, renderer, overwrite); } mitk::ImageVtkMapper2D::LocalStorage *mitk::ImageVtkMapper2D::GetLocalStorage(mitk::BaseRenderer *renderer) { return m_LSH.GetLocalStorage(renderer); } template vtkSmartPointer mitk::ImageVtkMapper2D::CreateOutlinePolyData(mitk::BaseRenderer *renderer) { LocalStorage *localStorage = this->GetLocalStorage(renderer); // get the min and max index values of each direction int *extent = localStorage->m_ReslicedImage->GetExtent(); int xMin = extent[0]; int xMax = extent[1]; int yMin = extent[2]; int yMax = extent[3]; int *dims = localStorage->m_ReslicedImage->GetDimensions(); // dimensions of the image int line = dims[0]; // how many pixels per line? int x = xMin; // pixel index x int y = yMin; // pixel index y // get the depth for each contour float depth = CalculateLayerDepth(renderer); vtkSmartPointer points = vtkSmartPointer::New(); // the points to draw vtkSmartPointer lines = vtkSmartPointer::New(); // the lines to connect the points // We take the pointer to the first pixel of the image auto* currentPixel = static_cast(localStorage->m_ReslicedImage->GetScalarPointer()); while (y <= yMax) { // if the current pixel value is set to something if ((currentPixel) && (*currentPixel != 0)) { // check in which direction a line is necessary // a line is added if the neighbor of the current pixel has the value 0 // and if the pixel is located at the edge of the image // if vvvvv not the first line vvvvv if (y > yMin && *(currentPixel - line) == 0) { // x direction - bottom edge of the pixel // add the 2 points vtkIdType p1 = points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); vtkIdType p2 = points->InsertNextPoint((x + 1) * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); // add the line between both points lines->InsertNextCell(2); lines->InsertCellPoint(p1); lines->InsertCellPoint(p2); } // if vvvvv not the last line vvvvv if (y < yMax && *(currentPixel + line) == 0) { // x direction - top edge of the pixel vtkIdType p1 = points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); vtkIdType p2 = points->InsertNextPoint( (x + 1) * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); lines->InsertNextCell(2); lines->InsertCellPoint(p1); lines->InsertCellPoint(p2); } // if vvvvv not the first pixel vvvvv if ((x > xMin || y > yMin) && *(currentPixel - 1) == 0) { // y direction - left edge of the pixel vtkIdType p1 = points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); vtkIdType p2 = points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); lines->InsertNextCell(2); lines->InsertCellPoint(p1); lines->InsertCellPoint(p2); } // if vvvvv not the last pixel vvvvv if ((y < yMax || (x < xMax)) && *(currentPixel + 1) == 0) { // y direction - right edge of the pixel vtkIdType p1 = points->InsertNextPoint((x + 1) * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); vtkIdType p2 = points->InsertNextPoint( (x + 1) * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); lines->InsertNextCell(2); lines->InsertCellPoint(p1); lines->InsertCellPoint(p2); } /* now consider pixels at the edge of the image */ // if vvvvv left edge of image vvvvv if (x == xMin) { // draw left edge of the pixel vtkIdType p1 = points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); vtkIdType p2 = points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); lines->InsertNextCell(2); lines->InsertCellPoint(p1); lines->InsertCellPoint(p2); } // if vvvvv right edge of image vvvvv if (x == xMax) { // draw right edge of the pixel vtkIdType p1 = points->InsertNextPoint((x + 1) * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); vtkIdType p2 = points->InsertNextPoint( (x + 1) * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); lines->InsertNextCell(2); lines->InsertCellPoint(p1); lines->InsertCellPoint(p2); } // if vvvvv bottom edge of image vvvvv if (y == yMin) { // draw bottom edge of the pixel vtkIdType p1 = points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); vtkIdType p2 = points->InsertNextPoint((x + 1) * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); lines->InsertNextCell(2); lines->InsertCellPoint(p1); lines->InsertCellPoint(p2); } // if vvvvv top edge of image vvvvv if (y == yMax) { // draw top edge of the pixel vtkIdType p1 = points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); vtkIdType p2 = points->InsertNextPoint( (x + 1) * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); lines->InsertNextCell(2); lines->InsertCellPoint(p1); lines->InsertCellPoint(p2); } } // end if currentpixel is set x++; if (x > xMax) { // reached end of line x = xMin; y++; } // Increase the pointer-position to the next pixel. // This is safe, as the while-loop and the x-reset logic above makes // sure we do not exceed the bounds of the image currentPixel++; } // end of while // Create a polydata to store everything in vtkSmartPointer polyData = vtkSmartPointer::New(); // Add the points to the dataset polyData->SetPoints(points); // Add the lines to the dataset polyData->SetLines(lines); return polyData; } void mitk::ImageVtkMapper2D::TransformActor(mitk::BaseRenderer *renderer) { LocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); // get the transformation matrix of the reslicer in order to render the slice as axial, coronal or saggital vtkSmartPointer trans = vtkSmartPointer::New(); vtkSmartPointer matrix = localStorage->m_Reslicer->GetResliceAxes(); trans->SetMatrix(matrix); // transform the plane/contour (the actual actor) to the corresponding view (axial, coronal or saggital) localStorage->m_Actor->SetUserTransform(trans); // transform the origin to center based coordinates, because MITK is center based. localStorage->m_Actor->SetPosition(-0.5 * localStorage->m_mmPerPixel[0], -0.5 * localStorage->m_mmPerPixel[1], 0.0); if (localStorage->m_Actors->GetNumberOfPaths() > 1) { auto *secondaryActor = dynamic_cast(localStorage->m_Actors->GetParts()->GetItemAsObject(0)); secondaryActor->SetUserTransform(trans); secondaryActor->SetPosition(-0.5 * localStorage->m_mmPerPixel[0], -0.5 * localStorage->m_mmPerPixel[1], 0.0); } } bool mitk::ImageVtkMapper2D::RenderingGeometryIntersectsImage(const PlaneGeometry *renderingGeometry, SlicedGeometry3D *imageGeometry) { // if either one of the two geometries is nullptr we return true // for safety reasons if (renderingGeometry == nullptr || imageGeometry == nullptr) return true; // get the distance for the first cornerpoint ScalarType initialDistance = renderingGeometry->SignedDistance(imageGeometry->GetCornerPoint(0)); for (int i = 1; i < 8; i++) { mitk::Point3D cornerPoint = imageGeometry->GetCornerPoint(i); // get the distance to the other cornerpoints ScalarType distance = renderingGeometry->SignedDistance(cornerPoint); // if it has not the same signing as the distance of the first point if (initialDistance * distance < 0) { // we have an intersection and return true return true; } } // all distances have the same sign, no intersection and we return false return false; } mitk::ImageVtkMapper2D::LocalStorage::~LocalStorage() { } mitk::ImageVtkMapper2D::LocalStorage::LocalStorage() : m_VectorComponentExtractor(vtkSmartPointer::New()) { m_LevelWindowFilter = vtkSmartPointer::New(); // Do as much actions as possible in here to avoid double executions. m_Plane = vtkSmartPointer::New(); m_Texture = vtkSmartPointer::New().GetPointer(); m_DefaultLookupTable = vtkSmartPointer::New(); m_BinaryLookupTable = vtkSmartPointer::New(); m_ColorLookupTable = vtkSmartPointer::New(); m_Mapper = vtkSmartPointer::New(); m_Actor = vtkSmartPointer::New(); m_Actors = vtkSmartPointer::New(); m_Reslicer = mitk::ExtractSliceFilter::New(); m_TSFilter = vtkSmartPointer::New(); m_OutlinePolyData = vtkSmartPointer::New(); m_ReslicedImage = vtkSmartPointer::New(); m_EmptyPolyData = vtkSmartPointer::New(); // the following actions are always the same and thus can be performed // in the constructor for each image (i.e. the image-corresponding local storage) m_TSFilter->ReleaseDataFlagOn(); mitk::LookupTable::Pointer mitkLUT = mitk::LookupTable::New(); // built a default lookuptable mitkLUT->SetType(mitk::LookupTable::GRAYSCALE); m_DefaultLookupTable = mitkLUT->GetVtkLookupTable(); mitkLUT->SetType(mitk::LookupTable::LEGACY_BINARY); m_BinaryLookupTable = mitkLUT->GetVtkLookupTable(); mitkLUT->SetType(mitk::LookupTable::LEGACY_RAINBOW_COLOR); m_ColorLookupTable = mitkLUT->GetVtkLookupTable(); // do not repeat the texture (the image) m_Texture->RepeatOff(); // set the mapper for the actor m_Actor->SetMapper(m_Mapper); vtkSmartPointer outlineShadowActor = vtkSmartPointer::New(); outlineShadowActor->SetMapper(m_Mapper); m_Actors->AddPart(outlineShadowActor); m_Actors->AddPart(m_Actor); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.cpp index 4f99755c61..2ca0acb543 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.cpp @@ -1,87 +1,96 @@ /*=================================================================== 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 #include "mitkIRenderWindowPart.h" // mitk gui common plugin #include // berry #include QmitkAbstractDataNodeAction::QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer workbenchPartSite) { m_WorkbenchPartSite = workbenchPartSite; } QmitkAbstractDataNodeAction::QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite* workbenchPartSite) { m_WorkbenchPartSite = berry::IWorkbenchPartSite::Pointer(workbenchPartSite); } QmitkAbstractDataNodeAction::~QmitkAbstractDataNodeAction() { // nothing here } void QmitkAbstractDataNodeAction::SetDataStorage(mitk::DataStorage* dataStorage) { if (m_DataStorage != dataStorage) { // set the new data storage m_DataStorage = dataStorage; } } +void QmitkAbstractDataNodeAction::SetBaseRenderer(mitk::BaseRenderer* baseRenderer) +{ + if (m_BaseRenderer != baseRenderer) + { + // set the new base renderer + m_BaseRenderer = baseRenderer; + } +} + QList QmitkAbstractDataNodeAction::GetSelectedNodes() { QList selectedNodes; if (m_WorkbenchPartSite.Expired()) { return selectedNodes; } berry::ISelection::ConstPointer selection = m_WorkbenchPartSite.Lock()->GetWorkbenchWindow()->GetSelectionService()->GetSelection(); mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); if (currentSelection.IsNull() || currentSelection->IsEmpty()) { return selectedNodes; } selectedNodes = QList::fromStdList(currentSelection->GetSelectedDataNodes()); return selectedNodes; } mitk::DataNode::Pointer QmitkAbstractDataNodeAction::GetSelectedNode() { QList selectedNodes = GetSelectedNodes(); if (selectedNodes.empty()) { return nullptr; } // no batch action; should only be called with a single node mitk::DataNode::Pointer dataNode = selectedNodes.front(); if (nullptr == dataNode) { return nullptr; } return dataNode; } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.h index e8ded7f3d5..894d61b696 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.h +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkAbstractDataNodeAction.h @@ -1,57 +1,60 @@ /*=================================================================== 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 QMITKABSTRACTDATANODEACTION_H #define QMITKABSTRACTDATANODEACTION_H #include // mitk core +#include #include #include // berry #include // qt #include class MITK_QT_APP QmitkAbstractDataNodeAction { public: QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite* workbenchPartSite); virtual ~QmitkAbstractDataNodeAction(); void SetDataStorage(mitk::DataStorage* dataStorage); + void SetBaseRenderer(mitk::BaseRenderer* baseRenderer); virtual void InitializeWithDataNode(const mitk::DataNode* dataNode) { } protected: virtual void InitializeAction() = 0; mitk::DataNode::Pointer GetSelectedNode(); QList GetSelectedNodes(); berry::IWorkbenchPartSite::WeakPtr m_WorkbenchPartSite; mitk::WeakPointer m_DataStorage; + mitk::WeakPointer m_BaseRenderer; }; #endif // QMITKABSTRACTDATANODEACTION_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.cpp index 582c667c63..fa7241c84d 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorAction.cpp @@ -1,130 +1,162 @@ /*=================================================================== 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 // mitk core #include // qt #include #include #include QmitkDataNodeColorAction::QmitkDataNodeColorAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QWidgetAction(parent) , QmitkAbstractDataNodeAction(workbenchPartSite) { InitializeAction(); } QmitkDataNodeColorAction::QmitkDataNodeColorAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QWidgetAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { InitializeAction(); } QmitkDataNodeColorAction::~QmitkDataNodeColorAction() { // nothing here } void QmitkDataNodeColorAction::InitializeAction() { m_ColorButton = new QPushButton; m_ColorButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); connect(m_ColorButton, &QPushButton::clicked, this, &QmitkDataNodeColorAction::OnColorChanged); QLabel* colorLabel = new QLabel(tr("Color: ")); colorLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); QHBoxLayout* colorWidgetLayout = new QHBoxLayout; colorWidgetLayout->setContentsMargins(4, 4, 4, 4); colorWidgetLayout->addWidget(colorLabel); colorWidgetLayout->addWidget(m_ColorButton); QWidget* colorWidget = new QWidget; colorWidget->setLayout(colorWidgetLayout); setDefaultWidget(colorWidget); connect(this, &QmitkDataNodeColorAction::changed, this, &QmitkDataNodeColorAction::OnActionChanged); } void QmitkDataNodeColorAction::InitializeWithDataNode(const mitk::DataNode* dataNode) { + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + float rgb[3]; - if (dataNode->GetColor(rgb)) + if (dataNode->GetColor(rgb, baseRenderer)) { QColor color(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255); QString styleSheet = QString("background-color: ") + color.name(QColor::HexRgb); m_ColorButton->setAutoFillBackground(true); m_ColorButton->setStyleSheet(styleSheet); } } void QmitkDataNodeColorAction::OnColorChanged() { + auto dataNodes = GetSelectedNodes(); + if (dataNodes.isEmpty()) + { + return; + } + + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + bool selectedColor = false; QColor newColor; - auto selectedNodes = GetSelectedNodes(); - for (auto& dataNode : selectedNodes) + for (auto& dataNode : dataNodes) { if (dataNode.IsNull()) { continue; } float rgb[3]; - if (dataNode->GetColor(rgb)) + if (dataNode->GetColor(rgb, baseRenderer)) { if (!selectedColor) { QColor initial(rgb[0] * 255, rgb[1] * 255, rgb[2] * 255); newColor = QColorDialog::getColor(initial, nullptr, QString(tr("Change color"))); if (newColor.isValid()) { selectedColor = true; } else { return; } } - dataNode->SetProperty("color", mitk::ColorProperty::New(newColor.redF(), newColor.greenF(), newColor.blueF())); - if (dataNode->GetProperty("binaryimage.selectedcolor")) + dataNode->SetProperty("color", mitk::ColorProperty::New(newColor.redF(), newColor.greenF(), newColor.blueF()), baseRenderer); + if (dataNode->GetProperty("binaryimage.selectedcolor", baseRenderer)) { - dataNode->SetProperty("binaryimage.selectedcolor", mitk::ColorProperty::New(newColor.redF(), newColor.greenF(), newColor.blueF())); + dataNode->SetProperty("binaryimage.selectedcolor", mitk::ColorProperty::New(newColor.redF(), newColor.greenF(), newColor.blueF()), baseRenderer); } } } - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); + } } void QmitkDataNodeColorAction::OnActionChanged() { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } InitializeWithDataNode(dataNode); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp index eb629da7f3..2f0e5e812a 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeColorMapAction.cpp @@ -1,141 +1,168 @@ /*=================================================================== 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 // mitk core #include #include #include #include #include // mitk gui common plugin #include // berry #include // qt #include QmitkDataNodeColorMapAction::QmitkDataNodeColorMapAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Colormap")); InitializeAction(); } QmitkDataNodeColorMapAction::QmitkDataNodeColorMapAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Colormap")); InitializeAction(); } QmitkDataNodeColorMapAction::~QmitkDataNodeColorMapAction() { // nothing here } void QmitkDataNodeColorMapAction::InitializeAction() { setCheckable(true); setMenu(new QMenu); connect(menu(), &QMenu::aboutToShow, this, &QmitkDataNodeColorMapAction::OnMenuAboutShow); } void QmitkDataNodeColorMapAction::OnMenuAboutShow() { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } - mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast(dataNode->GetProperty("LookupTable")); + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + + mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast(dataNode->GetProperty("LookupTable", baseRenderer)); if (lookupTableProperty.IsNull()) { mitk::LookupTable::Pointer mitkLut = mitk::LookupTable::New(); lookupTableProperty = mitk::LookupTableProperty::New(); lookupTableProperty->SetLookupTable(mitkLut); - dataNode->SetProperty("LookupTable", lookupTableProperty); + dataNode->SetProperty("LookupTable", lookupTableProperty, baseRenderer); } mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue(); if (lookupTable.IsNull()) { return; } menu()->clear(); - QAction* tmp; - int i = 0; - std::string lutType = lookupTable->typenameList[i]; - - while (lutType != "END_OF_ARRAY") + QAction* lutAction; + for (const auto& lutTypeString : lookupTable->typenameList) { - tmp = menu()->addAction(QString::fromStdString(lutType)); - tmp->setCheckable(true); + lutAction = menu()->addAction(QString::fromStdString(lutTypeString)); + lutAction->setCheckable(true); - if (lutType == lookupTable->GetActiveTypeAsString()) + if (lutTypeString == lookupTable->GetActiveTypeAsString()) { - tmp->setChecked(true); + lutAction->setChecked(true); } - connect(tmp, &QAction::triggered, this, &QmitkDataNodeColorMapAction::OnActionTriggered); - - lutType = lookupTable->typenameList[++i]; + connect(lutAction, &QAction::triggered, this, &QmitkDataNodeColorMapAction::OnActionTriggered); } } void QmitkDataNodeColorMapAction::OnActionTriggered(bool checked) { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } - mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast(dataNode->GetProperty("LookupTable")); + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + + mitk::LookupTableProperty::Pointer lookupTableProperty = dynamic_cast(dataNode->GetProperty("LookupTable", baseRenderer)); if (lookupTableProperty.IsNull()) { return; } mitk::LookupTable::Pointer lookupTable = lookupTableProperty->GetValue(); if (lookupTable.IsNull()) { return; } + mitk::LookupTable::Pointer renderWindowSpecificLutTab = lookupTable->Clone(); + QAction* senderAction = qobject_cast(QObject::sender()); if (nullptr == senderAction) { return; } + // set lookup table type defined by the action string std::string activatedItem = senderAction->text().toStdString(); - lookupTable->SetType(activatedItem); - lookupTableProperty->SetValue(lookupTable); - mitk::RenderingModeProperty::Pointer renderingMode = dynamic_cast(dataNode->GetProperty("Image Rendering.Mode")); + renderWindowSpecificLutTab->SetType(activatedItem); + dataNode->SetProperty("LookupTable", mitk::LookupTableProperty::New(renderWindowSpecificLutTab), baseRenderer); + + mitk::RenderingModeProperty::Pointer renderingMode = dynamic_cast(dataNode->GetProperty("Image Rendering.Mode", baseRenderer)); renderingMode->SetValue(mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); + } } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.cpp index 0250be552f..e58a6b2931 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeComponentAction.cpp @@ -1,111 +1,121 @@ /*=================================================================== 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 // mitk core #include #include #include // mitk gui common plugin #include // berry #include // qt #include #include QmitkDataNodeComponentAction::QmitkDataNodeComponentAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QWidgetAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { InitializeAction(); } QmitkDataNodeComponentAction::QmitkDataNodeComponentAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QWidgetAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { InitializeAction(); } QmitkDataNodeComponentAction::~QmitkDataNodeComponentAction() { // nothing here } void QmitkDataNodeComponentAction::InitializeAction() { setCheckable(true); m_ComponentSlider = new QmitkNumberPropertySlider; m_ComponentSlider->setOrientation(Qt::Horizontal); QLabel* componentLabel = new QLabel(tr("Component: ")); QHBoxLayout* componentWidgetLayout = new QHBoxLayout; componentWidgetLayout->setContentsMargins(4, 4, 4, 4); componentWidgetLayout->addWidget(componentLabel); componentWidgetLayout->addWidget(m_ComponentSlider); QLabel* componentValueLabel = new QLabel(); componentWidgetLayout->addWidget(componentValueLabel); connect(m_ComponentSlider, &QmitkNumberPropertySlider::valueChanged, componentValueLabel, static_cast(&QLabel::setNum)); QWidget* componentWidget = new QWidget; componentWidget->setLayout(componentWidgetLayout); setDefaultWidget(componentWidget); connect(this, &QmitkDataNodeComponentAction::changed, this, &QmitkDataNodeComponentAction::OnActionChanged); } void QmitkDataNodeComponentAction::InitializeWithDataNode(const mitk::DataNode* dataNode) { if (nullptr == dataNode) { m_ComponentSlider->SetProperty(static_cast(nullptr)); return; } mitk::Image* img = dynamic_cast(dataNode->GetData()); if (nullptr == img) { m_ComponentSlider->SetProperty(static_cast(nullptr)); return; } + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + int numComponents = 0; numComponents = img->GetPixelType().GetNumberOfComponents(); - mitk::IntProperty* componentProperty = dynamic_cast(dataNode->GetProperty("Image.Displayed Component")); + mitk::IntProperty* componentProperty = dynamic_cast(dataNode->GetProperty("Image.Displayed Component", baseRenderer)); if (numComponents <= 1 || nullptr == componentProperty) { m_ComponentSlider->SetProperty(static_cast(nullptr)); return; } m_ComponentSlider->SetProperty(componentProperty); m_ComponentSlider->setMinValue(0); m_ComponentSlider->setMaxValue(numComponents - 1); } void QmitkDataNodeComponentAction::OnActionChanged() { auto dataNode = GetSelectedNode(); InitializeWithDataNode(dataNode); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.cpp index 6512b9616b..6bf724edea 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.cpp @@ -1,538 +1,555 @@ /*=================================================================== 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 "QmitkDataNodeContextMenu.h" // mitk gui qt application plugin #include "mitkIContextMenuAction.h" #include "QmitkFileSaveAction.h" // mitk gui common plugin #include // qt widgets module #include #include // berry #include #include #include #include #include QmitkDataNodeContextMenu::QmitkDataNodeContextMenu(berry::IWorkbenchPartSite::Pointer workbenchPartSite, QWidget* parent) : QMenu(parent) { m_Parent = parent; m_WorkbenchPartSite = workbenchPartSite; InitNodeDescriptors(); InitDefaultActions(); InitExtensionPointActions(); } QmitkDataNodeContextMenu::~QmitkDataNodeContextMenu() { // remove the registered actions from each descriptor for (DescriptorActionListType::const_iterator it = m_DescriptorActionList.begin(); it != m_DescriptorActionList.end(); ++it) { (it->first)->RemoveAction(it->second); } } void QmitkDataNodeContextMenu::SetDataStorage(mitk::DataStorage* dataStorage) { if (m_DataStorage != dataStorage) { // set the new data storage - also for all actions m_DataStorage = dataStorage; for (DescriptorActionListType::const_iterator it = m_DescriptorActionList.begin(); it != m_DescriptorActionList.end(); ++it) { QmitkAbstractDataNodeAction* abstractDataNodeAction = dynamic_cast(it->second); if(nullptr != abstractDataNodeAction) { abstractDataNodeAction->SetDataStorage(m_DataStorage.Lock()); } } } } +void QmitkDataNodeContextMenu::SetBaseRenderer(mitk::BaseRenderer* baseRenderer) +{ + if (m_BaseRenderer != baseRenderer) + { + // set the new base renderer - also for all actions + m_BaseRenderer = baseRenderer; + for (DescriptorActionListType::const_iterator it = m_DescriptorActionList.begin(); it != m_DescriptorActionList.end(); ++it) + { + QmitkAbstractDataNodeAction* abstractDataNodeAction = dynamic_cast(it->second); + if (nullptr != abstractDataNodeAction) + { + abstractDataNodeAction->SetBaseRenderer(m_BaseRenderer.Lock()); + } + } + } +} + void QmitkDataNodeContextMenu::SetSurfaceDecimation(bool surfaceDecimation) { m_SurfaceDecimation = surfaceDecimation; } void QmitkDataNodeContextMenu::InitNodeDescriptors() { m_UnknownDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetUnknownDataNodeDescriptor(); m_ImageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Image"); m_MultiComponentImageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("MultiComponentImage"); m_DiffusionImageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("DiffusionImage"); m_FiberBundleDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("FiberBundle"); m_PeakImageDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PeakImage"); m_SegmentDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Segment"); m_SurfaceDataNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("Surface"); m_PointSetNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PointSet"); m_PlanarLineNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarLine"); m_PlanarCircleNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarCircle"); m_PlanarEllipseNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarEllipse"); m_PlanarAngleNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarAngle"); m_PlanarFourPointAngleNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarFourPointAngle"); m_PlanarRectangleNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarRectangle"); m_PlanarPolygonNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarPolygon"); m_PlanarPathNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarPath"); m_PlanarDoubleEllipseNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarDoubleEllipse"); m_PlanarBezierCurveNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarBezierCurve"); m_PlanarSubdivisionPolygonNodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor("PlanarSubdivisionPolygon"); } void QmitkDataNodeContextMenu::InitDefaultActions() { m_GlobalReinitAction = new QmitkDataNodeGlobalReinitAction(m_Parent, m_WorkbenchPartSite.Lock()); m_GlobalReinitAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png")); m_UnknownDataNodeDescriptor->AddAction(m_GlobalReinitAction, true); m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_GlobalReinitAction)); m_ReinitAction = new QmitkDataNodeReinitAction(m_Parent, m_WorkbenchPartSite.Lock()); m_ReinitAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/Refresh_48.png")); m_UnknownDataNodeDescriptor->AddAction(m_ReinitAction, true); m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_ReinitAction)); QAction* saveAction = new QmitkFileSaveAction(QIcon(":/org.mitk.gui.qt.datamanager/Save_48.png"), m_WorkbenchPartSite.Lock()->GetWorkbenchWindow()); m_UnknownDataNodeDescriptor->AddAction(saveAction, true); m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, saveAction)); m_RemoveAction = new QmitkDataNodeRemoveAction(m_Parent, m_WorkbenchPartSite.Lock()); m_RemoveAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/Remove_48.png")); m_UnknownDataNodeDescriptor->AddAction(m_RemoveAction, true); m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_RemoveAction)); m_ShowSelectedNodesAction = new QmitkDataNodeShowSelectedNodesAction(m_Parent, m_WorkbenchPartSite.Lock()); m_RemoveAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/ShowSelectedNode_48.png")); m_UnknownDataNodeDescriptor->AddAction(m_ShowSelectedNodesAction, true); m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_ShowSelectedNodesAction)); m_ToggleVisibilityAction = new QmitkDataNodeToggleVisibilityAction(m_Parent, m_WorkbenchPartSite.Lock()); m_ToggleVisibilityAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/InvertShowSelectedNode_48.png")); m_UnknownDataNodeDescriptor->AddAction(m_ToggleVisibilityAction, true); m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_ToggleVisibilityAction)); m_ShowDetailsAction = new QmitkDataNodeShowDetailsAction(m_Parent, m_WorkbenchPartSite.Lock()); m_ShowDetailsAction->setIcon(QIcon(":/org.mitk.gui.qt.datamanager/ShowDataInfo_48.png")); m_UnknownDataNodeDescriptor->AddAction(m_ShowDetailsAction, true); m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_ShowDetailsAction)); // default widget actions m_OpacityAction = new QmitkDataNodeOpacityAction(m_Parent, m_WorkbenchPartSite.Lock()); // not used for batch actions (no multi-selection action) m_UnknownDataNodeDescriptor->AddAction(m_OpacityAction, false); m_DescriptorActionList.push_back(std::make_pair(m_UnknownDataNodeDescriptor, m_OpacityAction)); m_ColorAction = new QmitkDataNodeColorAction(m_Parent, m_WorkbenchPartSite.Lock()); AddColorAction(m_ColorAction); m_ColormapAction = new QmitkDataNodeColorMapAction(m_Parent, m_WorkbenchPartSite.Lock()); // not used for batch actions (no multi-selection action) m_ImageDataNodeDescriptor->AddAction(m_ColormapAction, false); m_DescriptorActionList.push_back(std::make_pair(m_ImageDataNodeDescriptor, m_ColormapAction)); if (m_DiffusionImageDataNodeDescriptor != nullptr) { // not used for batch actions (no multi-selection action) m_DiffusionImageDataNodeDescriptor->AddAction(m_ColormapAction, false); m_DescriptorActionList.push_back(std::make_pair(m_DiffusionImageDataNodeDescriptor, m_ColormapAction)); } m_ComponentAction = new QmitkDataNodeComponentAction(m_Parent, m_WorkbenchPartSite.Lock()); // not used for batch actions (no multi-selection action) m_MultiComponentImageDataNodeDescriptor->AddAction(m_ComponentAction, false); m_DescriptorActionList.push_back(std::make_pair(m_MultiComponentImageDataNodeDescriptor, m_ComponentAction)); if (m_DiffusionImageDataNodeDescriptor != nullptr) { // not used for batch actions (no multi-selection action) m_DiffusionImageDataNodeDescriptor->AddAction(m_ComponentAction, false); m_DescriptorActionList.push_back(std::make_pair(m_DiffusionImageDataNodeDescriptor, m_ComponentAction)); } m_TextureInterpolationAction = new QmitkDataNodeTextureInterpolationAction(m_Parent, m_WorkbenchPartSite.Lock()); // not used for batch actions (no multi-selection action) m_ImageDataNodeDescriptor->AddAction(m_TextureInterpolationAction, false); m_DescriptorActionList.push_back(std::make_pair(m_ImageDataNodeDescriptor, m_TextureInterpolationAction)); if (m_DiffusionImageDataNodeDescriptor != nullptr) { // not used for batch actions (no multi-selection action) m_DiffusionImageDataNodeDescriptor->AddAction(m_TextureInterpolationAction, false); m_DescriptorActionList.push_back(std::make_pair(m_DiffusionImageDataNodeDescriptor, m_TextureInterpolationAction)); } if (m_SegmentDataNodeDescriptor != nullptr) { // not used for batch actions (no multi-selection action) m_SegmentDataNodeDescriptor->AddAction(m_TextureInterpolationAction, false); m_DescriptorActionList.push_back(std::make_pair(m_SegmentDataNodeDescriptor, m_TextureInterpolationAction)); } m_SurfaceRepresentationAction = new QmitkDataNodeSurfaceRepresentationAction(m_Parent, m_WorkbenchPartSite.Lock()); // not used for batch actions (no multi-selection action) m_SurfaceDataNodeDescriptor->AddAction(m_SurfaceRepresentationAction, false); m_DescriptorActionList.push_back(std::make_pair(m_SurfaceDataNodeDescriptor, m_SurfaceRepresentationAction)); } void QmitkDataNodeContextMenu::InitExtensionPointActions() { // find contextMenuAction extension points and add them to the node descriptor berry::IExtensionRegistry* extensionPointService = berry::Platform::GetExtensionRegistry(); QList customMenuConfigs = extensionPointService->GetConfigurationElementsFor("org.mitk.gui.qt.datamanager.contextMenuActions"); // prepare all custom QActions m_ConfigElements.clear(); DescriptorActionListType descriptorActionList; for (const auto& customMenuConfig : customMenuConfigs) { QString actionNodeDescriptorName = customMenuConfig->GetAttribute("nodeDescriptorName"); QString actionLabel = customMenuConfig->GetAttribute("label"); QString actionClass = customMenuConfig->GetAttribute("class"); if (actionNodeDescriptorName.isEmpty() || actionLabel.isEmpty() || actionClass.isEmpty()) { // no properties found for the current extension point continue; } // find matching descriptor auto nodeDescriptor = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(actionNodeDescriptorName); if (nullptr == nodeDescriptor) { MITK_WARN << "Cannot add action \"" << actionLabel << "\" because descriptor " << actionNodeDescriptorName << " does not exist."; continue; } // create action with or without icon QAction* contextMenuAction; QString actionIconName = customMenuConfig->GetAttribute("icon"); if (!actionIconName.isEmpty()) { QIcon actionIcon; if (QFile::exists(actionIconName)) { actionIcon = QIcon(actionIconName); } else { actionIcon = berry::AbstractUICTKPlugin::ImageDescriptorFromPlugin(customMenuConfig->GetContributor()->GetName(), actionIconName); } contextMenuAction = new QAction(actionIcon, actionLabel, m_Parent); } else { contextMenuAction = new QAction(actionLabel, m_Parent); } // connect action trigger connect(contextMenuAction, static_cast(&QAction::triggered), this, &QmitkDataNodeContextMenu::OnExtensionPointActionTriggered); // mark configuration element into lookup list for context menu handler m_ConfigElements[contextMenuAction] = customMenuConfig; // mark new action in sortable list for addition to descriptor descriptorActionList.emplace_back(nodeDescriptor, contextMenuAction); } AddDescriptorActionList(descriptorActionList); } void QmitkDataNodeContextMenu::InitServiceActions() { } void QmitkDataNodeContextMenu::OnContextMenuRequested(const QPoint& pos) { if (m_WorkbenchPartSite.Expired()) { return; } berry::ISelection::ConstPointer selection = m_WorkbenchPartSite.Lock()->GetWorkbenchWindow()->GetSelectionService()->GetSelection(); mitk::DataNodeSelection::ConstPointer currentSelection = selection.Cast(); if (currentSelection.IsNull() || currentSelection->IsEmpty()) { return; } m_SelectedNodes = QList::fromStdList(currentSelection->GetSelectedDataNodes()); if (!m_SelectedNodes.isEmpty()) { clear(); QList actions; if (m_SelectedNodes.size() == 1) { // no batch action; should only contain a single node actions = GetActions(m_SelectedNodes.front()); } else { // batch action actions = GetActions(m_SelectedNodes); } // initialize abstract data node actions for (auto& action : actions) { QmitkAbstractDataNodeAction* abstractDataNodeAction = dynamic_cast(action); if (nullptr != abstractDataNodeAction) { // use the first selected node to initialize the data node actions abstractDataNodeAction->InitializeWithDataNode(m_SelectedNodes.front()); } } /* if (!m_ShowInActions.isEmpty()) { QMenu* showInMenu = m_NodeMenu->addMenu(tr("Show In")); showInMenu->addActions(m_ShowInActions); } */ addActions(actions); popup(QCursor::pos()); } } void QmitkDataNodeContextMenu::OnExtensionPointActionTriggered(bool) { QAction* action = qobject_cast(sender()); ConfigurationElementsType::const_iterator it = m_ConfigElements.find(action); if (it == m_ConfigElements.end()) { MITK_WARN << "Associated configuration element for action " << action->text().toStdString() << " not found."; return; } berry::IConfigurationElement::Pointer confElem = it->second; mitk::IContextMenuAction* contextMenuAction = confElem->CreateExecutableExtension("class"); QString className = confElem->GetAttribute("class"); QString smoothed = confElem->GetAttribute("smoothed"); if (!m_DataStorage.IsExpired()) { auto dataStorage = m_DataStorage.Lock(); contextMenuAction->SetDataStorage(dataStorage); } if (className == "QmitkCreatePolygonModelAction") { if (smoothed == "false") { contextMenuAction->SetSmoothed(false); } else { contextMenuAction->SetSmoothed(true); } contextMenuAction->SetDecimated(m_SurfaceDecimation); } contextMenuAction->Run(m_SelectedNodes); } void QmitkDataNodeContextMenu::AddColorAction(QWidgetAction* colorAction) { bool colorActionCanBatch = true; if (nullptr != m_ImageDataNodeDescriptor) { m_ImageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_ImageDataNodeDescriptor, colorAction)); } if (nullptr != m_MultiComponentImageDataNodeDescriptor) { m_MultiComponentImageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_MultiComponentImageDataNodeDescriptor, colorAction)); } if (nullptr != m_DiffusionImageDataNodeDescriptor) { m_DiffusionImageDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_DiffusionImageDataNodeDescriptor, colorAction)); } if (nullptr != m_FiberBundleDataNodeDescriptor) { m_FiberBundleDataNodeDescriptor->AddAction(colorAction, false); m_DescriptorActionList.push_back(std::make_pair(m_FiberBundleDataNodeDescriptor, colorAction)); } if (nullptr != m_PeakImageDataNodeDescriptor) { m_PeakImageDataNodeDescriptor->AddAction(colorAction, false); m_DescriptorActionList.push_back(std::make_pair(m_PeakImageDataNodeDescriptor, colorAction)); } if (nullptr != m_SegmentDataNodeDescriptor) { m_SegmentDataNodeDescriptor->AddAction(colorAction, false); m_DescriptorActionList.push_back(std::make_pair(m_SegmentDataNodeDescriptor, colorAction)); } if (nullptr != m_SurfaceDataNodeDescriptor) { m_SurfaceDataNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_SurfaceDataNodeDescriptor, colorAction)); } if (nullptr != m_PointSetNodeDescriptor) { m_PointSetNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PointSetNodeDescriptor, colorAction)); } if (nullptr != m_PlanarLineNodeDescriptor) { m_PlanarLineNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarLineNodeDescriptor, colorAction)); } if (nullptr != m_PlanarCircleNodeDescriptor) { m_PlanarCircleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarCircleNodeDescriptor, colorAction)); } if (nullptr != m_PlanarEllipseNodeDescriptor) { m_PlanarEllipseNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarEllipseNodeDescriptor, colorAction)); } if (nullptr != m_PlanarAngleNodeDescriptor) { m_PlanarAngleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarAngleNodeDescriptor, colorAction)); } if (nullptr != m_PlanarFourPointAngleNodeDescriptor) { m_PlanarFourPointAngleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarFourPointAngleNodeDescriptor, colorAction)); } if (nullptr != m_PlanarRectangleNodeDescriptor) { m_PlanarRectangleNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarRectangleNodeDescriptor, colorAction)); } if (nullptr != m_PlanarPolygonNodeDescriptor) { m_PlanarPolygonNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarPolygonNodeDescriptor, colorAction)); } if (nullptr != m_PlanarPathNodeDescriptor) { m_PlanarPathNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarPathNodeDescriptor, colorAction)); } if (nullptr != m_PlanarDoubleEllipseNodeDescriptor) { m_PlanarDoubleEllipseNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarDoubleEllipseNodeDescriptor, colorAction)); } if (nullptr != m_PlanarBezierCurveNodeDescriptor) { m_PlanarBezierCurveNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarBezierCurveNodeDescriptor, colorAction)); } if (nullptr != m_PlanarSubdivisionPolygonNodeDescriptor) { m_PlanarSubdivisionPolygonNodeDescriptor->AddAction(colorAction, colorActionCanBatch); m_DescriptorActionList.push_back(std::make_pair(m_PlanarSubdivisionPolygonNodeDescriptor, colorAction)); } } void QmitkDataNodeContextMenu::AddDescriptorActionList(DescriptorActionListType& descriptorActionList) { // sort all custom QActions by their texts using ListEntryType = std::pair; std::sort(descriptorActionList.begin(), descriptorActionList.end(), [](const ListEntryType& left, const ListEntryType& right) -> bool { assert(left.second != nullptr && right.second != nullptr); // unless we messed up above return left.second->text() < right.second->text(); }); // add custom QActions in sorted order for (auto& descriptorActionPair : descriptorActionList) { auto& nodeDescriptor = descriptorActionPair.first; auto& contextMenuAction = descriptorActionPair.second; // add action to the descriptor nodeDescriptor->AddAction(contextMenuAction); // mark new action into list of descriptors to remove in destructor m_DescriptorActionList.push_back(descriptorActionPair); } } QList QmitkDataNodeContextMenu::GetActions(const mitk::DataNode* node) { QList actions; for (DescriptorActionListType::const_iterator it = m_DescriptorActionList.begin(); it != m_DescriptorActionList.end(); ++it) { if ((it->first)->CheckNode(node) || it->first->GetNameOfClass() == "Unknown") { actions.append(it->second); } } return actions; } QList QmitkDataNodeContextMenu::GetActions(const QList& nodes) { QList actions; for (DescriptorActionListType::const_iterator it = m_DescriptorActionList.begin(); it != m_DescriptorActionList.end(); ++it) { for (const auto& node : nodes) { if ((it->first)->CheckNode(node) || it->first->GetNameOfClass() == "Unknown") { const auto& batchActions = (it->first)->GetBatchActions(); if (std::find(batchActions.begin(), batchActions.end(), it->second) != batchActions.end()) { // current descriptor action is a batch action actions.append(it->second); } break; // only add action once; goto next descriptor action } } } return actions; } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.h index d5f3055074..a8198f282b 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.h +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeContextMenu.h @@ -1,134 +1,137 @@ /*=================================================================== 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 QMITKDATANODECONTEXTMENU_H #define QMITKDATANODECONTEXTMENU_H #include // qt widgets module #include "QmitkDataNodeGlobalReinitAction.h" #include "QmitkDataNodeReinitAction.h" #include "QmitkDataNodeRemoveAction.h" #include "QmitkDataNodeShowSelectedNodesAction.h" #include "QmitkDataNodeToggleVisibilityAction.h" #include "QmitkDataNodeShowDetailsAction.h" #include "QmitkDataNodeOpacityAction.h" #include "QmitkDataNodeColorAction.h" #include "QmitkDataNodeColorMapAction.h" #include "QmitkDataNodeComponentAction.h" #include "QmitkDataNodeTextureInterpolationAction.h" #include "QmitkDataNodeSurfaceRepresentationAction.h" #include "QmitkNodeDescriptor.h" // mitk core +#include #include #include // blueberry ui qt plugin #include #include // qt #include class MITK_QT_APP QmitkDataNodeContextMenu : public QMenu { Q_OBJECT public: QmitkDataNodeContextMenu(berry::IWorkbenchPartSite::Pointer workbenchPartSite, QWidget* parent = nullptr); virtual ~QmitkDataNodeContextMenu() override; void SetDataStorage(mitk::DataStorage* dataStorage); + void SetBaseRenderer(mitk::BaseRenderer* baseRenderer); void SetSurfaceDecimation(bool surfaceDecimation); public Q_SLOTS: void OnContextMenuRequested(const QPoint& pos); void OnExtensionPointActionTriggered(bool); private: using DescriptorActionListType = std::vector>; using ConfigurationElementsType = std::map; void InitNodeDescriptors(); void InitDefaultActions(); void InitExtensionPointActions(); void InitServiceActions(); void AddColorAction(QWidgetAction* colorAction); void AddDescriptorActionList(DescriptorActionListType& descriptorActionList); QList GetActions(const mitk::DataNode* node); QList GetActions(const QList& nodes); QWidget* m_Parent; berry::IWorkbenchPartSite::WeakPtr m_WorkbenchPartSite; mitk::WeakPointer m_DataStorage; + mitk::WeakPointer m_BaseRenderer; QList m_SelectedNodes; // store a list of all actions to remove them on menu destruction DescriptorActionListType m_DescriptorActionList; // stores the configuration elements for the context menu actions from extension points ConfigurationElementsType m_ConfigElements; QmitkNodeDescriptor* m_UnknownDataNodeDescriptor; QmitkNodeDescriptor* m_ImageDataNodeDescriptor; QmitkNodeDescriptor* m_MultiComponentImageDataNodeDescriptor; QmitkNodeDescriptor* m_DiffusionImageDataNodeDescriptor; QmitkNodeDescriptor* m_FiberBundleDataNodeDescriptor; QmitkNodeDescriptor* m_PeakImageDataNodeDescriptor; QmitkNodeDescriptor* m_SegmentDataNodeDescriptor; QmitkNodeDescriptor* m_SurfaceDataNodeDescriptor; QmitkNodeDescriptor* m_PointSetNodeDescriptor; QmitkNodeDescriptor* m_PlanarLineNodeDescriptor; QmitkNodeDescriptor* m_PlanarCircleNodeDescriptor; QmitkNodeDescriptor* m_PlanarEllipseNodeDescriptor; QmitkNodeDescriptor* m_PlanarAngleNodeDescriptor; QmitkNodeDescriptor* m_PlanarFourPointAngleNodeDescriptor; QmitkNodeDescriptor* m_PlanarRectangleNodeDescriptor; QmitkNodeDescriptor* m_PlanarPolygonNodeDescriptor; QmitkNodeDescriptor* m_PlanarPathNodeDescriptor; QmitkNodeDescriptor* m_PlanarDoubleEllipseNodeDescriptor; QmitkNodeDescriptor* m_PlanarBezierCurveNodeDescriptor; QmitkNodeDescriptor* m_PlanarSubdivisionPolygonNodeDescriptor; ////////////////////////////////////////////////////////////////////////// // default actions ////////////////////////////////////////////////////////////////////////// QmitkDataNodeGlobalReinitAction* m_GlobalReinitAction; QmitkDataNodeReinitAction* m_ReinitAction; QmitkDataNodeRemoveAction* m_RemoveAction; QmitkDataNodeShowSelectedNodesAction* m_ShowSelectedNodesAction; QmitkDataNodeToggleVisibilityAction* m_ToggleVisibilityAction; QmitkDataNodeShowDetailsAction* m_ShowDetailsAction; QmitkDataNodeOpacityAction* m_OpacityAction; QmitkDataNodeColorAction* m_ColorAction; QmitkDataNodeColorMapAction* m_ColormapAction; QmitkDataNodeComponentAction* m_ComponentAction; QmitkDataNodeTextureInterpolationAction* m_TextureInterpolationAction; QmitkDataNodeSurfaceRepresentationAction* m_SurfaceRepresentationAction; bool m_SurfaceDecimation; }; #endif // QMITKDATANODECONTEXTMENU_H diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.cpp index 9d034351df..85fc2a1fc5 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeHideAllNodesAction.cpp @@ -1,65 +1,82 @@ /*=================================================================== 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 // mitk core #include QmitkDataNodeHideAllNodesAction::QmitkDataNodeHideAllNodesAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Hide all nodes")); InitializeAction(); } QmitkDataNodeHideAllNodesAction::QmitkDataNodeHideAllNodesAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Hide all nodes")); InitializeAction(); } QmitkDataNodeHideAllNodesAction::~QmitkDataNodeHideAllNodesAction() { // nothing here } void QmitkDataNodeHideAllNodesAction::InitializeAction() { connect(this, &QmitkDataNodeHideAllNodesAction::triggered, this, &QmitkDataNodeHideAllNodesAction::OnActionTriggered); } void QmitkDataNodeHideAllNodesAction::OnActionTriggered(bool checked) { if (m_DataStorage.IsExpired()) { return; } + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + auto nodeset = m_DataStorage.Lock()->GetAll(); for (auto& node : *nodeset) { if (node.IsNotNull()) { - node->SetVisibility(false); + node->SetVisibility(false, baseRenderer); } } - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); + } } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.cpp index 58c58830bc..ed788ff314 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeOpacityAction.cpp @@ -1,99 +1,132 @@ /*=================================================================== 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 // mitk core #include // qt #include #include QmitkDataNodeOpacityAction::QmitkDataNodeOpacityAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QWidgetAction(parent) , QmitkAbstractDataNodeAction(workbenchPartSite) { InitializeAction(); } QmitkDataNodeOpacityAction::QmitkDataNodeOpacityAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QWidgetAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { InitializeAction(); } QmitkDataNodeOpacityAction::~QmitkDataNodeOpacityAction() { // nothing here } void QmitkDataNodeOpacityAction::InitializeAction() { m_OpacitySlider = new QSlider; m_OpacitySlider->setMinimum(0); m_OpacitySlider->setMaximum(100); m_OpacitySlider->setOrientation(Qt::Horizontal); connect(m_OpacitySlider, &QSlider::valueChanged, this, &QmitkDataNodeOpacityAction::OnOpacityChanged); QLabel* opacityLabel = new QLabel(tr("Opacity: ")); QHBoxLayout* opacityWidgetLayout = new QHBoxLayout; opacityWidgetLayout->setContentsMargins(4, 4, 4, 4); opacityWidgetLayout->addWidget(opacityLabel); opacityWidgetLayout->addWidget(m_OpacitySlider); QWidget* opacityWidget = new QWidget; opacityWidget->setLayout(opacityWidgetLayout); setDefaultWidget(opacityWidget); connect(this, &QAction::changed, this, &QmitkDataNodeOpacityAction::OnActionChanged); } void QmitkDataNodeOpacityAction::InitializeWithDataNode(const mitk::DataNode* dataNode) { + if (nullptr == dataNode) + { + m_OpacitySlider->setValue(static_cast(0)); + return; + } + + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + float opacity = 0.0; - if (dataNode->GetFloatProperty("opacity", opacity)) + if (dataNode->GetFloatProperty("opacity", opacity, baseRenderer)) { m_OpacitySlider->setValue(static_cast(opacity * 100)); } } void QmitkDataNodeOpacityAction::OnOpacityChanged(int value) { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + float opacity = static_cast(value) / 100.0f; - dataNode->SetFloatProperty("opacity", opacity); + dataNode->SetFloatProperty("opacity", opacity, baseRenderer); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); + } } void QmitkDataNodeOpacityAction::OnActionChanged() { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } InitializeWithDataNode(dataNode); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.cpp index 925d417c6b..d3a822b96f 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeReinitAction.cpp @@ -1,116 +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. ===================================================================*/ #include // mitk core #include #include #include #include #include // mitk gui common plugin #include QmitkDataNodeReinitAction::QmitkDataNodeReinitAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Reinit")); InitializeAction(); } QmitkDataNodeReinitAction::QmitkDataNodeReinitAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Reinit")); InitializeAction(); } QmitkDataNodeReinitAction::~QmitkDataNodeReinitAction() { // nothing here } void QmitkDataNodeReinitAction::InitializeAction() { connect(this, &QmitkDataNodeReinitAction::triggered, this, &QmitkDataNodeReinitAction::OnActionTriggered); } void QmitkDataNodeReinitAction::OnActionTriggered(bool checked) { if (m_WorkbenchPartSite.Expired()) { return; } auto renderWindow = mitk::WorkbenchUtil::GetRenderWindowPart(m_WorkbenchPartSite.Lock()->GetPage(), mitk::WorkbenchUtil::NONE); if (nullptr == renderWindow) { renderWindow = mitk::WorkbenchUtil::OpenRenderWindowPart(m_WorkbenchPartSite.Lock()->GetPage(), false); if (nullptr == renderWindow) { // no render window available return; } } if (m_DataStorage.IsExpired()) { return; } auto dataStorage = m_DataStorage.Lock(); auto dataNodes = GetSelectedNodes(); if (dataNodes.isEmpty()) { return; } - auto boundingBoxPredicate = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false))); + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + + auto boundingBoxPredicate = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false), baseRenderer)); mitk::DataStorage::SetOfObjects::Pointer nodes = mitk::DataStorage::SetOfObjects::New(); for (const auto& dataNode : dataNodes) { if (boundingBoxPredicate->CheckNode(dataNode)) { nodes->InsertElement(nodes->Size(), dataNode); } } if (nodes->empty()) { return; } if (1 == nodes->Size()) // Special case: If exactly one ... { auto image = dynamic_cast(nodes->ElementAt(0)->GetData()); if (nullptr != image) // ... image is selected, reinit is expected to rectify askew images. { - mitk::RenderingManager::GetInstance()->InitializeViews(image->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->InitializeViews(image->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); + } + else + { + mitk::RenderingManager::GetInstance()->InitializeView(baseRenderer->GetRenderWindow(), image->GetTimeGeometry(), true); + } return; } } - auto boundingGeometry = dataStorage->ComputeBoundingGeometry3D(nodes, "visible"); - mitk::RenderingManager::GetInstance()->InitializeViews(boundingGeometry); + auto boundingGeometry = dataStorage->ComputeBoundingGeometry3D(nodes, "visible", baseRenderer); + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->InitializeViews(boundingGeometry); + } + else + { + mitk::RenderingManager::GetInstance()->InitializeView(baseRenderer->GetRenderWindow(), boundingGeometry); + } } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.cpp index 678252076a..edd1c5b7e7 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeRemoveAction.cpp @@ -1,106 +1,111 @@ /*=================================================================== 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 #include // qt #include // berry #include #include #include QmitkDataNodeRemoveAction::QmitkDataNodeRemoveAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Remove")); m_Parent = parent; InitializeAction(); } QmitkDataNodeRemoveAction::QmitkDataNodeRemoveAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Remove")); m_Parent = parent; InitializeAction(); } QmitkDataNodeRemoveAction::~QmitkDataNodeRemoveAction() { // nothing here } void QmitkDataNodeRemoveAction::InitializeAction() { connect(this, &QmitkDataNodeRemoveAction::triggered, this, &QmitkDataNodeRemoveAction::OnActionTriggered); } void QmitkDataNodeRemoveAction::OnActionTriggered(bool checked) { if (m_DataStorage.IsExpired()) { return; } auto dataStorage = m_DataStorage.Lock(); + auto dataNodes = GetSelectedNodes(); + if (dataNodes.isEmpty()) + { + return; + } + QString question = tr("Do you really want to remove "); - auto selectedNodes = GetSelectedNodes(); - for (auto& dataNode : selectedNodes) + for (auto& dataNode : dataNodes) { if (nullptr == dataNode) { continue; } question.append(QString::fromStdString(dataNode->GetName())); question.append(", "); } // remove the last two characters = ", " question = question.remove(question.size() - 2, 2); question.append(tr(" from data storage?")); QMessageBox::StandardButton answerButton = QMessageBox::question(m_Parent, tr("DataManager"), question, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (answerButton == QMessageBox::Yes) { - for (auto& dataNode : selectedNodes) + for (auto& dataNode : dataNodes) { if (nullptr == dataNode) { continue; } dataStorage->Remove(dataNode); } berry::IPreferencesService* prefService = berry::Platform::GetPreferencesService(); berry::IPreferences::Pointer preferencesNode = prefService->GetSystemPreferences()->Node(QmitkDataNodeGlobalReinitAction::ACTION_ID); bool globalReinit = preferencesNode->GetBool("Call global reinit if node is deleted", true); if (globalReinit) { GlobalReinitAction::Run(m_WorkbenchPartSite.Lock(), dataStorage); } } } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.cpp index 43a802af99..72f8ac0f77 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeShowSelectedNodesAction.cpp @@ -1,68 +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. ===================================================================*/ #include // mitk core #include QmitkDataNodeShowSelectedNodesAction::QmitkDataNodeShowSelectedNodesAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Show only selected nodes")); InitializeAction(); } QmitkDataNodeShowSelectedNodesAction::QmitkDataNodeShowSelectedNodesAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Show only selected nodes")); InitializeAction(); } QmitkDataNodeShowSelectedNodesAction::~QmitkDataNodeShowSelectedNodesAction() { // nothing here } void QmitkDataNodeShowSelectedNodesAction::InitializeAction() { connect(this, &QmitkDataNodeShowSelectedNodesAction::triggered, this, &QmitkDataNodeShowSelectedNodesAction::OnActionTriggered); } void QmitkDataNodeShowSelectedNodesAction::OnActionTriggered(bool checked) { if (m_DataStorage.IsExpired()) { return; } - auto dataStorage = m_DataStorage.Lock(); + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } - auto selectedNodes = GetSelectedNodes(); - auto nodeset = dataStorage->GetAll(); + auto dataNodes = GetSelectedNodes(); + auto nodeset = m_DataStorage.Lock()->GetAll(); for (auto& node : *nodeset) { if (node.IsNotNull()) { - node->SetVisibility(selectedNodes.contains(node)); + node->SetVisibility(dataNodes.contains(node), baseRenderer); } } - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); + } } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.cpp index 9e71bd0de8..3190aec7a1 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeSurfaceRepresentationAction.cpp @@ -1,118 +1,145 @@ /*=================================================================== 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 // mitk core #include #include // qt #include QmitkDataNodeSurfaceRepresentationAction::QmitkDataNodeSurfaceRepresentationAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Surface Representation")); InitializeAction(); } QmitkDataNodeSurfaceRepresentationAction::QmitkDataNodeSurfaceRepresentationAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Surface Representation")); InitializeAction(); } QmitkDataNodeSurfaceRepresentationAction::~QmitkDataNodeSurfaceRepresentationAction() { // nothing here } void QmitkDataNodeSurfaceRepresentationAction::InitializeAction() { setCheckable(true); setMenu(new QMenu); connect(menu(), &QMenu::aboutToShow, this, &QmitkDataNodeSurfaceRepresentationAction::OnMenuAboutShow); } void QmitkDataNodeSurfaceRepresentationAction::OnMenuAboutShow() { mitk::DataNode::Pointer dataNode = GetSelectedNode(); if (nullptr == dataNode) { return; } - mitk::EnumerationProperty* representationProp = dynamic_cast(dataNode->GetProperty("material.representation")); + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + + mitk::EnumerationProperty* representationProp = dynamic_cast(dataNode->GetProperty("material.representation", baseRenderer)); if (nullptr == representationProp) { return; } menu()->clear(); QAction* tmp; for (mitk::EnumerationProperty::EnumConstIterator it = representationProp->Begin(); it != representationProp->End(); ++it) { tmp = menu()->addAction(QString::fromStdString(it->second)); tmp->setCheckable(true); if (it->second == representationProp->GetValueAsString()) { tmp->setChecked(true); } connect(tmp, &QAction::triggered, this, &QmitkDataNodeSurfaceRepresentationAction::OnActionTriggered); } } void QmitkDataNodeSurfaceRepresentationAction::OnActionTriggered(bool checked) { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } - mitk::EnumerationProperty* representationProp = dynamic_cast(dataNode->GetProperty("material.representation")); + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + + mitk::EnumerationProperty* representationProp = dynamic_cast(dataNode->GetProperty("material.representation", baseRenderer)); if (nullptr == representationProp) { return; } QAction* senderAction = qobject_cast(QObject::sender()); if (nullptr == senderAction) { return; } std::string activatedItem = senderAction->text().toStdString(); if (activatedItem != representationProp->GetValueAsString()) { if (representationProp->IsValidEnumerationValue(activatedItem)) { representationProp->SetValue(activatedItem); representationProp->InvokeEvent(itk::ModifiedEvent()); representationProp->Modified(); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); + } } } } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.cpp index 7dfac8d873..6a046dbb41 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeTextureInterpolationAction.cpp @@ -1,79 +1,113 @@ /*=================================================================== 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 // mitk core #include QmitkDataNodeTextureInterpolationAction::QmitkDataNodeTextureInterpolationAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Texture Interpolation")); InitializeAction(); } QmitkDataNodeTextureInterpolationAction::QmitkDataNodeTextureInterpolationAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Texture Interpolation")); InitializeAction(); } QmitkDataNodeTextureInterpolationAction::~QmitkDataNodeTextureInterpolationAction() { // nothing here } void QmitkDataNodeTextureInterpolationAction::InitializeAction() { setCheckable(true); connect(this, &QmitkDataNodeTextureInterpolationAction::toggled, this, &QmitkDataNodeTextureInterpolationAction::OnActionToggled); connect(this, &QmitkDataNodeTextureInterpolationAction::changed, this, &QmitkDataNodeTextureInterpolationAction::OnActionChanged); } void QmitkDataNodeTextureInterpolationAction::InitializeWithDataNode(const mitk::DataNode* dataNode) { + if (nullptr == dataNode) + { + setChecked(false); + return; + } + + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + bool textureInterpolation = false; - dataNode->GetBoolProperty("texture interpolation", textureInterpolation); + dataNode->GetBoolProperty("texture interpolation", textureInterpolation, baseRenderer); setChecked(textureInterpolation); } void QmitkDataNodeTextureInterpolationAction::OnActionToggled(bool checked) { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } - dataNode->SetBoolProperty("texture interpolation", checked); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + + dataNode->SetBoolProperty("texture interpolation", checked, baseRenderer); + + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); + } } void QmitkDataNodeTextureInterpolationAction::OnActionChanged() { auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } InitializeWithDataNode(dataNode); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.cpp index 1b40a398b5..61411824ea 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.cpp @@ -1,99 +1,116 @@ /*=================================================================== 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 #include // mitk core #include // berry #include #include #include // namespace that contains the concrete action namespace ToggleVisibilityAction { - void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage, QList selectedNodes /* = QList()*/) + void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage, QList selectedNodes /*= QList()*/, mitk::BaseRenderer* baseRenderer /*= nullptr*/) { bool isVisible; for (auto& node : selectedNodes) { if (node.IsNotNull()) { isVisible = false; - node->GetBoolProperty("visible", isVisible); - node->SetVisibility(!isVisible); + node->GetBoolProperty("visible", isVisible, baseRenderer); + node->SetVisibility(!isVisible, baseRenderer); } } berry::IPreferencesService* prefService = berry::Platform::GetPreferencesService(); berry::IPreferences::Pointer preferencesNode = prefService->GetSystemPreferences()->Node(QmitkDataNodeGlobalReinitAction::ACTION_ID); bool globalReinit = preferencesNode->GetBool("Call global reinit if node visibility is changed", false); if (globalReinit) { GlobalReinitAction::Run(workbenchPartSite, dataStorage); } else { - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + if (nullptr == baseRenderer) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } + else + { + mitk::RenderingManager::GetInstance()->RequestUpdate(baseRenderer->GetRenderWindow()); + } } } } QmitkDataNodeToggleVisibilityAction::QmitkDataNodeToggleVisibilityAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchpartSite) { setText(tr("Toggle visibility")); InitializeAction(); } QmitkDataNodeToggleVisibilityAction::QmitkDataNodeToggleVisibilityAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchpartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchpartSite)) { setText(tr("Toggle visibility")); InitializeAction(); } QmitkDataNodeToggleVisibilityAction::~QmitkDataNodeToggleVisibilityAction() { // nothing here } void QmitkDataNodeToggleVisibilityAction::InitializeAction() { connect(this, &QmitkDataNodeToggleVisibilityAction::triggered, this, &QmitkDataNodeToggleVisibilityAction::OnActionTriggered); } void QmitkDataNodeToggleVisibilityAction::OnActionTriggered(bool checked) { if (m_WorkbenchPartSite.Expired()) { return; } if (m_DataStorage.IsExpired()) { return; } - auto selectedNodes = GetSelectedNodes(); - ToggleVisibilityAction::Run(m_WorkbenchPartSite.Lock(), m_DataStorage.Lock(), selectedNodes); + mitk::BaseRenderer* baseRenderer; + if (m_BaseRenderer.IsExpired()) + { + baseRenderer = nullptr; + } + else + { + baseRenderer = m_BaseRenderer.Lock(); + } + + auto dataNodes = GetSelectedNodes(); + ToggleVisibilityAction::Run(m_WorkbenchPartSite.Lock(), m_DataStorage.Lock(), dataNodes, baseRenderer); } diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.h b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.h index acd9138b91..b5096b65e4 100644 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.h +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkDataNodeToggleVisibilityAction.h @@ -1,53 +1,56 @@ /*=================================================================== 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 QMITKDATANODETOGGLEVISIBILITYACTION_H #define QMITKDATANODETOGGLEVISIBILITYACTION_H #include #include "QmitkAbstractDataNodeAction.h" // qt #include namespace ToggleVisibilityAction { - MITK_QT_APP void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage, QList selectedNodes = QList()); + MITK_QT_APP void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, + mitk::DataStorage::Pointer dataStorage, + QList selectedNodes = QList(), + mitk::BaseRenderer* baseRenderer = nullptr); } class MITK_QT_APP QmitkDataNodeToggleVisibilityAction : public QAction, public QmitkAbstractDataNodeAction { Q_OBJECT public: QmitkDataNodeToggleVisibilityAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkDataNodeToggleVisibilityAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); virtual ~QmitkDataNodeToggleVisibilityAction() override; private Q_SLOTS: void OnActionTriggered(bool); protected: virtual void InitializeAction() override; }; #endif // QMITKDATANODETOGGLEVISIBILITYACTION_H diff --git a/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.cpp b/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.cpp index b3b5016eb4..b1cbad6b7d 100644 --- a/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.cpp +++ b/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.cpp @@ -1,83 +1,88 @@ /*=================================================================== 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. ===================================================================*/ // render window manager plugin #include "QmitkRenderWindowManagerView.h" // mitk core #include #include const std::string QmitkRenderWindowManagerView::VIEW_ID = "org.mitk.views.renderwindowmanager"; void QmitkRenderWindowManagerView::SetFocus() { // nothing here } void QmitkRenderWindowManagerView::CreateQtPartControl(QWidget* parent) { // create GUI widgets m_Controls.setupUi(parent); // add custom render window manager UI widget to the 'renderWindowManagerTab' m_RenderWindowInspector = new QmitkDataStorageRenderWindowInspector(parent); m_RenderWindowInspector->SetDataStorage(GetDataStorage()); m_RenderWindowInspector->setObjectName(QStringLiteral("m_RenderWindowManipulatorWidget")); m_Controls.verticalLayout->addWidget(m_RenderWindowInspector); SetControlledRenderer(); for (const auto& renderer : m_ControlledRenderer) { m_Controls.comboBoxRenderWindowSelection->addItem(renderer->GetName()); } - - OnRenderWindowSelectionChanged(m_Controls.comboBoxRenderWindowSelection->itemText(0)); connect(m_Controls.comboBoxRenderWindowSelection, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(OnRenderWindowSelectionChanged(const QString&))); // data node context menu and menu actions m_InspectorView = m_RenderWindowInspector->GetView(); m_DataNodeContextMenu = new QmitkDataNodeContextMenu(GetSite(), m_InspectorView); m_DataNodeContextMenu->SetDataStorage(GetDataStorage()); //m_DataNodeContextMenu->SetSurfaceDecimation(m_SurfaceDecimation); connect(m_InspectorView, SIGNAL(customContextMenuRequested(const QPoint&)), m_DataNodeContextMenu, SLOT(OnContextMenuRequested(const QPoint&))); + + OnRenderWindowSelectionChanged(m_Controls.comboBoxRenderWindowSelection->itemText(0)); } void QmitkRenderWindowManagerView::SetControlledRenderer() { const mitk::RenderingManager::RenderWindowVector allRegisteredRenderWindows = mitk::RenderingManager::GetInstance()->GetAllRegisteredRenderWindows(); mitk::BaseRenderer* baseRenderer = nullptr; for (const auto &renderWindow : allRegisteredRenderWindows) { baseRenderer = mitk::BaseRenderer::GetInstance(renderWindow); if (nullptr != baseRenderer) { m_ControlledRenderer.push_back(baseRenderer); } } m_RenderWindowInspector->SetControlledRenderer(m_ControlledRenderer); } -void QmitkRenderWindowManagerView::OnRenderWindowSelectionChanged(const QString &renderWindowId) +void QmitkRenderWindowManagerView::OnRenderWindowSelectionChanged(const QString& renderWindowId) { m_RenderWindowInspector->SetActiveRenderWindow(renderWindowId); + mitk::BaseRenderer* selectedRenderer = mitk::BaseRenderer::GetByName(renderWindowId.toStdString()); + if (nullptr != selectedRenderer) + { + m_DataNodeContextMenu->SetBaseRenderer(selectedRenderer); + } } QItemSelectionModel* QmitkRenderWindowManagerView::GetDataNodeSelectionModel() const { return m_InspectorView->selectionModel(); } diff --git a/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.h b/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.h index e94bf0afac..8eaec8973a 100644 --- a/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.h +++ b/Plugins/org.mitk.gui.qt.renderwindowmanager/src/internal/QmitkRenderWindowManagerView.h @@ -1,75 +1,75 @@ /*=================================================================== 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 QMITKRENDERWINDOWMANAGERVIEW_H #define QMITKRENDERWINDOWMANAGERVIEW_H // render window manager plugin #include "ui_QmitkRenderWindowManagerControls.h" // render window manager UI module #include // mitk gui qt application #include // mitk gui qt common plugin #include /** * @brief RenderWindowManager */ class QmitkRenderWindowManagerView : public QmitkAbstractView { Q_OBJECT public: static const std::string VIEW_ID; protected: virtual void SetFocus() override; virtual void CreateQtPartControl(QWidget* parent) override; private Q_SLOTS: /** * @brief Called when the user changes the render window selection in the combo box. * * @param renderWindowId The text inside the combo box. */ - void OnRenderWindowSelectionChanged(const QString &renderWindowId); + void OnRenderWindowSelectionChanged(const QString& renderWindowId); private: void SetControlledRenderer(); QWidget* m_Parent; Ui::QmitkRenderWindowManagerControls m_Controls; QmitkDataStorageRenderWindowInspector* m_RenderWindowInspector; QmitkDataNodeContextMenu* m_DataNodeContextMenu; QAbstractItemView* m_InspectorView; mitk::RenderWindowLayerUtilities::RendererVector m_ControlledRenderer; virtual QItemSelectionModel* GetDataNodeSelectionModel() const override; }; #endif // QMITKRENDERWINDOWMANAGERVIEW_H