Ejemplo n.º 1
0
void mitk::PlanarCircle::GeneratePolyLine()
{
    // TODO: start circle at specified boundary point...

    // clear the PolyLine-Contrainer, it will be reconstructed soon enough...
    this->ClearPolyLines();

    const Point2D &centerPoint = GetControlPoint( 0 );
    const Point2D &boundaryPoint = GetControlPoint( 1 );

    double radius = centerPoint.EuclideanDistanceTo( boundaryPoint );

    // Generate poly-line with 64 segments
    for ( int t = 0; t < 64; ++t )
    {
        double alpha = (double) t * vnl_math::pi / 32.0;

        // construct the new polyline point ...
        Point2D polyLinePoint;
        polyLinePoint[0] = centerPoint[0] + radius * cos( alpha );
        polyLinePoint[1] = centerPoint[1] + radius * sin( alpha );

        // ... and append it to the PolyLine.
        // No extending supported here, so we can set the index of the PolyLineElement to '0'
        this->AppendPointToPolyLine(0, polyLinePoint);
    }
}
Ejemplo n.º 2
0
void mitk::PlanarEllipse::GeneratePolyLine()
{
    // clear the PolyLine-Contrainer, it will be reconstructed soon enough...
    this->ClearPolyLines();

    const Point2D &centerPoint = GetControlPoint( 0 );
    const Point2D &boundaryPoint1 = GetControlPoint( 1 );
    const Point2D &boundaryPoint2 = GetControlPoint( 2 );

    Vector2D dir = boundaryPoint1 - centerPoint; dir.Normalize();
    vnl_matrix_fixed<float, 2, 2> rot;

    // differentiate between clockwise and counterclockwise rotation
    int start = 0;
    int end = 64;
    if (dir[1]<0)
    {
        dir[0] = -dir[0];
        start = -32;
        end = 32;
    }
    // construct rotation matrix to align ellipse with control point vector
    rot[0][0] = dir[0];
    rot[1][1] = rot[0][0];
    rot[1][0] = sin(acos(rot[0][0]));
    rot[0][1] = -rot[1][0];

    double radius1 = centerPoint.EuclideanDistanceTo( boundaryPoint1 );
    double radius2 = centerPoint.EuclideanDistanceTo( boundaryPoint2 );

    // Generate poly-line with 64 segments
    for ( int t = start; t < end; ++t )
    {
        double alpha = (double) t * vnl_math::pi / 32.0;

        // construct the new polyline point ...
        vnl_vector_fixed< float, 2 > vec;
        vec[0] = radius1 * cos( alpha );
        vec[1] = radius2 * sin( alpha );
        vec = rot*vec;

        Point2D polyLinePoint;
        polyLinePoint[0] = centerPoint[0] + vec[0];
        polyLinePoint[1] = centerPoint[1] + vec[1];

        // ... and append it to the PolyLine.
        // No extending supported here, so we can set the index of the PolyLineElement to '0'
        AppendPointToPolyLine( 0, PolyLineElement( polyLinePoint, 0 ) );
    }

    AppendPointToPolyLine( 1, PolyLineElement( centerPoint, 0 ) );
    AppendPointToPolyLine( 1, PolyLineElement( GetControlPoint( 3 ), 0 ) );
}
Ejemplo n.º 3
0
bool mitk::PlanarRectangle::SetControlPoint( unsigned int index, const Point2D &point, bool createIfDoesNotExist )
{
  // heres the deal with the rectangle:
  // when a point is moved all corresponding corner points are moved with him
  // e.g. if the lower right point (index=3) is moved the upper right point (index=1)
  // is moved in the same x direction
  // and the lower left point (index=2) is moved in the same y direction
  // the upper left point (index=0) is left untouched
  bool set = PlanarFigure::SetControlPoint( index, point, createIfDoesNotExist );

  if(set)
  {
    // can be made better ...
    unsigned int horizontalCorrespondingPointIndex = 1;
    unsigned int verticalCorrespondingPointIndex = 3;
    if(index == 1)
    {
      horizontalCorrespondingPointIndex = 0;
      verticalCorrespondingPointIndex = 2;
    }
    else if(index == 2)
    {
      horizontalCorrespondingPointIndex = 3;
      verticalCorrespondingPointIndex = 1;
    }
    else if(index == 3)
    {
      horizontalCorrespondingPointIndex = 2;
      verticalCorrespondingPointIndex = 0;
    }

    Point2D verticalCorrespondingPoint = GetControlPoint( verticalCorrespondingPointIndex );
    verticalCorrespondingPoint[0] = point[0];
    PlanarFigure::SetControlPoint( verticalCorrespondingPointIndex, verticalCorrespondingPoint );

    Point2D horizontalCorrespondingPoint = GetControlPoint( horizontalCorrespondingPointIndex );
    horizontalCorrespondingPoint[1] = point[1];
    PlanarFigure::SetControlPoint( horizontalCorrespondingPointIndex, horizontalCorrespondingPoint );
  }

  return set;
}
Ejemplo n.º 4
0
void mitk::PlanarRectangle::GeneratePolyLine()
{
  // TODO: start polygon at specified initalize point...

  ClearPolyLines();
 
  for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
  {
    AppendPointToPolyLine( 0, PolyLineElement( GetControlPoint(i), i ) );
  }
}
Ejemplo n.º 5
0
void mitk::PlanarFourPointAngle::GeneratePolyLine()
{
  this->ClearPolyLines();
  // TODO: start line at specified start point...
  // Generate poly-line

  for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
  {
    int index = i/2;
    this->AppendPointToPolyLine( index, PolyLineElement( GetControlPoint( i ), i ) );
  }
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
void mitk::PlanarRectangle::PrintSelf( std::ostream& os, itk::Indent indent) const
{
  Superclass::PrintSelf( os, indent );

  os << indent << "Number of control points: " << this->GetNumberOfControlPoints() << std::endl;

  os << indent << "Control points:" << std::endl;

  for ( unsigned int i = 0; i < this->GetNumberOfControlPoints(); ++i )
  {
    os << indent << indent << i << ": " <<GetControlPoint( i ) << std::endl;
  }
}
Ejemplo n.º 8
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;
}