diff --git a/Modules/Core/include/Colortables/Turbo.h b/Modules/Core/include/Colortables/Turbo.h new file mode 100644 index 0000000000..807f5c8045 --- /dev/null +++ b/Modules/Core/include/Colortables/Turbo.h @@ -0,0 +1,85 @@ +/*============================================================================ + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center (DKFZ) +All rights reserved. + +Use of this source code is governed by a 3-clause BSD license that can be +found in the LICENSE file. + +============================================================================*/ + +#ifndef _lut_Turbo_h_ +#define _lut_Turbo_h_ + +// The Turbo Colormap was developed by Anton Mikhailov at Google in 2019. +// It has been released unter the Apache 2.0 license. + +static const int Turbo[256][3] = { + { 48, 18, 59}, { 50, 21, 67}, { 51, 24, 74}, { 52, 27, 81}, + { 53, 30, 88}, { 54, 33, 95}, { 55, 36, 102}, { 56, 39, 109}, + { 57, 42, 115}, { 58, 45, 121}, { 59, 47, 128}, { 60, 50, 134}, + { 61, 53, 139}, { 62, 56, 145}, { 63, 59, 151}, { 63, 62, 156}, + { 64, 64, 162}, { 65, 67, 167}, { 65, 70, 172}, { 66, 73, 177}, + { 66, 75, 181}, { 67, 78, 186}, { 68, 81, 191}, { 68, 84, 195}, + { 68, 86, 199}, { 69, 89, 203}, { 69, 92, 207}, { 69, 94, 211}, + { 70, 97, 214}, { 70, 100, 218}, { 70, 102, 221}, { 70, 105, 224}, + { 70, 107, 227}, { 71, 110, 230}, { 71, 113, 233}, { 71, 115, 235}, + { 71, 118, 238}, { 71, 120, 240}, { 71, 123, 242}, { 70, 125, 244}, + { 70, 128, 246}, { 70, 130, 248}, { 70, 133, 250}, { 70, 135, 251}, + { 69, 138, 252}, { 69, 140, 253}, { 68, 143, 254}, { 67, 145, 254}, + { 66, 148, 255}, { 65, 150, 255}, { 64, 153, 255}, { 62, 155, 254}, + { 61, 158, 254}, { 59, 160, 253}, { 58, 163, 252}, { 56, 165, 251}, + { 55, 168, 250}, { 53, 171, 248}, { 51, 173, 247}, { 49, 175, 245}, + { 47, 178, 244}, { 46, 180, 242}, { 44, 183, 240}, { 42, 185, 238}, + { 40, 188, 235}, { 39, 190, 233}, { 37, 192, 231}, { 35, 195, 228}, + { 34, 197, 226}, { 32, 199, 223}, { 31, 201, 221}, { 30, 203, 218}, + { 28, 205, 216}, { 27, 208, 213}, { 26, 210, 210}, { 26, 212, 208}, + { 25, 213, 205}, { 24, 215, 202}, { 24, 217, 200}, { 24, 219, 197}, + { 24, 221, 194}, { 24, 222, 192}, { 24, 224, 189}, { 25, 226, 187}, + { 25, 227, 185}, { 26, 228, 182}, { 28, 230, 180}, { 29, 231, 178}, + { 31, 233, 175}, { 32, 234, 172}, { 34, 235, 170}, { 37, 236, 167}, + { 39, 238, 164}, { 42, 239, 161}, { 44, 240, 158}, { 47, 241, 155}, + { 50, 242, 152}, { 53, 243, 148}, { 56, 244, 145}, { 60, 245, 142}, + { 63, 246, 138}, { 67, 247, 135}, { 70, 248, 132}, { 74, 248, 128}, + { 78, 249, 125}, { 82, 250, 122}, { 85, 250, 118}, { 89, 251, 115}, + { 93, 252, 111}, { 97, 252, 108}, {101, 253, 105}, {105, 253, 102}, + {109, 254, 98}, {113, 254, 95}, {117, 254, 92}, {121, 254, 89}, + {125, 255, 86}, {128, 255, 83}, {132, 255, 81}, {136, 255, 78}, + {139, 255, 75}, {143, 255, 73}, {146, 255, 71}, {150, 254, 68}, + {153, 254, 66}, {156, 254, 64}, {159, 253, 63}, {161, 253, 61}, + {164, 252, 60}, {167, 252, 58}, {169, 251, 57}, {172, 251, 56}, + {175, 250, 55}, {177, 249, 54}, {180, 248, 54}, {183, 247, 53}, + {185, 246, 53}, {188, 245, 52}, {190, 244, 52}, {193, 243, 52}, + {195, 241, 52}, {198, 240, 52}, {200, 239, 52}, {203, 237, 52}, + {205, 236, 52}, {208, 234, 52}, {210, 233, 53}, {212, 231, 53}, + {215, 229, 53}, {217, 228, 54}, {219, 226, 54}, {221, 224, 55}, + {223, 223, 55}, {225, 221, 55}, {227, 219, 56}, {229, 217, 56}, + {231, 215, 57}, {233, 213, 57}, {235, 211, 57}, {236, 209, 58}, + {238, 207, 58}, {239, 205, 58}, {241, 203, 58}, {242, 201, 58}, + {244, 199, 58}, {245, 197, 58}, {246, 195, 58}, {247, 193, 58}, + {248, 190, 57}, {249, 188, 57}, {250, 186, 57}, {251, 184, 56}, + {251, 182, 55}, {252, 179, 54}, {252, 177, 54}, {253, 174, 53}, + {253, 172, 52}, {254, 169, 51}, {254, 167, 50}, {254, 164, 49}, + {254, 161, 48}, {254, 158, 47}, {254, 155, 45}, {254, 153, 44}, + {254, 150, 43}, {254, 147, 42}, {254, 144, 41}, {253, 141, 39}, + {253, 138, 38}, {252, 135, 37}, {252, 132, 35}, {251, 129, 34}, + {251, 126, 33}, {250, 123, 31}, {249, 120, 30}, {249, 117, 29}, + {248, 114, 28}, {247, 111, 26}, {246, 108, 25}, {245, 105, 24}, + {244, 102, 23}, {243, 99, 21}, {242, 96, 20}, {241, 93, 19}, + {240, 91, 18}, {239, 88, 17}, {237, 85, 16}, {236, 83, 15}, + {235, 80, 14}, {234, 78, 13}, {232, 75, 12}, {231, 73, 12}, + {229, 71, 11}, {228, 69, 10}, {226, 67, 10}, {225, 65, 9}, + {223, 63, 8}, {221, 61, 8}, {220, 59, 7}, {218, 57, 7}, + {216, 55, 6}, {214, 53, 6}, {212, 51, 5}, {210, 49, 5}, + {208, 47, 5}, {206, 45, 4}, {204, 43, 4}, {202, 42, 4}, + {200, 40, 3}, {197, 38, 3}, {195, 37, 3}, {193, 35, 2}, + {190, 33, 2}, {188, 32, 2}, {185, 30, 2}, {183, 29, 2}, + {180, 27, 1}, {178, 26, 1}, {175, 24, 1}, {172, 23, 1}, + {169, 22, 1}, {167, 20, 1}, {164, 19, 1}, {161, 18, 1}, + {158, 16, 1}, {155, 15, 1}, {152, 14, 1}, {149, 13, 1}, + {146, 11, 1}, {142, 10, 1}, {139, 9, 2}, {136, 8, 2}, + {133, 7, 2}, {129, 6, 2}, {126, 5, 2}, {122, 4, 3}}; + +#endif diff --git a/Modules/Core/include/mitkLookupTable.h b/Modules/Core/include/mitkLookupTable.h index 5ab7de7dba..8646564eca 100644 --- a/Modules/Core/include/mitkLookupTable.h +++ b/Modules/Core/include/mitkLookupTable.h @@ -1,274 +1,277 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef 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 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); /** * @brief Updates the output information of the current object by calling * updateOutputInformation of the data objects source object. */ void UpdateOutputInformation() override; /** * @brief Sets the requested Region to the largest possible region. * This method is not implemented, since this is the default * behavior of the itk pipeline and we do not support the * requested-region mechanism for lookup-tables */ void SetRequestedRegionToLargestPossibleRegion() override; /** * @brief Checks, if the requested region lies outside of the buffered region by * calling verifyRequestedRegion(). */ bool RequestedRegionIsOutsideOfTheBufferedRegion() override; /** * @brief 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; /** * @brief 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. + * \li TURBO An improved rainbow LookupTable for visualization. * * 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 + PET_20, + TURBO }; 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. */ virtual LookupTableType GetActiveType() const; /** * @brief Return the current look-up table type as a string. */ virtual std::string GetActiveTypeAsString() const; 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(); + virtual void BuildTurboLookupTable(); vtkSmartPointer m_LookupTable; float m_Window; float m_Level; float m_Opacity; 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 3022e09869..f8e21faa15 100644 --- a/Modules/Core/src/DataManagement/mitkLookupTable.cpp +++ b/Modules/Core/src/DataManagement/mitkLookupTable.cpp @@ -1,647 +1,666 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "mitkLookupTable.h" #include #include #include #include #include #include #include #include #include #include #include #include +#include #include 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" + "PET 20", + "Turbo" }; mitk::LookupTable::LookupTable() : m_LookupTable(vtkSmartPointer::New()) , m_Window(0.0) , m_Level(0.0) , m_Opacity(1.0) , m_Type(mitk::LookupTable::GRAYSCALE) { this->BuildGrayScaleLookupTable(); } mitk::LookupTable::LookupTable(const LookupTable &other) : itk::DataObject() , m_LookupTable(vtkSmartPointer::New()) , m_Window(other.m_Window) , m_Level(other.m_Level) , m_Opacity(other.m_Opacity) , m_Type(other.m_Type) { 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) 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::TURBO): + this->BuildTurboLookupTable(); + break; case (mitk::LookupTable::LEGACY_RAINBOW_COLOR): this->BuildLegacyRainbowColorLookupTable(); break; default: MITK_ERROR << "non-existing colormap"; return; } m_Type = type; } void mitk::LookupTable::SetType(const std::string &typeName) { for (size_t i = 0; i < typenameList.size(); ++i) { if (typenameList.at(i) == typeName) { this->SetType(static_cast(i)); } } } mitk::LookupTable::LookupTableType mitk::LookupTable::GetActiveType() const { return m_Type; } std::string mitk::LookupTable::GetActiveTypeAsString() const { 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); } 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; } bool mitk::LookupTable::operator!=(const mitk::LookupTable &other) const { return !(*this == other); } 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::BuildTurboLookupTable() +{ + auto 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)Turbo[i][0] / 255.0, (double)Turbo[i][1] / 255.0, (double)Turbo[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->Build(); lut->SetTableValue(0, 0.0, 0.0, 0.0, 0.0); // background for (int i = 0; i < 25; i++) { lut->SetTableValue(i+1, Multilabel[i][0], Multilabel[i][1], Multilabel[i][2], 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(); }