Medical Imaging Interaction Toolkit  2026.06.00
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 
101  {
102  public:
104 
106  typedef unsigned short PixelType;
107 
108  itkNewMacro(Self);
109  mitkNewMacro2Param(Self, PixelType, const std::string&);
110 
113 
115  static constexpr PixelType UNLABELED_VALUE = 0;
116 
122  void SetLocked(bool locked);
123 
128  bool GetLocked() const;
129 
134  void SetVisible(bool visible);
135 
140  bool GetVisible() const;
141 
146  void SetOpacity(float opacity);
147 
152  float GetOpacity() const;
153 
158  void SetName(const std::string &name);
159 
164  std::string GetName() const;
165 
170  void SetTrackingID(const std::string& trackingID);
171 
176  std::string GetTrackingID() const;
177 
186  bool HasTrackingID() const;
187 
192  void SetTrackingUID(const std::string& trackingUID);
193 
198  std::string GetTrackingUID() const;
199 
209  bool HasTrackingUID() const;
210 
215  void SetDescription(const std::string& description);
216 
221  std::string GetDescription() const;
222 
229 
236 
241 
246  itk::ModifiedTimeType GetCenterOfMassMTime() const;
247 
253  void UpdateCenterOfMass(const mitk::Point3D& index, const mitk::Point3D& coordinates);
254 
259  void SetColor(const mitk::Color & color);
260 
265  const mitk::Color &GetColor() const;
266 
271  void SetValue(PixelType pixelValue);
272 
278 
282  enum class AlgorithmType
283  {
284  Undefined = 0,
285  MANUAL,
286  SEMIAUTOMATIC,
287  AUTOMATIC
288  };
289 
295 
300  void SetAlgorithmTypeStr(const std::string& algoType);
301 
307 
312  std::string GetAlgorithmTypeStr() const;
313 
318  void SetAlgorithmName(const std::string& algoName);
319 
324  std::string GetAlgorithmName() const;
325 
334  bool HasAlgorithmName() const;
335 
355  void AddToolUse(AlgorithmType algoType, const std::string& algoName);
356 
368  void MergeToolUses(const Label* other);
369 
375  void SetAnatomicRegion(const DICOMCodeSequenceWithModifiers& code, std::size_t index = 0);
376 
382  DICOMCodeSequenceWithModifiers GetAnatomicRegion(std::size_t index = 0) const;
383 
388  std::size_t GetAnatomicRegionCount() const;
389 
394  void RemoveAnatomicRegion(std::size_t index);
395 
401  void SetPrimaryAnatomicStructure(const DICOMCodeSequenceWithModifiers& code, std::size_t index = 0);
402 
409 
414  std::size_t GetPrimaryAnatomicStructureCount() const;
415 
420  void RemovePrimaryAnatomicStructure(std::size_t index);
421 
427 
432  std::optional<DICOMCodeSequence> GetSegmentedPropertyCategory() const;
433 
439 
444  std::optional<DICOMCodeSequenceWithModifiers> GetSegmentedPropertyType() const;
445 
453  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
454 
462  BaseProperty::ConstPointer GetConstProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = true) const override;
463 
471  BaseProperty* GetNonConstProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = true) override;
472 
473  using itk::Object::Modified;
475  void Modified() { Superclass::Modified(); }
476 
483  void Update(const Label* templateLabel, bool updateLabelValue = false);
484 
491  Label();
492 
498  Label(PixelType value, const std::string& name);
499 
501  ~Label() override;
502 
503  protected:
504  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
506 
507  Label(const Label &other);
508 
510 
511  void SetCenterOfMassIndex(const mitk::Point3D& center);
513 
514  private:
515  PixelType m_Value;
516 
523  void SetDICOMCodeSequenceAsProperties(const PropertyKeyPath& basePath,
524  const DICOMCodeSequence& code,
525  bool withModifiers);
526 
532  std::optional<DICOMCodeSequence> GetDICOMCodeSequenceFromProperties(const PropertyKeyPath& basePath) const;
533 
539  std::optional<DICOMCodeSequenceWithModifiers> GetDICOMCodeSequenceWithModifiersFromProperties(const PropertyKeyPath& basePath) const;
540 
545  void RemoveDICOMCodeSequenceProperties(const PropertyKeyPath& basePath);
546  };
547 
549  using LabelVector = std::vector<Label::Pointer>;
550 
552  using ConstLabelVector = std::vector<Label::ConstPointer>;
553 
568  MITKMULTILABEL_EXPORT bool Equal(const mitk::Label &leftHandSide,
569  const mitk::Label &rightHandSide,
570  ScalarType eps,
571  bool verbose);
572 
573 } // namespace mitk
574 
575 #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 in a multi-label segmentation.
Definition: mitkLabel.h:101
DICOMCodeSequenceWithModifiers GetAnatomicRegion(std::size_t index=0) const
Gets an anatomic region code at the specified index.
mitkCloneMacro(Label)
std::string GetAlgorithmName() const
Returns the name of the algorithm used to create or modify this label.
void ResetCenterOfMass()
Resets (clears) the center of mass properties.
BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) override
Returns a non-const pointer to the property with the given key.
mitk::Point3D GetCenterOfMassCoordinates() const
Returns the center of mass of the label in world coordinates.
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...
bool HasAlgorithmName() const
Returns whether an algorithm name property is set on the label.
void Modified()
Marks this label as modified.
Definition: mitkLabel.h:475
~Label() override
Destructor.
bool GetVisible() const
Returns the visibility state of the label.
void MergeToolUses(const Label *other)
Absorbs another label's recorded provenance (algorithm type and tool names) into this one.
void SetValue(PixelType pixelValue)
Sets the pixel value that identifies this label in the segmentation image.
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)
Sets the DICOM tracking ID of the label.
std::string GetName() const
Returns the (class) name of the label.
mitkNewMacro2Param(Self, PixelType, const std::string &)
std::optional< DICOMCodeSequence > GetSegmentedPropertyCategory() const
Gets the segmented property category code.
void SetOpacity(float opacity)
Sets the opacity of the label for rendering.
void SetAlgorithmName(const std::string &algoName)
Sets the name of the algorithm used to create or modify this label.
void SetSegmentedPropertyType(const DICOMCodeSequenceWithModifiers &code)
Sets the segmented property type code with optional modifiers.
bool HasTrackingUID() const
Returns whether a tracking UID property is set on the label.
void SetCenterOfMassCoordinates(const mitk::Point3D &center)
mitk::Point3D GetCenterOfMassIndex() const
Returns the center of mass of the label as image index coordinates.
std::string GetDescription() const
Returns the textual description of the label.
void SetAnatomicRegion(const DICOMCodeSequenceWithModifiers &code, std::size_t index=0)
Sets an anatomic region code at the specified index.
AlgorithmType GetAlgorithmType() const
Returns the algorithm type used to create or modify this label.
void SetAlgorithmType(AlgorithmType algoType)
Sets the algorithm type that was used to create or modify this label.
std::string GetAlgorithmTypeStr() const
Returns the algorithm type as a string.
std::string GetTrackingUID() const
Returns the DICOM tracking unique identifier (UID) of the label.
void SetSegmentedPropertyCategory(const DICOMCodeSequence &code)
Sets the segmented property category code.
void SetTrackingUID(const std::string &trackingUID)
Sets the DICOM tracking unique identifier (UID) of the label.
float GetOpacity() const
Returns the opacity of the label.
unsigned short PixelType
Pixel type used for label values (unsigned short).
Definition: mitkLabel.h:106
void SetName(const std::string &name)
Sets the (class) name of the label.
void SetLocked(bool locked)
Sets the lock state of the label.
BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) const override
Returns a const pointer to the property with the given key.
PixelType GetValue() const
Returns the pixel value that identifies this label in the segmentation image.
void UpdateCenterOfMass(const mitk::Point3D &index, const mitk::Point3D &coordinates)
Updates the center of mass with new index and world coordinates.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
AlgorithmType
Enumeration describing how a label was created or refined.
Definition: mitkLabel.h:283
void SetColor(const mitk::Color &color)
Sets the display color of the label.
void SetVisible(bool visible)
Sets the visibility state of the label for rendering.
std::size_t GetPrimaryAnatomicStructureCount() const
Gets the number of primary anatomic structure codes stored.
Label(const Label &other)
bool GetLocked() const
Returns the lock state of the label.
DICOMCodeSequenceWithModifiers GetPrimaryAnatomicStructure(std::size_t index=0) const
Gets a primary anatomic structure code at the specified index.
const mitk::Color & GetColor() const
Returns the display color of the label.
void SetCenterOfMassIndex(const mitk::Point3D &center)
Label(PixelType value, const std::string &name)
Constructor that creates a label with a specified pixel value and name.
std::optional< DICOMCodeSequenceWithModifiers > GetSegmentedPropertyType() const
Gets the segmented property type code with modifiers.
std::string GetTrackingID() const
Returns the DICOM tracking ID of the label.
mitkClassMacro(Label, mitk::PropertyList)
std::size_t GetAnatomicRegionCount() const
Gets the number of anatomic region codes stored.
itk::ModifiedTimeType GetCenterOfMassMTime() const
Returns the modification time of the last center of mass property update.
void SetAlgorithmTypeStr(const std::string &algoType)
Sets the algorithm type from a string representation.
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Sets a property on this label.
static const PixelType MAX_LABEL_VALUE
The maximum value a label can have (65535 for unsigned short).
Definition: mitkLabel.h:112
void AddToolUse(AlgorithmType algoType, const std::string &algoName)
Records that a tool/operation contributed to this label, updating algorithm type and name.
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.
bool HasTrackingID() const
Returns whether a tracking ID property is set on the label.
void SetDescription(const std::string &description)
Sets a textual description for the label.
Label()
Default constructor. Creates a label with default properties.
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
Type alias for a vector of const Label smart pointers.
Definition: mitkLabel.h:552
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
std::vector< Label::Pointer > LabelVector
Type alias for a vector of mutable Label smart pointers.
Definition: mitkLabel.h:549
itk::RGBPixel< float > Color
Standard RGB color typedef using float components.
double ScalarType
Scalar type used throughout MITK for geometric computations.
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.