Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkLabelSuggestionHelper.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 mitkLabelSuggestionHelper_h
14 #define mitkLabelSuggestionHelper_h
15 
16 #include <MitkMultilabelExports.h>
17 
18 #include <mitkLabel.h>
19 #include <mitkLabelSetImage.h>
20 
21 #include <nlohmann/json.hpp>
22 
23 #include <string>
24 #include <string_view>
25 #include <vector>
26 #include <optional>
27 
28 namespace mitk
29 {
44  class MITKMULTILABEL_EXPORT LabelSuggestionHelper : public itk::Object
45  {
46  public:
48  itkFactorylessNewMacro(Self);
49  itkCloneMacro(Self);
50 
52  static constexpr const char* PROPERTY_MAX_INSTANCE_OCCURRENCE = "_max_instance_occurrence";
53 
55 
56  struct Preferences
57  {
59  std::string externalLabelSuggestionFile = "";
61  std::string standardLabelSuggestionResource = "MitkCore:mitk_classic";
62  bool replaceStandardSuggestions = true;
63  bool enforceSuggestions = false;
66  bool suggestionOnce = true;
67  };
68 
69  // Get all relevant preferences and consider command-line arguments overrides.
71 
78  static std::map<std::string, nlohmann::json> GetAllAvailableBuiltInSuggestions();
79 
81  std::optional<nlohmann::json> GetStandardSuggesitions();
82 
84 
91  bool ParseSuggestions(const std::string& filePath, bool replaceExisting = true);
92 
99  bool ParseSuggestions(const nlohmann::json& jsonSuggestions, bool replaceExisting = true);
100 
113 
125  const std::string_view labelName) const;
126 
136  bool IsNewInstanceAllowed(const MultiLabelSegmentation* segmentation, const std::string_view labelName) const;
137 
144 
149 
155  void AddSuggestion(Label::Pointer label);
156 
157  protected:
161  LabelSuggestionHelper& operator= (const LabelSuggestionHelper&) = delete;
162 
163  private:
170  std::optional<unsigned int> GetMaxInstanceOccurrence(const std::string_view labelname) const;
171 
181  static ConstLabelVectorType FilterSuggestions(const ConstLabelVectorType& suggestions,
182  const MultiLabelSegmentation* segmentation,
183  const std::optional<std::string_view> labelName = std::nullopt);
184 
185  ConstLabelVectorType m_Suggestions;
186  };
187 
188 } // namespace mitk
189 
190 #endif // mitkLabelSuggestionHelper_h
#define MITKMULTILABEL_EXPORT
Helper class for handling label suggestions with constraint checking.
std::optional< nlohmann::json > GetStandardSuggesitions()
ConstLabelVectorType GetValidSuggestionsForNewLabels(const MultiLabelSegmentation *segmentation=nullptr) const
Get valid suggestions for adding new labels to a segmentation.
LabelSuggestionHelper(const LabelSuggestionHelper &)=delete
mitkClassMacroItkParent(LabelSuggestionHelper, itk::Object)
static Preferences GetSuggestionPreferences()
static std::map< std::string, nlohmann::json > GetAllAvailableBuiltInSuggestions()
bool ParseSuggestions(const nlohmann::json &jsonSuggestions, bool replaceExisting=true)
Parse label suggestions from a JSON object.
ConstLabelVectorType GetAllSuggestions() const
Get all currently loaded suggestions (unfiltered).
bool ParseSuggestions(const std::string &filePath, bool replaceExisting=true)
Parse label suggestions from a JSON file.
void AddSuggestion(Label::Pointer label)
Add a single suggestion manually.
ConstLabelVectorType GetValidSuggestionsForRenamingLabels(const MultiLabelSegmentation *segmentation, const std::string_view labelName) const
Get valid suggestions for renaming a specific label.
bool IsNewInstanceAllowed(const MultiLabelSegmentation *segmentation, const std::string_view labelName) const
Check if a new instance of a label is allowed.
MultiLabelSegmentation::ConstLabelVectorType ConstLabelVectorType
void ClearSuggestions()
Clear all loaded suggestions.
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
ConstLabelVector ConstLabelVectorType
nlohmann::json json
Find image slices visible on a given plane.