Пример #1
0
void mitk::FastMarchingTool3D::OnAddPoint()
{
  // Add a new seed point for FastMarching algorithm
  mitk::Point3D clickInIndex;

  m_ReferenceImage->GetGeometry()->WorldToIndex(m_SeedsAsPointSet->GetPoint(m_SeedsAsPointSet->GetSize()-1),
                                                clickInIndex);
  itk::Index<3> seedPosition;
  seedPosition[0] = clickInIndex[0];
  seedPosition[1] = clickInIndex[1];
  seedPosition[2] = clickInIndex[2];

  NodeType node;
  const double seedValue = 0.0;
  node.SetValue( seedValue );
  node.SetIndex( seedPosition );
  this->m_SeedContainer->InsertElement(this->m_SeedContainer->Size(), node);
  m_FastMarchingFilter->Modified();

  mitk::RenderingManager::GetInstance()->RequestUpdateAll();

  m_NeedUpdate = true;

  this->Update();
}
Пример #2
0
bool mitk::FastMarchingTool::OnAddPoint( StateMachineAction*, InteractionEvent* interactionEvent )
{
  if ( SegTool2D::CanHandleEvent(interactionEvent) < 1.0 )
      return false;

  // Add a new seed point for FastMarching algorithm
  mitk::InteractionPositionEvent* positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>( interactionEvent );
  //const PositionEvent* p = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if ( positionEvent == NULL ) return false;

  if ( m_PositionEvent.IsNotNull() )
      m_PositionEvent = NULL;

  m_PositionEvent = InteractionPositionEvent::New( positionEvent->GetSender(),
                                                   positionEvent->GetPointerPositionOnScreen(),
                                                   positionEvent->GetPositionInWorld() );

  //if click was on another renderwindow or slice then reset pipeline and preview
  if( (m_LastEventSender != m_PositionEvent->GetSender()) || (m_LastEventSlice != m_PositionEvent->GetSender()->GetSlice()) )
  {
      this->BuildITKPipeline();
      this->ClearSeeds();
  }

  m_LastEventSender = m_PositionEvent->GetSender();
  m_LastEventSlice = m_LastEventSender->GetSlice();

  mitk::Point3D clickInIndex;

  m_ReferenceImageSlice->GetGeometry()->WorldToIndex(m_PositionEvent->GetPositionInWorld(), clickInIndex);
  itk::Index<2> seedPosition;
  seedPosition[0] = clickInIndex[0];
  seedPosition[1] = clickInIndex[1];

  NodeType node;
  const double seedValue = 0.0;
  node.SetValue( seedValue );
  node.SetIndex( seedPosition );
  this->m_SeedContainer->InsertElement(this->m_SeedContainer->Size(), node);
  m_FastMarchingFilter->Modified();

  m_SeedsAsPointSet->InsertPoint(m_SeedsAsPointSet->GetSize(), m_PositionEvent->GetPositionInWorld());

  mitk::RenderingManager::GetInstance()->RequestUpdateAll();

  m_NeedUpdate = true;

  this->Update();

  m_ReadyMessage.Send();

  return true;
}
Пример #3
0
bool mitk::FastMarchingTool::OnAddPoint(Action* action, const StateEvent* stateEvent)
{
  // Add a new seed point for FastMarching algorithm
  const PositionEvent* p = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!p) return false;

  if (m_PositionEvent != NULL)
      delete m_PositionEvent;
  m_PositionEvent = new PositionEvent(p->GetSender(), p->GetType(), p->GetButton(), p->GetButtonState(), p->GetKey(), p->GetDisplayPosition(), p->GetWorldPosition() );

  //if click was on another renderwindow or slice then reset pipeline and preview
  if( (m_LastEventSender != m_PositionEvent->GetSender()) || (m_LastEventSlice != m_PositionEvent->GetSender()->GetSlice()) )
  {
      this->BuildITKPipeline();
      this->ClearSeeds();
  }

  m_LastEventSender = m_PositionEvent->GetSender();
  m_LastEventSlice = m_LastEventSender->GetSlice();

  mitk::Point3D clickInIndex;

  m_ReferenceImageSlice->GetGeometry()->WorldToIndex(m_PositionEvent->GetWorldPosition(), clickInIndex);
  itk::Index<2> seedPosition;
  seedPosition[0] = clickInIndex[0];
  seedPosition[1] = clickInIndex[1];

  NodeType node;
  const double seedValue = 0.0;
  node.SetValue( seedValue );
  node.SetIndex( seedPosition );
  this->m_SeedContainer->InsertElement(this->m_SeedContainer->Size(), node);
  m_FastMarchingFilter->Modified();

  m_SeedsAsPointSet->InsertPoint(m_SeedsAsPointSet->GetSize(), m_PositionEvent->GetWorldPosition());

  mitk::RenderingManager::GetInstance()->RequestUpdateAll();

  m_NeedUpdate = true;

  m_ReadyMessage.Send();

  this->Update();

  return true;
}
Пример #4
0
void FastMarchingImageFilterITK::fastMarchingImageFilterITK() {

    if (!enableProcessing_.get()) {
        outport1_.setData(inport1_.getData(), false);
        return;
    }

    //typedefs images
    typedef itk::Image<T, 3> InputImageType;

    //input image p1
    typename InputImageType::Pointer p1 = voreenToITK<T>(inport1_.getData());

    typedef  itk::FastMarchingImageFilter< InputImageType, InputImageType >    FastMarchingFilterType;
    typename FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();

    typedef typename FastMarchingFilterType::NodeContainer   NodeContainer;
    typedef typename FastMarchingFilterType::NodeType        NodeType;

    typename NodeContainer::Pointer seeds = NodeContainer::New();

    if (seedPointPort_.hasChanged()) {
        const PointListGeometry<tgt::vec3>* pointList = dynamic_cast< const PointListGeometry<tgt::vec3>* >(seedPointPort_.getData());
        if (pointList) {
            seedPoints = pointList->getData();
            if (!seedPoints.empty()) {
                numSeedPoint_.setMinValue(1);
                numSeedPoint_.setMaxValue(seedPoints.size());
                numSeedPoint_.set(seedPoints.size());
            }
            else {
                numSeedPoint_.setMinValue(0);
                numSeedPoint_.setMaxValue(0);
                numSeedPoint_.set(0);
            }
        }
    }

    if(!seedPoints.empty()) {
        seedPoint_.set(seedPoints[numSeedPoint_.get()-1]);
    }
    else {
        seedPoint_.set(tgt::vec3 (1));
    }


    typename InputImageType::IndexType  seedPosition;

    seedPosition[0] = seedPoint_.get().x;
    seedPosition[1] = seedPoint_.get().y;
    seedPosition[2] = seedPoint_.get().z;

    const double initialDistance = initialDistance_.get();

    NodeType node;

    const double seedValue = - initialDistance;

    node.SetValue( seedValue);
    node.SetIndex (seedPosition);

    seeds->Initialize();
    seeds->InsertElement( 0, node);

    fastMarching->SetTrialPoints( seeds );
    fastMarching->SetSpeedConstant( 1.0f );
    fastMarching->SetStoppingValue( stoptime_.get() );

    fastMarching->SetInput(p1);

    observe(fastMarching.GetPointer());

    try
    {
        fastMarching->Update();
    }
    catch (itk::ExceptionObject &e)
    {
        LERROR(e);
    }

    Volume* outputVolume1 = 0;
    outputVolume1 = ITKToVoreenCopy<T>(fastMarching->GetOutput());

    if (outputVolume1) {
        transferTransformation(inport1_.getData(), outputVolume1);
        outport1_.setData(outputVolume1);
    }
    else
        outport1_.setData(0);

}
int main(int argc, const char *argv[])
{
	// Validate input parameters
	if (argc < 15) {
		std::cerr << "Missing parameters! Usage:" << std::endl;
		std::cerr << argv[0];
		std::cerr << " <Read/WriteDir> <InputImg> <OutputImg> ";
		std::cerr << "[seedX] [seedY] [seedZ] [initDist] ";
		std::cerr << "[sigma] [sigmoid K1] [sigmoid K2] ";
		std::cerr << "[propagation] [curvature] [advection] [iterations]";
		std::cerr << std::endl;
		return EXIT_FAILURE;
	}
	
	const unsigned int Dimension = 3;
	typedef float InputPixelType;
	typedef unsigned char OutputPixelType;
    typedef itk::Image< InputPixelType, Dimension > InputImageType;
	typedef itk::Image< OutputPixelType, Dimension > OutputImageType;

    ////////////////////////////////////////////////
    // 1) Read the input image

	typedef itk::ImageFileReader< InputImageType >  ReaderType;
	ReaderType::Pointer reader = ReaderType::New();
	std::string readpath( argv[1] );
	readpath.append( argv[2] );
	reader->SetFileName( readpath );
	reader->Update();
	
    ////////////////////////////////////////////////
    // 2) Curvature anisotropic diffusion
	
	typedef itk::CurvatureAnisotropicDiffusionImageFilter< 
		InputImageType, InputImageType > SmoothingFilterType;
	SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
	smoothing->SetTimeStep(0.04);
	smoothing->SetNumberOfIterations(5);
	smoothing->SetConductanceParameter(9.0);
	smoothing->SetInput( reader->GetOutput() );
	
    ////////////////////////////////////////////////
    // 3) Gradient magnitude recursive Gaussian
	
	const double sigma = atof(argv[8]);
	typedef itk::GradientMagnitudeRecursiveGaussianImageFilter< 
		InputImageType, InputImageType > GradientFilterType;
	GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
	gradientMagnitude->SetSigma( sigma );
	gradientMagnitude->SetInput( smoothing->GetOutput() );
	
    ////////////////////////////////////////////////
    // 4) Sigmoid mapping
	
	const double K1 = atof(argv[9]);
	const double K2 = atof(argv[10]);
	typedef itk::SigmoidImageFilter< InputImageType, InputImageType > 
		SigmoidFilterType;
	SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
	sigmoid->SetOutputMinimum(0.0);
	sigmoid->SetOutputMaximum(1.0);
	sigmoid->SetAlpha( (K2 - K1)/6 );
	sigmoid->SetBeta( (K1 + K2)/2 );
	sigmoid->SetInput( gradientMagnitude->GetOutput() );
	
    ////////////////////////////////////////////////
    // 5) Segmentation with geodesic active contour
	
	typedef itk::FastMarchingImageFilter< InputImageType, InputImageType > 
		FastMarchingFilterType;
	FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
	
	typedef itk::GeodesicActiveContourLevelSetImageFilter< 
		InputImageType, InputImageType > GeodesicActiveContourFilterType;
	GeodesicActiveContourFilterType::Pointer geodesicActiveContour = 
		GeodesicActiveContourFilterType::New();
	
	const double propagation = atof( argv[11] );
	const double curvature = atof( argv[12] );
	const double advection = atof( argv[13] );
	const double iterations = atoi( argv[14] );
	geodesicActiveContour->SetPropagationScaling( propagation );
	geodesicActiveContour->SetCurvatureScaling( curvature );
	geodesicActiveContour->SetAdvectionScaling( advection );
	geodesicActiveContour->SetMaximumRMSError(0.01);
	geodesicActiveContour->SetNumberOfIterations( iterations );
	
	geodesicActiveContour->SetInput( fastMarching->GetOutput() );
	geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
	
    ////////////////////////////////////////////////
    // 6) Binary thresholding
	
	typedef itk::BinaryThresholdImageFilter< InputImageType, OutputImageType > 
		ThresholdingFilterType;
	ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
	thresholder->SetLowerThreshold(-1000.0);
	thresholder->SetUpperThreshold(0.0);
	thresholder->SetOutsideValue(0);
	thresholder->SetInsideValue(255);
	thresholder->SetInput( geodesicActiveContour->GetOutput() );
	
    ////////////////////////////////////////////////
    // 7) Finish setting up fast marching
	
	typedef FastMarchingFilterType::NodeContainer NodeContainer;
	typedef FastMarchingFilterType::NodeType NodeType;
	
	NodeContainer::Pointer seeds = NodeContainer::New();
	InputImageType::IndexType seedPosition;
	seedPosition[0] = atoi( argv[4] );
	seedPosition[1] = atoi( argv[5] );
	seedPosition[2] = atoi( argv[6] );
	const double initialDistance = atof( argv[7] );
	const double seedValue = -initialDistance;
	NodeType node;
	node.SetValue( seedValue );
	node.SetIndex( seedPosition );
	seeds->Initialize();
	seeds->InsertElement(0, node);
	
	fastMarching->SetTrialPoints( seeds );
	fastMarching->SetSpeedConstant(1.0);
	fastMarching->SetOutputSize( reader->GetOutput()->GetBufferedRegion().GetSize() );
	fastMarching->SetOutputRegion( reader->GetOutput()->GetBufferedRegion() );
	fastMarching->SetOutputSpacing( reader->GetOutput()->GetSpacing() );
	fastMarching->SetOutputOrigin( reader->GetOutput()->GetOrigin() );
	
	////////////////////////////////////////////////
    // 7) Write output image
	
	typedef itk::ImageFileWriter< OutputImageType > WriterType;
	WriterType::Pointer writer = WriterType::New();
	std::string writepath( argv[1] );
	writepath.append( argv[3] );
	writer->SetFileName( writepath );
	writer->SetInput( thresholder->GetOutput() );
	
	try {
		writer->Update();
	}
	catch( itk::ExceptionObject &excep ) {
		std::cerr << "Exception caught!" << std::endl;
		std::cerr << excep << std::endl;
		return EXIT_FAILURE;
	}
	
	// The following writer is used to save the output of the sigmoid mapping
	typedef itk::ImageFileWriter< InputImageType > InternalWriterType;
	InternalWriterType::Pointer speedWriter = InternalWriterType::New();
	speedWriter->SetInput( sigmoid->GetOutput() );
	std::string sigmoidpath( argv[1] );
	speedWriter->SetFileName( sigmoidpath.append("SigmoidForGeodesic.mha"));
	speedWriter->Update();
	
	return 0;
}
Пример #6
0
void segment::Execute(int first,int last,double sig_min, double sig_max, double propagation, double curvature, double advection, double rms, int iterations, double alpha, double beta, double distance){
    ifstream myfile ("/home/gustavo/temp/endocardium.txt");
    for(int i =first; i<last;i++){
        typedef   float           InternalPixelType;
        const     unsigned int    Dimension = 2;

        typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;

        typedef unsigned char                            OutputPixelType;
        typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
        typedef itk::BinaryThresholdImageFilter<
                InternalImageType,
                OutputImageType    >       ThresholdingFilterType;
        ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
        thresholder->SetLowerThreshold( -1000.0 );
        thresholder->SetUpperThreshold(     0.0 );
        thresholder->SetOutsideValue(  0  );
        thresholder->SetInsideValue(  255 );

        typedef  itk::ImageFileReader< InternalImageType > ReaderType;
        typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
        ReaderType::Pointer reader = ReaderType::New();
        WriterType::Pointer writer = WriterType::New();
        //WriterType::Pointer writer_out = WriterType::New();
        stringstream ss;

        string name = "/home/gustavo/temp/cine_";
        string type = ".tif";

        ss<<name<<(i+1)<<type;

        string filename = ss.str();
        ss.str("");

        reader->SetFileName(filename);
        reader->Update();

        InternalImageType::Pointer val = reader->GetOutput();

        typedef itk::RescaleIntensityImageFilter<
                InternalImageType,
                OutputImageType >   CastFilterType;

        typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
                InternalImageType,
                InternalImageType >  GradientFilterType;
        typedef   itk::SigmoidImageFilter<
                InternalImageType,
                InternalImageType >  SigmoidFilterType;
        GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();
        SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();

        sigmoid->SetOutputMinimum(sig_min);
        sigmoid->SetOutputMaximum(sig_max);

        typedef  itk::FastMarchingImageFilter<
                InternalImageType,
                InternalImageType >    FastMarchingFilterType;

        FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();
        //const InternalImageType * inputImage = reader->GetOutput();
        const InternalImageType * inputImage = val;
        fastMarching->SetOutputRegion( inputImage->GetBufferedRegion() );
        fastMarching->SetOutputSpacing( inputImage->GetSpacing() );
        fastMarching->SetOutputOrigin( inputImage->GetOrigin() );
        fastMarching->SetOutputDirection( inputImage->GetDirection() );

        typedef  itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
                InternalImageType >    GeodesicActiveContourFilterType;
        GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
                GeodesicActiveContourFilterType::New();

        const double propagationScaling = propagation;
        //  Software Guide : BeginCodeSnippet
        geodesicActiveContour->SetPropagationScaling( propagationScaling );
        geodesicActiveContour->SetCurvatureScaling(curvature);
        geodesicActiveContour->SetAdvectionScaling(advection);

        geodesicActiveContour->SetMaximumRMSError(rms);
        geodesicActiveContour->SetNumberOfIterations(iterations);

        gradientMagnitude->SetInput(val);
        sigmoid->SetInput( gradientMagnitude->GetOutput() );
        geodesicActiveContour->SetInput(  fastMarching->GetOutput() );
        geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
        thresholder->SetInput( geodesicActiveContour->GetOutput() );
        //ImageOut = thresholder->GetOutput();
        //writer->SetInput( thresholder->GetOutput() );

        const double sigma = 0.5;
        gradientMagnitude->SetSigma(  sigma  );

        sigmoid->SetAlpha( alpha );
        sigmoid->SetBeta(  beta  );

        string line;
        int x;
        int y;

        if (myfile.is_open())
        {
            getline (myfile,line);
            string cmd = line;
            string arg;
            string::size_type pos = cmd.find(' ');
            if(cmd.npos != pos) {
                arg = cmd.substr(pos + 1);
                cmd = cmd.substr(0, pos);
            }
            x = atoi(cmd.c_str());
            y = atoi(arg.c_str());
        }

        typedef FastMarchingFilterType::NodeContainer  NodeContainer;
        typedef FastMarchingFilterType::NodeType       NodeType;
        NodeContainer::Pointer seeds = NodeContainer::New();
        InternalImageType::IndexType  seedPosition;
        seedPosition.SetElement(0,x);
        seedPosition.SetElement(1,y);
        //seedPosition.SetElement(2,(int)z);
        cout<<"X, Y = "<<x<<" "<<y<<endl;
        NodeType node;
        const double seedValue = - distance;
        node.SetValue( seedValue );
        node.SetIndex( seedPosition );

        seeds->Initialize();
        seeds->InsertElement( 0, node );

        fastMarching->SetTrialPoints(  seeds  );

        fastMarching->SetSpeedConstant( 4.0 );

        CastFilterType::Pointer caster2 = CastFilterType::New();
        CastFilterType::Pointer caster3 = CastFilterType::New();
        CastFilterType::Pointer caster4 = CastFilterType::New();
        WriterType::Pointer writer2 = WriterType::New();
        WriterType::Pointer writer3 = WriterType::New();
        WriterType::Pointer writer4 = WriterType::New();

        caster2->SetInput( gradientMagnitude->GetOutput() );
        writer2->SetInput( caster2->GetOutput() );
        writer2->SetFileName("/home/gustavo/temp/GeodesicActiveContourImageFilterOutput2.tif");
        caster2->SetOutputMinimum(   0 );
        caster2->SetOutputMaximum( 255 );
        writer2->Update();
        caster3->SetInput( sigmoid->GetOutput() );
        writer3->SetInput( caster3->GetOutput() );
        writer3->SetFileName("/home/gustavo/temp/GeodesicActiveContourImageFilterOutput3.tif");
        caster3->SetOutputMinimum(   0 );
        caster3->SetOutputMaximum( 255 );
        writer3->Update();
        caster4->SetInput( fastMarching->GetOutput() );
        writer4->SetInput( caster4->GetOutput() );
        writer4->SetFileName("/home/gustavo/temp/GeodesicActiveContourImageFilterOutput4.tif");
        caster4->SetOutputMinimum(   0 );
        caster4->SetOutputMaximum( 255 );

        fastMarching->SetOutputSize(
                    reader->GetOutput()->GetBufferedRegion().GetSize() );
        reader->Update();

        stringstream ss2;

        string name2 = "/home/gustavo/temp/segmented_";
        string type2 = ".tif";

        if(i<9)
            ss2<<name2<<"00"<<(i+1)<<type2;
        if(i>=9 && i<99)
            ss2<<name2<<"0"<<(i+1)<<type2;
        if(i>=99)
            ss2<<name2<<(i+1)<<type2;
        string filename2 = ss2.str();
        ss2.str("");

        typedef itk::GradientMagnitudeImageFilter<OutputImageType, OutputImageType >  GradientType;
        GradientType::Pointer gradient = GradientType::New();
        gradient->SetInput(thresholder->GetOutput());
        gradient->Update();

        try
        {
            writer->SetFileName(filename2);
            writer->SetInput( gradient->GetOutput() );
            writer->Update();
        }
        catch( itk::ExceptionObject & excep )
        {
            std::cerr << "Exception caught !" << std::endl;
            std::cerr << excep << std::endl;
        }

        std::cout << std::endl;
        std::cout << "Max. no. iterations: " << geodesicActiveContour->GetNumberOfIterations() << std::endl;
        std::cout << "Max. RMS error: " << geodesicActiveContour->GetMaximumRMSError() << std::endl;
        std::cout << std::endl;
        std::cout << "No. elpased iterations: " << geodesicActiveContour->GetElapsedIterations() << std::endl;
        std::cout << "RMS change: " << geodesicActiveContour->GetRMSChange() << std::endl;
        writer4->Update();

        typedef itk::ImageFileWriter< InternalImageType > InternalWriterType;
        InternalWriterType::Pointer mapWriter = InternalWriterType::New();
        mapWriter->SetInput( fastMarching->GetOutput() );
        mapWriter->SetFileName("/home/gustavo/temp/GeodesicActiveContourImageFilterOutput4.mha");
        mapWriter->Update();
        InternalWriterType::Pointer speedWriter = InternalWriterType::New();
        speedWriter->SetInput( sigmoid->GetOutput() );
        speedWriter->SetFileName("/home/gustavo/temp/GeodesicActiveContourImageFilterOutput3.mha");
        speedWriter->Update();
        InternalWriterType::Pointer gradientWriter = InternalWriterType::New();
        gradientWriter->SetInput( gradientMagnitude->GetOutput() );
        gradientWriter->SetFileName("/home/gustavo/temp/GeodesicActiveContourImageFilterOutput2.mha");
        gradientWriter->Update();
    }
    myfile.close();

}
void ttt::AJSegmentationDijkstraFilter<TInputAJGraph,TPlatenessImage, TVertexnessImage,TOutputAJGraph>::DoFastMarching() {

	typedef itk::Image<int, NumDimensions> VoronoiImageType;

	typedef itk::ImageFileWriter<VoronoiImageType> VoronoiWriterType;

	typename VoronoiWriterType::Pointer voronoiWriter = VoronoiWriterType::New();
	voronoiWriter->SetFileName("VertexVoronoi.mha");

	typedef ttt::VoronoiTesselationImageFilter<VoronoiImageType,typename TPlatenessImage::PixelType> VoronoiFilterType;

	typename VoronoiFilterType::Pointer voronoiFilter = VoronoiFilterType::New();

	typedef ttt::FastMarchingImageFilter<LevelSetImageType, PlatenessImageType> FastMarchingImageFilterType;

	typename FastMarchingImageFilterType::Pointer fastMarching = FastMarchingImageFilterType::New();
	fastMarching->SetInput(m_Speed);

	typedef typename VoronoiFilterType::NodeContainer VoronoiNodeContainer;
	typedef typename VoronoiFilterType::LevelSetNodeType VoronoiNodeType;

	typedef typename FastMarchingImageFilterType::NodeContainer NodeContainer;
	typedef typename FastMarchingImageFilterType::NodeType NodeType;
	typename NodeContainer::Pointer seeds = NodeContainer::New();
	seeds->Initialize();

	typename VoronoiNodeContainer::Pointer seedsVoronoi = VoronoiNodeContainer::New();
	;
	seedsVoronoi->Initialize();

	int k = 0;

	for (auto vit = this->GetInputAJGraph()->VerticesBegin(); vit != this->GetInputAJGraph()->VerticesEnd(); vit++) {

		typename PlatenessImageType::PointType seedPosition = this->GetInputAJGraph()->GetAJVertex(*vit)->GetPosition();
		typename PlatenessImageType::IndexType seedIndex;

		this->GetPlatenessImage()->TransformPhysicalPointToIndex(seedPosition, seedIndex);

		NodeType node;
		const double seedValue = 0.0;
		node.SetValue(seedValue);
		node.SetIndex(seedIndex);

		seeds->InsertElement(k, node);

		VoronoiNodeType nodeVoronoi;

		nodeVoronoi.SetValue(seedValue);
		node.SetIndex(seedIndex);
		seedsVoronoi->InsertElement(k, nodeVoronoi);

		k++;
	}

	voronoiFilter->SetOutputSize(m_Speed->GetLargestPossibleRegion().GetSize());
	voronoiFilter->SetOutputDirection(m_Speed->GetDirection());
	voronoiFilter->SetOutputRegion(m_Speed->GetLargestPossibleRegion());
	voronoiFilter->SetOutputSpacing(m_Speed->GetSpacing());
	voronoiFilter->SetOutputOrigin(m_Speed->GetOrigin());

	voronoiFilter->SetTrialPoints(seeds);
	voronoiFilter->Update();

	voronoiWriter->SetInput(voronoiFilter->GetOutput());
	voronoiWriter->Update();

	fastMarching->SetStoppingValue(m_StoppingValue);
	fastMarching->SetTrialPoints(seeds);
	fastMarching->SetOutputSize(m_Speed->GetBufferedRegion().GetSize());

	fastMarching->SetVoronoiImage(voronoiFilter->GetOutput());
	fastMarching->Update();

	m_LevelSet = fastMarching->GetOutput();
	m_Labels = fastMarching->GetClusterImage();

	itk::ImageRegionIterator<LevelSetImageType> levelsetIterator(m_LevelSet, m_LevelSet->GetLargestPossibleRegion());

	levelsetIterator.GoToBegin();

	while (!levelsetIterator.IsAtEnd()) {

		if (levelsetIterator.Value() == static_cast<double>(itk::NumericTraits<double>::max() / 2.0)) {
			levelsetIterator.Set(-1);
		}

		++levelsetIterator;
	}

	typedef itk::ImageFileWriter<LevelSetImageType> LevelSetWriterType;

	typename LevelSetWriterType::Pointer levelSetWriter = LevelSetWriterType::New();

	levelSetWriter->SetFileName("LevelSet.mha");
	levelSetWriter->SetInput(m_LevelSet);
	levelSetWriter->Update();

}
void GeodesicActiveContourShapePriorLevelSetImageFilterWorkflowITK::geodesicActiveContourShapePriorLevelSetImageFilterWorkflowITK() {

    inputIsBinary_.setVisible(true);
    squaredDistance_.setVisible(true);
    useImageSpacing_.setVisible(true);

    if (!enableProcessing_.get()) {
        outport1_.setData(inport1_.getData(), false);
        return;
    }

    //typedefs images
    typedef itk::Image<T, 3> InputImageType;

    //input image p1
    typename InputImageType::Pointer p1 = voreenToITK<T>(inport1_.getData());

    //LevelsetFilter
    typedef itk::GeodesicActiveContourShapePriorLevelSetImageFilter<InputImageType, InputImageType> LevelType;
    typename LevelType::Pointer levelfilter = LevelType::New();
    typename LevelType::Pointer levelfilter2 = LevelType::New();

    //smoothing, gradient, sigmoid
    typedef   itk::CurvatureAnisotropicDiffusionImageFilter<
                               InputImageType,
                               InputImageType >  SmoothingFilterType;

    typename SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();

    typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
                               InputImageType,
                               InputImageType >  GradientFilterType;

    typedef   itk::SigmoidImageFilter<
                               InputImageType,
                               InputImageType >  SigmoidFilterType;

    typename GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();

    typename SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
    sigmoid->SetOutputMinimum( 0.0 );
    sigmoid->SetOutputMaximum( 1.0 );

    smoothing->SetInput(p1);
    smoothing->SetTimeStep( timestep_.get() );
    smoothing->SetNumberOfIterations(  numberofiterations_.get() );
    smoothing->SetConductanceParameter( conductanceparameter_.get() );

    gradientMagnitude->SetInput( smoothing->GetOutput() );
    gradientMagnitude->SetSigma( sigma_.get());
    sigmoid->SetInput( gradientMagnitude->GetOutput() );
    sigmoid->SetAlpha( alpha_.get() );
    sigmoid->SetBeta( beta_.get() );
    sigmoid->SetOutputMinimum(  0.0  );
    sigmoid->SetOutputMaximum(  1.0f  );

    if (initLevelSet_.isSelected("danielsson")){

        //initial Level Set using DanielssonDistanceMapImageFiler
        typedef itk::DanielssonDistanceMapImageFilter<InputImageType, InputImageType> DanielssonType;
        typename DanielssonType::Pointer danielssonfilter = DanielssonType::New();


        danielssonfilter->SetInput(p1);
        danielssonfilter->SetInputIsBinary(inputIsBinary_.get());
        danielssonfilter->SetSquaredDistance(squaredDistance_.get());
        danielssonfilter->SetUseImageSpacing(useImageSpacing_.get());


        levelfilter->SetInput(danielssonfilter->GetOutput());
        levelfilter->SetFeatureImage (sigmoid->GetOutput());
        levelfilter->SetPropagationScaling(propagationScaling_.get());
        levelfilter->SetCurvatureScaling( 1.0 );
        levelfilter->SetAdvectionScaling( 1.0 );
        levelfilter->SetMaximumRMSError( 0.02 );
        levelfilter->SetNumberOfIterations( 800 );

        observe(levelfilter.GetPointer());

        try
        {
            levelfilter->Update();
        }
        catch (itk::ExceptionObject &e)
        {
            LERROR(e);
        }


        Volume* outputVolume1 = 0;
        outputVolume1 = ITKToVoreenCopy<T>(levelfilter->GetOutput());

        if (outputVolume1) {
            transferTransformation(inport1_.getData(), outputVolume1);
            outport1_.setData(outputVolume1);
        }
        else
            outport1_.setData(0);
    }

    else if (initLevelSet_.isSelected("fastmarching")){

        inputIsBinary_.setVisible(false);
        squaredDistance_.setVisible(false);
        useImageSpacing_.setVisible(false);

        //initial Level set using FastMarchingImageFilter
        typedef  itk::FastMarchingImageFilter<
                              InputImageType,
                              InputImageType >    FastMarchingFilterType;

        typename FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();

        typedef typename FastMarchingFilterType::NodeContainer   NodeContainer;
        typedef typename FastMarchingFilterType::NodeType        NodeType;

        typename NodeContainer::Pointer seeds = NodeContainer::New();

        if (seedPointPort_.hasChanged()) {
            const PointListGeometry<tgt::vec3>* pointList = dynamic_cast< const PointListGeometry<tgt::vec3>* >(seedPointPort_.getData());
            if (pointList) {
                seedPoints = pointList->getData();
                if (!seedPoints.empty()) {
                    numSeedPoint_.setMinValue(1);
                    numSeedPoint_.setMaxValue(seedPoints.size());
                    numSeedPoint_.set(seedPoints.size());
                }
                else {
                    numSeedPoint_.setMinValue(0);
                    numSeedPoint_.setMaxValue(0);
                    numSeedPoint_.set(0);
                }
            }
        }

        if(!seedPoints.empty()) {
            seedPoint_.set(seedPoints[numSeedPoint_.get()-1]);
        }
        else {
            seedPoint_.set(tgt::vec3 (1));
        }


        typename InputImageType::IndexType  seedPosition;

        seedPosition[0] = seedPoint_.get().x;
        seedPosition[1] = seedPoint_.get().y;
        seedPosition[2] = seedPoint_.get().z;

        const double initialDistance = initialDistance_.get();

        NodeType node;

        const double seedValue = - initialDistance;

        node.SetValue( seedValue);
        node.SetIndex (seedPosition);

        seeds->Initialize();
        seeds->InsertElement( 0, node);

        fastMarching->SetTrialPoints( seeds );

        fastMarching->SetSpeedConstant( 1.0f );
        fastMarching->SetStoppingValue( stoptime_.get() );

        fastMarching->SetInput(p1);

        observe(levelfilter2.GetPointer());

        levelfilter2->SetInput(fastMarching->GetOutput());
        levelfilter2->SetFeatureImage (sigmoid->GetOutput());
        levelfilter2->SetPropagationScaling(propagationScaling_.get());
        levelfilter2->SetCurvatureScaling( 1.0 );
        levelfilter2->SetAdvectionScaling( 1.0 );
        levelfilter2->SetMaximumRMSError( 0.02 );
        levelfilter2->SetNumberOfIterations( 800 );


        try
        {
            levelfilter2->Update();
        }
        catch (itk::ExceptionObject &e)
        {
            LERROR(e);
        }

        Volume* outputVolume1 = 0;
        outputVolume1 = ITKToVoreenCopy<T>(levelfilter2->GetOutput());

        if (outputVolume1) {
            transferTransformation(inport1_.getData(), outputVolume1);
            outport1_.setData(outputVolume1);
        }
        else
            outport1_.setData(0);

    }
}