void SliceNavigationController::Update(SliceNavigationController::ViewDirection viewDirection,
                                         bool top,
                                         bool frontside,
                                         bool rotated)
  {
    TimeGeometry::ConstPointer worldTimeGeometry = m_InputWorldTimeGeometry;

    if (m_BlockUpdate || (m_InputWorldTimeGeometry.IsNull() && m_InputWorldGeometry3D.IsNull()) ||
        ((worldTimeGeometry.IsNotNull()) && (worldTimeGeometry->CountTimeSteps() == 0)))
    {
      return;
    }

    m_BlockUpdate = true;

    if (m_InputWorldTimeGeometry.IsNotNull() && m_LastUpdateTime < m_InputWorldTimeGeometry->GetMTime())
    {
      Modified();
    }
    if (m_InputWorldGeometry3D.IsNotNull() && m_LastUpdateTime < m_InputWorldGeometry3D->GetMTime())
    {
      Modified();
    }
    this->SetViewDirection(viewDirection);
    this->SetTop(top);
    this->SetFrontSide(frontside);
    this->SetRotated(rotated);

    if (m_LastUpdateTime < GetMTime())
    {
      m_LastUpdateTime = GetMTime();

      // initialize the viewplane
      SlicedGeometry3D::Pointer slicedWorldGeometry = SlicedGeometry3D::Pointer();
      BaseGeometry::ConstPointer currentGeometry = BaseGeometry::ConstPointer();
      if (m_InputWorldTimeGeometry.IsNotNull())
        if (m_InputWorldTimeGeometry->IsValidTimeStep(GetTime()->GetPos()))
          currentGeometry = m_InputWorldTimeGeometry->GetGeometryForTimeStep(GetTime()->GetPos());
        else
          currentGeometry = m_InputWorldTimeGeometry->GetGeometryForTimeStep(0);
      else
        currentGeometry = m_InputWorldGeometry3D;

      m_CreatedWorldGeometry = mitk::TimeGeometry::Pointer();
      switch (viewDirection)
      {
        case Original:
          if (worldTimeGeometry.IsNotNull())
          {
            m_CreatedWorldGeometry = worldTimeGeometry->Clone();

            worldTimeGeometry = m_CreatedWorldGeometry.GetPointer();

            slicedWorldGeometry = dynamic_cast<SlicedGeometry3D *>(
              m_CreatedWorldGeometry->GetGeometryForTimeStep(this->GetTime()->GetPos()).GetPointer());

            if (slicedWorldGeometry.IsNotNull())
            {
              break;
            }
          }
          else
          {
            const SlicedGeometry3D *worldSlicedGeometry =
              dynamic_cast<const SlicedGeometry3D *>(currentGeometry.GetPointer());

          if ( worldSlicedGeometry != nullptr )
            {
              slicedWorldGeometry = static_cast<SlicedGeometry3D *>(currentGeometry->Clone().GetPointer());
              break;
            }
          }
          slicedWorldGeometry = SlicedGeometry3D::New();
          slicedWorldGeometry->InitializePlanes(currentGeometry, PlaneGeometry::None, top, frontside, rotated);
          slicedWorldGeometry->SetSliceNavigationController(this);
          break;

        case Axial:
          slicedWorldGeometry = SlicedGeometry3D::New();
          slicedWorldGeometry->InitializePlanes(currentGeometry, PlaneGeometry::Axial, top, frontside, rotated);
          slicedWorldGeometry->SetSliceNavigationController(this);
          break;

        case Frontal:
          slicedWorldGeometry = SlicedGeometry3D::New();
          slicedWorldGeometry->InitializePlanes(currentGeometry, PlaneGeometry::Frontal, top, frontside, rotated);
          slicedWorldGeometry->SetSliceNavigationController(this);
          break;

        case Sagittal:
          slicedWorldGeometry = SlicedGeometry3D::New();
          slicedWorldGeometry->InitializePlanes(currentGeometry, PlaneGeometry::Sagittal, top, frontside, rotated);
          slicedWorldGeometry->SetSliceNavigationController(this);
          break;
        default:
          itkExceptionMacro("unknown ViewDirection");
      }

      m_Slice->SetPos(0);
      m_Slice->SetSteps((int)slicedWorldGeometry->GetSlices());

      if ( worldTimeGeometry.IsNull() )
      {
        auto createdTimeGeometry = ProportionalTimeGeometry::New();
        createdTimeGeometry->Initialize( slicedWorldGeometry, 1 );
        m_CreatedWorldGeometry = createdTimeGeometry;
      
        m_Time->SetSteps(0);
        m_Time->SetPos(0);
        m_Time->InvalidateRange();
      }
      else
      {
        m_BlockUpdate = true;
        m_Time->SetSteps(worldTimeGeometry->CountTimeSteps());
        m_Time->SetPos(0);

        const TimeBounds &timeBounds = worldTimeGeometry->GetTimeBounds();
        m_Time->SetRange(timeBounds[0], timeBounds[1]);

        m_BlockUpdate = false;

        const auto currentTemporalPosition = this->GetTime()->GetPos();
        assert( worldTimeGeometry->GetGeometryForTimeStep( currentTemporalPosition ).IsNotNull() );

      if ( dynamic_cast<const mitk::ProportionalTimeGeometry*>( worldTimeGeometry.GetPointer() ) != nullptr )
      {
        const TimePointType minimumTimePoint =
          worldTimeGeometry->TimeStepToTimePoint( currentTemporalPosition );
        
        const TimePointType stepDuration =
          worldTimeGeometry->TimeStepToTimePoint( currentTemporalPosition + 1 ) - minimumTimePoint;

        auto createdTimeGeometry = ProportionalTimeGeometry::New();
        createdTimeGeometry->Initialize( slicedWorldGeometry, worldTimeGeometry->CountTimeSteps() );
        createdTimeGeometry->SetFirstTimePoint( minimumTimePoint );
        createdTimeGeometry->SetStepDuration( stepDuration );

        m_CreatedWorldGeometry = createdTimeGeometry;
      }
      else
      {
        auto createdTimeGeometry = mitk::ArbitraryTimeGeometry::New();
        const TimeStepType numberOfTimeSteps = worldTimeGeometry->CountTimeSteps();
        createdTimeGeometry->ReserveSpaceForGeometries( numberOfTimeSteps );

        for ( TimeStepType i = 0; i < numberOfTimeSteps; ++i )
        {
          const BaseGeometry::Pointer clonedGeometry = slicedWorldGeometry->Clone().GetPointer();
          const auto bounds = worldTimeGeometry->GetTimeBounds( i );
          createdTimeGeometry->AppendNewTimeStep( clonedGeometry,
            bounds[0], bounds[1]);
        }
        createdTimeGeometry->Update();

        m_CreatedWorldGeometry = createdTimeGeometry;
      }
      }
    }

    // unblock update; we may do this now, because if m_BlockUpdate was already
    // true before this method was entered, then we will never come here.
    m_BlockUpdate = false;

    // Send the geometry. Do this even if nothing was changed, because maybe
    // Update() was only called to re-send the old geometry and time/slice data.
    this->SendCreatedWorldGeometry();
    this->SendSlice();
    this->SendTime();

    // Adjust the stepper range of slice stepper according to geometry
    this->AdjustSliceStepperRange();
  }
