Medical Imaging Interaction Toolkit  2024.12.99-67e306ee
Medical Imaging Interaction Toolkit
mitkColorProperty.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkColorProperty_h
14 #define mitkColorProperty_h
15 
16 #include <mitkBaseProperty.h>
17 #include <MitkCoreExports.h>
18 
19 #include <itkRGBPixel.h>
20 
21 #include <nlohmann/json.hpp>
22 
23 namespace mitk
24 {
25 #ifdef _MSC_VER
26 #pragma warning(push)
27 #pragma warning(disable : 4522)
28 #endif
29 
38  typedef itk::RGBPixel<float> Color;
39 
40  inline Color MakeColor(float r, float g, float b)
41  {
42  Color color;
43  color.Set(r, g, b);
44  return color;
45  }
46 
58  {
59  protected:
61 
62  ColorProperty();
63 
64  ColorProperty(const ColorProperty &other);
65 
66  ColorProperty(const float red, const float green, const float blue);
67 
68  ColorProperty(const float color[3]);
69 
70  ColorProperty(const mitk::Color &color);
71 
72  public:
74  itkFactorylessNewMacro(Self);
75  itkCloneMacro(Self) mitkNewMacro1Param(ColorProperty, const float *);
77  mitkNewMacro3Param(ColorProperty, const float, const float, const float);
78 
79  typedef mitk::Color ValueType;
80 
81  const mitk::Color &GetColor() const;
82  const mitk::Color &GetValue() const;
83  std::string GetValueAsString() const override;
84  void SetColor(const mitk::Color &color);
85  void SetValue(const mitk::Color &color);
86  void SetColor(float red, float green, float blue);
87 
88  bool ToJSON(nlohmann::json &j) const override;
89  bool FromJSON(const nlohmann::json &j) override;
90 
91  using BaseProperty::operator=;
92 
93  private:
94  // purposely not implemented
95  ColorProperty &operator=(const ColorProperty &);
96 
97  itk::LightObject::Pointer InternalClone() const override;
98 
99  bool IsEqual(const BaseProperty &property) const override;
100  bool Assign(const BaseProperty &property) override;
101  };
102 
103 #ifdef _MSC_VER
104 #pragma warning(pop)
105 #endif
106 
107 } // namespace mitk
108 
109 namespace itk
110 {
111  template <typename TComponent>
112  void to_json(nlohmann::json& j, const RGBPixel<TComponent>& c)
113  {
114  j = nlohmann::json::array();
115 
116  for (size_t i = 0; i < 3; ++i)
117  j.push_back(c[i]);
118  }
119 
120  template <typename TComponent>
121  void from_json(const nlohmann::json& j, RGBPixel<TComponent>& c)
122  {
123  for (size_t i = 0; i < 3; ++i)
124  j.at(i).get_to(c[i]);
125  }
126 } // namespace itk
127 
128 #endif
mitk::BaseProperty
Abstract base class for properties.
Definition: mitkBaseProperty.h:36
mitk::ColorProperty::ValueType
mitk::Color ValueType
Definition: mitkColorProperty.h:77
mitk::FromJSON
MITKCORE_EXPORT void FromJSON(const nlohmann::json &j, AffineTransform3D::Pointer transform)
Read transform from JSON array (16 elements, resp. 4x4 matrix).
mitk::ColorProperty::m_Color
mitk::Color m_Color
Definition: mitkColorProperty.h:60
mitk::MakeColor
Color MakeColor(float r, float g, float b)
Definition: mitkColorProperty.h:40
mitkNewMacro1Param
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:68
mitk::Color
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
Definition: mitkColorProperty.h:38
mitkNewMacro3Param
#define mitkNewMacro3Param(classname, typea, typeb, typec)
Definition: mitkCommon.h:94
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
itk::to_json
void to_json(nlohmann::json &j, const RGBPixel< TComponent > &c)
Definition: mitkColorProperty.h:112
itk::from_json
void from_json(const nlohmann::json &j, RGBPixel< TComponent > &c)
Definition: mitkColorProperty.h:121
mitk::ColorProperty
The ColorProperty class RGB color property.
Definition: mitkColorProperty.h:57
json
nlohmann::json json
Definition: mitkModelTestFixture.h:29
MitkCoreExports.h
mitk::nnInteractive::GetColor
const MITKPYTHONSEGMENTATION_EXPORT Color & GetColor(PromptType promptType, ColorIntensity colorIntensity)
Returns the color associated with a specific prompt type and color intensity.
mitk::ToJSON
MITKCORE_EXPORT void ToJSON(nlohmann::json &j, AffineTransform3D::ConstPointer transform)
Write transform (4x4 matrix) as JSON array with 16 elements.
itk
SET FUNCTIONS.
Definition: itkIntelligentBinaryClosingFilter.h:30
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitkBaseProperty.h
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15