void mitk::PointSetToCurvedGeometryFilter::GenerateOutputInformation()
{
  mitk::PointSet::ConstPointer input  = this->GetInput();
  mitk::Geometry2DData::Pointer output  = dynamic_cast<mitk::Geometry2DData*> ( this->GetOutput() );

  if ( input.IsNull() )
    itkGenericExceptionMacro ( "Input point set is NULL!" );

  if ( input->GetTimeGeometry()->CountTimeSteps() != 1 )
    itkWarningMacro ( "More than one time step is not yet supported!" );

  if ( output.IsNull() )
    itkGenericExceptionMacro ( "Output is NULL!" );

  if ( m_ImageToBeMapped.IsNull() )
    itkGenericExceptionMacro ( "Image to be mapped is NULL!" );

  bool update = false;
  if ( output->GetGeometry() == NULL || output->GetGeometry2D() == NULL || output->GetTimeGeometry() == NULL )
    update = true;
  if ( ( ! update ) && ( output->GetTimeGeometry()->CountTimeSteps() != input->GetTimeGeometry()->CountTimeSteps() ) )
    update = true;
  if ( update )
  {
    mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New();
    output->SetGeometry(curvedGeometry);
  }
}
void mitk::PointSetToCurvedGeometryFilter::GenerateOutputInformation()
{
  mitk::PointSet::ConstPointer input  = this->GetInput();
  mitk::Geometry2DData::Pointer output  = dynamic_cast<mitk::Geometry2DData*> ( this->GetOutput() );

  if ( input.IsNull() )
    itkGenericExceptionMacro ( "Input point set is NULL!" );

  if ( input->GetTimeSlicedGeometry()->GetTimeSteps() != 1 )
    itkWarningMacro ( "More than one time step is not yet supported!" );

  if ( output.IsNull() )
    itkGenericExceptionMacro ( "Output is NULL!" );

  if ( m_ImageToBeMapped.IsNull() )
    itkGenericExceptionMacro ( "Image to be mapped is NULL!" );

  bool update = false;
  if ( output->GetGeometry() == NULL || output->GetGeometry2D() == NULL || output->GetTimeSlicedGeometry() == NULL )
    update = true;
  if ( ( ! update ) && ( output->GetTimeSlicedGeometry()->GetTimeSteps() != input->GetTimeSlicedGeometry()->GetTimeSteps() ) )
    update = true;
  if ( update )
  {
    mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New();
    output->SetGeometry(curvedGeometry);

    /*
    mitk::TimeSlicedGeometry::Pointer timeGeometry = mitk::TimeSlicedGeometry::New();
    mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New();

    timeGeometry->InitializeEvenlyTimed ( curvedGeometry, input->GetPointSetSeriesSize() );

    for ( unsigned int t = 1; t < input->GetPointSetSeriesSize(); ++t )
    {
      mitk::ThinPlateSplineCurvedGeometry::Pointer tmpCurvedGeometry = mitk::ThinPlateSplineCurvedGeometry::New();
      timeGeometry->SetGeometry3D ( tmpCurvedGeometry.GetPointer(), t );
    }
    output->SetGeometry ( timeGeometry );
    output->SetGeometry2D ( curvedGeometry ); // @FIXME SetGeometry2D of mitk::Geometry2DData reinitializes the TimeSlicedGeometry to 1 time step
    */
  }
}
Exemple #3
0
mitk::Image::Pointer LoadImage( std::string filename )
{
  mitk::ItkImageFileReader::Pointer reader = mitk::ItkImageFileReader::New();
  reader->SetFileName ( filename.c_str() );
  reader->Update();
  if ( reader->GetOutput() == NULL )
    itkGenericExceptionMacro("File "<<filename <<" could not be read!");
  mitk::Image::Pointer image = reader->GetOutput();
  return image;
}
Exemple #4
0
mitk::ModelBase::ModelResultType mitk::InterpolateSignalToNewTimeGrid(const ModelBase::ModelResultType& inputSignal, const ModelBase::TimeGridType& inputGrid, const ModelBase::TimeGridType& outputGrid)
{
    mitk::ModelBase::ModelResultType result(outputGrid.GetSize());
    if (! inputSignal.GetSize())
    {
      return result;
    }

    if (inputSignal.GetSize() != inputGrid.GetSize())
    {
      itkGenericExceptionMacro("Input signal and input time grid have not the same size.");
    }

    mitk::ModelBase::ModelResultType::ValueType lastValue = inputSignal[0];
    mitk::ModelBase::TimeGridType::ValueType lastTime = itk::NumericTraits<mitk::ModelBase::TimeGridType::ValueType>::NonpositiveMin();

    mitk::ModelBase::TimeGridType::const_iterator posITime = inputGrid.begin();
    mitk::ModelBase::ModelResultType::const_iterator posValue = inputSignal.begin();
    mitk::ModelBase::ModelResultType::iterator posResult = result.begin();

    for(mitk::ModelBase::TimeGridType::const_iterator posOTime = outputGrid.begin(); posOTime != outputGrid.end(); ++posResult, ++posOTime)
    {
        while(posITime!=inputGrid.end() && *posOTime > *posITime)
      { //forward in the input grid until the current output point
        //is between last and the current input point.
        lastValue = *posValue;
        lastTime = *posITime;
        ++posValue;
        ++posITime;
      }

      double weightLast = 1 - (*posOTime - lastTime)/(*posITime - lastTime);
      double weightNext = 1 - (*posITime - *posOTime)/(*posITime - lastTime);

      *posResult = weightLast * lastValue + weightNext * (*posValue);
    }

    return result;
};
void mitk::PointSetToCurvedGeometryFilter::GenerateData()
{
  mitk::PointSet::ConstPointer input  = this->GetInput();
  mitk::GeometryData::Pointer output  = this->GetOutput();

  //
  // check preconditions
  //
  if ( input.IsNull() )
    itkGenericExceptionMacro ( "Input point set is NULL!" );
  if ( output.IsNull() )
    itkGenericExceptionMacro ( "output geometry data is NULL!" );
  if ( output->GetTimeGeometry() == NULL )
    itkGenericExceptionMacro ( "Output time sliced geometry is NULL!" );
  if ( output->GetTimeGeometry()->GetGeometryForTimeStep ( 0 ).IsNull() )
    itkGenericExceptionMacro ( "Output geometry3d is NULL!" );
  mitk::ThinPlateSplineCurvedGeometry::Pointer curvedGeometry = dynamic_cast<mitk::ThinPlateSplineCurvedGeometry*> ( output->GetTimeGeometry()->GetGeometryForTimeStep( 0 ).GetPointer() );
  if ( curvedGeometry.IsNull() )
    itkGenericExceptionMacro ( "Output geometry3d is not an instance of mitk::ThinPlateSPlineCurvedGeometry!" );
  if ( m_ImageToBeMapped.IsNull() )
    itkGenericExceptionMacro ( "Image to be mapped is NULL!" );

  //
  // initialize members if needed
  //
  if ( m_XYPlane.IsNull()  ||  m_XZPlane.IsNull() || m_YZPlane.IsNull() )
  {
    m_ImageToBeMapped->UpdateOutputInformation();
    const mitk::Geometry3D* imageGeometry = m_ImageToBeMapped->GetUpdatedGeometry();
    imageGeometry = m_ImageToBeMapped->GetUpdatedGeometry();
    m_XYPlane = mitk::PlaneGeometry::New();
    m_XZPlane = mitk::PlaneGeometry::New();
    m_YZPlane = mitk::PlaneGeometry::New();
    m_XYPlane->InitializeStandardPlane ( imageGeometry, mitk::PlaneGeometry::Axial );
    m_YZPlane->InitializeStandardPlane ( imageGeometry, mitk::PlaneGeometry::Sagittal );
    m_XZPlane->InitializeStandardPlane ( imageGeometry, mitk::PlaneGeometry::Frontal );
  }
  if ( m_PlaneLandmarkProjector.IsNull() )
  {
    m_PlaneLandmarkProjector = mitk::PlaneLandmarkProjector::New();
    m_SphereLandmarkProjector = mitk::SphereLandmarkProjector::New();
  }

  //
  // set up geometry according to the current settings
  //
  if ( m_ProjectionMode == Sphere )
  {
    curvedGeometry->SetLandmarkProjector ( m_SphereLandmarkProjector );
  }
  else
  {
    if ( m_ProjectionMode == XYPlane )
      m_PlaneLandmarkProjector->SetProjectionPlane ( m_XYPlane );
    else if ( m_ProjectionMode == XZPlane )
      m_PlaneLandmarkProjector->SetProjectionPlane ( m_XZPlane );
    else if ( m_ProjectionMode == YZPlane )
      m_PlaneLandmarkProjector->SetProjectionPlane ( m_YZPlane );
    else if ( m_ProjectionMode == PCAPlane )
    {
      itkExceptionMacro ( "PCAPlane not yet implemented!" );
      m_PCAPlaneCalculator->SetInput ( input );
      m_PCAPlaneCalculator->Update();
      m_PlaneLandmarkProjector->SetProjectionPlane ( dynamic_cast<mitk::PlaneGeometry*> ( m_PCAPlaneCalculator->GetOutput() ) );
    }
    else
      itkExceptionMacro ( "Unknown projection mode" );

    curvedGeometry->SetLandmarkProjector ( m_PlaneLandmarkProjector );
  }
  //curvedGeometry->SetReferenceGeometry( m_ImageToBeMapped->GetGeometry() );
  curvedGeometry->SetTargetLandmarks ( input->GetPointSet ( 0 )->GetPoints() );
  curvedGeometry->SetSigma ( m_Sigma );
  curvedGeometry->ComputeGeometry();
  curvedGeometry->SetOversampling ( 1.0 );

}