コード例 #1
0
void QmitkDeformableRegistrationView::ApplyDeformationField()
{

  ImageReaderType::Pointer reader  = ImageReaderType::New();
  reader->SetFileName( m_Controls.m_QmitkBSplineRegistrationViewControls->m_Controls.m_DeformationField->text().toStdString() );
  reader->Update();

  DeformationFieldType::Pointer deformationField = reader->GetOutput();

  mitk::Image * mimage = dynamic_cast<mitk::Image*> (m_MovingNode->GetData());
  mitk::Image * fimage = dynamic_cast<mitk::Image*> (m_FixedNode->GetData());

  typedef itk::Image<float, 3> FloatImageType;

  FloatImageType::Pointer itkMovingImage = FloatImageType::New();
  FloatImageType::Pointer itkFixedImage = FloatImageType::New();
  mitk::CastToItkImage(mimage, itkMovingImage);
  mitk::CastToItkImage(fimage, itkFixedImage);

  typedef itk::WarpImageFilter<
                            FloatImageType,
                            FloatImageType,
                            DeformationFieldType  >     WarperType;

  typedef itk::LinearInterpolateImageFunction<
                                    FloatImageType,
                                    double          >  InterpolatorType;

  WarperType::Pointer warper = WarperType::New();
  InterpolatorType::Pointer interpolator = InterpolatorType::New();

  warper->SetInput( itkMovingImage );
  warper->SetInterpolator( interpolator );
  warper->SetOutputSpacing( itkFixedImage->GetSpacing() );
  warper->SetOutputOrigin( itkFixedImage->GetOrigin() );
  warper->SetOutputDirection (itkFixedImage->GetDirection() );
  warper->SetDisplacementField( deformationField );
  warper->Update();

  FloatImageType::Pointer outputImage = warper->GetOutput();
  mitk::Image::Pointer result = mitk::Image::New();

  mitk::CastToMitkImage(outputImage, result);

  // Create new DataNode
  mitk::DataNode::Pointer newNode = mitk::DataNode::New();
  newNode->SetData( result );
  newNode->SetProperty( "name", mitk::StringProperty::New("warped image") );

  // add the new datatree node to the datatree
  this->GetDefaultDataStorage()->Add(newNode);
  mitk::RenderingManager::GetInstance()->RequestUpdateAll();

  //Image::Pointer outputImage = this->GetOutput();
  //mitk::CastToMitkImage( warper->GetOutput(), outputImage );


}
コード例 #2
0
ファイル: mitkTractAnalyzer.cpp プロジェクト: Maggunator/MITK
  void TractAnalyzer::MakeRoi()
  {

    m_CostSum = 0.0;

    int n = 0;
    if(m_PointSetNode.IsNotNull())
    {
      n = m_PointSetNode->GetSize();
      if(n==0)
      {
        QMessageBox msgBox;
        msgBox.setText("No points have been set yet.");
        msgBox.exec();
      }
    }
    else{
      QMessageBox msgBox;
      msgBox.setText("No points have been set yet.");
      msgBox.exec();
    }

    std::string pathDescription = "";
    std::vector< itk::Index<3> > totalPath;

    if(n>0)
    {
      for(int i=0; i<n-1; ++i)
      {

        mitk::ProgressBar::GetInstance()->Progress();

        mitk::Point3D p = m_PointSetNode->GetPoint(i);
        mitk::Point3D p2 = m_PointSetNode->GetPoint(i+1);


        itk::Index<3> startPoint;
        itk::Index<3> endPoint;

        m_InputImage->GetGeometry()->WorldToIndex(p,startPoint);
        m_InputImage->GetGeometry()->WorldToIndex(p2,endPoint);

        MITK_INFO << "create roi";

        std::vector< itk::Index<3> > path = CreateSegment(startPoint, endPoint);

        for(std::vector< itk::Index<3> >::iterator it = path.begin();
            it != path.end(); it++)
        {
          itk::Index<3> ix = *it;

          if (!(ix==endPoint))
          {
            mitk::ProgressBar::GetInstance()->Progress();

            totalPath.push_back(ix);
            std::stringstream ss;
            ss << ix[0] << " " << ix[1] << " " << ix[2] << "\n";
            pathDescription += ss.str();
          }
          else
          {
            // Only when dealing with the last segment the last point should be added. This one will not occur
            // as the first point of the next roi segment.
            if(i == (n-2))
            {
              totalPath.push_back(endPoint);
              std::stringstream ss;
              ss << endPoint[0] << " " << endPoint[1] << " " << endPoint[2] << "\n";
              pathDescription += ss.str();
            }

          }

        }

      }


      // save pathDescription to m_PathDescription
      m_PathDescription = pathDescription;

      FloatImageType::Pointer itkImg = FloatImageType::New();
      mitk::CastToItkImage(m_InputImage, itkImg);

      CharImageType::Pointer roiImg = CharImageType::New();
      roiImg->SetRegions(itkImg->GetLargestPossibleRegion().GetSize());
      roiImg->SetOrigin(itkImg->GetOrigin());
      roiImg->SetSpacing(itkImg->GetSpacing());
      roiImg->SetDirection(itkImg->GetDirection());
      roiImg->Allocate();
      roiImg->FillBuffer(0);


      std::vector< itk::Index<3> > roi;

      std::vector< itk::Index<3> >::iterator it;
      for(it = totalPath.begin();
          it != totalPath.end();
          it++)
      {
        itk::Index<3> ix = *it;
        roiImg->SetPixel(ix, 1);
        roi.push_back(ix);
      }


      m_TbssRoi = mitk::TbssRoiImage::New();

      m_TbssRoi->SetRoi(roi);

      m_TbssRoi->SetImage(roiImg);

      m_TbssRoi->InitializeFromImage();



    }



  }