Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
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 
51  {
52  protected:
54 
55  ColorProperty();
56 
57  ColorProperty(const ColorProperty &other);
58 
59  ColorProperty(const float red, const float green, const float blue);
60 
61  ColorProperty(const float color[3]);
62 
63  ColorProperty(const mitk::Color &color);
64 
65  public:
67  itkFactorylessNewMacro(Self);
68  itkCloneMacro(Self) mitkNewMacro1Param(ColorProperty, const float *);
70  mitkNewMacro3Param(ColorProperty, const float, const float, const float);
71 
72  typedef mitk::Color ValueType;
73 
74  const mitk::Color &GetColor() const;
75  const mitk::Color &GetValue() const;
76  std::string GetValueAsString() const override;
77  void SetColor(const mitk::Color &color);
78  void SetValue(const mitk::Color &color);
79  void SetColor(float red, float green, float blue);
80 
81  bool ToJSON(nlohmann::json &j) const override;
82  bool FromJSON(const nlohmann::json &j) override;
83 
84  using BaseProperty::operator=;
85 
86  private:
87  // purposely not implemented
88  ColorProperty &operator=(const ColorProperty &);
89 
90  itk::LightObject::Pointer InternalClone() const override;
91 
92  bool IsEqual(const BaseProperty &property) const override;
93  bool Assign(const BaseProperty &property) override;
94  };
95 
96 #ifdef _MSC_VER
97 #pragma warning(pop)
98 #endif
99 
100 } // namespace mitk
101 
102 namespace itk
103 {
104  template <typename TComponent>
105  void to_json(nlohmann::json& j, const RGBPixel<TComponent>& c)
106  {
107  j = nlohmann::json::array();
108 
109  for (size_t i = 0; i < 3; ++i)
110  j.push_back(c[i]);
111  }
112 
113  template <typename TComponent>
114  void from_json(const nlohmann::json& j, RGBPixel<TComponent>& c)
115  {
116  for (size_t i = 0; i < 3; ++i)
117  j.at(i).get_to(c[i]);
118  }
119 } // namespace itk
120 
121 #endif
mitk::BaseProperty
Abstract base class for properties.
Definition: mitkBaseProperty.h:36
mitk::ColorProperty::ValueType
mitk::Color ValueType
Definition: mitkColorProperty.h:70
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:53
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:105
itk::from_json
void from_json(const nlohmann::json &j, RGBPixel< TComponent > &c)
Definition: mitkColorProperty.h:114
mitk::ColorProperty
The ColorProperty class RGB color property.
Definition: mitkColorProperty.h:50
json
nlohmann::json json
Definition: mitkModelTestFixture.h:29
MitkCoreExports.h
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