コード例 #1
0
    foreach ( mitk::DataNode::Pointer node, selectedNodes )
    {
        if (node)
        {
            mitk::Image::Pointer image = dynamic_cast<mitk::Image*>( node->GetData() );
            if (image.IsNull()) return;

            mitk::ProgressBar::GetInstance()->AddStepsToDo(10);
            mitk::ProgressBar::GetInstance()->Progress(2);

            qApp->processEvents();

            mitk::AutoCropImageFilter::Pointer cropFilter = mitk::AutoCropImageFilter::New();
            cropFilter->SetInput( image );
            cropFilter->SetBackgroundValue( 0 );
            try
            {
                cropFilter->Update();

                image = cropFilter->GetOutput();

                if (image.IsNotNull())
                {

                    if (image->GetDimension() == 4)
                    {
                        MITK_INFO << "4D AUTOCROP DOES NOT WORK AT THE MOMENT";
                        throw "4D AUTOCROP DOES NOT WORK AT THE MOMENT";

                        unsigned int timesteps = image->GetDimension(3);
                        for (unsigned int i = 0; i < timesteps; i++)
                        {
                            mitk::ImageTimeSelector::Pointer imageTimeSelector = mitk::ImageTimeSelector::New();
                            imageTimeSelector->SetInput(image);
                            imageTimeSelector->SetTimeNr(i);
                            imageTimeSelector->UpdateLargestPossibleRegion();

                            // We split a long nested code line into separate calls for debugging:
                            mitk::ImageSource::OutputImageType *_3dSlice = imageTimeSelector->GetOutput();
                            mitk::Image::Pointer _cropped3dSlice = this->IncreaseCroppedImageSize(_3dSlice);

                            // +++ BUG +++ BUG +++ BUG +++ BUG +++ BUG +++ BUG +++ BUG +++
                            mitk::ImageWriteAccessor imAccess(_cropped3dSlice);
                            void *_data = imAccess.GetData();

                            // <ToBeRemoved>
                            // We write some stripes into the image
                            if ((i & 1) == 0)
                            {
                                int depth = _cropped3dSlice->GetDimension(2);
                                int height = _cropped3dSlice->GetDimension(1);
                                int width = _cropped3dSlice->GetDimension(0);

                                for (int z = 0; z < depth; ++z)
                                    for (int y = 0; y < height; ++y)
                                        for (int x = 0; x < width; ++x)
                                            reinterpret_cast<unsigned char *>(_data)[(width * height * z) + (width * y) + x] = x & 1;
                                // </ToBeRemoved>
                            }

                            image->SetVolume(_data, i);
                        }
                        node->SetData( image ); // bug fix 3145
                    }
                    else
                    {
                        node->SetData( this->IncreaseCroppedImageSize(image) ); // bug fix 3145
                    }
                    // Reinit node
                    mitk::RenderingManager::GetInstance()->InitializeViews(
                        node->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
                    mitk::RenderingManager::GetInstance()->RequestUpdateAll();

                }
            }
            catch(...)
            {
                MITK_ERROR << "Cropping image failed...";
            }
            mitk::ProgressBar::GetInstance()->Progress(8);
        }
        else
        {
            MITK_INFO << "   a NULL node selected";
        }
    }
コード例 #2
0
void QmitkTbssRoiAnalysisWidget::PlotFiberBundles(const mitk::PixelType ptype, TractContainerType tracts, mitk::Image *img, bool avg)
{

  m_PlottingFiberBundle = true;

  this->Clear();
  std::vector<TractType>::iterator it = tracts.begin();


  std::vector< std::vector <mitk::ScalarType > > profiles;

  mitk::ImagePixelReadAccessor<T,3> imAccess(img,img->GetVolumeData(0));

  it = tracts.begin();
  while(it != tracts.end())
  {

    TractType tract = *it;
    TractType::iterator tractIt = tract.begin();

    std::vector<mitk::ScalarType> profile;

    while(tractIt != tract.end())
    {
      PointType p = *tractIt;

      // Get value from image
      profile.push_back( (mitk::ScalarType) imAccess.GetPixelByWorldCoordinates(p) );

      ++tractIt;
    }

    profiles.push_back(profile);
    std::cout << std::endl;

    ++it;
  }


  if(profiles.size() == 0)
    return;

  m_IndividualProfiles = profiles;


  std::string title = "Fiber bundle plot";
  this->SetPlotTitle( title.c_str() );


  // initialize average profile
  std::vector<mitk::ScalarType> averageProfile;
  std::vector<mitk::ScalarType> profile = profiles.at(0); // can do this because we checked the size of profiles before
  for(unsigned int i=0; i<profile.size(); ++i)
  {
    averageProfile.push_back(0.0);
  }


  std::vector< std::vector<mitk::ScalarType> >::iterator profit = profiles.begin();

  int id=0;
  while(profit != profiles.end())
  {
    std::vector<mitk::ScalarType> profile = *profit;



    std::vector<mitk::ScalarType> xAxis;
    for(unsigned int i=0; i<profile.size(); ++i)
    {
      xAxis.push_back((mitk::ScalarType)i);
      averageProfile.at(i) += profile.at(i) / profiles.size();
    }

    int curveId = this->InsertCurve( "" );

    this->SetCurveData( curveId, xAxis, profile );

    ++profit;
    id++;


  }

  m_Average = averageProfile;


  if(avg)
  {

    // Draw the average profile
    std::vector<mitk::ScalarType> xAxis;
    for(unsigned int i=0; i<averageProfile.size(); ++i)
    {
      xAxis.push_back((mitk::ScalarType)i);
    }

    int curveId = this->InsertCurve( "" );
    this->SetCurveData( curveId, xAxis, averageProfile );




    QPen pen( Qt::SolidLine );
    pen.setWidth(3);
    pen.setColor(Qt::red);

    this->SetCurvePen( curveId, pen );



    id++;


  }

  this->Replot();





}