diff --git a/Modules/Core/include/Colortables/Inferno.h b/Modules/Core/include/Colortables/Inferno.h new file mode 100644 index 0000000000..9434cfe203 --- /dev/null +++ b/Modules/Core/include/Colortables/Inferno.h @@ -0,0 +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 _lut_Inferno_h_ +#define _lut_Inferno_h_ + +static const int Inferno[256][3] = +{ +{ 0, 0, 4 },{ 1, 0, 5 },{ 1, 1, 6 },{ 1, 1, 8 },{ 2, 1, 10 },{ 2, 2, 12 },{ 2, 2, 14 },{ 3, 2, 16 },{ 4, 3, 18 },{ 4, 3, 20 }, +{ 5, 4, 23 },{ 6, 4, 25 },{ 7, 5, 27 },{ 8, 5, 29 },{ 9, 6, 31 },{ 10, 7, 34 },{ 11, 7, 36 },{ 12, 8, 38 },{ 13, 8, 41 },{ 14, 9, 43 }, +{ 16, 9, 45 },{ 17, 10, 48 },{ 18, 10, 50 },{ 20, 11, 52 },{ 21, 11, 55 },{ 22, 11, 57 },{ 24, 12, 60 },{ 25, 12, 62 },{ 27, 12, 65 }, +{ 28, 12, 67 },{ 30, 12, 69 },{ 31, 12, 72 },{ 33, 12, 74 },{ 35, 12, 76 },{ 36, 12, 79 },{ 38, 12, 81 },{ 40, 11, 83 },{ 41, 11, 85 }, +{ 43, 11, 87 },{ 45, 11, 89 },{ 47, 10, 91 },{ 49, 10, 92 },{ 50, 10, 94 },{ 52, 10, 95 },{ 54, 9, 97 },{ 56, 9, 98 },{ 57, 9, 99 }, +{ 59, 9, 100 },{ 61, 9, 101 },{ 62, 9, 102 },{ 64, 10, 103 },{ 66, 10, 104 },{ 68, 10, 104 },{ 69, 10, 105 },{ 71, 11, 106 }, +{ 73, 11, 106 },{ 74, 12, 107 },{ 76, 12, 107 },{ 77, 13, 108 },{ 79, 13, 108 },{ 81, 14, 108 },{ 82, 14, 109 },{ 84, 15, 109 }, +{ 85, 15, 109 },{ 87, 16, 110 },{ 89, 16, 110 },{ 90, 17, 110 },{ 92, 18, 110 },{ 93, 18, 110 },{ 95, 19, 110 },{ 97, 19, 110 }, +{ 98, 20, 110 },{ 100, 21, 110 },{ 101, 21, 110 },{ 103, 22, 110 },{ 105, 22, 110 },{ 106, 23, 110 },{ 108, 24, 110 },{ 109, 24, 110 }, +{ 111, 25, 110 },{ 113, 25, 110 },{ 114, 26, 110 },{ 116, 26, 110 },{ 117, 27, 110 },{ 119, 28, 109 },{ 120, 28, 109 },{ 122, 29, 109 }, +{ 124, 29, 109 },{ 125, 30, 109 },{ 127, 30, 108 },{ 128, 31, 108 },{ 130, 32, 108 },{ 132, 32, 107 },{ 133, 33, 107 },{ 135, 33, 107 }, +{ 136, 34, 106 },{ 138, 34, 106 },{ 140, 35, 105 },{ 141, 35, 105 },{ 143, 36, 105 },{ 144, 37, 104 },{ 146, 37, 104 },{ 147, 38, 103 }, +{ 149, 38, 103 },{ 151, 39, 102 },{ 152, 39, 102 },{ 154, 40, 101 },{ 155, 41, 100 },{ 157, 41, 100 },{ 159, 42, 99 },{ 160, 42, 99 }, +{ 162, 43, 98 },{ 163, 44, 97 },{ 165, 44, 96 },{ 166, 45, 96 },{ 168, 46, 95 },{ 169, 46, 94 },{ 171, 47, 94 },{ 173, 48, 93 }, +{ 174, 48, 92 },{ 176, 49, 91 },{ 177, 50, 90 },{ 179, 50, 90 },{ 180, 51, 89 },{ 182, 52, 88 },{ 183, 53, 87 },{ 185, 53, 86 }, +{ 186, 54, 85 },{ 188, 55, 84 },{ 189, 56, 83 },{ 191, 57, 82 },{ 192, 58, 81 },{ 193, 58, 80 },{ 195, 59, 79 },{ 196, 60, 78 }, +{ 198, 61, 77 },{ 199, 62, 76 },{ 200, 63, 75 },{ 202, 64, 74 },{ 203, 65, 73 },{ 204, 66, 72 },{ 206, 67, 71 },{ 207, 68, 70 }, +{ 208, 69, 69 },{ 210, 70, 68 },{ 211, 71, 67 },{ 212, 72, 66 },{ 213, 74, 65 },{ 215, 75, 63 },{ 216, 76, 62 },{ 217, 77, 61 }, +{ 218, 78, 60 },{ 219, 80, 59 },{ 221, 81, 58 },{ 222, 82, 56 },{ 223, 83, 55 },{ 224, 85, 54 },{ 225, 86, 53 },{ 226, 87, 52 }, +{ 227, 89, 51 },{ 228, 90, 49 },{ 229, 92, 48 },{ 230, 93, 47 },{ 231, 94, 46 },{ 232, 96, 45 },{ 233, 97, 43 },{ 234, 99, 42 }, +{ 235, 100, 41 },{ 235, 102, 40 },{ 236, 103, 38 },{ 237, 105, 37 },{ 238, 106, 36 },{ 239, 108, 35 },{ 239, 110, 33 },{ 240, 111, 32 }, +{ 241, 113, 31 },{ 241, 115, 29 },{ 242, 116, 28 },{ 243, 118, 27 },{ 243, 120, 25 },{ 244, 121, 24 },{ 245, 123, 23 },{ 245, 125, 21 }, +{ 246, 126, 20 },{ 246, 128, 19 },{ 247, 130, 18 },{ 247, 132, 16 },{ 248, 133, 15 },{ 248, 135, 14 },{ 248, 137, 12 },{ 249, 139, 11 }, +{ 249, 140, 10 },{ 249, 142, 9 },{ 250, 144, 8 },{ 250, 146, 7 },{ 250, 148, 7 },{ 251, 150, 6 },{ 251, 151, 6 },{ 251, 153, 6 }, +{ 251, 155, 6 },{ 251, 157, 7 },{ 252, 159, 7 },{ 252, 161, 8 },{ 252, 163, 9 },{ 252, 165, 10 },{ 252, 166, 12 },{ 252, 168, 13 }, +{ 252, 170, 15 },{ 252, 172, 17 },{ 252, 174, 18 },{ 252, 176, 20 },{ 252, 178, 22 },{ 252, 180, 24 },{ 251, 182, 26 },{ 251, 184, 29 }, +{ 251, 186, 31 },{ 251, 188, 33 },{ 251, 190, 35 },{ 250, 192, 38 },{ 250, 194, 40 },{ 250, 196, 42 },{ 250, 198, 45 },{ 249, 199, 47 }, +{ 249, 201, 50 },{ 249, 203, 53 },{ 248, 205, 55 },{ 248, 207, 58 },{ 247, 209, 61 },{ 247, 211, 64 },{ 246, 213, 67 },{ 246, 215, 70 }, +{ 245, 217, 73 },{ 245, 219, 76 },{ 244, 221, 79 },{ 244, 223, 83 },{ 244, 225, 86 },{ 243, 227, 90 },{ 243, 229, 93 },{ 242, 230, 97 }, +{ 242, 232, 101 },{ 242, 234, 105 },{ 241, 236, 109 },{ 241, 237, 113 },{ 241, 239, 117 },{ 241, 241, 121 },{ 242, 242, 125 }, +{ 242, 244, 130 },{ 243, 245, 134 },{ 243, 246, 138 },{ 244, 248, 142 },{ 245, 249, 146 },{ 246, 250, 150 },{ 248, 251, 154 }, +{ 249, 252, 157 },{ 250, 253, 161 },{ 252, 255, 164 } +}; + +#endif diff --git a/Modules/Core/include/Colortables/Viridis.h b/Modules/Core/include/Colortables/Viridis.h new file mode 100644 index 0000000000..f1d329438f --- /dev/null +++ b/Modules/Core/include/Colortables/Viridis.h @@ -0,0 +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 _lut_Viridis_h_ +#define _lut_Viridis_h_ + +static const int Viridis[256][3] = +{ +{ 68, 1, 84 },{ 68, 2, 86 },{ 69, 4, 87 },{ 69, 5, 89 },{ 70, 7, 90 },{ 70, 8, 92 },{ 70, 10, 93 },{ 70, 11, 94 }, +{ 71, 13, 96 },{ 71, 14, 97 },{ 71, 16, 99 },{ 71, 17, 100 },{ 71, 19, 101 },{ 72, 20, 103 },{ 72, 22, 104 },{ 72, 23, 105 }, +{ 72, 24, 106 },{ 72, 26, 108 },{ 72, 27, 109 },{ 72, 28, 110 },{ 72, 29, 111 },{ 72, 31, 112 },{ 72, 32, 113 },{ 72, 33, 115 }, +{ 72, 35, 116 },{ 72, 36, 117 },{ 72, 37, 118 },{ 72, 38, 119 },{ 72, 40, 120 },{ 72, 41, 121 },{ 71, 42, 122 },{ 71, 44, 122 }, +{ 71, 45, 123 },{ 71, 46, 124 },{ 71, 47, 125 },{ 70, 48, 126 },{ 70, 50, 126 },{ 70, 51, 127 },{ 70, 52, 128 },{ 69, 53, 129 }, +{ 69, 55, 129 },{ 69, 56, 130 },{ 68, 57, 131 },{ 68, 58, 131 },{ 68, 59, 132 },{ 67, 61, 132 },{ 67, 62, 133 },{ 66, 63, 133 }, +{ 66, 64, 134 },{ 66, 65, 134 },{ 65, 66, 135 },{ 65, 68, 135 },{ 64, 69, 136 },{ 64, 70, 136 },{ 63, 71, 136 },{ 63, 72, 137 }, +{ 62, 73, 137 },{ 62, 74, 137 },{ 62, 76, 138 },{ 61, 77, 138 },{ 61, 78, 138 },{ 60, 79, 138 },{ 60, 80, 139 },{ 59, 81, 139 }, +{ 59, 82, 139 },{ 58, 83, 139 },{ 58, 84, 140 },{ 57, 85, 140 },{ 57, 86, 140 },{ 56, 88, 140 },{ 56, 89, 140 },{ 55, 90, 140 }, +{ 55, 91, 141 },{ 54, 92, 141 },{ 54, 93, 141 },{ 53, 94, 141 },{ 53, 95, 141 },{ 52, 96, 141 },{ 52, 97, 141 },{ 51, 98, 141 }, +{ 51, 99, 141 },{ 50, 100, 142 },{ 50, 101, 142 },{ 49, 102, 142 },{ 49, 103, 142 },{ 49, 104, 142 },{ 48, 105, 142 },{ 48, 106, 142 }, +{ 47, 107, 142 },{ 47, 108, 142 },{ 46, 109, 142 },{ 46, 110, 142 },{ 46, 111, 142 },{ 45, 112, 142 },{ 45, 113, 142 },{ 44, 113, 142 }, +{ 44, 114, 142 },{ 44, 115, 142 },{ 43, 116, 142 },{ 43, 117, 142 },{ 42, 118, 142 },{ 42, 119, 142 },{ 42, 120, 142 },{ 41, 121, 142 }, +{ 41, 122, 142 },{ 41, 123, 142 },{ 40, 124, 142 },{ 40, 125, 142 },{ 39, 126, 142 },{ 39, 127, 142 },{ 39, 128, 142 },{ 38, 129, 142 }, +{ 38, 130, 142 },{ 38, 130, 142 },{ 37, 131, 142 },{ 37, 132, 142 },{ 37, 133, 142 },{ 36, 134, 142 },{ 36, 135, 142 },{ 35, 136, 142 }, +{ 35, 137, 142 },{ 35, 138, 141 },{ 34, 139, 141 },{ 34, 140, 141 },{ 34, 141, 141 },{ 33, 142, 141 },{ 33, 143, 141 },{ 33, 144, 141 }, +{ 33, 145, 140 },{ 32, 146, 140 },{ 32, 146, 140 },{ 32, 147, 140 },{ 31, 148, 140 },{ 31, 149, 139 },{ 31, 150, 139 },{ 31, 151, 139 }, +{ 31, 152, 139 },{ 31, 153, 138 },{ 31, 154, 138 },{ 30, 155, 138 },{ 30, 156, 137 },{ 30, 157, 137 },{ 31, 158, 137 },{ 31, 159, 136 }, +{ 31, 160, 136 },{ 31, 161, 136 },{ 31, 161, 135 },{ 31, 162, 135 },{ 32, 163, 134 },{ 32, 164, 134 },{ 33, 165, 133 },{ 33, 166, 133 }, +{ 34, 167, 133 },{ 34, 168, 132 },{ 35, 169, 131 },{ 36, 170, 131 },{ 37, 171, 130 },{ 37, 172, 130 },{ 38, 173, 129 },{ 39, 173, 129 }, +{ 40, 174, 128 },{ 41, 175, 127 },{ 42, 176, 127 },{ 44, 177, 126 },{ 45, 178, 125 },{ 46, 179, 124 },{ 47, 180, 124 },{ 49, 181, 123 }, +{ 50, 182, 122 },{ 52, 182, 121 },{ 53, 183, 121 },{ 55, 184, 120 },{ 56, 185, 119 },{ 58, 186, 118 },{ 59, 187, 117 },{ 61, 188, 116 }, +{ 63, 188, 115 },{ 64, 189, 114 },{ 66, 190, 113 },{ 68, 191, 112 },{ 70, 192, 111 },{ 72, 193, 110 },{ 74, 193, 109 },{ 76, 194, 108 }, +{ 78, 195, 107 },{ 80, 196, 106 },{ 82, 197, 105 },{ 84, 197, 104 },{ 86, 198, 103 },{ 88, 199, 101 },{ 90, 200, 100 },{ 92, 200, 99 }, +{ 94, 201, 98 },{ 96, 202, 96 },{ 99, 203, 95 },{ 101, 203, 94 },{ 103, 204, 92 },{ 105, 205, 91 },{ 108, 205, 90 },{ 110, 206, 88 }, +{ 112, 207, 87 },{ 115, 208, 86 },{ 117, 208, 84 },{ 119, 209, 83 },{ 122, 209, 81 },{ 124, 210, 80 },{ 127, 211, 78 },{ 129, 211, 77 }, +{ 132, 212, 75 },{ 134, 213, 73 },{ 137, 213, 72 },{ 139, 214, 70 },{ 142, 214, 69 },{ 144, 215, 67 },{ 147, 215, 65 },{ 149, 216, 64 }, +{ 152, 216, 62 },{ 155, 217, 60 },{ 157, 217, 59 },{ 160, 218, 57 },{ 162, 218, 55 },{ 165, 219, 54 },{ 168, 219, 52 },{ 170, 220, 50 }, +{ 173, 220, 48 },{ 176, 221, 47 },{ 178, 221, 45 },{ 181, 222, 43 },{ 184, 222, 41 },{ 186, 222, 40 },{ 189, 223, 38 },{ 192, 223, 37 }, +{ 194, 223, 35 },{ 197, 224, 33 },{ 200, 224, 32 },{ 202, 225, 31 },{ 205, 225, 29 },{ 208, 225, 28 },{ 210, 226, 27 },{ 213, 226, 26 }, +{ 216, 226, 25 },{ 218, 227, 25 },{ 221, 227, 24 },{ 223, 227, 24 },{ 226, 228, 24 },{ 229, 228, 25 },{ 231, 228, 25 },{ 234, 229, 26 }, +{ 236, 229, 27 },{ 239, 229, 28 },{ 241, 229, 29 },{ 244, 230, 30 },{ 246, 230, 32 },{ 248, 230, 33 },{ 251, 231, 35 },{ 253, 231, 37 } +}; + +#endif diff --git a/Modules/Core/include/mitkLookupTable.h b/Modules/Core/include/mitkLookupTable.h index d658bddb10..1e3339e157 100644 --- a/Modules/Core/include/mitkLookupTable.h +++ b/Modules/Core/include/mitkLookupTable.h @@ -1,267 +1,271 @@ /*=================================================================== 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 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, LEGACY_BINARY, LEGACY_RAINBOW_COLOR, MULTILABEL, PET_COLOR, PET_20 }; static const char *const 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 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; 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 194381ba02..9844b8cf3d 100644 --- a/Modules/Core/src/DataManagement/mitkLookupTable.cpp +++ b/Modules/Core/src/DataManagement/mitkLookupTable.cpp @@ -1,603 +1,645 @@ /*=================================================================== 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 const char *const mitk::LookupTable::typenameList[] = { "Grayscale", "Inverse Grayscale", "Hot Iron", "Jet", "Jet Transparent", "Plasma", + "Inferno", + "Viridis", "Legacy Binary", "Legacy Rainbow Color", "Multilabel", "PET Color", "PET 20", "END_OF_ARRAY" // Do not add typenames after this entry (see QmitkDataManagerView::ColormapMenuAboutToShow()) }; 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) 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::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; } void mitk::LookupTable::SetType(const std::string &typeName) { int i = 0; std::string lutType = this->typenameList[i]; while (lutType != "END_OF_ARRAY") { if (lutType == typeName) { this->SetType(static_cast(i)); } lutType = this->typenameList[++i]; } } const std::string mitk::LookupTable::GetActiveTypeAsString() { return std::string(typenameList[(int)m_type]); } 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(); } \ No newline at end of file