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

Method OnCreateCroppedMask

Modules/SegmentationUI/src/QmitkMultiLabelManager.cpp:253–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253void QmitkMultiLabelManager::OnCreateCroppedMask(bool)
254{
255 mitk::ToolManagerProvider::GetInstance()->GetToolManager()->ActivateTool(-1);
256
257 mitk::Image::Pointer maskImage;
258 auto currentLabel = this->GetMultiLabelSegmentation()->GetLabel(this->GetSelectedLabels().front());
259 try
260 {
261 this->WaitCursorOn();
262
263 if (currentLabel.IsNull())
264 mitkThrow() << "Invalid state context menu action was triggered with an invalid label id. Label id: " << this->GetSelectedLabels().front();
265
266 auto pixelValue = currentLabel->GetValue();
267
268 mitk::AutoCropImageFilter::Pointer cropFilter = mitk::AutoCropImageFilter::New();
269 cropFilter->SetInput(mitk::CreateLabelMask(this->GetMultiLabelSegmentation(),pixelValue));
270 cropFilter->SetBackgroundValue(0);
271 cropFilter->SetMarginFactor(1.15);
272 cropFilter->Update();
273
274 maskImage = cropFilter->GetOutput();
275
276 this->WaitCursorOff();
277 }
278 catch (mitk::Exception &e)
279 {
280 this->WaitCursorOff();
281 MITK_ERROR << "Exception caught: " << e.GetDescription();
282 QMessageBox::information(this, "Create Mask", "Could not create a mask out of the selected label.\n");
283 return;
284 }
285
286 if (maskImage.IsNull())
287 {
288 QMessageBox::information(this, "Create Mask", "Could not create a mask out of the selected label.\n");
289 return;
290 }
291
292 mitk::DataNode::Pointer maskNode = mitk::DataNode::New();
293 std::string name = currentLabel->GetName();
294 name += "-mask";
295 maskNode->SetName(name);
296 maskNode->SetData(maskImage);
297 maskNode->SetBoolProperty("binary", true);
298 maskNode->SetBoolProperty("outline binary", true);
299 maskNode->SetBoolProperty("outline binary shadow", true);
300 maskNode->SetFloatProperty("outline width", 2.0);
301 maskNode->SetColor(currentLabel->GetColor());
302 maskNode->SetOpacity(1.0);
303
304 m_DataStorage->Add(maskNode, this->GetMultiLabelNode());
305}
306
307void QmitkMultiLabelManager::OnCreateMask(bool /*triggered*/)
308{

Callers

nothing calls this directly

Calls 15

GetSelectedLabelsMethod · 0.95
WaitCursorOnMethod · 0.95
WaitCursorOffMethod · 0.95
GetMultiLabelNodeMethod · 0.95
ActivateToolMethod · 0.80
frontMethod · 0.80
NewFunction · 0.50
GetToolManagerMethod · 0.45
GetLabelMethod · 0.45
IsNullMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected