Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkLabel.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 mitkLabel_h
14 #define mitkLabel_h
15 
16 #include "MitkMultilabelExports.h"
17 #include <mitkColorProperty.h>
18 #include <mitkPropertyList.h>
19 #include <mitkPoint.h>
20 #include <mitkVector.h>
21 #include <mitkPropertyKeyPath.h>
22 #include <mitkDICOMCodeSequence.h>
24 
25 #include <optional>
26 #include <map>
27 
28 namespace mitk
29 {
33  namespace LabelPropertyConstants
34  {
40 
46 
52 
58 
64 
70 
76 
82  }
83 
84  //##
85  //##Documentation
86  //## @brief A data structure describing a label.
87  //## @ingroup Data
88  //##
90  {
91  public:
93 
94  typedef unsigned short PixelType;
95 
96  itkNewMacro(Self);
97  mitkNewMacro2Param(Self, PixelType, const std::string&);
98 
101 
102  //** Value indicating pixels that are not labeled at all.*/
103  static constexpr PixelType UNLABELED_VALUE = 0;
104 
105  void SetLocked(bool locked);
106  bool GetLocked() const;
107 
108  void SetVisible(bool visible);
109  bool GetVisible() const;
110 
111  void SetOpacity(float opacity);
112  float GetOpacity() const;
113 
114  void SetName(const std::string &name);
115  std::string GetName() const;
116 
117  void SetTrackingID(const std::string& trackingID);
118  std::string GetTrackingID() const;
119 
120  void SetTrackingUID(const std::string& trackingUID);
121  std::string GetTrackingUID() const;
122 
123  void SetDescription(const std::string& description);
124  std::string GetDescription() const;
125 
127 
130  //returns the mtime of the last center of mass property update.
131  itk::ModifiedTimeType GetCenterOfMassMTime() const;
132  void UpdateCenterOfMass(const mitk::Point3D& index, const mitk::Point3D& coordinates);
133 
134  void SetColor(const mitk::Color &);
135  const mitk::Color &GetColor() const;
136 
137  void SetValue(PixelType pixelValue);
139 
140  enum class AlgorithmType
141  {
143  Undefined = 0,
145  MANUAL,
147  SEMIAUTOMATIC,
149  AUTOMATIC
150  };
151 
153  void SetAlgorithmTypeStr(const std::string& algoType);
155  std::string GetAlgorithmTypeStr() const;
156  void SetAlgorithmName(const std::string& algoName);
157  std::string GetAlgorithmName() const;
158 
164  void AddToolUse(AlgorithmType algoType, const std::string& algoName);
165 
171  void SetAnatomicRegion(const DICOMCodeSequenceWithModifiers& code, std::size_t index = 0);
172 
178  DICOMCodeSequenceWithModifiers GetAnatomicRegion(std::size_t index = 0) const;
179 
184  std::size_t GetAnatomicRegionCount() const;
185 
190  void RemoveAnatomicRegion(std::size_t index);
191 
197  void SetPrimaryAnatomicStructure(const DICOMCodeSequenceWithModifiers& code, std::size_t index = 0);
198 
205 
210  std::size_t GetPrimaryAnatomicStructureCount() const;
211 
216  void RemovePrimaryAnatomicStructure(std::size_t index);
217 
223 
228  std::optional<DICOMCodeSequence> GetSegmentedPropertyCategory() const;
229 
235 
240  std::optional<DICOMCodeSequenceWithModifiers> GetSegmentedPropertyType() const;
241 
242  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
243  BaseProperty::ConstPointer GetConstProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = true) const override;
244  BaseProperty* GetNonConstProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = true) override;
245 
246  using itk::Object::Modified;
247  void Modified() { Superclass::Modified(); }
248 
255  void Update(const Label* templateLabel, bool updateLabelValue = false);
256 
257  Label();
258  Label(PixelType value, const std::string& name);
259  ~Label() override;
260 
261  protected:
262  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
264 
265  Label(const Label &other);
266 
267  void SetCenterOfMassIndex(const mitk::Point3D& center);
269 
270  private:
271  PixelType m_Value;
272 
273  itk::LightObject::Pointer InternalClone() const override;
274 
281  void SetDICOMCodeSequenceAsProperties(const PropertyKeyPath& basePath,
282  const DICOMCodeSequence& code,
283  bool withModifiers);
284 
290  std::optional<DICOMCodeSequence> GetDICOMCodeSequenceFromProperties(const PropertyKeyPath& basePath) const;
291 
297  std::optional<DICOMCodeSequenceWithModifiers> GetDICOMCodeSequenceWithModifiersFromProperties(const PropertyKeyPath& basePath) const;
298 
303  void RemoveDICOMCodeSequenceProperties(const PropertyKeyPath& basePath);
304  };
305 
306  using LabelVector = std::vector<Label::Pointer>;
307  using ConstLabelVector = std::vector<Label::ConstPointer>;
308 
323  MITKMULTILABEL_EXPORT bool Equal(const mitk::Label &leftHandSide,
324  const mitk::Label &rightHandSide,
325  ScalarType eps,
326  bool verbose);
327 
328 } // namespace mitk
329 
330 #endif
#define MITKMULTILABEL_EXPORT
Abstract base class for properties.
Represents a DICOM Code Sequence with optional modifiers.
Represents a DICOM Code Sequence with value, scheme, and meaning.
A data structure describing a label.
Definition: mitkLabel.h:90
DICOMCodeSequenceWithModifiers GetAnatomicRegion(std::size_t index=0) const
Gets an anatomic region code at the specified index.
std::string GetAlgorithmName() const
void ResetCenterOfMass()
BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) override
Get property by its key.
mitk::Point3D GetCenterOfMassCoordinates() const
void Update(const Label *templateLabel, bool updateLabelValue=false)
Function updates the property values of a label provided as templates. If a property exists in the de...
void Modified()
Definition: mitkLabel.h:247
~Label() override
bool GetVisible() const
void SetValue(PixelType pixelValue)
void SetPrimaryAnatomicStructure(const DICOMCodeSequenceWithModifiers &code, std::size_t index=0)
Sets a primary anatomic structure code at the specified index.
void SetTrackingID(const std::string &trackingID)
std::string GetName() const
mitkNewMacro2Param(Self, PixelType, const std::string &)
std::optional< DICOMCodeSequence > GetSegmentedPropertyCategory() const
Gets the segmented property category code.
void SetOpacity(float opacity)
void SetAlgorithmName(const std::string &algoName)
void SetSegmentedPropertyType(const DICOMCodeSequenceWithModifiers &code)
Sets the segmented property type code with optional modifiers.
void SetCenterOfMassCoordinates(const mitk::Point3D &center)
mitk::Point3D GetCenterOfMassIndex() const
std::string GetDescription() const
void SetAnatomicRegion(const DICOMCodeSequenceWithModifiers &code, std::size_t index=0)
Sets an anatomic region code at the specified index.
AlgorithmType GetAlgorithmType() const
void SetAlgorithmType(AlgorithmType algoType)
std::string GetAlgorithmTypeStr() const
std::string GetTrackingUID() const
void SetSegmentedPropertyCategory(const DICOMCodeSequence &code)
Sets the segmented property category code.
void SetTrackingUID(const std::string &trackingUID)
float GetOpacity() const
unsigned short PixelType
Definition: mitkLabel.h:94
void SetName(const std::string &name)
void SetLocked(bool locked)
BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) const override
Get property by its key.
PixelType GetValue() const
void UpdateCenterOfMass(const mitk::Point3D &index, const mitk::Point3D &coordinates)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void SetVisible(bool visible)
std::size_t GetPrimaryAnatomicStructureCount() const
Gets the number of primary anatomic structure codes stored.
Label(const Label &other)
bool GetLocked() const
DICOMCodeSequenceWithModifiers GetPrimaryAnatomicStructure(std::size_t index=0) const
Gets a primary anatomic structure code at the specified index.
const mitk::Color & GetColor() const
void SetCenterOfMassIndex(const mitk::Point3D &center)
Label(PixelType value, const std::string &name)
std::optional< DICOMCodeSequenceWithModifiers > GetSegmentedPropertyType() const
Gets the segmented property type code with modifiers.
std::string GetTrackingID() const
mitkClassMacro(Label, mitk::PropertyList)
std::size_t GetAnatomicRegionCount() const
Gets the number of anatomic region codes stored.
itk::ModifiedTimeType GetCenterOfMassMTime() const
void SetAlgorithmTypeStr(const std::string &algoType)
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
static const PixelType MAX_LABEL_VALUE
The maximum value a label can get: Since the value is of type unsigned short MAX_LABEL_VALUE = 65535.
Definition: mitkLabel.h:100
void AddToolUse(AlgorithmType algoType, const std::string &algoName)
Helper function to add the usage of multiple tools correctly to the label. Mixture of types always le...
void RemovePrimaryAnatomicStructure(std::size_t index)
Removes a primary anatomic structure code at the specified index.
void RemoveAnatomicRegion(std::size_t index)
Removes an anatomic region code at the specified index.
void SetDescription(const std::string &description)
void SetColor(const mitk::Color &)
Class that can be used to specify nested or wild carded property keys. E.g. for the use in context of...
Key-value list holding instances of BaseProperty.
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
MITKMULTILABEL_EXPORT const std::string & GetSchemePropertySubName()
Gets the property key path element for code scheme.
MITKMULTILABEL_EXPORT const std::string & GetPrimaryAnatomicStructurePropertyBaseName()
Gets the property key path element for primary anatomic structure.
MITKMULTILABEL_EXPORT const std::string & GetAnatomicRegionPropertyBaseName()
Gets the property key path element for anatomic region.
MITKMULTILABEL_EXPORT const std::string & GetMeaningPropertySubName()
Gets the property key path element for code meaning.
MITKMULTILABEL_EXPORT const std::string & GetValuePropertySubName()
Gets the property key path element for code value.
MITKMULTILABEL_EXPORT const std::string & GetSegmentedPropertyCategoryPropertyBaseName()
Gets the property key path element for segmented property category.
MITKMULTILABEL_EXPORT const std::string & GetModifierPropertySubName()
Gets the property key path element for modifier.
MITKMULTILABEL_EXPORT const std::string & GetSegmentedPropertyTypePropertyBaseName()
Gets the property key path element for segmented property type.
Find image slices visible on a given plane.
std::vector< Label::ConstPointer > ConstLabelVector
Definition: mitkLabel.h:307
MITKCORE_EXPORT const ScalarType eps
std::vector< Label::Pointer > LabelVector
Definition: mitkLabel.h:306
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
double ScalarType
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.