24 #include "itkOrImageFilter.h"
44 m_UpperThreshold(200),
58 if (referenceData == NULL)
61 Image *image =
dynamic_cast<Image *
>(referenceData);
86 return "Fast Marching 3D";
91 m_UpperThreshold = value / 10.0;
92 m_ThresholdFilter->SetUpperThreshold(m_UpperThreshold);
98 m_LowerThreshold = value / 10.0;
99 m_ThresholdFilter->SetLowerThreshold(m_LowerThreshold);
108 m_SigmoidFilter->SetBeta(m_Beta);
115 if (m_Sigma != value)
120 m_GradientMagnitudeFilter->SetSigma(m_Sigma);
128 if (m_Alpha != value)
131 m_SigmoidFilter->SetAlpha(m_Alpha);
138 if (m_StoppingValue != value)
140 m_StoppingValue = value;
141 m_FastMarchingFilter->SetStoppingValue(m_StoppingValue);
148 Superclass::Activated();
151 m_ResultImageNode->SetName(
"FastMarching_Preview");
152 m_ResultImageNode->SetBoolProperty(
"helper object",
true);
153 m_ResultImageNode->SetColor(0.0, 1.0, 0.0);
154 m_ResultImageNode->SetVisibility(
true);
155 m_ToolManager->GetDataStorage()->Add(this->m_ResultImageNode, m_ToolManager->GetReferenceData(0));
159 m_SeedsAsPointSetNode->SetData(m_SeedsAsPointSet);
160 m_SeedsAsPointSetNode->SetName(
"3D_FastMarching_PointSet");
161 m_SeedsAsPointSetNode->SetBoolProperty(
"helper object",
true);
162 m_SeedsAsPointSetNode->SetColor(0.0, 1.0, 0.0);
163 m_SeedsAsPointSetNode->SetVisibility(
true);
168 m_SeedPointInteractor->LoadStateMachine(
"PointSet.xml");
170 m_SeedPointInteractor->SetEventConfig(
"PointSetConfig.xml");
172 m_SeedPointInteractor->SetDataNode(m_SeedsAsPointSetNode);
179 m_ThresholdFilter->SetLowerThreshold(m_LowerThreshold);
180 m_ThresholdFilter->SetUpperThreshold(m_UpperThreshold);
181 m_ThresholdFilter->SetOutsideValue(0);
182 m_ThresholdFilter->SetInsideValue(1.0);
185 m_SmoothFilter->AddObserver(itk::ProgressEvent(), m_ProgressCommand);
186 m_SmoothFilter->SetTimeStep(0.05);
187 m_SmoothFilter->SetNumberOfIterations(2);
188 m_SmoothFilter->SetConductanceParameter(9.0);
191 m_GradientMagnitudeFilter->AddObserver(itk::ProgressEvent(), m_ProgressCommand);
192 m_GradientMagnitudeFilter->SetSigma(m_Sigma);
195 m_SigmoidFilter->AddObserver(itk::ProgressEvent(), m_ProgressCommand);
196 m_SigmoidFilter->SetAlpha(m_Alpha);
197 m_SigmoidFilter->SetBeta(m_Beta);
198 m_SigmoidFilter->SetOutputMinimum(0.0);
199 m_SigmoidFilter->SetOutputMaximum(1.0);
202 m_FastMarchingFilter->AddObserver(itk::ProgressEvent(), m_ProgressCommand);
203 m_FastMarchingFilter->SetStoppingValue(m_StoppingValue);
206 m_SeedContainer->Initialize();
207 m_FastMarchingFilter->SetTrialPoints(m_SeedContainer);
210 m_SmoothFilter->SetInput(m_ReferenceImageAsITK);
211 m_GradientMagnitudeFilter->SetInput(m_SmoothFilter->GetOutput());
212 m_SigmoidFilter->SetInput(m_GradientMagnitudeFilter->GetOutput());
213 m_FastMarchingFilter->SetInput(m_SigmoidFilter->GetOutput());
214 m_ThresholdFilter->SetInput(m_FastMarchingFilter->GetOutput());
216 m_ToolManager->GetDataStorage()->Add(m_SeedsAsPointSetNode, m_ToolManager->GetWorkingData(0));
221 m_PointSetAddObserverTag = m_SeedsAsPointSet->AddObserver(mitk::PointSetAddEvent(), pointAddedCommand);
226 m_PointSetRemoveObserverTag = m_SeedsAsPointSet->AddObserver(mitk::PointSetRemoveEvent(), pointRemovedCommand);
233 m_ToolManager->GetDataStorage()->Remove(this->m_ResultImageNode);
234 m_ToolManager->GetDataStorage()->Remove(this->m_SeedsAsPointSetNode);
236 this->m_SmoothFilter->RemoveAllObservers();
237 this->m_SigmoidFilter->RemoveAllObservers();
238 this->m_GradientMagnitudeFilter->RemoveAllObservers();
239 this->m_FastMarchingFilter->RemoveAllObservers();
240 m_ResultImageNode = NULL;
243 unsigned int numberOfPoints = m_SeedsAsPointSet->GetSize();
244 for (
unsigned int i = 0; i < numberOfPoints; ++i)
248 m_SeedsAsPointSet->ExecuteOperation(doOp);
251 m_SeedPointInteractor->SetDataNode(NULL);
252 m_ToolManager->GetDataStorage()->Remove(m_SeedsAsPointSetNode);
253 m_SeedsAsPointSetNode = NULL;
254 m_SeedsAsPointSet->RemoveObserver(m_PointSetAddObserverTag);
255 m_SeedsAsPointSet->RemoveObserver(m_PointSetRemoveObserverTag);
257 Superclass::Deactivated();
262 m_ReferenceImage =
dynamic_cast<mitk::Image *
>(m_ToolManager->GetReferenceData(0)->GetData());
263 if (m_ReferenceImage->GetTimeGeometry()->CountTimeSteps() > 1)
266 timeSelector->SetInput(m_ReferenceImage);
267 timeSelector->SetTimeNr(m_CurrentTimeStep);
268 timeSelector->UpdateLargestPossibleRegion();
269 m_ReferenceImage = timeSelector->GetOutput();
272 m_SmoothFilter->SetInput(m_ReferenceImageAsITK);
279 if (dynamic_cast<mitk::Image *>(m_ResultImageNode->GetData()))
285 if (workingImage->GetTimeGeometry()->CountTimeSteps() > 1)
288 timeSelector->SetInput(workingImage);
289 timeSelector->SetTimeNr(m_CurrentTimeStep);
290 timeSelector->UpdateLargestPossibleRegion();
291 CastToItkImage(timeSelector->GetOutput(), segmentationImageInITK);
298 typedef itk::OrImageFilter<OutputImageType, OutputImageType> OrImageFilterType;
301 orFilter->SetInput(0, m_ThresholdFilter->GetOutput());
302 orFilter->SetInput(1, segmentationImageInITK);
306 workingImage->SetVolume((
void *)(m_ThresholdFilter->GetOutput()->GetPixelContainer()->GetBufferPointer()),
308 this->m_ResultImageNode->SetVisibility(
false);
310 workingImage->Modified();
314 m_ToolManager->ActivateTool(-1);
322 m_ReferenceImage->GetGeometry()->WorldToIndex(m_SeedsAsPointSet->GetPoint(m_SeedsAsPointSet->GetSize() - 1),
325 seedPosition[0] = clickInIndex[0];
326 seedPosition[1] = clickInIndex[1];
327 seedPosition[2] = clickInIndex[2];
330 const double seedValue = 0.0;
331 node.SetValue(seedValue);
332 node.SetIndex(seedPosition);
333 this->m_SeedContainer->InsertElement(this->m_SeedContainer->Size(), node);
334 m_FastMarchingFilter->Modified();
342 m_ReadyMessage.Send();
348 if (!(this->m_SeedContainer->empty()))
351 this->m_SeedContainer->pop_back();
352 m_FastMarchingFilter->Modified();
364 const unsigned int progress_steps = 200;
368 m_ProgressCommand->AddStepsToDo(progress_steps);
371 m_SeedPointInteractor->SetDataNode(NULL);
372 CurrentlyBusy.Send(
true);
375 m_ThresholdFilter->Update();
377 catch (itk::ExceptionObject &excep)
379 MITK_ERROR <<
"Exception caught: " << excep.GetDescription();
381 m_ProgressCommand->SetProgress(progress_steps);
382 CurrentlyBusy.Send(
false);
384 std::string msg = excep.GetDescription();
385 ErrorMessage.Send(msg);
389 m_ProgressCommand->SetProgress(progress_steps);
390 CurrentlyBusy.Send(
false);
395 result->GetGeometry()->SetOrigin(m_ReferenceImage->GetGeometry()->GetOrigin());
396 result->GetGeometry()->SetIndexToWorldTransform(m_ReferenceImage->GetGeometry()->GetIndexToWorldTransform());
397 m_ResultImageNode->SetData(result);
398 m_ResultImageNode->SetVisibility(
true);
402 m_SeedPointInteractor->SetDataNode(m_SeedsAsPointSetNode);
409 if (this->m_SeedContainer.IsNotNull())
410 this->m_SeedContainer->Initialize();
412 if (this->m_SeedsAsPointSet.IsNotNull())
415 m_SeedsAsPointSet->RemoveObserver(m_PointSetAddObserverTag);
416 m_SeedsAsPointSet->RemoveObserver(m_PointSetRemoveObserverTag);
420 this->m_SeedsAsPointSetNode->SetData(this->m_SeedsAsPointSet);
421 m_SeedsAsPointSetNode->SetName(
"Seeds_Preview");
422 m_SeedsAsPointSetNode->SetBoolProperty(
"helper object",
true);
423 m_SeedsAsPointSetNode->SetColor(0.0, 1.0, 0.0);
424 m_SeedsAsPointSetNode->SetVisibility(
true);
430 m_PointSetAddObserverTag = m_SeedsAsPointSet->AddObserver(mitk::PointSetAddEvent(), pointAddedCommand);
435 m_PointSetRemoveObserverTag = m_SeedsAsPointSet->AddObserver(mitk::PointSetRemoveEvent(), pointRemovedCommand);
438 if (this->m_FastMarchingFilter.IsNotNull())
439 m_FastMarchingFilter->Modified();
441 this->m_NeedUpdate =
true;
449 m_ResultImageNode->SetVisibility(
false);
456 if (m_CurrentTimeStep != t)
458 m_CurrentTimeStep = t;
itk::SmartPointer< Self > Pointer
Base of all data objects.
static void Update(vtkPolyData *)
#define MITKSEGMENTATION_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
Constants for most interaction classes, due to the generic StateMachines.
static RenderingManager * GetInstance()
Module * GetModule() const
Image class for storing images.
Operation that handles all actions on one Point.
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.
unsigned int GetDimension() const
Get dimension of the image.
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.