13 #ifndef mitkMultiLabelSegmentation_h
14 #define mitkMultiLabelSegmentation_h
16 #include <shared_mutex>
83 bool IsSliceSet(
int s = 0,
int t = 0,
int n = 0)
const override;
88 bool IsVolumeSet(
int t = 0,
int n = 0)
const override;
93 bool IsChannelSet(
int n = 0)
const override;
98 unsigned int GetDimension()
const;
259 void InsertGroup(GroupIndexType groupID,
ConstLabelVector labels = {}, std::string name =
"");
284 void RemoveGroup(GroupIndexType group);
288 bool ExistLabel(LabelValueType value)
const;
296 bool ExistLabel(LabelValueType value, GroupIndexType groupIndex)
const;
303 bool ExistGroup(GroupIndexType index)
const;
308 GroupIndexType GetGroupIndexOfLabel(LabelValueType value)
const;
325 const ConstLabelVectorType GetLabels()
const;
326 const LabelVectorType GetLabels();
330 const LabelValueVectorType GetAllLabelValues()
const;
338 const LabelVectorType GetLabelsByValue(
const LabelValueVectorType& labelValues,
bool ignoreMissing =
true);
344 const ConstLabelVectorType GetConstLabelsByValue(
const LabelValueVectorType& labelValues,
bool ignoreMissing =
false)
const;
347 static LabelValueVectorType ExtractLabelValuesFromLabelVector(
const ConstLabelVectorType& labels);
349 static LabelValueVectorType ExtractLabelValuesFromLabelVector(
const LabelVectorType& labels);
352 static ConstLabelVectorType ConvertLabelVectorConst(
const LabelVectorType& labels);
361 const LabelValueVectorType GetLabelValuesByGroup(GroupIndexType index)
const;
371 const LabelValueVectorType GetLabelValuesByName(GroupIndexType index,
const std::string_view name)
const;
376 std::vector<std::string> GetLabelClassNames()
const;
382 std::vector<std::string> GetLabelClassNamesByGroup(GroupIndexType index)
const;
388 LabelValueType GetUnusedLabelValue()
const;
390 itkGetConstMacro(UnlabeledLabelLock,
bool);
391 itkSetMacro(UnlabeledLabelLock,
bool);
392 itkBooleanMacro(UnlabeledLabelLock);
396 void SetAllLabelsVisible(
bool visible);
401 void SetAllLabelsVisibleByGroup(GroupIndexType group,
bool visible);
407 void SetAllLabelsVisibleByName(GroupIndexType group,
const std::string_view name,
bool visible);
411 bool IsLabelLocked(LabelValueType value)
const;
415 void SetAllLabelsLocked(
bool locked);
420 void SetAllLabelsLockedByGroup(GroupIndexType group,
bool locked);
426 void SetAllLabelsLockedByName(GroupIndexType group,
const std::string_view name,
bool locked);
439 void ReplaceGroupLabels(
const GroupIndexType groupID,
const ConstLabelVectorType& newLabels);
441 void ReplaceGroupLabels(
const GroupIndexType groupID,
const LabelVectorType& newLabels);
455 void ReplaceLabels(
const ConstLabelVectorType& labelsUpdates);
457 void ReplaceLabels(
const LabelVectorType& newLabels);
461 mitk::Image* GetGroupImage(GroupIndexType groupID);
465 const mitk::Image* GetGroupImage(GroupIndexType groupID)
const;
482 void ClearGroupImage(GroupIndexType groupID);
488 void ClearGroupImage(GroupIndexType groupID,
TimeStepType timestep);
494 void ClearGroupImages();
505 const std::string& GetGroupName(GroupIndexType groupID)
const;
509 void SetGroupName(GroupIndexType groupID,
const std::string& name);
512 void SetLookupTable(LookupTable* lut);
516 void UpdateLookupTable(LabelValueType pixelValue);
520 void Initialize()
override;
536 void Initialize(
const mitk::Image* templateImage,
bool resetLabels =
true,
bool ensure1stGroup =
true);
552 void Initialize(
const mitk::TimeGeometry* geometry,
bool resetLabels =
true,
bool ensure1stGroup =
true);
560 void InitializeByLabeledImage(
const mitk::Image* image);
563 itk::ModifiedTimeType GetMTime()
const override;
567 void UpdateCenterOfMass(LabelValueType pixelValue);
573 bool IsEmpty(
const Label* label,
TimeStepType t = 0)
const;
574 bool IsEmpty(LabelValueType pixelValue,
TimeStepType t = 0)
const;
581 unsigned int GetActiveLayer()
const;
583 void SetActiveLabel(LabelValueType label);
584 Label* GetActiveLabel();
585 const Label* GetActiveLabel()
const;
592 unsigned int GetNumberOfLabels(
unsigned int group)
const;
598 unsigned int GetTotalNumberOfLabels()
const;
600 unsigned int GetNumberOfGroups()
const;
605 MultiLabelSegmentation();
606 MultiLabelSegmentation(
const MultiLabelSegmentation& other);
607 ~MultiLabelSegmentation()
override;
609 void OnLabelModified(
const Object* sender,
const itk::EventObject&);
612 void AddLabelToMap(LabelValueType labelValue, Label* label, GroupIndexType groupID);
613 void RemoveLabelFromMap(LabelValueType labelValue);
615 void RegisterLabel(Label* label);
617 void ReleaseLabel(Label* label);
621 void ApplyToLabels(
const LabelValueVectorType& values, std::function<
void(Label*)>&& lambda);
625 void VisitLabels(
const LabelValueVectorType& values, std::function<
void(
const Label*)>&& lambda)
const;
629 template <
typename ImageType>
630 void CalculateCenterOfMassProcessing(ImageType* input,
LabelValueType index);
632 template <
typename ImageType>
633 void EraseLabelProcessing(ImageType* input,
LabelValueType index);
635 template <
typename MultiLabelSegmentationType,
typename ImageType>
636 void InitializeByLabeledImageProcessing(MultiLabelSegmentationType* input,
const ImageType* other);
647 std::vector<Image::Pointer> m_GroupContainer;
649 using LabelMapType = std::map<LabelValueType, Label::Pointer>;
651 LabelMapType m_LabelMap;
653 using GroupNameVectorType = std::vector<std::string>;
655 GroupNameVectorType m_Groups;
659 using GroupToLabelMapType = std::vector<LabelValueVectorType>;
661 GroupToLabelMapType m_GroupToLabelMap;
662 using LabelToGroupMapType = std::map<LabelValueType, GroupIndexType>;
664 LabelToGroupMapType m_LabelToGroupMap;
666 using LabelEventGuardMapType = std::map<LabelValueType, ITKEventObserverGuard>;
667 LabelEventGuardMapType m_LabelModEventGuardMap;
672 bool m_UnlabeledLabelLock;
675 std::shared_mutex m_LabelNGroupMapsMutex;
739 bool orderIsRelevant =
false);
813 bool destinationBackgroundLocked =
false,
825 bool destinationBackgroundLocked =
false,