Ejemplo n.º 1
0
void mitk::BaseRenderer::SetWorldGeometry(mitk::Geometry3D* geometry)
{
    itkDebugMacro("setting WorldGeometry to " << geometry);

    if (m_WorldGeometry != geometry)
    {
        if (geometry->GetBoundingBox()->GetDiagonalLength2() == 0)
            return;

        m_WorldGeometry = geometry;
        m_TimeSlicedWorldGeometry = dynamic_cast<TimeSlicedGeometry*>(geometry);
        SlicedGeometry3D* slicedWorldGeometry;
        if (m_TimeSlicedWorldGeometry.IsNotNull())
        {
            itkDebugMacro("setting TimeSlicedWorldGeometry to " << m_TimeSlicedWorldGeometry);
            if (m_TimeStep >= m_TimeSlicedWorldGeometry->GetTimeSteps())
                m_TimeStep = m_TimeSlicedWorldGeometry->GetTimeSteps() - 1;
            slicedWorldGeometry = dynamic_cast<SlicedGeometry3D*>(m_TimeSlicedWorldGeometry->GetGeometry3D(m_TimeStep));
        }
        else
        {
            slicedWorldGeometry = dynamic_cast<SlicedGeometry3D*>(geometry);
        }
        Geometry2D::Pointer geometry2d;
        if (slicedWorldGeometry != NULL)
        {
            if (m_Slice >= slicedWorldGeometry->GetSlices() && (m_Slice != 0))
                m_Slice = slicedWorldGeometry->GetSlices() - 1;
            geometry2d = slicedWorldGeometry->GetGeometry2D(m_Slice);
            if (geometry2d.IsNull())
            {
                PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New();
                plane->InitializeStandardPlane(slicedWorldGeometry);
                geometry2d = plane;
            }
            SetCurrentWorldGeometry(slicedWorldGeometry);
        }
        else
        {
            geometry2d = dynamic_cast<Geometry2D*>(geometry);
            if (geometry2d.IsNull())
            {
                PlaneGeometry::Pointer plane = PlaneGeometry::New();
                plane->InitializeStandardPlane(geometry);
                geometry2d = plane;
            }
            SetCurrentWorldGeometry(geometry);
        }
        SetCurrentWorldGeometry2D(geometry2d); // calls Modified()
    }
    if (m_CurrentWorldGeometry2D.IsNull())
        itkWarningMacro("m_CurrentWorldGeometry2D is NULL");
}
Ejemplo n.º 2
0
void mitk::SlicedData::SetGeometry(Geometry3D* aGeometry3D)
{
  if(aGeometry3D!=NULL)
  {
    TimeSlicedGeometry::Pointer timeSlicedGeometry = dynamic_cast<TimeSlicedGeometry*>(aGeometry3D);
    if(timeSlicedGeometry.IsNull())
    {
      SlicedGeometry3D::Pointer slicedGeometry = dynamic_cast<SlicedGeometry3D*>(aGeometry3D);
      if(slicedGeometry.IsNull())
      {
        Geometry2D* geometry2d = dynamic_cast<Geometry2D*>(aGeometry3D);
        if(geometry2d!=NULL)
        {
          if((GetSlicedGeometry()->GetGeometry2D(0)==geometry2d) && (GetSlicedGeometry()->GetSlices()==1))
            return;
          slicedGeometry = SlicedGeometry3D::New();
          slicedGeometry->InitializeEvenlySpaced(geometry2d, 1);
        }
        else
        {
          slicedGeometry = SlicedGeometry3D::New();
          PlaneGeometry::Pointer planeGeometry = PlaneGeometry::New();
          planeGeometry->InitializeStandardPlane(aGeometry3D);
          slicedGeometry->InitializeEvenlySpaced(planeGeometry, (unsigned int)(aGeometry3D->GetExtent(2)));
        }
      }
      assert(slicedGeometry.IsNotNull());

      timeSlicedGeometry = TimeSlicedGeometry::New();
      timeSlicedGeometry->InitializeEvenlyTimed(slicedGeometry, 1);
    }
    Superclass::SetGeometry(timeSlicedGeometry);
  }
  else
  {
    if(GetGeometry()==NULL)
      return;
    Superclass::SetGeometry(NULL);
  }
}
Ejemplo n.º 3
0
void mitk::SlicedData::SetGeometry(BaseGeometry *aGeometry3D)
{
  if (aGeometry3D != nullptr)
  {
    ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New();
    SlicedGeometry3D::Pointer slicedGeometry = dynamic_cast<SlicedGeometry3D *>(aGeometry3D);
    if (slicedGeometry.IsNull())
    {
      PlaneGeometry *geometry2d = dynamic_cast<PlaneGeometry *>(aGeometry3D);
      if (geometry2d != nullptr && dynamic_cast<mitk::AbstractTransformGeometry *>(aGeometry3D) == nullptr)
      {
        if ((GetSlicedGeometry()->GetPlaneGeometry(0) == geometry2d) && (GetSlicedGeometry()->GetSlices() == 1))
          return;
        slicedGeometry = SlicedGeometry3D::New();
        slicedGeometry->InitializeEvenlySpaced(geometry2d, 1);
      }
      else
      {
        slicedGeometry = SlicedGeometry3D::New();
        PlaneGeometry::Pointer planeGeometry = PlaneGeometry::New();
        planeGeometry->InitializeStandardPlane(aGeometry3D);
        slicedGeometry->InitializeEvenlySpaced(planeGeometry, (unsigned int)(aGeometry3D->GetExtent(2)));
      }
    }
    assert(slicedGeometry.IsNotNull());

    timeGeometry->Initialize(slicedGeometry, 1);
    Superclass::SetTimeGeometry(timeGeometry);
  }
  else
  {
    if (GetGeometry() == nullptr)
      return;
    Superclass::SetGeometry(nullptr);
  }
}
Ejemplo n.º 4
0
void mitk::Image::Initialize(const mitk::PixelType& type, unsigned int dimension, const unsigned int *dimensions, unsigned int channels)
{
  Clear();

  m_Dimension=dimension;

  if(!dimensions)
    itkExceptionMacro(<< "invalid zero dimension image");

  unsigned int i;
  for(i=0;i<dimension;++i)
  {
    if(dimensions[i]<1)
      itkExceptionMacro(<< "invalid dimension[" << i << "]: " << dimensions[i]);
  }

  // create new array since the old was deleted
  m_Dimensions = new unsigned int[MAX_IMAGE_DIMENSIONS];

  // initialize the first four dimensions to 1, the remaining 4 to 0
  FILL_C_ARRAY(m_Dimensions, 4, 1u);
  FILL_C_ARRAY((m_Dimensions+4), 4, 0u);

  // copy in the passed dimension information
  std::memcpy(m_Dimensions, dimensions, sizeof(unsigned int)*m_Dimension);

  this->m_ImageDescriptor = mitk::ImageDescriptor::New();
  this->m_ImageDescriptor->Initialize( this->m_Dimensions, this->m_Dimension );

  for(i=0;i<4;++i)
  {
    m_LargestPossibleRegion.SetIndex(i, 0);
    m_LargestPossibleRegion.SetSize (i, m_Dimensions[i]);
  }
  m_LargestPossibleRegion.SetIndex(i, 0);
  m_LargestPossibleRegion.SetSize(i, channels);

  if(m_LargestPossibleRegion.GetNumberOfPixels()==0)
  {
    delete [] m_Dimensions;
    m_Dimensions = NULL;
    return;
  }

  for( unsigned int i=0u; i<channels; i++)
  {
    this->m_ImageDescriptor->AddNewChannel( type );
  }

  PlaneGeometry::Pointer planegeometry = PlaneGeometry::New();
  planegeometry->InitializeStandardPlane(m_Dimensions[0], m_Dimensions[1]);

  SlicedGeometry3D::Pointer slicedGeometry = SlicedGeometry3D::New();
  slicedGeometry->InitializeEvenlySpaced(planegeometry, m_Dimensions[2]);

  if(dimension>=4)
  {
    TimeBounds timebounds;
    timebounds[0] = 0.0;
    timebounds[1] = 1.0;
    slicedGeometry->SetTimeBounds(timebounds);
  }

  ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New();
  timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]);
  for (TimeStepType step = 0; step < timeGeometry->CountTimeSteps(); ++step)
  {
    timeGeometry->GetGeometryForTimeStep(step)->ImageGeometryOn();
  }
  SetTimeGeometry(timeGeometry);

  ImageDataItemPointer dnull=NULL;

  m_Channels.assign(GetNumberOfChannels(), dnull);

  m_Volumes.assign(GetNumberOfChannels()*m_Dimensions[3], dnull);

  m_Slices.assign(GetNumberOfChannels()*m_Dimensions[3]*m_Dimensions[2], dnull);

  ComputeOffsetTable();

  Initialize();

  m_Initialized = true;
}
void
  mitk::SlicedGeometry3D::InitializePlanes(
  const mitk::BaseGeometry *geometry3D,
  mitk::PlaneGeometry::PlaneOrientation planeorientation,
  bool top, bool frontside, bool rotated )
{
  m_ReferenceGeometry = const_cast< BaseGeometry * >( geometry3D );

  PlaneGeometry::Pointer planeGeometry = mitk::PlaneGeometry::New();
  planeGeometry->InitializeStandardPlane(
    geometry3D, top, planeorientation, frontside, rotated );

  ScalarType viewSpacing = 1;
  unsigned int slices = 1;

  switch ( planeorientation )
  {
  case PlaneGeometry::Axial:
    viewSpacing = geometry3D->GetSpacing()[2];
    slices = (unsigned int) geometry3D->GetExtent( 2 );
    break;

  case PlaneGeometry::Frontal:
    viewSpacing = geometry3D->GetSpacing()[1];
    slices = (unsigned int) geometry3D->GetExtent( 1 );
    break;

  case PlaneGeometry::Sagittal:
    viewSpacing = geometry3D->GetSpacing()[0];
    slices = (unsigned int) geometry3D->GetExtent( 0 );
    break;

  default:
    itkExceptionMacro("unknown PlaneOrientation");
  }

  mitk::Vector3D normal = this->AdjustNormal( planeGeometry->GetNormal() );

  ScalarType directedExtent =
    std::abs( m_ReferenceGeometry->GetExtentInMM( 0 ) * normal[0] )
    + std::abs( m_ReferenceGeometry->GetExtentInMM( 1 ) * normal[1] )
    + std::abs( m_ReferenceGeometry->GetExtentInMM( 2 ) * normal[2] );

  if ( directedExtent >= viewSpacing )
  {
    slices = static_cast< int >(directedExtent / viewSpacing + 0.5);
  }
  else
  {
    slices = 1;
  }

  bool flipped = (top == false);

  if ( frontside == false )
  {
    flipped = !flipped;
  }
  if ( planeorientation == PlaneGeometry::Frontal )
  {
    flipped = !flipped;
  }

  this->InitializeEvenlySpaced( planeGeometry, viewSpacing, slices, flipped );
}
Ejemplo n.º 6
0
void mitk::ExtractImageFilter::GenerateData()
{
   Image::ConstPointer input = ImageToImageFilter::GetInput(0);

   if ( (input->GetDimension() > 4) || (input->GetDimension() < 2) )
   {
     MITK_ERROR << "mitk::ExtractImageFilter:GenerateData works only with 3D and 3D+t images, sorry." << std::endl;
     itkExceptionMacro("mitk::ExtractImageFilter works only with 3D and 3D+t images, sorry.");
     return;
   }
   else if (input->GetDimension() == 4)
   {
     ImageTimeSelector::Pointer timeSelector = ImageTimeSelector::New();
     timeSelector->SetInput( input );
     timeSelector->SetTimeNr( m_TimeStep );
     timeSelector->UpdateLargestPossibleRegion();
     input = timeSelector->GetOutput();
   }
   else if (input->GetDimension() == 2)
   {
     Image::Pointer resultImage = ImageToImageFilter::GetOutput();
     resultImage = const_cast<Image*>(input.GetPointer());
     ImageToImageFilter::SetNthOutput( 0, resultImage );
     return;
   }

  if ( m_SliceDimension >= input->GetDimension() )
  {
    MITK_ERROR << "mitk::ExtractImageFilter:GenerateData  m_SliceDimension == " << m_SliceDimension << " makes no sense with an " << input->GetDimension() << "D image." << std::endl;
    itkExceptionMacro("This is not a sensible value for m_SliceDimension.");
    return;
  }

   AccessFixedDimensionByItk( input, ItkImageProcessing, 3 );

  // set a nice geometry for display and point transformations
  Geometry3D* inputImageGeometry = ImageToImageFilter::GetInput(0)->GetGeometry();
  if (!inputImageGeometry)
  {
    MITK_ERROR << "In ExtractImageFilter::ItkImageProcessing: Input image has no geometry!" << std::endl;
    return;
  }

  PlaneGeometry::PlaneOrientation orientation = PlaneGeometry::Axial;

  switch ( m_SliceDimension )
  {
    default:
    case 2: 
      orientation = PlaneGeometry::Axial;
      break;
    case 1: 
      orientation = PlaneGeometry::Frontal;
      break;
    case 0: 
      orientation = PlaneGeometry::Sagittal;
      break;
   }
 
  PlaneGeometry::Pointer planeGeometry = PlaneGeometry::New();
  planeGeometry->InitializeStandardPlane( inputImageGeometry, orientation, (ScalarType)m_SliceIndex, true, false );
  Image::Pointer resultImage = ImageToImageFilter::GetOutput();
  planeGeometry->ChangeImageGeometryConsideringOriginOffset(true);
  resultImage->SetGeometry( planeGeometry );
}