MCPcopy Create free account
hub / github.com/MITK/MITK / CreateNewSegmentationNode

Method CreateNewSegmentationNode

Modules/Multilabel/src/mitkLabelSetImageHelper.cpp:111–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109
110
111mitk::DataNode::Pointer mitk::LabelSetImageHelper::CreateNewSegmentationNode(const DataNode* referenceNode,
112 const Image* initialSegmentationImage, const std::string& segmentationName, const DataStorage* dataStorage)
113{
114 std::string newSegmentationName = segmentationName;
115 if (newSegmentationName.empty())
116 {
117 newSegmentationName = (nullptr!= referenceNode)? referenceNode->GetName() : "unknown";
118
119 if (!newSegmentationName.empty())
120 newSegmentationName.append("-");
121
122 newSegmentationName.append("labels");
123 }
124
125 if (dataStorage != nullptr && dataStorage->GetNamedNode(newSegmentationName) != nullptr)
126 {
127 int id = 2;
128 std::string suffix = "-" + std::to_string(id);
129
130 while (dataStorage->GetNamedNode(newSegmentationName + suffix) != nullptr)
131 suffix = "-" + std::to_string(++id);
132
133 newSegmentationName.append(suffix);
134 }
135
136 if (nullptr == initialSegmentationImage)
137 {
138 return nullptr;
139 }
140
141 auto newLabelSetImage = mitk::MultiLabelSegmentation::New();
142 try
143 {
144 newLabelSetImage->Initialize(initialSegmentationImage);
145 }
146 catch (mitk::Exception &e)
147 {
148 mitkReThrow(e) << "Could not initialize new label set image.";
149 return nullptr;
150 }
151
152 auto newSegmentationNode = CreateEmptySegmentationNode(newSegmentationName);
153 newSegmentationNode->SetData(newLabelSetImage);
154
155 if (referenceNode != nullptr)
156 {
157 if (auto referenceImage = dynamic_cast<const Image*>(referenceNode->GetData()))
158 {
159 SetupDerivedSegmentation(newLabelSetImage, referenceImage);
160 }
161 }
162
163 return newSegmentationNode;
164}
165
166void mitk::LabelSetImageHelper::SetupDerivedSegmentation(MultiLabelSegmentation* seg,
167 const Image* source)

Callers

nothing calls this directly

Calls 7

GetNamedNodeMethod · 0.80
NewFunction · 0.50
emptyMethod · 0.45
GetNameMethod · 0.45
InitializeMethod · 0.45
SetDataMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected