Exemplo n.º 1
0
void mitk::PlanarArrow::GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight)
{
  // Generate helper polyline (orientation line orthogonal to first line)
  // if the third control point is currently being set
  if ( this->GetNumberOfControlPoints() != 2 )
  {
    m_HelperPolyLinesToBePainted->SetElement( 0, false );
    m_HelperPolyLinesToBePainted->SetElement( 1, false );
 
    return;
  }

  this->ClearHelperPolyLines();

  m_HelperPolyLinesToBePainted->SetElement( 0, true );
  m_HelperPolyLinesToBePainted->SetElement( 1, true );
 
  //Fixed size depending on screen size for the angle
  float scaleFactor = 0.015;
  if ( m_ArrowTipScaleFactor > 0.0 )
  {
    scaleFactor = m_ArrowTipScaleFactor;
  }
  double nonScalingLength = displayHeight * mmPerDisplayUnit * scaleFactor;


  // Calculate arrow peak
  const Point2D p1 = this->GetControlPoint( 0 );
  const Point2D p2 = this->GetControlPoint( 1 );

  //const Point2D& p1 = m_ControlPoints->ElementAt( 0 );
  //const Point2D& p2 = m_ControlPoints->ElementAt( 1 );
  Vector2D n1 = p1 - p2;
  n1.Normalize();
 
  double degrees = 100.0;
  Vector2D temp;
  temp[0] = n1[0] * cos(degrees) - n1[1] * sin(degrees);
  temp[1] = n1[0] * sin(degrees) + n1[1] * cos(degrees);
  Vector2D temp2;
  temp2[0] = n1[0] * cos(-degrees) - n1[1] * sin(-degrees);
  temp2[1] = n1[0] * sin(-degrees) + n1[1] * cos(-degrees);

  this->AppendPointToHelperPolyLine( 0, PolyLineElement( p1, 0 ));
  this->AppendPointToHelperPolyLine( 0, PolyLineElement( p1 - temp * nonScalingLength, 0 ));
  this->AppendPointToHelperPolyLine( 1, PolyLineElement( p1, 0 ));
  this->AppendPointToHelperPolyLine( 1, PolyLineElement( p1 - temp2 * nonScalingLength, 0 ));

  //m_HelperPolyLines->ElementAt( 0 )->ElementAt( 0 ) = p1;
  //m_HelperPolyLines->ElementAt( 0 )->ElementAt( 1 ) = p1 - temp * nonScalingLength;
  //m_HelperPolyLines->ElementAt( 1 )->ElementAt( 0 ) = p1;
  //m_HelperPolyLines->ElementAt( 1 )->ElementAt( 1 ) = p1 - temp2 * nonScalingLength;
 
}
Exemplo 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 ) );
}
Exemplo n.º 3
0
void mitk::PlanarArrow::GeneratePolyLine()
{
  this->ClearPolyLines();

  this->AppendPointToPolyLine( 0, PolyLineElement( this->GetControlPoint( 0 ), 0 ));
  this->AppendPointToPolyLine( 0, PolyLineElement( this->GetControlPoint( 1 ), 0 ));

  // TODO: start line at specified start point...
  // Generate poly-line 
  //m_PolyLines->ElementAt( 0 )->Reserve( 2 );
  //m_PolyLines->ElementAt( 0 )->ElementAt( 0 ) = m_ControlPoints->ElementAt( 0 );
  //m_PolyLines->ElementAt( 0 )->ElementAt( 1 ) = m_ControlPoints->ElementAt( 1 );
}
Exemplo n.º 4
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'
    AppendPointToPolyLine( 0, PolyLineElement( polyLinePoint, 0 ) );
  }
}
Exemplo n.º 5
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 ) );
  }
}
Exemplo n.º 6
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 ) );
  }
}
Exemplo n.º 7
0
void mitk::PlanarAngle::GenerateHelperPolyLine(double mmPerDisplayUnit, unsigned int displayHeight)
{
  // Generate helper-poly-line for angle
  if ( this->GetNumberOfControlPoints() < 3)
  {
    m_HelperPolyLinesToBePainted->SetElement(0, false);
    return; //We do not need to draw an angle as there are no two arms yet
  }

  this->ClearHelperPolyLines();

  const Point2D centerPoint = this->GetControlPoint( 1 );
  const Point2D boundaryPointOne = this->GetControlPoint( 0 );
  const Point2D boundaryPointTwo = this->GetControlPoint( 2 );


  double radius = centerPoint.EuclideanDistanceTo( boundaryPointOne );
  if ( radius > centerPoint.EuclideanDistanceTo( boundaryPointTwo ) )
  {
    radius = centerPoint.EuclideanDistanceTo( boundaryPointTwo );
  }

  //Fixed size radius depending on screen size for the angle
  double nonScalingRadius = displayHeight * mmPerDisplayUnit * 0.05;

  if (nonScalingRadius > radius)
  {
    m_HelperPolyLinesToBePainted->SetElement(0, false);
    return; //if the arc has a radius that is longer than the shortest arm it should not be painted
  }

  m_HelperPolyLinesToBePainted->SetElement(0, true);
  radius = nonScalingRadius;

  double angle = this->GetQuantity( FEATURE_ID_ANGLE );

  //Determine from which arm the angle should be drawn

  Vector2D v0 = boundaryPointOne - centerPoint;
  Vector2D v1 = boundaryPointTwo - centerPoint;
  Vector2D v2;
  v2[0] = 1.0;
  v2[1] = 0.0;

  v0[0] = v0[0] * cos( 0.001 ) - v0[1] * sin( 0.001 ); //rotate one arm a bit
  v0[1] = v0[0] * sin( 0.001 ) + v0[1] * cos( 0.001 );
  v0.Normalize();
  v1.Normalize();
  double testAngle = acos( v0 * v1 );
  //if the rotated arm is closer to the other arm than before it is the one from which we start drawing
  //else we start drawing from the other arm (we want to draw in the mathematically positive direction)
  if( angle > testAngle )
  {
    v1[0] = v0[0] * cos( -0.001 ) - v0[1] * sin( -0.001 ); 
    v1[1] = v0[0] * sin( -0.001 ) + v0[1] * cos( -0.001 );

    //We determine if the arm is mathematically forward or backward
    //assuming we rotate between -pi and pi
    if ( acos( v0 * v2 ) > acos ( v1 * v2 ))
    {
      testAngle = acos( v1 * v2 );
    }
    else
    {
      testAngle = -acos( v1 * v2 );
    }
  }
  else
  {
    v0[0] = v1[0] * cos( -0.001 ) - v1[1] * sin( -0.001 ); 
    v0[1] = v1[0] * sin( -0.001 ) + v1[1] * cos( -0.001 );
    //We determine if the arm is mathematically forward or backward
    //assuming we rotate between -pi and pi
    if ( acos( v0 * v2 ) < acos ( v1 * v2 ))
    {
      testAngle = acos( v1 * v2 );
    }
    else
    {
      testAngle = -acos( v1 * v2 );
    }
  }
  // Generate poly-line with 16 segments
  for ( int t = 0; t < 16; ++t )
  {
    double alpha = (double) t * angle / 15.0 + testAngle;

    Point2D polyLinePoint;
    polyLinePoint[0] = centerPoint[0] + radius * cos( alpha );
    polyLinePoint[1] = centerPoint[1] + radius * sin( alpha );

    AppendPointToHelperPolyLine( 0, PolyLineElement( polyLinePoint, t ) );
  }
}