24 #include "itkOrImageFilter.h"
44 m_UpperThreshold(200),
54 if (this->m_SmoothFilter.IsNotNull())
55 this->m_SmoothFilter->RemoveAllObservers();
57 if (this->m_SigmoidFilter.IsNotNull())
58 this->m_SigmoidFilter->RemoveAllObservers();
60 if (this->m_GradientMagnitudeFilter.IsNotNull())
61 this->m_GradientMagnitudeFilter->RemoveAllObservers();
63 if (this->m_FastMarchingFilter.IsNotNull())
64 this->m_FastMarchingFilter->RemoveAllObservers();
95 return "2D Fast Marching";
102 m_ReferenceImageSlice = GetAffectedReferenceSlice(m_PositionEvent);
103 CastToItkImage(m_ReferenceImageSlice, m_ReferenceImageSliceAsITK);
108 m_SmoothFilter->SetInput(m_ReferenceImageSliceAsITK);
109 m_SmoothFilter->SetTimeStep(0.05);
110 m_SmoothFilter->SetNumberOfIterations(2);
111 m_SmoothFilter->SetConductanceParameter(9.0);
114 m_GradientMagnitudeFilter->SetSigma(m_Sigma);
117 m_SigmoidFilter->SetAlpha(m_Alpha);
118 m_SigmoidFilter->SetBeta(m_Beta);
119 m_SigmoidFilter->SetOutputMinimum(0.0);
120 m_SigmoidFilter->SetOutputMaximum(1.0);
123 m_FastMarchingFilter->SetStoppingValue(m_StoppingValue);
126 m_ThresholdFilter->SetLowerThreshold(m_LowerThreshold);
127 m_ThresholdFilter->SetUpperThreshold(m_UpperThreshold);
128 m_ThresholdFilter->SetOutsideValue(0);
129 m_ThresholdFilter->SetInsideValue(1.0);
132 m_SeedContainer->Initialize();
133 m_FastMarchingFilter->SetTrialPoints(m_SeedContainer);
135 if (this->m_SmoothFilter.IsNotNull())
136 this->m_SmoothFilter->RemoveAllObservers();
138 if (this->m_SigmoidFilter.IsNotNull())
139 this->m_SigmoidFilter->RemoveAllObservers();
141 if (this->m_GradientMagnitudeFilter.IsNotNull())
142 this->m_GradientMagnitudeFilter->RemoveAllObservers();
144 if (this->m_FastMarchingFilter.IsNotNull())
145 this->m_FastMarchingFilter->RemoveAllObservers();
147 m_SmoothFilter->AddObserver(itk::ProgressEvent(), m_ProgressCommand);
148 m_GradientMagnitudeFilter->AddObserver(itk::ProgressEvent(), m_ProgressCommand);
149 m_SigmoidFilter->AddObserver(itk::ProgressEvent(), m_ProgressCommand);
150 m_FastMarchingFilter->AddObserver(itk::ProgressEvent(), m_ProgressCommand);
152 m_SmoothFilter->SetInput(m_ReferenceImageSliceAsITK);
153 m_GradientMagnitudeFilter->SetInput(m_SmoothFilter->GetOutput());
154 m_SigmoidFilter->SetInput(m_GradientMagnitudeFilter->GetOutput());
155 m_FastMarchingFilter->SetInput(m_SigmoidFilter->GetOutput());
156 m_ThresholdFilter->SetInput(m_FastMarchingFilter->GetOutput());
162 if (m_UpperThreshold != value)
164 m_UpperThreshold = value / 10.0;
165 m_ThresholdFilter->SetUpperThreshold(m_UpperThreshold);
172 if (m_LowerThreshold != value)
174 m_LowerThreshold = value / 10.0;
175 m_ThresholdFilter->SetLowerThreshold(m_LowerThreshold);
185 m_SigmoidFilter->SetBeta(m_Beta);
192 if (m_Sigma != value)
195 m_GradientMagnitudeFilter->SetSigma(m_Sigma);
202 if (m_Alpha != value)
205 m_SigmoidFilter->SetAlpha(m_Alpha);
212 if (m_StoppingValue != value)
214 m_StoppingValue = value;
215 m_FastMarchingFilter->SetStoppingValue(m_StoppingValue);
222 Superclass::Activated();
225 m_ResultImageNode->SetName(
"FastMarching_Preview");
226 m_ResultImageNode->SetBoolProperty(
"helper object",
true);
227 m_ResultImageNode->SetColor(0.0, 1.0, 0.0);
228 m_ResultImageNode->SetVisibility(
true);
229 m_ToolManager->GetDataStorage()->Add(this->m_ResultImageNode, m_ToolManager->GetReferenceData(0));
233 m_SeedsAsPointSetNode->SetData(m_SeedsAsPointSet);
234 m_SeedsAsPointSetNode->SetName(
"Seeds_Preview");
235 m_SeedsAsPointSetNode->SetBoolProperty(
"helper object",
true);
236 m_SeedsAsPointSetNode->SetColor(0.0, 1.0, 0.0);
237 m_SeedsAsPointSetNode->SetVisibility(
true);
238 m_ToolManager->GetDataStorage()->Add(this->m_SeedsAsPointSetNode, m_ToolManager->GetReferenceData(0));
245 m_ToolManager->GetDataStorage()->Remove(this->m_ResultImageNode);
246 m_ToolManager->GetDataStorage()->Remove(this->m_SeedsAsPointSetNode);
248 m_ResultImageNode = NULL;
249 m_SeedsAsPointSetNode = NULL;
252 Superclass::Deactivated();
257 m_ReferenceImage =
dynamic_cast<mitk::Image *
>(m_ToolManager->GetReferenceData(0)->GetData());
258 if (m_ReferenceImage->GetTimeGeometry()->CountTimeSteps() > 1)
261 timeSelector->SetInput(m_ReferenceImage);
262 timeSelector->SetTimeNr(m_CurrentTimeStep);
263 timeSelector->UpdateLargestPossibleRegion();
264 m_ReferenceImage = timeSelector->GetOutput();
272 if (dynamic_cast<mitk::Image *>(m_ResultImageNode->GetData()))
278 workingImageSlice = GetAffectedImageSliceAs2DImage(m_WorkingPlane, workingImage, m_CurrentTimeStep);
282 bool isDeprecatedUnsignedCharSegmentation =
283 (workingImage->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR);
285 if (isDeprecatedUnsignedCharSegmentation)
287 typedef itk::Image<unsigned char, 2> OutputUCharImageType;
292 typedef itk::OrImageFilter<OutputImageType, OutputUCharImageType, OutputUCharImageType> OrImageFilterType;
295 orFilter->SetInput1(m_ThresholdFilter->GetOutput());
296 orFilter->SetInput2(workingImageSliceInITK);
307 typedef itk::OrImageFilter<OutputImageType, OutputImageType> OrImageFilterType;
310 orFilter->SetInput(0, m_ThresholdFilter->GetOutput());
311 orFilter->SetInput(1, workingImageSliceInITK);
317 segmentationResult->GetGeometry()->SetOrigin(workingImageSlice->GetGeometry()->GetOrigin());
318 segmentationResult->GetGeometry()->SetIndexToWorldTransform(
319 workingImageSlice->GetGeometry()->GetIndexToWorldTransform());
323 this->WriteBackSegmentationResult(m_WorkingPlane, segmentationResult, m_CurrentTimeStep);
324 this->m_ResultImageNode->SetVisibility(
false);
330 m_ToolManager->ActivateTool(-1);
338 if (positionEvent == NULL)
341 if (m_PositionEvent.IsNotNull())
342 m_PositionEvent = NULL;
348 if ((m_LastEventSender != m_PositionEvent->GetSender()) ||
349 (m_LastEventSlice != m_PositionEvent->GetSender()->GetSlice()))
351 this->BuildITKPipeline();
355 m_LastEventSender = m_PositionEvent->GetSender();
356 m_LastEventSlice = m_LastEventSender->GetSlice();
361 m_ReferenceImageSlice->GetGeometry()->WorldToIndex(m_PositionEvent->GetPositionInWorld(), clickInIndex);
363 seedPosition[0] = clickInIndex[0];
364 seedPosition[1] = clickInIndex[1];
367 const double seedValue = 0.0;
368 node.SetValue(seedValue);
369 node.SetIndex(seedPosition);
370 this->m_SeedContainer->InsertElement(this->m_SeedContainer->Size(), node);
371 m_FastMarchingFilter->Modified();
373 m_SeedsAsPointSet->InsertPoint(m_SeedsAsPointSet->GetSize(), m_PositionEvent->GetPositionInWorld());
381 m_ReadyMessage.Send();
387 if (!(this->m_SeedContainer->empty()))
390 this->m_SeedContainer->pop_back();
391 m_FastMarchingFilter->Modified();
394 m_SeedsAsPointSet->GetPointSet()->GetPoints()->DeleteIndex(m_SeedsAsPointSet->GetSize() - 1);
406 const unsigned int progress_steps = 20;
411 m_ProgressCommand->AddStepsToDo(progress_steps);
412 CurrentlyBusy.Send(
true);
415 m_ThresholdFilter->Update();
417 catch (itk::ExceptionObject &excep)
419 MITK_ERROR <<
"Exception caught: " << excep.GetDescription();
422 m_ProgressCommand->SetProgress(progress_steps);
423 CurrentlyBusy.Send(
false);
425 std::string msg = excep.GetDescription();
426 ErrorMessage.Send(msg);
430 m_ProgressCommand->SetProgress(progress_steps);
431 CurrentlyBusy.Send(
false);
436 result->GetGeometry()->SetOrigin(m_ReferenceImageSlice->GetGeometry()->GetOrigin());
437 result->GetGeometry()->SetIndexToWorldTransform(m_ReferenceImageSlice->GetGeometry()->GetIndexToWorldTransform());
438 m_ResultImageNode->SetData(result);
439 m_ResultImageNode->SetVisibility(
true);
447 if (this->m_SeedContainer.IsNotNull())
448 this->m_SeedContainer->Initialize();
450 if (this->m_SeedsAsPointSet.IsNotNull())
453 this->m_SeedsAsPointSetNode->SetData(this->m_SeedsAsPointSet);
454 m_SeedsAsPointSetNode->SetName(
"Seeds_Preview");
455 m_SeedsAsPointSetNode->SetBoolProperty(
"helper object",
true);
456 m_SeedsAsPointSetNode->SetColor(0.0, 1.0, 0.0);
457 m_SeedsAsPointSetNode->SetVisibility(
true);
460 if (this->m_FastMarchingFilter.IsNotNull())
461 m_FastMarchingFilter->Modified();
463 this->m_NeedUpdate =
true;
471 m_ResultImageNode->SetVisibility(
false);
478 if (m_CurrentTimeStep != t)
480 m_CurrentTimeStep = t;
Super class for all position events.
itk::SmartPointer< Self > Pointer
BaseRenderer * GetSender() const
static void Update(vtkPolyData *)
#define MITKSEGMENTATION_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
Constants for most interaction classes, due to the generic StateMachines.
static Pointer New(BaseRenderer *_arga, const Point2D &_argb)
Point2D GetPointerPositionOnScreen() const
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
Module * GetModule() const
Image class for storing images.
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
#define CONNECT_FUNCTION(a, f)
ModuleResource GetResource(const std::string &path) const
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.