Beispiel #1
0
bool mitk::PlanarCircle::SetControlPoint( unsigned int index, const Point2D &point, bool /*createIfDoesNotExist*/ )
{
  // moving center point
  if(index == 0)
  {
    const Point2D &centerPoint = GetControlPoint( 0 );
    Point2D boundaryPoint = GetControlPoint( 1 );
    vnl_vector<float> vec = (point.GetVnlVector() - centerPoint.GetVnlVector());

    boundaryPoint[0] += vec[0];
    boundaryPoint[1] += vec[1];
    PlanarFigure::SetControlPoint( 0, point );
    PlanarFigure::SetControlPoint( 1, boundaryPoint );
  }
  else if ( index == 1 )
  {
    PlanarFigure::SetControlPoint( index, point );
    return true;
  }
  return false;
}
Beispiel #2
0
bool mitk::PlanarEllipse::SetControlPoint( unsigned int index, const Point2D &point, bool createIfDoesNotExist )
{
    if(index == 0) // moving center point and control points accordingly
    {
        const Point2D &centerPoint = GetControlPoint( 0 );
        Point2D boundaryPoint1 = GetControlPoint( 1 );
        Point2D boundaryPoint2 = GetControlPoint( 2 );
        Point2D boundaryPoint3 = GetControlPoint( 3 );
        vnl_vector<ScalarType> vec = (point.GetVnlVector() - centerPoint.GetVnlVector());

        boundaryPoint1[0] += vec[0];
        boundaryPoint1[1] += vec[1];
        boundaryPoint2[0] += vec[0];
        boundaryPoint2[1] += vec[1];
        boundaryPoint3[0] += vec[0];
        boundaryPoint3[1] += vec[1];
        PlanarFigure::SetControlPoint( 0, point, createIfDoesNotExist );
        PlanarFigure::SetControlPoint( 1, boundaryPoint1, createIfDoesNotExist );
        PlanarFigure::SetControlPoint( 2, boundaryPoint2, createIfDoesNotExist );
        PlanarFigure::SetControlPoint( 3, boundaryPoint3, createIfDoesNotExist );
        return true;
    }
    else if (index < 3)
    {
        PlanarFigure::SetControlPoint( index, point, createIfDoesNotExist );
        int otherIndex = index+1;
        if (otherIndex > 2)
            otherIndex = 1;

        const Point2D &centerPoint = GetControlPoint( 0 );
        Point2D otherPoint = GetControlPoint( otherIndex );
        Point2D point3 = GetControlPoint( 3 );

        Vector2D vec1 = point - centerPoint;
        Vector2D vec2;

        if (index == 1 && m_TreatAsCircle )
        {
            float x = vec1[0];
            vec2[0] = vec1[1];
            vec2[1] = x;

            if (index==1)
                vec2[0] *= -1;
            else
                vec2[1] *= -1;

            otherPoint = centerPoint+vec2;
            PlanarFigure::SetControlPoint( otherIndex, otherPoint, createIfDoesNotExist );
            float r = centerPoint.EuclideanDistanceTo(otherPoint);

            // adjust additional third control point
            Point2D p3 = this->GetControlPoint(3);
            Vector2D vec3;
            vec3[0] = p3[0]-centerPoint[0];
            vec3[1] = p3[1]-centerPoint[1];
            if (vec3[0]!=0 || vec3[1]!=0)
            {
                vec3.Normalize();
                vec3 *= r;
            }
            else
            {
                vec3[0] = r;
                vec3[1] = 0;
            }
            point3 = centerPoint + vec3;
            PlanarFigure::SetControlPoint( 3, point3, createIfDoesNotExist );
        }
        else if ( vec1.GetNorm() > 0 )
        {
            float r = centerPoint.EuclideanDistanceTo(otherPoint);
            float x = vec1[0];
            vec2[0] = vec1[1];
            vec2[1] = x;

            if (index==1)
                vec2[0] *= -1;
            else
                vec2[1] *= -1;

            vec2.Normalize(); vec2 *= r;

            if ( vec2.GetNorm() > 0 )
            {
                otherPoint = centerPoint+vec2;
                PlanarFigure::SetControlPoint( otherIndex, otherPoint, createIfDoesNotExist );
            }

            // adjust third control point
            Vector2D vec3 = point3 - centerPoint; vec3.Normalize();
            double r1 = centerPoint.EuclideanDistanceTo( GetControlPoint( 1 ) );
            double r2 = centerPoint.EuclideanDistanceTo( GetControlPoint( 2 ) );
            Point2D newPoint = centerPoint + vec3*std::max(r1, r2);
            PlanarFigure::SetControlPoint( 3, newPoint, createIfDoesNotExist );

            m_TreatAsCircle = false;
        }
        return true;
    }
    else if (index == 3)
    {
        Point2D centerPoint = GetControlPoint( 0 );
        Vector2D vec3 = point - centerPoint; vec3.Normalize();
        double r1 = centerPoint.EuclideanDistanceTo( GetControlPoint( 1 ) );
        double r2 = centerPoint.EuclideanDistanceTo( GetControlPoint( 2 ) );
        Point2D newPoint = centerPoint + vec3*std::max(r1, r2);
        PlanarFigure::SetControlPoint( index, newPoint, createIfDoesNotExist );
        m_TreatAsCircle = false;
        return true;
    }
    return false;
}