MITK中调节Image Navigator时切片切换流程分析

void QmitkImageNavigatorView::CreateQtPartControl(QWidget *parent)

  connect(m_Controls.m_XWorldCoordinateSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnMillimetreCoordinateValueChanged()));

void QmitkImageNavigatorView::OnMillimetreCoordinateValueChanged()
{
  if (m_IRenderWindowPart)
  {
    mitk::TimeGeometry::ConstPointer geometry = m_IRenderWindowPart->GetActiveQmitkRenderWindow()->GetSliceNavigationController()->GetInputWorldTimeGeometry();

    if (geometry.IsNotNull())
    {
      mitk::Point3D positionInWorldCoordinates;
      positionInWorldCoordinates[0] = m_Controls.m_XWorldCoordinateSpinBox->value();
      positionInWorldCoordinates[1] = m_Controls.m_YWorldCoordinateSpinBox->value();
      positionInWorldCoordinates[2] = m_Controls.m_ZWorldCoordinateSpinBox->value();

      m_IRenderWindowPart->SetSelectedPosition(positionInWorldCoordinates);
    }
  }
}

class ORG_MITK_GUI_QT_STDMULTIWIDGETEDITOR QmitkStdMultiWidgetEditor
    : public QmitkAbstractRenderEditor, public mitk::ILinkedRenderWindowPart

void QmitkStdMultiWidgetEditor::SetSelectedPosition(const mitk::Point3D &pos, const QString &/*id*/)
{
  d->m_StdMultiWidget->MoveCrossToPosition(pos);
}
void QmitkStdMultiWidget::MoveCrossToPosition(const mitk::Point3D &newPosition)
{
  mitkWidget1->GetSliceNavigationController()->SelectSliceByPoint(newPosition);
  mitkWidget2->GetSliceNavigationController()->SelectSliceByPoint(newPosition);
  mitkWidget3->GetSliceNavigationController()->SelectSliceByPoint(newPosition);

  m_RenderingManager->RequestUpdateAll();
}

  void SliceNavigationController::SelectSliceByPoint(const Point3D &point)
  {
    if (m_CreatedWorldGeometry.IsNull())
    {
      return;
    }

    //@todo add time to PositionEvent and use here!!
    SlicedGeometry3D *slicedWorldGeometry = dynamic_cast<SlicedGeometry3D *>(
      m_CreatedWorldGeometry->GetGeometryForTimeStep(this->GetTime()->GetPos()).GetPointer());

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

      int s, slices;
      slices = slicedWorldGeometry->GetSlices();
      if (slicedWorldGeometry->GetEvenlySpaced())
      {
        mitk::PlaneGeometry *plane = slicedWorldGeometry->GetPlaneGeometry(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 default 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->GetPlaneGeometry(s)->Project(point, projectedPoint);
          const 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();
    }
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值