Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkVectorProperty.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 mitkVectorProperty_h
14 #define mitkVectorProperty_h
15 
16 // MITK
17 #include <MitkCoreExports.h>
18 #include <mitkBaseProperty.h>
19 
20 // STL
21 #include <vector>
22 
23 namespace mitk
24 {
36  template <typename D>
38  {
41  static const char *prefix() { return "Invalid"; }
42  };
43 
60  template <typename DATATYPE>
62  {
63  public:
65  typedef std::vector<DATATYPE> VectorType;
66 
67  // Manually expand most of mitkClassMacro:
68  // mitkClassMacro(VectorProperty<DATATYPE>, mitk::BaseProperty);
69  // This manual expansion is done to override explicitly
70  // the GetNameOfClass() and GetStaticNameOfClass() methods
75  std::vector<std::string> GetClassHierarchy() const override { return mitk::GetClassHierarchy<Self>(); }
76 
85  static const char *GetStaticNameOfClass()
86  {
87  // concatenate a prefix dependent on the template type and our own classname
88  static std::string nameOfClass = std::string(VectorPropertyDataType<DATATYPE>::prefix()).append("VectorProperty");
89  return nameOfClass.c_str();
90  }
91 
92  const char *GetNameOfClass() const override { return this->GetStaticNameOfClass(); }
93  itkFactorylessNewMacro(Self);
94  itkCloneMacro(Self);
95 
105  std::string GetValueAsString() const override;
106 
111  virtual const VectorType &GetValue() const;
112 
117  virtual void SetValue(const VectorType &parameter_vector);
118 
125  bool ToJSON(nlohmann::json& j) const override;
126 
133  bool FromJSON(const nlohmann::json& j) override;
134 
135  protected:
136  VectorProperty() = default;
137  VectorProperty(const Self &other) : BaseProperty(other), m_PropertyContent(other.m_PropertyContent) {}
138 
140 
141  private:
143  VectorProperty &operator=(const Self &);
144 
146  bool IsEqual(const BaseProperty &an_other_property) const override;
147 
149  bool Assign(const BaseProperty &an_other_property) override;
150 
152  VectorType m_PropertyContent;
153  };
154 
156 #define MITK_DECLARE_VECTOR_PROPERTY(TYPE, PREFIX) \
157  \
158  typedef VectorProperty<TYPE> PREFIX##VectorProperty; \
159  \
160  template <> \
161  \
162  struct VectorPropertyDataType<TYPE> \
163  { \
164  static const char *prefix() { return #PREFIX; } \
165  };
166 
168 #define MITK_DEFINE_VECTOR_PROPERTY(TYPE) template class VectorProperty<TYPE>;
169 
172 
173 } // namespace
174 
175 #endif
#define MITKCORE_EXPORT
Abstract base class for properties.
Property for storing a std::vector of values.
VectorProperty(const Self &other)
VectorProperty< DATATYPE > Self
std::vector< DATATYPE > VectorType
The type of the std::vector stored by this property.
virtual void SetValue(const VectorType &parameter_vector)
Set the content vector.
std::string GetValueAsString() const override
Return the property value as a human-readable string.
static const char * GetStaticNameOfClass()
Return the static class name including the type-dependent prefix.
std::vector< std::string > GetClassHierarchy() const override
itk::SmartPointer< const Self > ConstPointer
itk::SmartPointer< Self > Pointer
const char * GetNameOfClass() const override
VectorProperty()=default
bool FromJSON(const nlohmann::json &j) override
Deserialize the vector from a JSON array.
virtual const VectorType & GetValue() const
Get a const reference to the contained vector.
bool ToJSON(nlohmann::json &j) const override
Serialize the vector to JSON as a JSON array.
nlohmann::json json
#define MITK_DECLARE_VECTOR_PROPERTY(TYPE, PREFIX)
This should be used in .h files.
Find image slices visible on a given plane.
Helper trait for VectorProperty to determine a good ITK class name prefix.
static const char * prefix()
Return the prefix string for the class name.