コード例 #1
0
void
SliceNavigationController::SelectSliceByPoint( const Point3D &point )
{
  //@todo add time to PositionEvent and use here!!
  SlicedGeometry3D* slicedWorldGeometry = dynamic_cast< SlicedGeometry3D * >(
    m_CreatedWorldGeometry->GetGeometry3D( this->GetTime()->GetPos() ) );

  if ( slicedWorldGeometry )
  {
    int bestSlice = -1;
    double bestDistance = itk::NumericTraits<double>::max();

    int s, slices;
    slices = slicedWorldGeometry->GetSlices();
    if ( slicedWorldGeometry->GetEvenlySpaced() )
    {
      mitk::Geometry2D *plane = slicedWorldGeometry->GetGeometry2D( 0 );

      const Vector3D &direction = slicedWorldGeometry->GetDirectionVector();
      
      Point3D projectedPoint;
      plane->Project( point, projectedPoint );

      // Check whether the point is somewhere within the slice stack volume;
      // otherwise, the defualt slice (0) will be selected
      if ( direction[0] * (point[0] - projectedPoint[0])
         + direction[1] * (point[1] - projectedPoint[1])
         + direction[2] * (point[2] - projectedPoint[2]) >= 0 )
      {
        bestSlice = (int)(plane->Distance( point )
          / slicedWorldGeometry->GetSpacing()[2] + 0.5);
      }
    }
    else
    {
      Point3D projectedPoint;
      for ( s = 0; s < slices; ++s )
      {
        slicedWorldGeometry->GetGeometry2D( s )->Project( point, projectedPoint );
        Vector3D distance = projectedPoint - point;
        ScalarType currentDistance = distance.GetSquaredNorm();

        if ( currentDistance < bestDistance )
        {
          bestDistance = currentDistance;
          bestSlice = s;
        }
      }
    }
    if ( bestSlice >= 0 )
    {
      this->GetSlice()->SetPos( bestSlice );
    }
    else
    {
      this->GetSlice()->SetPos( 0 );
    }
    this->SendCreatedWorldGeometryUpdate();
  }
}
コード例 #2
0
ファイル: mitkBaseRenderer.cpp プロジェクト: beneon/MITK
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
ファイル: mitkBaseRenderer.cpp プロジェクト: beneon/MITK
void mitk::BaseRenderer::UpdateGeometry(const itk::EventObject & geometryUpdateEvent)
{
    const SliceNavigationController::GeometryUpdateEvent* updateEvent =
        dynamic_cast<const SliceNavigationController::GeometryUpdateEvent*>(&geometryUpdateEvent);

    if (updateEvent == NULL)
        return;

    if (m_CurrentWorldGeometry.IsNotNull())
    {
        SlicedGeometry3D* slicedWorldGeometry = dynamic_cast<SlicedGeometry3D*>(m_CurrentWorldGeometry.GetPointer());
        if (slicedWorldGeometry)
        {
            Geometry2D* geometry2D = slicedWorldGeometry->GetGeometry2D(m_Slice);

            SetCurrentWorldGeometry2D(geometry2D); // calls Modified()
        }
    }
}
コード例 #4
0
ファイル: mitkBaseRenderer.cpp プロジェクト: beneon/MITK
void mitk::BaseRenderer::SetSlice(unsigned int slice)
{
    if (m_Slice != slice)
    {
        m_Slice = slice;
        if (m_TimeSlicedWorldGeometry.IsNotNull())
        {
            SlicedGeometry3D* slicedWorldGeometry = dynamic_cast<SlicedGeometry3D*>(m_TimeSlicedWorldGeometry->GetGeometry3D(m_TimeStep));
            if (slicedWorldGeometry != NULL)
            {
                if (m_Slice >= slicedWorldGeometry->GetSlices())
                    m_Slice = slicedWorldGeometry->GetSlices() - 1;
                SetCurrentWorldGeometry2D(slicedWorldGeometry->GetGeometry2D(m_Slice));
                SetCurrentWorldGeometry(slicedWorldGeometry);
            }
        }
        else
            Modified();
    }
}
コード例 #5
0
ファイル: mitkBaseRenderer.cpp プロジェクト: beneon/MITK
void mitk::BaseRenderer::SetTimeStep(unsigned int timeStep)
{
    if (m_TimeStep != timeStep)
    {
        m_TimeStep = timeStep;
        m_TimeStepUpdateTime.Modified();

        if (m_TimeSlicedWorldGeometry.IsNotNull())
        {
            if (m_TimeStep >= m_TimeSlicedWorldGeometry->GetTimeSteps())
                m_TimeStep = m_TimeSlicedWorldGeometry->GetTimeSteps() - 1;
            SlicedGeometry3D* slicedWorldGeometry = dynamic_cast<SlicedGeometry3D*>(m_TimeSlicedWorldGeometry->GetGeometry3D(m_TimeStep));
            if (slicedWorldGeometry != NULL)
            {
                SetCurrentWorldGeometry2D(slicedWorldGeometry->GetGeometry2D(m_Slice));
                SetCurrentWorldGeometry(slicedWorldGeometry);
            }
        }
        else
            Modified();
    }
}
コード例 #6
0
ファイル: mitkImage.cpp プロジェクト: ClydeChen/MITK
void mitk::Image::Initialize(vtkImageData* vtkimagedata, int channels, int tDim, int sDim, int pDim)
{
  if(vtkimagedata==NULL) return;

  m_Dimension=vtkimagedata->GetDataDimension();
  unsigned int i, *tmpDimensions=new unsigned int[m_Dimension>4?m_Dimension:4];
  for(i=0;i<m_Dimension;++i) tmpDimensions[i]=vtkimagedata->GetDimensions()[i];
  if(m_Dimension<4)
  {
    unsigned int *p;
    for(i=0,p=tmpDimensions+m_Dimension;i<4-m_Dimension;++i, ++p)
      *p=1;
  }

  if(pDim>=0)
  {
    tmpDimensions[1]=pDim;
    if(m_Dimension < 2)
      m_Dimension = 2;
  }
  if(sDim>=0)
  {
    tmpDimensions[2]=sDim;
    if(m_Dimension < 3)
      m_Dimension = 3;
  }
  if(tDim>=0)
  {
    tmpDimensions[3]=tDim;
    if(m_Dimension < 4)
      m_Dimension = 4;
  }


  switch ( vtkimagedata->GetScalarType() )
  {
  case VTK_BIT:
  case VTK_CHAR:
    //pixelType.Initialize(typeid(char), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<char>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_UNSIGNED_CHAR:
    //pixelType.Initialize(typeid(unsigned char), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<unsigned char>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_SHORT:
    //pixelType.Initialize(typeid(short), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<short>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_UNSIGNED_SHORT:
    //pixelType.Initialize(typeid(unsigned short), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<unsigned short>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_INT:
    //pixelType.Initialize(typeid(int), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<int>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_UNSIGNED_INT:
    //pixelType.Initialize(typeid(unsigned int), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<unsigned int>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_LONG:
    //pixelType.Initialize(typeid(long), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<long>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_UNSIGNED_LONG:
    //pixelType.Initialize(typeid(unsigned long), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<unsigned long>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_FLOAT:
    //pixelType.Initialize(typeid(float), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<float>(), m_Dimension, tmpDimensions, channels);
    break;
  case VTK_DOUBLE:
    //pixelType.Initialize(typeid(double), vtkimagedata->GetNumberOfScalarComponents());
    Initialize(mitk::MakeScalarPixelType<double>(), m_Dimension, tmpDimensions, channels);
    break;
  default:
    break;
  }
  /*
  Initialize(pixelType,
    m_Dimension,
    tmpDimensions,
    channels);
*/

  const double *spacinglist = vtkimagedata->GetSpacing();
  Vector3D spacing;
  FillVector3D(spacing, spacinglist[0], 1.0, 1.0);
  if(m_Dimension>=2)
    spacing[1]=spacinglist[1];
  if(m_Dimension>=3)
    spacing[2]=spacinglist[2];

  // access origin of vtkImage
  Point3D origin;
  double vtkorigin[3];
  vtkimagedata->GetOrigin(vtkorigin);
  FillVector3D(origin, vtkorigin[0], 0.0, 0.0);
  if(m_Dimension>=2)
    origin[1]=vtkorigin[1];
  if(m_Dimension>=3)
    origin[2]=vtkorigin[2];

  SlicedGeometry3D* slicedGeometry = GetSlicedGeometry(0);

  // re-initialize PlaneGeometry with origin and direction
  PlaneGeometry* planeGeometry = static_cast<PlaneGeometry*>(slicedGeometry->GetGeometry2D(0));
  planeGeometry->SetOrigin(origin);

  // re-initialize SlicedGeometry3D
  slicedGeometry->SetOrigin(origin);
  slicedGeometry->SetSpacing(spacing);

  ProportionalTimeGeometry::Pointer timeGeometry = ProportionalTimeGeometry::New();
  timeGeometry->Initialize(slicedGeometry, m_Dimensions[3]);
  SetTimeGeometry(timeGeometry);

  delete [] tmpDimensions;
}