Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitk::LabelSuggestionHelper Class Reference

Helper class for handling label suggestions with constraint checking. More...

#include <mitkLabelSuggestionHelper.h>

Inheritance diagram for mitk::LabelSuggestionHelper:
Collaboration diagram for mitk::LabelSuggestionHelper:

Classes

struct  Preferences
 

Public Types

using ConstLabelVectorType = MultiLabelSegmentation::ConstLabelVectorType
 

Public Member Functions

 mitkClassMacroItkParent (LabelSuggestionHelper, itk::Object)
 
Pointer Clone () const
 
std::optional< nlohmann::jsonGetStandardSuggesitions ()
 
void LoadStandardSuggestions ()
 
bool ParseSuggestions (const std::string &filePath, bool replaceExisting=true)
 Parse label suggestions from a JSON file. More...
 
bool ParseSuggestions (const nlohmann::json &jsonSuggestions, bool replaceExisting=true)
 Parse label suggestions from a JSON object. More...
 
ConstLabelVectorType GetValidSuggestionsForNewLabels (const MultiLabelSegmentation *segmentation=nullptr) const
 Get valid suggestions for adding new labels to a segmentation. More...
 
ConstLabelVectorType GetValidSuggestionsForRenamingLabels (const MultiLabelSegmentation *segmentation, const std::string_view labelName) const
 Get valid suggestions for renaming a specific label. More...
 
bool IsNewInstanceAllowed (const MultiLabelSegmentation *segmentation, const std::string_view labelName) const
 Check if a new instance of a label is allowed. More...
 
ConstLabelVectorType GetAllSuggestions () const
 Get all currently loaded suggestions (unfiltered). More...
 
void ClearSuggestions ()
 Clear all loaded suggestions. More...
 
void AddSuggestion (Label::Pointer label)
 Add a single suggestion manually. More...
 

Static Public Member Functions

static Pointer New ()
 
static Preferences GetSuggestionPreferences ()
 
static std::map< std::string, nlohmann::jsonGetAllAvailableBuiltInSuggestions ()
 

Static Public Attributes

static constexpr const char * PROPERTY_MAX_INSTANCE_OCCURRENCE
 

Protected Member Functions

 LabelSuggestionHelper ()
 
 ~LabelSuggestionHelper ()
 
 LabelSuggestionHelper (const LabelSuggestionHelper &)=delete
 
LabelSuggestionHelperoperator= (const LabelSuggestionHelper &)=delete
 

Detailed Description

Helper class for handling label suggestions with constraint checking.

This class provides functionality to:

  • Parse label suggestions from JSON files (both new MITK stack format and legacy format)
  • Filter suggestions based on occurrence constraints
  • Determine valid suggestions for adding new labels (instances)
  • Determine valid suggestions for renaming existing labels
  • Check if new label instances are allowed

The helper supports special label properties:

  • _max_instance_occurrence: Maximum number of instances of a specific label

Definition at line 44 of file mitkLabelSuggestionHelper.h.

Member Typedef Documentation

◆ ConstLabelVectorType

Constructor & Destructor Documentation

◆ LabelSuggestionHelper() [1/2]

mitk::LabelSuggestionHelper::LabelSuggestionHelper ( )
protected

◆ ~LabelSuggestionHelper()

mitk::LabelSuggestionHelper::~LabelSuggestionHelper ( )
protected

◆ LabelSuggestionHelper() [2/2]

mitk::LabelSuggestionHelper::LabelSuggestionHelper ( const LabelSuggestionHelper )
protecteddelete

Member Function Documentation

◆ AddSuggestion()

void mitk::LabelSuggestionHelper::AddSuggestion ( Label::Pointer  label)

Add a single suggestion manually.

Parameters
labelThe label to add as a suggestion

◆ ClearSuggestions()

void mitk::LabelSuggestionHelper::ClearSuggestions ( )

Clear all loaded suggestions.

◆ Clone()

Pointer mitk::LabelSuggestionHelper::Clone ( ) const

◆ GetAllAvailableBuiltInSuggestions()

static std::map<std::string, nlohmann::json> mitk::LabelSuggestionHelper::GetAllAvailableBuiltInSuggestions ( )
static

