void mitk::PlanesPerpendicularToLinesFilter::CreatePlane(const mitk::Point3D& curr)
{
  int j;
  for(j=0;j<3;++j)
    normal[j] = last[j]-curr[j]; //@todo globally define normal direction of display xxx
  normal.normalize();

  down = vnl_cross_3d(normal, targetRight);
  down.normalize();
  right = vnl_cross_3d(down, normal);
  right.normalize();

  itk2vtk(last.GetVnlVector()-right*halfWidthInMM-down*halfHeightInMM, origin);
  right  *= targetSpacing[0];
  down   *= targetSpacing[1];
  normal *= targetSpacing[2];

  mitk::Matrix3D matrix;
  matrix.GetVnlMatrix().set_column(0, right);
  matrix.GetVnlMatrix().set_column(1, down);
  matrix.GetVnlMatrix().set_column(2, normal);

  PlaneGeometry::Pointer plane = PlaneGeometry::New();
  plane->GetIndexToWorldTransform()->SetMatrix(matrix);
  plane->SetOrigin(origin);
  plane->SetBounds(bounds);

  planes.push_back(plane);

  last = curr;
}
示例#2
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");
}
示例#3
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);
  }
}
mitk::SlicedGeometry3D::SlicedGeometry3D(const SlicedGeometry3D& other)
  : Superclass(other),
  m_EvenlySpaced( other.m_EvenlySpaced ),
  m_Slices( other.m_Slices ),
  m_ReferenceGeometry( other.m_ReferenceGeometry ),
  m_SliceNavigationController( other.m_SliceNavigationController )
{
  m_DirectionVector.Fill(0);
  SetSpacing( other.GetSpacing() );
  SetDirectionVector( other.GetDirectionVector() );

  if ( m_EvenlySpaced )
  {
    PlaneGeometry::Pointer geometry = other.m_PlaneGeometries[0]->Clone();
    assert(geometry.IsNotNull());
    SetPlaneGeometry(geometry, 0);
  }
  else
  {
    unsigned int s;
    for ( s = 0; s < other.m_Slices; ++s )
    {
      if ( other.m_PlaneGeometries[s].IsNull() )
      {
        assert(other.m_EvenlySpaced);
        m_PlaneGeometries[s] = nullptr;
      }
      else
      {
        PlaneGeometry* geometry2D = other.m_PlaneGeometries[s]->Clone();
        assert(geometry2D!=nullptr);
        SetPlaneGeometry(geometry2D, s);
      }
    }
  }
}
示例#5
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);
  }
}
示例#6
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::PlanesPerpendicularToLinesFilter::GenerateData()
{
  mitk::Mesh::ConstPointer input  = this->GetInput();
  mitk::GeometryData::Pointer output = this->GetOutput();

  if(m_Plane.IsNotNull())
  {
    targetRight   = m_Plane->GetMatrixColumn(0);
    targetSpacing = m_Plane->GetSpacing();
    bounds = m_Plane->GetBoundingBox()->GetBounds();
    halfWidthInMM  = m_Plane->GetExtentInMM(0)*0.5;
    halfHeightInMM = m_Plane->GetExtentInMM(1)*0.5;
  }
  else
  {
    FillVector3D(targetRight, 1.0, 0.0, 0.0);
    targetSpacing.Fill(1.0);
    halfWidthInMM=halfHeightInMM=100.0;
    ScalarType stdBounds[6] = {0.0, 2.0*halfWidthInMM, 0.0, 2.0*halfHeightInMM, 0.0, 0.0};
    bounds = stdBounds;
  }

  if(m_UseAllPoints==false)
  {
    int i, size;
    //iterate through all cells and build planes
    Mesh::ConstCellIterator cellIt, cellEnd;
    cellEnd = input->GetMesh()->GetCells()->End();
    for( cellIt = input->GetMesh()->GetCells()->Begin(); cellIt != cellEnd; ++cellIt )
    {
      Mesh::CellType& cell = *cellIt->Value();

      Mesh::PointIdIterator ptIt, ptEnd;
      ptEnd = cell.PointIdsEnd();

      size=cell.GetNumberOfPoints();
      if(size<=1)
        continue;

      ptIt = cell.PointIdsBegin();
      last = input->GetPoint(*ptIt);
      ++ptIt;
      for(i=1;i<size;++i, ++ptIt)
      {
        CreatePlane(input->GetPoint(*ptIt));
      }
    }
  }
  else //m_UseAllPoints==true
  {
    //iterate through all points and build planes
    mitk::PointSet::PointsConstIterator it, pend = input->GetPointSet()->GetPoints()->End();
    it=input->GetPointSet()->GetPoints()->Begin();
    last = it.Value();
    ++it;
    for(;it!=pend;++it)
    {
        CreatePlane(it.Value());
    }
  }

  if(planes.size()>0)
  {
    //initialize sliced-geometry for the number of created planes
    m_CreatedGeometries->InitializeSlicedGeometry(planes.size()+1);

    //set last plane at last point with same normal as the one before the last
    PlaneGeometry::Pointer plane = static_cast<PlaneGeometry*>((*planes.rbegin())->Clone().GetPointer());
    itk2vtk(last.GetVnlVector()-right*halfWidthInMM-down*halfHeightInMM, origin);
    plane->SetOrigin(origin);
    m_CreatedGeometries->SetGeometry2D(plane, planes.size());

    //add all planes to sliced-geometry
    int s;
    for(s=0; planes.empty()==false; planes.pop_front(), ++s)
    {
      m_CreatedGeometries->SetGeometry2D(planes.front(), s);
    }

    m_CreatedGeometries->SetEvenlySpaced(false);

    if(m_FrameGeometry.IsNotNull())
    {
      m_CreatedGeometries->SetIndexToWorldTransform(m_FrameGeometry->GetIndexToWorldTransform());
      m_CreatedGeometries->SetBounds(m_FrameGeometry->GetBounds());
      m_CreatedGeometries->SetReferenceGeometry(m_FrameGeometry);
    }
  }

  output->SetGeometry(m_CreatedGeometries);
}
void
  mitk::SlicedGeometry3D::ExecuteOperation(Operation* operation)
{
  switch ( operation->GetOperationType() )
  {
  case OpNOTHING:
    break;

  case OpROTATE:
    if ( m_EvenlySpaced )
    {
      // Need a reference frame to align the rotation
      if ( m_ReferenceGeometry )
      {
        // Clear all generated geometries and then rotate only the first slice.
        // The other slices will be re-generated on demand

        // Save first slice
        PlaneGeometry::Pointer geometry2D = m_PlaneGeometries[0];

        RotationOperation *rotOp = dynamic_cast< RotationOperation * >( operation );

        // Generate a RotationOperation using the dataset center instead of
        // the supplied rotation center. This is necessary so that the rotated
        // zero-plane does not shift away. The supplied center is instead used
        // to adjust the slice stack afterwards.
        Point3D center = m_ReferenceGeometry->GetCenter();

        RotationOperation centeredRotation(
          rotOp->GetOperationType(),
          center,
          rotOp->GetVectorOfRotation(),
          rotOp->GetAngleOfRotation()
          );

        // Rotate first slice
        geometry2D->ExecuteOperation( &centeredRotation );

        // Clear the slice stack and adjust it according to the center of
        // the dataset and the supplied rotation center (see documentation of
        // ReinitializePlanes)
        this->ReinitializePlanes( center, rotOp->GetCenterOfRotation() );

        geometry2D->SetSpacing(this->GetSpacing());

        if ( m_SliceNavigationController )
        {
          m_SliceNavigationController->SelectSliceByPoint(
            rotOp->GetCenterOfRotation() );
          m_SliceNavigationController->AdjustSliceStepperRange();
        }

        BaseGeometry::ExecuteOperation( &centeredRotation );
      }
      else
      {
        // we also have to consider the case, that there is no reference geometry available.
        if ( m_PlaneGeometries.size() > 0 )
        {
          // Reach through to all slices in my container
          for (auto iter = m_PlaneGeometries.begin();
            iter != m_PlaneGeometries.end();
            ++iter)
          {
            // Test for empty slices, which can happen if evenly spaced geometry
            if ((*iter).IsNotNull())
            {
              (*iter)->ExecuteOperation(operation);
            }
          }

          // rotate overall geometry
          RotationOperation *rotOp = dynamic_cast< RotationOperation * >( operation );
          BaseGeometry::ExecuteOperation( rotOp);
        }
      }
    }
    else
    {
      // Reach through to all slices
      for (auto iter = m_PlaneGeometries.begin();
        iter != m_PlaneGeometries.end();
        ++iter)
      {
        (*iter)->ExecuteOperation(operation);
      }
    }
    break;

  case OpORIENT:
    if ( m_EvenlySpaced )
    {
      // get operation data
      PlaneOperation *planeOp = dynamic_cast< PlaneOperation * >( operation );

      // Get first slice
      PlaneGeometry::Pointer planeGeometry = m_PlaneGeometries[0];

      // Need a PlaneGeometry, a PlaneOperation and a reference frame to
      // carry out the re-orientation. If not all avaialble, stop here
      if ( !m_ReferenceGeometry                                                                       ||
           ( !planeGeometry || dynamic_cast<AbstractTransformGeometry*>(planeGeometry.GetPointer()) ) ||
           !planeOp )
      {
        break;
      }

      // General Behavior:
      // Clear all generated geometries and then rotate only the first slice.
      // The other slices will be re-generated on demand

      //
      // 1st Step: Reorient Normal Vector of first plane
      //
      Point3D center = planeOp->GetPoint(); //m_ReferenceGeometry->GetCenter();
      mitk::Vector3D currentNormal = planeGeometry->GetNormal();
      mitk::Vector3D newNormal;
      if (planeOp->AreAxisDefined())
      {
        // If planeOp was defined by one centerpoint and two axis vectors
        newNormal = CrossProduct(planeOp->GetAxisVec0(), planeOp->GetAxisVec1());
      }
      else
      {
        // If planeOp was defined by one centerpoint and one normal vector
        newNormal = planeOp->GetNormal();
      }

      // Get Rotation axis und angle
      currentNormal.Normalize();
      newNormal.Normalize();
      ScalarType rotationAngle = angle(currentNormal.GetVnlVector(),newNormal.GetVnlVector());

      rotationAngle *= 180.0 / vnl_math::pi; // from rad to deg
      Vector3D rotationAxis = itk::CrossProduct( currentNormal, newNormal );
      if (std::abs(rotationAngle-180) < mitk::eps )
      {
        // current Normal and desired normal are not linear independent!!(e.g 1,0,0 and -1,0,0).
        // Rotation Axis should be ANY vector that is 90� to current Normal
        mitk::Vector3D helpNormal;
        helpNormal = currentNormal;
        helpNormal[0] += 1;
        helpNormal[1] -= 1;
        helpNormal[2] += 1;
        helpNormal.Normalize();
        rotationAxis = itk::CrossProduct( helpNormal, currentNormal );
      }

      RotationOperation centeredRotation(
        mitk::OpROTATE,
        center,
        rotationAxis,
        rotationAngle
        );

      // Rotate first slice
      planeGeometry->ExecuteOperation( &centeredRotation );

      // Reinitialize planes and select slice, if my rotations are all done.
      if (!planeOp->AreAxisDefined())
      {
        // Clear the slice stack and adjust it according to the center of
        // rotation and plane position (see documentation of ReinitializePlanes)
        this->ReinitializePlanes( center, planeOp->GetPoint() );

        if ( m_SliceNavigationController )
        {
          m_SliceNavigationController->SelectSliceByPoint( planeOp->GetPoint() );
          m_SliceNavigationController->AdjustSliceStepperRange();
        }
      }

      // Also apply rotation on the slicedGeometry - Geometry3D (Bounding geometry)
      BaseGeometry::ExecuteOperation( &centeredRotation );

      //
      // 2nd step. If axis vectors were defined, rotate the plane around its normal to fit these
      //

      if (planeOp->AreAxisDefined())
      {
        mitk::Vector3D vecAxixNew = planeOp->GetAxisVec0();
        vecAxixNew.Normalize();
        mitk::Vector3D VecAxisCurr = planeGeometry->GetAxisVector(0);
        VecAxisCurr.Normalize();

        ScalarType rotationAngle = angle(VecAxisCurr.GetVnlVector(),vecAxixNew.GetVnlVector());
        rotationAngle = rotationAngle * 180 / PI; // Rad to Deg

        // we rotate around the normal of the plane, but we do not know, if we need to rotate clockwise
        // or anti-clockwise. So we rotate around the crossproduct of old and new Axisvector.
        // Since both axis vectors lie in the plane, the crossproduct is the planes normal or the negative planes normal

        rotationAxis = itk::CrossProduct( VecAxisCurr, vecAxixNew  );
        if (std::abs(rotationAngle-180) < mitk::eps )
        {
          // current axisVec and desired axisVec are not linear independent!!(e.g 1,0,0 and -1,0,0).
          // Rotation Axis can be just plane Normal. (have to rotate by 180�)
          rotationAxis = newNormal;
        }

        // Perfom Rotation
        mitk::RotationOperation op(mitk::OpROTATE, center, rotationAxis, rotationAngle);
        planeGeometry->ExecuteOperation( &op );

        // Apply changes on first slice to whole slice stack
        this->ReinitializePlanes( center, planeOp->GetPoint() );

        if ( m_SliceNavigationController )
        {
          m_SliceNavigationController->SelectSliceByPoint( planeOp->GetPoint() );
          m_SliceNavigationController->AdjustSliceStepperRange();
        }

        // Also apply rotation on the slicedGeometry - Geometry3D (Bounding geometry)
        BaseGeometry::ExecuteOperation( &op );
      }
    }
    else
    {
      // Reach through to all slices
      for (auto iter = m_PlaneGeometries.begin();
        iter != m_PlaneGeometries.end();
        ++iter)
      {
        (*iter)->ExecuteOperation(operation);
      }
    }
    break;

  case OpRESTOREPLANEPOSITION:
    if ( m_EvenlySpaced )
    {
      // Save first slice
      PlaneGeometry::Pointer planeGeometry = m_PlaneGeometries[0];

      RestorePlanePositionOperation *restorePlaneOp = dynamic_cast< RestorePlanePositionOperation* >( operation );

      // Need a PlaneGeometry, a PlaneOperation and a reference frame to
      // carry out the re-orientation
      if ( m_ReferenceGeometry && (planeGeometry && dynamic_cast<AbstractTransformGeometry*>(planeGeometry.GetPointer()) == nullptr) && restorePlaneOp )
      {
        // Clear all generated geometries and then rotate only the first slice.
        // The other slices will be re-generated on demand

        // Rotate first slice
        planeGeometry->ExecuteOperation( restorePlaneOp );

        m_DirectionVector = restorePlaneOp->GetDirectionVector();

        double centerOfRotationDistance =
          planeGeometry->SignedDistanceFromPlane( m_ReferenceGeometry->GetCenter() );

        if ( centerOfRotationDistance > 0 )
        {
          m_DirectionVector = m_DirectionVector;
        }
        else
        {
          m_DirectionVector = -m_DirectionVector;
        }

        Vector3D spacing = restorePlaneOp->GetSpacing();

        Superclass::SetSpacing( spacing );

        // /*Now we need to calculate the number of slices in the plane's normal
        // direction, so that the entire volume is covered. This is done by first
        // calculating the dot product between the volume diagonal (the maximum
        // distance inside the volume) and the normal, and dividing this value by
        // the directed spacing calculated above.*/
        ScalarType directedExtent =
          std::abs( m_ReferenceGeometry->GetExtentInMM( 0 ) * m_DirectionVector[0] )
          + std::abs( m_ReferenceGeometry->GetExtentInMM( 1 ) * m_DirectionVector[1] )
          + std::abs( m_ReferenceGeometry->GetExtentInMM( 2 ) * m_DirectionVector[2] );

        if ( directedExtent >= spacing[2] )
        {
          m_Slices = static_cast< unsigned int >(directedExtent / spacing[2] + 0.5);
        }
        else
        {
          m_Slices = 1;
        }

        m_PlaneGeometries.assign( m_Slices, PlaneGeometry::Pointer( nullptr ) );

        if ( m_Slices > 0 )
        {
          m_PlaneGeometries[0] = planeGeometry;
        }

        m_SliceNavigationController->GetSlice()->SetSteps( m_Slices );

        this->Modified();

        //End Reinitialization

        if ( m_SliceNavigationController )
        {
          m_SliceNavigationController->GetSlice()->SetPos( restorePlaneOp->GetPos() );
          m_SliceNavigationController->AdjustSliceStepperRange();
        }
        BaseGeometry::ExecuteOperation(restorePlaneOp);
      }
    }
    else
    {
      // Reach through to all slices
      for (auto iter = m_PlaneGeometries.begin();
        iter != m_PlaneGeometries.end();
        ++iter)
      {
        (*iter)->ExecuteOperation(operation);
      }
    }
    break;

  case OpAPPLYTRANSFORMMATRIX:

    // Clear all generated geometries and then transform only the first slice.
    // The other slices will be re-generated on demand

    // Save first slice
    PlaneGeometry::Pointer geometry2D = m_PlaneGeometries[0];

    ApplyTransformMatrixOperation *applyMatrixOp = dynamic_cast< ApplyTransformMatrixOperation* >( operation );

    // Apply transformation to first plane
    geometry2D->ExecuteOperation( applyMatrixOp );

    // Generate a ApplyTransformMatrixOperation using the dataset center instead of
    // the supplied rotation center. The supplied center is instead used to adjust the
    // slice stack afterwards (see OpROTATE).
    Point3D center = m_ReferenceGeometry->GetCenter();

    // Clear the slice stack and adjust it according to the center of
    // the dataset and the supplied rotation center (see documentation of
    // ReinitializePlanes)
    this->ReinitializePlanes( center, applyMatrixOp->GetReferencePoint() );

    BaseGeometry::ExecuteOperation( applyMatrixOp );
    break;
  }

  this->Modified();
}
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 );
}
示例#10
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 );
}