Exemple #2
0
void mitk::Image::Initialize(const mitk::PixelType& type, int sDim, const mitk::PlaneGeometry& geometry2d, bool flipped, unsigned int channels, int tDim )
{
  SlicedGeometry3D::Pointer slicedGeometry = SlicedGeometry3D::New();
  slicedGeometry->InitializeEvenlySpaced(static_cast<PlaneGeometry*>(geometry2d.Clone().GetPointer()), sDim, flipped);
  Initialize(type, *slicedGeometry, channels, tDim);
}
void
SliceNavigationController::Update(
  SliceNavigationController::ViewDirection viewDirection,
  bool top, bool frontside, bool rotated )
{
  const TimeSlicedGeometry* worldTimeSlicedGeometry =
    dynamic_cast< const TimeSlicedGeometry * >(
      m_InputWorldGeometry.GetPointer() );

  if( m_BlockUpdate || 
      m_InputWorldGeometry.IsNull() || 
      ( (worldTimeSlicedGeometry != NULL) && (worldTimeSlicedGeometry->GetTimeSteps() == 0) )
    )
  {
    return;
  }

  m_BlockUpdate = true;

  if ( m_LastUpdateTime < m_InputWorldGeometry->GetMTime() )
  {
    Modified();
  }

  this->SetViewDirection( viewDirection );
  this->SetTop( top );
  this->SetFrontSide( frontside );
  this->SetRotated( rotated );

  if ( m_LastUpdateTime < GetMTime() )
  {
    m_LastUpdateTime = GetMTime();

    // initialize the viewplane
    SlicedGeometry3D::Pointer slicedWorldGeometry = NULL;
    
    m_CreatedWorldGeometry = NULL;
    switch ( viewDirection )
    {
    case Original:
      if ( worldTimeSlicedGeometry != NULL )
      {
        m_CreatedWorldGeometry = static_cast< TimeSlicedGeometry * >(
          m_InputWorldGeometry->Clone().GetPointer() );

        worldTimeSlicedGeometry = m_CreatedWorldGeometry.GetPointer();

        slicedWorldGeometry = dynamic_cast< SlicedGeometry3D * >(
          m_CreatedWorldGeometry->GetGeometry3D( this->GetTime()->GetPos() ) );

        if ( slicedWorldGeometry.IsNotNull() )
        {
          break;
        }
      }
      else
      {
        const SlicedGeometry3D *worldSlicedGeometry =
          dynamic_cast< const SlicedGeometry3D * >(
            m_InputWorldGeometry.GetPointer());

        if ( worldSlicedGeometry != NULL )
        {
          slicedWorldGeometry = static_cast< SlicedGeometry3D * >(
            m_InputWorldGeometry->Clone().GetPointer());
          break;
        }
      }
      //else: use Transversal: no "break" here!!

    case Transversal:
      slicedWorldGeometry = SlicedGeometry3D::New();
      slicedWorldGeometry->InitializePlanes(
        m_InputWorldGeometry, PlaneGeometry::Transversal,
        top, frontside, rotated );
      slicedWorldGeometry->SetSliceNavigationController( this );
      break;

    case Frontal:
      slicedWorldGeometry = SlicedGeometry3D::New();
      slicedWorldGeometry->InitializePlanes( m_InputWorldGeometry,
        PlaneGeometry::Frontal, top, frontside, rotated );
      slicedWorldGeometry->SetSliceNavigationController( this );
      break;

    case Sagittal:
      slicedWorldGeometry = SlicedGeometry3D::New();
      slicedWorldGeometry->InitializePlanes( m_InputWorldGeometry,
        PlaneGeometry::Sagittal, top, frontside, rotated );
      slicedWorldGeometry->SetSliceNavigationController( this );
      break;
    default:
      itkExceptionMacro("unknown ViewDirection");
    }

    m_Slice->SetPos( 0 );
    m_Slice->SetSteps( (int)slicedWorldGeometry->GetSlices() );
  
    if ( m_CreatedWorldGeometry.IsNull() )
    {
      // initialize TimeSlicedGeometry
      m_CreatedWorldGeometry = TimeSlicedGeometry::New();
    }
    if ( worldTimeSlicedGeometry == NULL )
    {
      m_CreatedWorldGeometry->InitializeEvenlyTimed( slicedWorldGeometry, 1 );
      m_Time->SetSteps( 0 );
      m_Time->SetPos( 0 );
      m_Time->InvalidateRange();
    }
    else
    {
      m_BlockUpdate = true;
      m_Time->SetSteps( worldTimeSlicedGeometry->GetTimeSteps() );
      m_Time->SetPos( 0 );

      const TimeBounds &timeBounds = worldTimeSlicedGeometry->GetTimeBounds();
      m_Time->SetRange( timeBounds[0], timeBounds[1] );

      m_BlockUpdate = false;

      assert( worldTimeSlicedGeometry->GetGeometry3D( this->GetTime()->GetPos() ) != NULL );

      slicedWorldGeometry->SetTimeBounds(
        worldTimeSlicedGeometry->GetGeometry3D( this->GetTime()->GetPos() )->GetTimeBounds() );

      //@todo implement for non-evenly-timed geometry!
      m_CreatedWorldGeometry->InitializeEvenlyTimed(
        slicedWorldGeometry, worldTimeSlicedGeometry->GetTimeSteps() );
    }
  }

  // unblock update; we may do this now, because if m_BlockUpdate was already
  // true before this method was entered, then we will never come here.
  m_BlockUpdate = false;

  // Send the geometry. Do this even if nothing was changed, because maybe
  // Update() was only called to re-send the old geometry and time/slice data.
  this->SendCreatedWorldGeometry();
  this->SendSlice();
  this->SendTime();

  // Adjust the stepper range of slice stepper according to geometry
  this->AdjustSliceStepperRange();
}
Exemple #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 = nullptr;
    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]);

  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=nullptr;

  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;
}
mitk::Image::Pointer mitk::PicFileReader::CreateImage()
{
  Image::Pointer output = Image::New();

  std::string fileName = this->GetLocalFileName();

  mitkIpPicDescriptor *header = mitkIpPicGetHeader(const_cast<char *>(fileName.c_str()), NULL);

  if (!header)
  {
    mitkThrow() << "File could not be read.";
  }

  header = mitkIpPicGetTags(const_cast<char *>(fileName.c_str()), header);

  int channels = 1;

  mitkIpPicTSV_t *tsv;
  if ((tsv = mitkIpPicQueryTag(header, "SOURCE HEADER")) != NULL)
  {
    if (tsv->n[0] > 1e+06)
    {
      mitkIpPicTSV_t *tsvSH;
      tsvSH = mitkIpPicDelTag(header, "SOURCE HEADER");
      mitkIpPicFreeTag(tsvSH);
    }
  }
  if ((tsv = mitkIpPicQueryTag(header, "ICON80x80")) != NULL)
  {
    mitkIpPicTSV_t *tsvSH;
    tsvSH = mitkIpPicDelTag(header, "ICON80x80");
    mitkIpPicFreeTag(tsvSH);
  }
  if ((tsv = mitkIpPicQueryTag(header, "VELOCITY")) != NULL)
  {
    ++channels;
    mitkIpPicDelTag(header, "VELOCITY");
  }

  if (header == NULL || header->bpe == 0)
  {
    mitkThrow() << " Could not read file " << fileName;
  }

  // if pic image only 2D, the n[2] value is not initialized
  unsigned int slices = 1;
  if (header->dim == 2)
  {
    header->n[2] = slices;
  }

  // First initialize the geometry of the output image by the pic-header
  SlicedGeometry3D::Pointer slicedGeometry = mitk::SlicedGeometry3D::New();
  PicHelper::InitializeEvenlySpaced(header, header->n[2], slicedGeometry);

  // if pic image only 3D, the n[3] value is not initialized
  unsigned int timesteps = 1;
  if (header->dim > 3)
  {
    timesteps = header->n[3];
  }

  slicedGeometry->ImageGeometryOn();
  ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New();
  timeGeometry->Initialize(slicedGeometry, timesteps);

  // Cast the pic descriptor to ImageDescriptor and initialize the output

  output->Initialize(CastToImageDescriptor(header));
  output->SetTimeGeometry(timeGeometry);
  mitkIpPicFree(header);

  return output;
}