Is there a way to plot a perimeter line around all 1's on a grid of data?

The grid of data are QVectors of x, y, and z. Where x & y are meters of type double, and z are binary 1's and 0's.

I am using QCPCurve::addData(QVector& x, QVector& y). I am trying to avoid plotting zig-zag lines inside the perimeter. The grid data is in a typical x/y cartesian index order.

Example:

Plot a circle/perimeter around all the 1's:

<------ x -------->

0 0 0 0 0 0 0 0 ^

0 0 1 1 1 1 0 0 |

0 1 1 1 1 1 1 0 y

0 0 1 1 1 1 0 0 |

0 0 0 0 0 0 0 0 v

Thank you in advance!