13 #ifndef mitkLabelSetImage_h
14 #define mitkLabelSetImage_h
16 #include <shared_mutex>
85 bool IsSliceSet(
int s = 0,
int t = 0,
int n = 0)
const override;
403 std::optional<GroupIndexType> index = std::make_optional<GroupIndexType>())
const;
422 itkGetConstMacro(UnlabeledLabelLock,
bool);
423 itkSetMacro(UnlabeledLabelLock,
bool);
424 itkBooleanMacro(UnlabeledLabelLock);
488 void ReplaceGroupLabels(std::map<MultiLabelSegmentation::GroupIndexType, MultiLabelSegmentation::ConstLabelVectorType> newGroupLabels);
684 template <
typename ImageType>
687 template <
typename ImageType>
690 template <
typename MultiLabelSegmentationType,
typename ImageType>
700 Image::Pointer GenerateNewGroupImage()
const;
702 std::vector<Image::Pointer> m_GroupContainer;
704 using LabelMapType = std::map<LabelValueType, Label::Pointer>;
706 LabelMapType m_LabelMap;
708 using GroupNameVectorType = std::vector<std::string>;
710 GroupNameVectorType m_Groups;
714 using GroupToLabelMapType = std::vector<LabelValueVectorType>;
716 GroupToLabelMapType m_GroupToLabelMap;
717 using LabelToGroupMapType = std::map<LabelValueType, GroupIndexType>;
719 LabelToGroupMapType m_LabelToGroupMap;
721 using LabelEventGuardMapType = std::map<LabelValueType, ITKEventObserverGuard>;
722 LabelEventGuardMapType m_LabelModEventGuardMap;
724 LookupTable::Pointer m_LookupTable;
727 bool m_UnlabeledLabelLock;
730 std::shared_mutex m_LabelNGroupMapsMutex;
794 bool orderIsRelevant =
false);
868 bool destinationBackgroundLocked =
false,
880 bool destinationBackgroundLocked =
false,
#define MITKMULTILABEL_EXPORT
virtual bool IsEmpty() const
Check whether the object contains data at any time step.
@ DefaultBehavior
Default behavior: wait for locked memory to be released.
Image class for storing multi-dimensional medical image data.
A data structure describing a label in a multi-label segmentation.
unsigned short PixelType
Pixel type used for label values (unsigned short).
MITK wrapper for a vtkLookupTable.
Event/message/notification class.
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
LabelValueType m_ActiveLabelValue
void ClearGroupImage(GroupIndexType groupID, TimeStepType timestep)
clears all label pixel content from the indicated group.
itkGetModifiableObjectMacro(LookupTable, mitk::LookupTable)
void InsertGroup(GroupIndexType groupID, ConstLabelVector labels={}, std::string name="")
Inserts a new group to the MultiLabelSegmentation. The new group will be set as the active one,...
@ RegardLocks
Locked labels in the same spatial group will not be overwritten/changed.
void RemoveGroup(GroupIndexType group)
Removes a whole group including all its labels.
void RemoveLabels(const LabelValueVectorType &vectorOfLabelPixelValues)
Removes labels from the mitk::MultiLabelSegmentation. The label is removed from the labelset and the ...
void ClearGroupImage(GroupIndexType groupID)
clears all label pixel content from the indicated group.
void SetAllLabelsLocked(bool locked)
bool ExistGroup(GroupIndexType index) const
Returns true if the spatial group exists in the MultiLabelSegmentation instance.
void ReplaceGroupLabels(const GroupIndexType groupID, const LabelVectorType &newLabels)
bool IsEmpty(LabelValueType pixelValue, TimeStepType t=0) const
static PixelType GetPixelType()
void RenameLabel(LabelValueType labelValue, const std::string &name, const Color &color)
allows to adapt name and color of a certain label
void EraseLabelProcessing(ImageType *input, LabelValueType index)
void CalculateCenterOfMassProcessing(ImageType *input, LabelValueType index)
static const LabelValueType UNLABELED_VALUE
std::size_t GroupIndexType
const std::string & GetGroupName(GroupIndexType groupID) const
const GroupImageDimensionVectorType & GetDimensions() const
Returns a vector of that contains the size (in pixel) for all dimensions of the MultiLabelSegmentatio...
void RemoveLabel(LabelValueType labelValue)
Removes the label with the given value. The label is removed from the labelset and the pixel with the...
ConstLabelVector ConstLabelVectorType
static LabelValueVectorType ExtractLabelValuesFromLabelVector(const LabelVectorType &labels)
void ReplaceGroupLabels(const GroupIndexType groupID, const ConstLabelVectorType &newLabels)
Replaces the labels of a group with a given vector of labels.
const LabelValueVectorType GetLabelValuesByGroup(GroupIndexType index) const
Returns a vector of all label values located on the specified group.
void RemoveLabelFromMap(LabelValueType labelValue)
LabelValueType GetUnusedLabelValue() const
std::vector< LabelValueType > LabelValueVectorType
LabelValueVectorType GetUsedLabelValues() const
mitk::Label * AddLabel(const std::string &name, const Color &color, GroupIndexType groupID)
Adds a new label to a group of the image by providing name and color.
mitk::Label::PixelType LabelValueType
bool IsVolumeSet(int t=0, int n=0) const override
Check whether volume at time t in channel n is set.
GroupIndexType AddGroup(ConstLabelVector labels={})
Adds a new group to the MultiLabelSegmentation. The new group will be set as the active one,...
void SetAllLabelsVisibleByName(GroupIndexType group, const std::string_view name, bool visible)
static LabelValueVectorType ExtractLabelValuesFromLabelVector(const ConstLabelVectorType &labels)
GroupIndexType GetGroupIndexOfLabel(LabelValueType value) const
mitk::Label::Pointer GetLabel(LabelValueType value)
Message AfterChangeLayerEvent
AfterchangeLayerEvent (e.g. used for GUI integration) As soon as active labelset was changed,...
const LabelValueVectorType GetAllLabelValues() const
void Initialize(const mitk::Image *templateImage, bool resetLabels=true, bool ensure1stGroup=true)
Initialize new (or re-initialize) the segmentation based on the properties and geometric information ...
void VisitLabels(const LabelValueVectorType &values, std::function< void(const Label *)> &&lambda) const
const LabelVectorType GetLabels()
void InitializeByLabeledImageProcessing(MultiLabelSegmentationType *input, const ImageType *other)
std::vector< unsigned int > GroupImageDimensionVectorType
void Initialize(const mitk::TimeGeometry *geometry, bool resetLabels=true, bool ensure1stGroup=true)
Initialize new (or re-initialize) the segmentation based on the passed time geometry information....
void InitializeByLabeledImage(const mitk::Image *image)
Initialize a new mitk::MultiLabelSegmentation by a given image. For all distinct pixel values of the ...
bool ExistLabel(LabelValueType value) const
Returns true if the value exists in the MultiLabelSegmentation instance.
static ConstLabelVectorType ConvertLabelVectorConst(const LabelVectorType &labels)
unsigned int GetDimension() const
Get dimension of the MultiLabelSegmentation instance.
unsigned int GetActiveLayer() const
Gets the ID of the currently active group.
const ConstLabelVectorType GetLabels() const
const mitk::Image * GetGroupImage(GroupIndexType groupID) const
void UpdateLookupTable(LabelValueType pixelValue)
void ReplaceLabels(const ConstLabelVectorType &labelsUpdates)
Replaces the labels in the segmentation by their passed counterparts.
void UpdateGroupImage(GroupIndexType groupID, const mitk::Image *sourceImage, TimeStepType timestep, TimeStepType sourceTimestep=0, int sourceAccessOptions=ImageAccessorBase::DefaultBehavior)
void UpdateCenterOfMass(LabelValueType pixelValue)
void MergeLabels(LabelValueType targetLabelValue, const LabelValueVectorType &sourceLabelValues, OverwriteStyle overwriteStyle=OverwriteStyle::RegardLocks)
Merges the content of a source labels into the target label.
unsigned int GetTotalNumberOfLabels() const
Returns the number of all labels summed up across all layers.
void EraseLabel(LabelValueType labelValue)
Erases the label with the given value from the labelset image. The label itself will not be erased fr...
void Initialize() override
~MultiLabelSegmentation() override
MultiLabelSegmentation(const MultiLabelSegmentation &other)
void SetAllLabelsLockedByName(GroupIndexType group, const std::string_view name, bool locked)
void MergeLabel(LabelValueType targetLabelValue, LabelValueType sourceLabelValue, OverwriteStyle overwriteStyle=OverwriteStyle::RegardLocks)
Merges the content of a source label into the target label.
void ClearGroupImages(TimeStepType timestep)
clears all label pixel content of all groups in one time step.
mitk::Label::ConstPointer GetLabel(LabelValueType value) const
Returns the mitk::Label with the given value.
const LabelValueVectorType GetLabelValuesByCoordinates(const Point3D &coordinates, TimeStepType timeStep=0, std::optional< GroupIndexType > index=std::make_optional< GroupIndexType >()) const
Returns a vector of all label values that are covering passed position in world coordinates.
void AddLabelToMap(LabelValueType labelValue, Label *label, GroupIndexType groupID)
void InsertGroup(GroupIndexType groupID, mitk::Image *layerImage, ConstLabelVector labels={}, std::string name="")
Inserts a new group to the MultiLabelSegmentation. The new group will be set as the active one,...
void ApplyToLabels(const LabelValueVectorType &values, std::function< void(Label *)> &&lambda)
std::vector< std::string > GetLabelClassNamesByGroup(GroupIndexType index) const
bool IsEmpty(const Label *label, TimeStepType t=0) const
Checks if a label is empty at a given time step (does not contain any pixels).
bool IsChannelSet(int n=0) const override
Check whether the channel n is set.
mitkClassMacro(MultiLabelSegmentation, SlicedData)
bool ExistLabel(LabelValueType value, GroupIndexType groupIndex) const
Checks if a label belongs in a certain spatial group.
void OnLabelModified(const Object *sender, const itk::EventObject &)
LabelVector LabelVectorType
void EraseLabels(const LabelValueVectorType &labelValues)
Erases a list of labels with the given values from the labelset image.
unsigned int GetNumberOfLabels(unsigned int group) const
Get the number of all existing mitk::Labels for a given group.
std::vector< std::string > GetLabelClassNames() const
void ReplaceGroupLabels(std::map< MultiLabelSegmentation::GroupIndexType, MultiLabelSegmentation::ConstLabelVectorType > newGroupLabels)
Replaces the labels of all passed group IDs (map key) with a given vector of labels (map value).
void SetActiveLabel(LabelValueType label)
Sets the active label by its value.
void ClearGroupImages()
clears all label pixel content of all groups.
const Label * GetActiveLabel() const
void SetAllLabelsVisibleByGroup(GroupIndexType group, bool visible)
void UpdateLabel(LabelValueType labelValue, const Label *templateLabel)
allows to update the properties of a certain label If a property exists in the destination label only...
itk::ModifiedTimeType GetMTime() const override
const LabelValueVectorType GetLabelValuesByName(const std::string_view name) const
Returns a vector of all label values of the segmentation having a certain name.
void ReplaceLabels(const LabelVectorType &newLabels)
const ConstLabelVectorType GetConstLabelsByValue(const LabelValueVectorType &labelValues, bool ignoreMissing=false) const
Returns a vector with const pointers to all labels in the MultiLabelSegmentation indicated by the pas...
mitk::Image * GetGroupImage(GroupIndexType groupID)
void ReleaseLabel(Label *label)
bool IsLabelLocked(LabelValueType value) const
bool IsSliceSet(int s=0, int t=0, int n=0) const override
Check whether slice s at time t in channel n is set.
unsigned int GetNumberOfGroups() const
GroupIndexType AddGroup(mitk::Image *layerImage, ConstLabelVector labels={})
Adds a group based on a provided mitk::Image.
void RegisterLabel(Label *label)
const LabelValueVectorType GetLabelValuesByName(GroupIndexType index, const std::string_view name) const
Returns a vector of all label values located on the specified group having a certain name.
mitk::Label * AddLabelWithContent(Label *label, const Image *labelContent, GroupIndexType groupID, LabelValueType contentLabelValue, bool addAsClone=true, bool correctLabelValue=true)
Adds a label instance to a group of the multi label image including its pixel content.
mitk::Label * AddLabel(Label *label, GroupIndexType groupID, bool addAsClone=true, bool correctLabelValue=true)
Adds a label instance to a group of the multi label image.
void SetLookupTable(LookupTable *lut)
const LabelVectorType GetLabelsByValue(const LabelValueVectorType &labelValues, bool ignoreMissing=true)
Returns a vector with pointers to all labels in the MultiLabelSegmentation indicated by the passed la...
void SetAllLabelsVisible(bool visible)
void SetGroupName(GroupIndexType groupID, const std::string &name)
void SetAllLabelsLockedByGroup(GroupIndexType group, bool locked)
Describes the data type of image pixels.
Super class of data objects consisting of slices.
Find image slices visible on a given plane.
std::vector< std::pair< Label::PixelType, Label::PixelType > > LabelValueMappingVector
std::vector< Label::ConstPointer > ConstLabelVector
Type alias for a vector of const Label smart pointers.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
MITKMULTILABEL_EXPORT void TransferLabelContentAtTimeStep(const MultiLabelSegmentation *sourceImage, MultiLabelSegmentation *destinationImage, const TimeStepType timeStep, LabelValueMappingVector labelMapping={ {1, 1} }, MultiLabelSegmentation::MergeStyle mergeStyle=MultiLabelSegmentation::MergeStyle::Replace, MultiLabelSegmentation::OverwriteStyle overwriteStlye=MultiLabelSegmentation::OverwriteStyle::RegardLocks)
std::vector< Label::Pointer > LabelVector
Type alias for a vector of mutable Label smart pointers.
itk::RGBPixel< float > Color
Standard RGB color typedef using float components.
MITKMULTILABEL_EXPORT void TransferLabelContent(const MultiLabelSegmentation *sourceImage, MultiLabelSegmentation *destinationImage, LabelValueMappingVector labelMapping={ {1, 1} }, MultiLabelSegmentation::MergeStyle mergeStyle=MultiLabelSegmentation::MergeStyle::Replace, MultiLabelSegmentation::OverwriteStyle overwriteStlye=MultiLabelSegmentation::OverwriteStyle::RegardLocks)
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).
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.