void QmitkInteractiveTransformationWidget::SetGeometry( mitk::BaseGeometry::Pointer geometry, mitk::BaseGeometry::Pointer defaultValues )
{
  m_Geometry = geometry;
  itk::LightObject::Pointer lopointer = geometry->Clone();
  m_ResetGeometry = dynamic_cast<mitk::BaseGeometry*>(lopointer.GetPointer());

  //set default values
  if (defaultValues.IsNotNull())
    {
    //first: some conversion
    mitk::NavigationData::Pointer transformConversionHelper = mitk::NavigationData::New(defaultValues->GetIndexToWorldTransform());
    double eulerAlphaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[0] / vnl_math::pi * 180;
    double eulerBetaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[1] / vnl_math::pi * 180;
    double eulerGammaDegrees = transformConversionHelper->GetOrientation().rotation_euler_angles()[2] / vnl_math::pi * 180;

    //set translation
    OnXTranslationValueChanged(defaultValues->GetIndexToWorldTransform()->GetOffset()[0]);
    OnYTranslationValueChanged(defaultValues->GetIndexToWorldTransform()->GetOffset()[1]);
    OnZTranslationValueChanged(defaultValues->GetIndexToWorldTransform()->GetOffset()[2]);

    //set rotation
    OnXRotationValueChanged(eulerAlphaDegrees);
    OnYRotationValueChanged(eulerBetaDegrees);
    OnZRotationValueChanged(eulerGammaDegrees);
    }
  else
    {
    //reset everything
    OnXTranslationValueChanged(0);
    OnYTranslationValueChanged(0);
    OnZTranslationValueChanged(0);
    OnXRotationValueChanged(0);
    OnYRotationValueChanged(0);
    OnZRotationValueChanged(0);
    }
}
void mitk::ClippedSurfaceBoundsCalculator::CalculateIntersectionPoints(const mitk::PlaneGeometry* geometry)
{
  // SEE HEADER DOCUMENTATION for explanation

  const mitk::BaseGeometry::Pointer imageGeometry = m_Image->GetGeometry()->Clone();

  //  the cornerpoint(0) is the corner based Origin, which is original center based
  Point3D origin = imageGeometry->GetCornerPoint(0);           //Left, bottom, front

  //Get axis vector for the spatial directions
  const Vector3D xDirection = imageGeometry->GetAxisVector(0);
  const Vector3D yDirection = imageGeometry->GetAxisVector(1);
  const Vector3D zDirection = imageGeometry->GetAxisVector(2);

  const Point3D leftBottomFront = origin;
  const Point3D leftTopFront = origin + yDirection;
  const Point3D leftBottomBack = origin + zDirection;
  const Point3D leftTopBack = origin + yDirection + zDirection;
  const Point3D rightBottomFront = origin + xDirection;
  const Point3D rightTopFront = origin + xDirection + yDirection;
  const Point3D rightBottomBack = origin + xDirection + zDirection;
  const Point3D rightTopBack = origin + xDirection + yDirection + zDirection;

  typedef std::vector< std::pair<mitk::Point3D, mitk::Point3D> > EdgesVector;
  EdgesVector edgesOf3DBox;
  edgesOf3DBox.reserve(12);

  edgesOf3DBox.push_back(std::make_pair(leftBottomFront,     // x = left=xfront, y=bottom=yfront, z=front=zfront
    leftTopFront));     // left, top, front

  edgesOf3DBox.push_back(std::make_pair(leftBottomFront,    // left, bottom, front
    leftBottomBack));   // left, bottom, back

  edgesOf3DBox.push_back(std::make_pair(leftBottomFront,    // left, bottom, front
    rightBottomFront)); // right, bottom, front

  edgesOf3DBox.push_back(std::make_pair(leftTopFront,       // left, top, front
    rightTopFront));    // right, top, front

  edgesOf3DBox.push_back(std::make_pair(leftTopFront,       // left, top, front
    leftTopBack));      // left, top, back

  edgesOf3DBox.push_back(std::make_pair(rightTopFront,      // right, top, front
    rightTopBack));     // right, top, back

  edgesOf3DBox.push_back(std::make_pair(rightTopFront,      // right, top, front
    rightBottomFront)); // right, bottom, front

  edgesOf3DBox.push_back(std::make_pair(rightBottomFront,   // right, bottom, front
    rightBottomBack));  // right, bottom, back

  edgesOf3DBox.push_back(std::make_pair(rightBottomBack,    // right, bottom, back
    leftBottomBack));   // left, bottom, back

  edgesOf3DBox.push_back(std::make_pair(rightBottomBack,    // right, bottom, back
    rightTopBack));     // right, top, back

  edgesOf3DBox.push_back(std::make_pair(rightTopBack,       // right, top, back
    leftTopBack));      // left, top, back

  edgesOf3DBox.push_back(std::make_pair(leftTopBack,        // left, top, back
    leftBottomBack));   // left, bottom, back

  for ( auto iterator = edgesOf3DBox.cbegin(); iterator != edgesOf3DBox.cend(); ++iterator )
  {
    const Point3D startPoint = (*iterator).first;   // start point of the line
    const Point3D endPoint   = (*iterator).second;  // end point of the line
    const Vector3D lineDirection = endPoint - startPoint;

    const mitk::Line3D line(startPoint, lineDirection);

    // Get intersection point of line and plane geometry
    Point3D intersectionWorldPoint(std::numeric_limits<int>::min());

    double t = -1.0;
    bool doesLineIntersectWithPlane(false);

    const double norm = line.GetDirection().GetNorm();
    const double dist = geometry->Distance(line.GetPoint1());
    if( norm < mitk::eps && dist < mitk::sqrteps)
    {
      t = 1.0;
      doesLineIntersectWithPlane = true;
      intersectionWorldPoint = line.GetPoint1();
    }
    else
    {
      geometry->IntersectionPoint(line, intersectionWorldPoint);
      doesLineIntersectWithPlane = geometry->IntersectionPointParam(line, t);
    }

    //Get index point
    mitk::Point3D intersectionIndexPoint;
    imageGeometry->WorldToIndex(intersectionWorldPoint, intersectionIndexPoint);

    const bool lowerBoundGood = (0-mitk::sqrteps) <= t;
    const bool upperBoundGood = t <= 1.0 + mitk::sqrteps;
    if ( doesLineIntersectWithPlane && lowerBoundGood && upperBoundGood )
    {
      for( int dim = 0; dim < 3; ++dim )
      {
        m_MinMaxOutput[dim].first = std::min( m_MinMaxOutput[dim].first, ROUND_P(intersectionIndexPoint[dim]) );
        m_MinMaxOutput[dim].second = std::max( m_MinMaxOutput[dim].second, ROUND_P(intersectionIndexPoint[dim]) );
      }
      this->EnforceImageBounds();
    }
  }
}
Пример #3
0
std::vector<mitk::Point3D> mitk::GetCornerPoints(mitk::BaseGeometry::Pointer geometry, bool visualizationOffset)
{
  if (geometry == nullptr)
    mitkThrow() << "Geometry is not valid.";

  mitk::BoundingBox::ConstPointer boundingBox = geometry->GetBoundingBox();
  mitk::Point3D BBmin = boundingBox->GetMinimum();
  mitk::Point3D BBmax = boundingBox->GetMaximum();

  // use 0.5 offset because the vtkCubeSource is not center pixel based (only for visualization purpose)
  if (visualizationOffset)
  {
    BBmin -= 0.5;
    BBmax -= 0.5;
  }
  mitk::Point3D p0;
  p0[0] = BBmin[0];
  p0[1] = BBmin[1];
  p0[2] = BBmin[2]; // bottom - left - back corner
  mitk::Point3D p1;
  p1[0] = BBmin[0];
  p1[1] = BBmin[1];
  p1[2] = BBmax[2]; // top - left - back corner
  mitk::Point3D p2;
  p2[0] = BBmin[0];
  p2[1] = BBmax[1];
  p2[2] = BBmin[2]; // bottom - left - front corner
  mitk::Point3D p3;
  p3[0] = BBmin[0];
  p3[1] = BBmax[1];
  p3[2] = BBmax[2]; // top - left - front corner
  mitk::Point3D p4;
  p4[0] = BBmax[0];
  p4[1] = BBmin[1];
  p4[2] = BBmin[2]; // bottom - right - back corner
  mitk::Point3D p5;
  p5[0] = BBmax[0];
  p5[1] = BBmin[1];
  p5[2] = BBmax[2]; // top - right - back corner
  mitk::Point3D p6;
  p6[0] = BBmax[0];
  p6[1] = BBmax[1];
  p6[2] = BBmin[2]; // bottom - right - front corner
  mitk::Point3D p7;
  p7[0] = BBmax[0];
  p7[1] = BBmax[1];
  p7[2] = BBmax[2]; // top - right - front corner

  std::vector<mitk::Point3D> cornerPoints;

  cornerPoints.push_back(geometry->GetIndexToWorldTransform()->TransformPoint(p0));
  cornerPoints.push_back(geometry->GetIndexToWorldTransform()->TransformPoint(p1));
  cornerPoints.push_back(geometry->GetIndexToWorldTransform()->TransformPoint(p2));
  cornerPoints.push_back(geometry->GetIndexToWorldTransform()->TransformPoint(p3));
  cornerPoints.push_back(geometry->GetIndexToWorldTransform()->TransformPoint(p4));
  cornerPoints.push_back(geometry->GetIndexToWorldTransform()->TransformPoint(p5));
  cornerPoints.push_back(geometry->GetIndexToWorldTransform()->TransformPoint(p6));
  cornerPoints.push_back(geometry->GetIndexToWorldTransform()->TransformPoint(p7));

  return cornerPoints;
}
Пример #4
0
int compareGeometry(const mitk::TimeGeometry &timeGeometry,
                    const mitk::ScalarType &width,
                    const mitk::ScalarType &height,
                    const mitk::ScalarType &numSlices,
                    const mitk::ScalarType &widthInMM,
                    const mitk::ScalarType &heightInMM,
                    const mitk::ScalarType &thicknessInMM,
                    const mitk::Point3D &cornerpoint0,
                    const mitk::Vector3D &right,
                    const mitk::Vector3D &bottom,
                    const mitk::Vector3D &normal)
{
  // Probleme durch umstellung von Time-SlicedGeometry auf  TimeGeometry?
  // Eventuell gibt es keine Entsprechung mehr.
  const mitk::BaseGeometry::Pointer geometry = timeGeometry.GetGeometryForTimeStep(0);
  std::cout << "Testing width, height and thickness (in units): ";
  if ((mitk::Equal(geometry->GetExtent(0), width) == false) || (mitk::Equal(geometry->GetExtent(1), height) == false) ||
      (mitk::Equal(geometry->GetExtent(2), numSlices) == false))
  {
    std::cout << "[FAILED]" << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "[PASSED]" << std::endl;

  std::cout << "Testing width, height and thickness (in mm): ";
  if ((mitk::Equal(geometry->GetExtentInMM(0), widthInMM) == false) ||
      (mitk::Equal(geometry->GetExtentInMM(1), heightInMM) == false) ||
      (mitk::Equal(geometry->GetExtentInMM(2), thicknessInMM) == false))
  {
    std::cout << "[FAILED]" << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "[PASSED]" << std::endl;

  std::cout << "Testing GetAxisVector(): ";
  std::cout << "dir=0 ";
  mitk::Vector3D dv;
  dv = right;
  dv.Normalize();
  dv *= widthInMM;
  if ((mitk::Equal(geometry->GetAxisVector(0), dv) == false))
  {
    std::cout << "[FAILED]" << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "[PASSED]";
  std::cout << ", dir=1 ";
  dv = bottom;
  dv.Normalize();
  dv *= heightInMM;
  if ((mitk::Equal(geometry->GetAxisVector(1), dv) == false))
  {
    std::cout << "[FAILED]" << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "[PASSED]";
  std::cout << ", dir=2 ";
  dv = normal;
  dv.Normalize();
  dv *= thicknessInMM;
  if ((mitk::Equal(geometry->GetAxisVector(2), dv) == false))
  {
    std::cout << "[FAILED]" << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "[PASSED]" << std::endl;

  std::cout << "Testing offset: ";
  if ((mitk::Equal(geometry->GetCornerPoint(0), cornerpoint0, (double)vnl_math::float_eps) == false))
  {
    std::cout << "[FAILED]" << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "[PASSED]" << std::endl;
  return EXIT_SUCCESS;
}