예제 #1
0
static void TestPlanarCrossPlacementSingleLine(mitk::PlanarCross::Pointer planarCross)
{
  // Test for correct minimum number of control points in cross-mode
  MITK_TEST_CONDITION( planarCross->GetMinimumNumberOfControlPoints() == 2, "Minimum number of control points" );

  // Test for correct maximum number of control points in cross-mode
  MITK_TEST_CONDITION( planarCross->GetMaximumNumberOfControlPoints() == 2, "Maximum number of control points" );

  // Initial placement of PlanarCross
  mitk::Point2D p0;
  p0[0] = 25.0; p0[1] = 10.0;
  planarCross->PlaceFigure( p0 );

  // Add second control point
  mitk::Point2D p1;
  p1[0] = 30.0; p1[1] = 60.0;
  planarCross->SetCurrentControlPoint( p1 );

  // Verify that no helper line is drawn
  MITK_TEST_CONDITION( planarCross->IsHelperToBePainted( 0 ) == false, "No helper line to be painted in single-line mode" );

  // Test for number of control points
  MITK_TEST_CONDITION( planarCross->GetNumberOfControlPoints() == 2, "Number of control points after placement" );

  // Test if PlanarFigure is closed
  MITK_TEST_CONDITION( !planarCross->IsClosed(), "Is PlanarFigure closed?" );


  // Test for number of polylines
  const mitk::PlanarFigure::PolyLineType polyLine0 = planarCross->GetPolyLine( 0 );
  mitk::PlanarFigure::PolyLineType::const_iterator iter = polyLine0.begin();
  MITK_TEST_CONDITION( planarCross->GetPolyLinesSize() == 1, "Number of polylines after placement" );

  // Get polylines and check if the generated coordinates are OK
  const mitk::Point2D& pp0 = iter->Point;
  iter++;
  const mitk::Point2D& pp1 = iter->Point;
  MITK_TEST_CONDITION( ((pp0 == p0) && (pp1 == p1))
    || ((pp0 == p1) && (pp1 == p0)), "Correct polyline 1" );


  // Test for number of measurement features
  planarCross->EvaluateFeatures();
  MITK_TEST_CONDITION( planarCross->GetNumberOfFeatures() == 1, "Number of measurement features" );

  // Test for correct feature evaluation
  double length0 = sqrt( 5.0 * 5.0 + 50.0 * 50.0 );
  MITK_TEST_CONDITION( fabs( planarCross->GetQuantity( 0 ) - length0) < mitk::eps, "Size of diameter" );

  // Test if reset called on single-line PlanarCross returns false (nothing to reset)
  MITK_TEST_CONDITION( planarCross->ResetOnPointSelect() == false, "Single-line PlanarCross should not be reset on point edit" );
}
void mitk::PlanarFigureMapper2D::PaintPolyLine(
  mitk::PlanarFigure::PolyLineType vertices,  
  bool closed,
  float* color, 
  float opacity, 
  float lineWidth, 
  Point2D& firstPoint, 
  const Geometry2D* planarFigureGeometry2D, 
  const Geometry2D* rendererGeometry2D, 
  const DisplayGeometry* displayGeometry)
{
  glColor4f( color[0], color[1], color[2], opacity );
  glLineWidth(lineWidth);

  if ( closed )
  {
    glBegin( GL_LINE_LOOP );
  }
  else 
  {
    glBegin( GL_LINE_STRIP );
  }

  for ( PlanarFigure::PolyLineType::iterator iter = vertices.begin(); iter!=vertices.end(); iter++ )
  {
    // Draw this 2D point as OpenGL vertex
    mitk::Point2D displayPoint;
    this->TransformObjectToDisplay( iter->Point, displayPoint,
      planarFigureGeometry2D, rendererGeometry2D, displayGeometry );

    if(iter == vertices.begin())
      firstPoint = displayPoint;

    glVertex2f( displayPoint[0], displayPoint[1] );
  }

  glEnd();
}
static mitk::Point2D GetCenterPoint(const mitk::PlanarFigure::PolyLineType& polyLine)
{
  mitk::Point2D centerPoint;

  centerPoint[0] = 0;
  centerPoint[1] = 0;

  mitk::PlanarFigure::PolyLineType::const_iterator polyLineEnd = polyLine.end();

  for (mitk::PlanarFigure::PolyLineType::const_iterator polyLineIter = polyLine.begin(); polyLineIter != polyLineEnd; ++polyLineIter)
  {
    centerPoint[0] += static_cast<mitk::Point2D>(*polyLineIter)[0];
    centerPoint[1] += static_cast<mitk::Point2D>(*polyLineIter)[1];
  }

  size_t numPoints = polyLine.size();

  centerPoint[0] /= numPoints;
  centerPoint[1] /= numPoints;

  return centerPoint;
}
예제 #4
0
static void TestPlanarArrowPlacement( mitk::PlanarArrow::Pointer PlanarArrow )
{
  // Test for correct minimum number of control points in cross-mode
  MITK_TEST_CONDITION( PlanarArrow->GetMinimumNumberOfControlPoints() == 2, "Minimum number of control points" );

  // Test for correct maximum number of control points in cross-mode
  MITK_TEST_CONDITION( PlanarArrow->GetMaximumNumberOfControlPoints() == 2, "Maximum number of control points" );

  // Initial placement of PlanarArrow
  mitk::Point2D p0;
  p0[0] = 00.0; p0[1] = 0.0;
  PlanarArrow->PlaceFigure( p0 );

  // Add second control point
  mitk::Point2D p1;
  p1[0] = 50.0; p1[1] = 00.0;
  PlanarArrow->SetControlPoint(1, p1 );

  // Test for number of control points
  MITK_TEST_CONDITION( PlanarArrow->GetNumberOfControlPoints() == 2, "Number of control points after placement" );

  // Test for number of polylines
  const mitk::PlanarFigure::PolyLineType polyLine0 = PlanarArrow->GetPolyLine( 0 );
  auto iter = polyLine0.begin();
  MITK_TEST_CONDITION( PlanarArrow->GetPolyLinesSize() == 1, "Number of polylines after placement" );


  // Get polylines and check if the generated coordinates are OK
  const mitk::Point2D& pp0 = *iter;
  iter++;
  const mitk::Point2D& pp1 = *iter;
  MITK_TEST_CONDITION( (pp0 == p0) && (pp1 == p1), "Correct polyline 1" );


  // Test for number of measurement features
  // none yet

}
예제 #5
0
static void TestPlanarPolygonPlacement( mitk::PlanarPolygon::Pointer planarPolygon )
{
  // Test for correct minimum number of control points in cross-mode
  MITK_TEST_CONDITION( planarPolygon->GetMinimumNumberOfControlPoints() == 3, "Minimum number of control points" );

  // Test for correct maximum number of control points in cross-mode
  MITK_TEST_CONDITION( planarPolygon->GetMaximumNumberOfControlPoints() == 1000, "Maximum number of control points" );

  // Initial placement of PlanarPolygon
  mitk::Point2D p0;
  p0[0] = 00.0; p0[1] = 0.0;
  planarPolygon->PlaceFigure( p0 );

  // Add second control point
  mitk::Point2D p1;
  p1[0] = 50.0; p1[1] = 00.0;
  planarPolygon->SetControlPoint(1, p1 );

  // Add third control point
  mitk::Point2D p2;
  p2[0] = 50.0; p2[1] = 50.0;
  planarPolygon->AddControlPoint( p2 );

  // Add fourth control point
  mitk::Point2D p3;
  p3[0] = 0.0; p3[1] = 50.0;
  planarPolygon->AddControlPoint( p3 );

  // Test for number of control points
  MITK_TEST_CONDITION( planarPolygon->GetNumberOfControlPoints() == 4, "Number of control points after placement" );

  // Test if PlanarFigure is closed
  MITK_TEST_CONDITION( planarPolygon->IsClosed(), "planar polygon should not be closed, yet, right?" );
  
  planarPolygon->SetClosed(true);

  MITK_TEST_CONDITION( planarPolygon->IsClosed(), "planar polygon should be closed after function call, right?" );
  
  // Test for number of polylines
  const mitk::PlanarFigure::PolyLineType polyLine0 = planarPolygon->GetPolyLine( 0 );
  mitk::PlanarFigure::PolyLineType::const_iterator iter = polyLine0.begin();
  MITK_TEST_CONDITION( planarPolygon->GetPolyLinesSize() == 1, "Number of polylines after placement" );

  // Get polylines and check if the generated coordinates are OK
  const mitk::Point2D& pp0 = iter->Point;
  ++iter;
  const mitk::Point2D& pp1 = iter->Point;
  MITK_TEST_CONDITION( ((pp0 == p0) && (pp1 == p1))
    || ((pp0 == p1) && (pp1 == p0)), "Correct polyline 1" );

    
  // Test for number of measurement features
  planarPolygon->EvaluateFeatures();
  MITK_TEST_CONDITION( planarPolygon->GetNumberOfFeatures() == 2, "Number of measurement features" );

  // Test for correct feature evaluation
  double length0 = 4 * 50.0; // circumference
  MITK_TEST_CONDITION( fabs( planarPolygon->GetQuantity( 0 ) - length0) < mitk::eps, "Size of longest diameter" );

  double length1 = 50.0 * 50.0 ; // area
  MITK_TEST_CONDITION( fabs( planarPolygon->GetQuantity( 1 ) - length1) < mitk::eps, "Size of short axis diameter" );
}
static void TestPlanarSubdivisionPolygonPlacement( mitk::PlanarSubdivisionPolygon::Pointer planarSubdivisionPolygon )
{
  // Test for correct minimum number of control points in cross-mode
  MITK_TEST_CONDITION( planarSubdivisionPolygon->GetMinimumNumberOfControlPoints() == 3, "Minimum number of control points" );

  // Test for correct maximum number of control points in cross-mode
  MITK_TEST_CONDITION( planarSubdivisionPolygon->GetMaximumNumberOfControlPoints() == 1000, "Maximum number of control points" );

  // Test for correct rounds of subdivisionPoints
  MITK_TEST_CONDITION( planarSubdivisionPolygon->GetSubdivisionRounds() == 5, "Subdivision point generation depth" );

  // Test for correct tension parameter
  MITK_TEST_CONDITION( planarSubdivisionPolygon->GetTensionParameter() == 0.0625, "Tension parameter" );

  planarSubdivisionPolygon->SetProperty( "initiallyplaced", mitk::BoolProperty::New( true ) );

  // Initial placement of planarSubdivisionPolygon
  mitk::Point2D p0;
  p0[0] = 25.0; p0[1] = 25.0;
  planarSubdivisionPolygon->PlaceFigure( p0 );

  // Add second control point
  mitk::Point2D p1;
  p1[0] = 75.0; p1[1] = 25.0;
  planarSubdivisionPolygon->SetControlPoint(1, p1 );

  // Add third control point
  mitk::Point2D p2;
  p2[0] = 75.0; p2[1] = 75.0;
  planarSubdivisionPolygon->AddControlPoint( p2 );

  // Add fourth control point
  mitk::Point2D p3;
  p3[0] = 25.0; p3[1] = 75.0;
  planarSubdivisionPolygon->AddControlPoint( p3 );

  // Test for number of control points
  MITK_TEST_CONDITION( planarSubdivisionPolygon->GetNumberOfControlPoints() == 4, "Number of control points after placement" );

  // Test if PlanarFigure is closed
  MITK_TEST_CONDITION( planarSubdivisionPolygon->IsClosed(), "Test if property 'closed' is set by default" );

  // Test for number of polylines
  const mitk::PlanarFigure::PolyLineType polyLine0 = planarSubdivisionPolygon->GetPolyLine( 0 );
  mitk::PlanarFigure::PolyLineType::const_iterator iter = polyLine0.begin();
  MITK_TEST_CONDITION( planarSubdivisionPolygon->GetPolyLinesSize() == 1, "Number of polylines after placement" );

  // Test if subdivision point count is correct
  MITK_TEST_CONDITION( polyLine0.size() == 128, "correct number of subdivision points for this depth level" );

  // Test if control points are in correct order between subdivision points
  bool correctPoint = true;
  iter = polyLine0.begin();

  if( iter->Point != p0 ){ correctPoint = false; }
  advance(iter, 32);
  if( iter->Point != p1 ){ correctPoint = false; }
  advance(iter, 32);
  if( iter->Point != p2 ){ correctPoint = false; }
  advance(iter, 32);
  if( iter->Point != p3 ){ correctPoint = false; }
  MITK_TEST_CONDITION( correctPoint, "Test if control points are in correct order in polyline" );


  // Test if a picked point has the correct coordinates
  correctPoint = true;

  mitk::Point2D testPoint;
  testPoint[0] = 81.25;
  testPoint[1] = 48.243;
  iter = polyLine0.begin();
  advance(iter, 47);
  if( (iter->Point[0] - testPoint[0]) + (iter->Point[1] - testPoint[1]) > mitk::eps ){ correctPoint = false; }

  testPoint[0] = 39.624;
  testPoint[1] = 19.3268;
  iter = polyLine0.begin();
  advance(iter, 10);
  if( (iter->Point[0] - testPoint[0]) + (iter->Point[1] - testPoint[1]) > mitk::eps ){ correctPoint = false; }

  testPoint[0] = 71.2887;
  testPoint[1] = 77.5248;
  iter = polyLine0.begin();
  advance(iter, 67);
  if( (iter->Point[0] - testPoint[0]) + (iter->Point[1] - testPoint[1]) > mitk::eps ){ correctPoint = false; }

  MITK_TEST_CONDITION( correctPoint, "Test if subdivision points are calculated correctly" )

  // Test for number of measurement features
  /*
  Does not work yet

  planarSubdivisionPolygon->EvaluateFeatures();
  MITK_TEST_CONDITION( planarSubdivisionPolygon->GetNumberOfFeatures() == 2, "Number of measurement features" );

  // Test for correct feature evaluation
  double length0 = 4 * 50.0; // circumference
  MITK_TEST_CONDITION( fabs( planarSubdivisionPolygon->GetQuantity( 0 ) - length0) < mitk::eps, "Size of longest diameter" );

  double length1 = 50.0 * 50.0 ; // area
  MITK_TEST_CONDITION( fabs( planarSubdivisionPolygon->GetQuantity( 1 ) - length1) < mitk::eps, "Size of short axis diameter" );
  */
}
예제 #7
0
static void TestPlanarCrossPlacement( mitk::PlanarCross::Pointer planarCross )
{
  // Test for correct minimum number of control points in cross-mode
  MITK_TEST_CONDITION( planarCross->GetMinimumNumberOfControlPoints() == 4, "Minimum number of control points" );

  // Test for correct maximum number of control points in cross-mode
  MITK_TEST_CONDITION( planarCross->GetMaximumNumberOfControlPoints() == 4, "Maximum number of control points" );

  // Initial placement of PlanarCross
  mitk::Point2D p0;
  p0[0] = 20.0; p0[1] = 20.0;
  planarCross->PlaceFigure( p0 );

  // Add second control point
  mitk::Point2D p1;
  p1[0] = 80.0; p1[1] = 80.0;
  planarCross->SetCurrentControlPoint( p1 );

  // Add third control point
  mitk::Point2D p2;
  p2[0] = 90.0; p2[1] = 10.0;
  planarCross->AddControlPoint( p2 );

  // Test if helper polyline is generated
  const mitk::PlanarFigure::PolyLineType helperPolyLine = planarCross->GetHelperPolyLine( 0, 1.0, 100 );
  MITK_TEST_CONDITION( planarCross->GetHelperPolyLinesSize() == 1, "Number of helper polylines after placing 3 points" );

  // Test if helper polyline is marked as "to be painted"
  MITK_TEST_CONDITION( planarCross->IsHelperToBePainted( 0 ), "Helper line to be painted after placing 3 points" );

  // Test if helper polyline is orthogonal to first line
  mitk::Vector2D v0 = p1 - p0;
  v0.Normalize();

  // TODO: make it work again

  //mitk::Vector2D hv = helperPolyLine->ElementAt( 1 ) - helperPolyLine->ElementAt( 0 );
  //hv.Normalize();
  //MITK_TEST_CONDITION( fabs(v0 * hv) < mitk::eps, "Helper line is orthogonal to first line" );

  //// Test if helper polyline is placed correctly
  //mitk::Vector2D hv1 = helperPolyLine->ElementAt( 1 ) - p2;
  //hv1.Normalize();
  //MITK_TEST_CONDITION( fabs(hv * hv1 - 1.0) < mitk::eps, "Helper line is aligned to third point" );


  // Add fourth control point
  mitk::Point2D p3;
  p3[0] = 10.0; p3[1] = 90.0;
  planarCross->AddControlPoint( p3 );

  // Test for number of control points
  MITK_TEST_CONDITION( planarCross->GetNumberOfControlPoints() == 4, "Number of control points after placement" );

  // Test if PlanarFigure is closed
  MITK_TEST_CONDITION( !planarCross->IsClosed(), "Is PlanarFigure closed?" );

  // Test if helper polyline is no longer marked as "to be painted"
  MITK_TEST_CONDITION( planarCross->IsHelperToBePainted( 0 ), "Helper line no longer to be painted after placement of all 4 points" );


  // Test for number of polylines
  const mitk::PlanarFigure::PolyLineType polyLine0 = planarCross->GetPolyLine( 0 );
  const mitk::PlanarFigure::PolyLineType polyLine1 = planarCross->GetPolyLine( 1 );
  MITK_TEST_CONDITION( planarCross->GetPolyLinesSize() == 2, "Number of polylines after placement" );

  mitk::PlanarFigure::PolyLineType::const_iterator iter0 = polyLine0.begin();
  mitk::PlanarFigure::PolyLineType::const_iterator iter1 = polyLine1.begin();
  
  // Get polylines and check if the generated coordinates are OK
  const mitk::Point2D& pp0 = iter0->Point;
  iter0++;
  const mitk::Point2D& pp1 = iter0->Point;
  MITK_TEST_CONDITION( ((pp0 == p0) && (pp1 == p1))
    || ((pp0 == p1) && (pp1 == p0)), "Correct polyline 1" );

  const mitk::Point2D& pp2 = iter1->Point;
  iter1++;
  const mitk::Point2D& pp3 = iter1->Point;
  MITK_TEST_CONDITION( ((pp2 == p2) && (pp3 == p3))
    || ((pp2 == p3) && (pp3 == p2)), "Correct polyline 2" );

  
  // Test for number of measurement features
  planarCross->EvaluateFeatures();
  MITK_TEST_CONDITION( planarCross->GetNumberOfFeatures() == 2, "Number of measurement features" );

  // Test for correct feature evaluation
  double length0 = sqrt( 80.0 * 80.0 * 2.0 );
  MITK_TEST_CONDITION( fabs( planarCross->GetQuantity( 0 ) - length0) < mitk::eps, "Size of longest diameter" );

  double length1 = sqrt( 60.0 * 60.0 * 2.0 );
  MITK_TEST_CONDITION( fabs( planarCross->GetQuantity( 1 ) - length1) < mitk::eps, "Size of short axis diameter" );
}