0

following the delaunay triangulation given in learning opencv, I'm having some trouble understanding this snippet which is the final piece responsible for graphing the tesselation, here draw_subdiv_facet is being fed one voroni edge at a time

static void draw_subdiv_facet( IplImage* img, CvSubdiv2DEdge edge )
{
    CvSubdiv2DEdge t = edge;
    int i, count = 0;

    //cvpoint structure
    //param x:  x-coordinate of the point.
    //param y:  y-coordinate of the point.
    //param point:  the point to convert.
    CvPoint* buf = 0;

    // count number of edges in facet
    do
    {
        count++;
        t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
    } while (t != edge );
    cout<<"\ncount is : "<<count<<endl;

    //allocate the array
    buf = (CvPoint*)malloc( count * sizeof(buf[0]));

    // gather points
    t = edge;
    for( i = 0; i < count; i++ )
    {
        //
        CvSubdiv2DPoint* pt = cvSubdiv2DEdgeOrg( t );          
        if( !pt ) break;


        buf[i] = cvPoint( cvRound(pt->pt.x), cvRound(pt->pt.y));
        cout<<"pt.x is : "<<cvRound(pt->pt.x);
        cout<<"   pt.y is : "<<cvRound(pt->pt.y)<<endl;
        cout<<"converted to cvPoint gives"<<buf[i].x<<" , "<<buf[i].y<<endl;
        t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
    }

    if( i == count )   
    {
        CvSubdiv2DPoint* pt = cvSubdiv2DEdgeDst( cvSubdiv2DRotateEdge( edge, 1 ));
        //cvFillConvexPoly( img, buf, count, CV_RGB(rand()&255,rand()&255,rand()&255), CV_AA, 0 );


        CvPoint xx = buf[0];
        cout<<"located at "<<xx.x<<","<<xx.y<<endl;
        cvPolyLine( img, &buf, &count, 1, 1, CV_RGB(0,0,0), 1, CV_AA, 0);
        draw_subdiv_point( img, pt->pt, CV_RGB(0,0,0));
    }
    free( buf );
}

This is responsible for plotting the lines and coloring in the polygons as you can see but the points being outputted by the cout are much larger than the window itself, ie the canvas being

CvRect rect = { 0, 0, 600, 600 };
img = cvCreateImage( cvSize(rect.width,rect.height), 8, 3 );

the points are are on the order of -1000 or more so how is it still plotting the points.

berak
  • 39,159
  • 9
  • 91
  • 89
tweaking
  • 350
  • 4
  • 6

2 Answers2

1

It's unclear what you're asking, exactly. If the points are 'on the order of 1000 or more', then probably the source image is that big. The points are relative to the source image, not the window. You'll need to manually scale the points yourself if you need them to fit inside the drawing window.

damian
  • 3,604
  • 1
  • 27
  • 46
0

you're right my mistake. It was plotting maybe 10 out of 200+ points with coordinates btw 0 and 1000, I just didn't see those points and got confused but they were there all along. Thanks.

tweaking
  • 350
  • 4
  • 6