Get all built-in suggestions for labels compiled into on of the modules. The function searches all modules for resources in the sub folder "/LabelSuggestions".

Returns
map with key value pairs where the value is the json representing the found configuration and the key is a ID string in the format "<module_name>:<resource_basename>"; one example is e.g. "MitkCore:mitk_classic" will point to the resource "LabelSuggestions/mitk_classic.json" of MitkCore module.

◆ GetAllSuggestions()

ConstLabelVectorType mitk::LabelSuggestionHelper::GetAllSuggestions ( ) const

Get all currently loaded suggestions (unfiltered).

Returns
Vector of all suggestions

◆ GetStandardSuggesitions()

std::optional<nlohmann::json> mitk::LabelSuggestionHelper::GetStandardSuggesitions ( )

Get the built-in label suggestion config that is currently indicated by the preferences.

◆ GetSuggestionPreferences()

static Preferences mitk::LabelSuggestionHelper::GetSuggestionPreferences ( )
static

◆ GetValidSuggestionsForNewLabels()

ConstLabelVectorType mitk::LabelSuggestionHelper::GetValidSuggestionsForNewLabels ( const MultiLabelSegmentation segmentation = nullptr) const

Get valid suggestions for adding new labels to a segmentation.

Filters suggestions based on:

  • Occurrence constraints (_max_instance_occurrence)
  • Suggest-once policy (if enabled)
  • Existing labels in the segmentation
Parameters
segmentationThe segmentation to check against (can be nullptr)
Returns
Vector of valid label suggestions

◆ GetValidSuggestionsForRenamingLabels()

ConstLabelVectorType mitk::LabelSuggestionHelper::GetValidSuggestionsForRenamingLabels ( const MultiLabelSegmentation segmentation,
const std::string_view  labelName 
) const

Get valid suggestions for renaming a specific label.

Returns suggestions that would be valid if the given label were renamed. Takes into account that renaming removes the old label name from the count.

Parameters
segmentationThe segmentation containing the label
labelNameThe label name that should be checked for renaming
Returns
Vector of valid label suggestions for renaming

◆ IsNewInstanceAllowed()

bool mitk::LabelSuggestionHelper::IsNewInstanceAllowed ( const MultiLabelSegmentation segmentation,
const std::string_view  labelName 
) const

Check if a new instance of a label is allowed.

Checks the _max_instance_occurrence constraint if present.

Parameters
segmentationThe segmentation to check against
labelNameThe label name that should be checked for if another instance is allowed.
Returns
true if a new instance is allowed, false otherwise

◆ LoadStandardSuggestions()

void mitk::LabelSuggestionHelper::LoadStandardSuggestions ( )

◆ mitkClassMacroItkParent()

mitk::LabelSuggestionHelper::mitkClassMacroItkParent ( LabelSuggestionHelper  ,
itk::Object   
)

◆ New()

static Pointer mitk::LabelSuggestionHelper::New ( )
static

◆ operator=()

LabelSuggestionHelper& mitk::LabelSuggestionHelper::operator= ( const LabelSuggestionHelper )
protecteddelete

◆ ParseSuggestions() [1/2]

bool mitk::LabelSuggestionHelper::ParseSuggestions ( const nlohmann::json jsonSuggestions,
bool  replaceExisting = true 
)

Parse label suggestions from a JSON object.

Parameters
jsonSuggestionssuggestions stored as json object
replaceExistingIf true, replace all existing suggestions; if false, merge with existing
Returns
true if parsing was successful, false otherwise

◆ ParseSuggestions() [2/2]

bool mitk::LabelSuggestionHelper::ParseSuggestions ( const std::string &  filePath,
bool  replaceExisting = true 
)

Parse label suggestions from a JSON file.

Parameters
filePathPath to the JSON file
replaceExistingIf true, replace all existing suggestions; if false, merge with existing
Returns
true if parsing was successful, false otherwise

Member Data Documentation

◆ PROPERTY_MAX_INSTANCE_OCCURRENCE

constexpr const char* mitk::LabelSuggestionHelper::PROPERTY_MAX_INSTANCE_OCCURRENCE
staticconstexpr

Property names for occurrence constraints

Definition at line 52 of file mitkLabelSuggestionHelper.h.


The documentation for this class was generated from the following file: