| 251 | } |
| 252 | |
| 253 | void 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 | |
| 307 | void QmitkMultiLabelManager::OnCreateMask(bool /*triggered*/) |
| 308 | { |
nothing calls this directly
no test coverage detected