I'm afraid I don't know of a much nicer way...
Using the vertices alone would probably work most of the time, although could fail if there is a large distance between any consecutive pair of vertices.
I don't really have a feeling for how the Delaunay triangulation would help, but there is an OpenCV implementation accessible through QuPath. You can see an example of its use within
DelaunayTriangulation.java - although be warned that this is not exactly the easiest code to follow. It's also not the easiest to write; because using OpenCV brings things outside the Java world, small errors and bugs frequently end quite catastrophically (i.e. QuPath may shut down without warning, rather than throwing a more helpful exception). Debugging becomes particularly exhilarating when the catastrophe turns out to be triggered by the garbage collector.
On the other hand, the implementation is fast and it doesn't require another dependency.
If you don't mind adding another dependency, then there may well be other specialized Java geometry-related libraries that would help perform the calculations much more easily.
Personally, my tendency is to convert problems like these into image processing ones. With that in mind, my first approach would be to create a Groovy script that does the following:
- Based on the original image dimensions, create a ByteProcessor in ImageJ that has been scaled down to a manageable size - i.e. figure out a 'downsample' factor and divide the full image width and height by this
- Convert the QuPath ROI for Annotation A into an ImageJ 'Roi' - scaling accordingly - and use it to fill the ByteProcessor with white pixels
- Apply a (32-bit) distance transform to the ByteProcessor in ImageJ to calculate the distance to every white pixel (ImageJ has 'EDM.java' to do this)
- For each cell centroid, downsample it accordingly to fit with the distance map and calculate the interpolated pixel value for the downsampled x,y coordinates
- Scale the interpolated distance map value by the downsample * pixel size in microns to get an approximate distance
- Add this distance to the measurement list for each cell, and use Measure -> Show measurement maps and the line tool to check everything looks ok
This doesn't exactly feel optimal, but it should be fast. If you decide to go this way, feel free to ask for more information about any of the vaguely-defined steps. But if you find an alternative that is better, please do post it here as well - it's an interesting problem, and one that I suspect could be worth solving for others as well.