Medical Imaging Interaction Toolkit  2025.12.02
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 
63 
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 
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
#define MITKCORE_EXPORT
Abstract base class for properties.
The ColorProperty class RGB color property.
const mitk::Color & GetColor() const
mitkNewMacro3Param(ColorProperty, const float, const float, const float)
ColorProperty(const float color[3])
void SetColor(float red, float green, float blue)
std::string GetValueAsString() const override
void SetValue(const mitk::Color &color)
ColorProperty(const ColorProperty &other)
mitkClassMacro(ColorProperty, BaseProperty)
bool FromJSON(const nlohmann::json &j) override
Deserialize property value(s) from JSON.
bool ToJSON(nlohmann::json &j) const override
Serialize property value(s) to JSON.
void SetColor(const mitk::Color &color)
ColorProperty(const float red, const float green, const float blue)
ColorProperty(const mitk::Color &color)
mitkNewMacro1Param(ColorProperty, const mitk::Color &)
const mitk::Color & GetValue() const
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:68
nlohmann::json json
void from_json(const nlohmann::json &j, RGBPixel< TComponent > &c)
void to_json(nlohmann::json &j, const RGBPixel< TComponent > &c)
Find image slices visible on a given plane.
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
Color MakeColor(float r, float g, float b)