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();
    }
  }
}
Exemple #2
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;
}