Example usage for org.opencv.imgproc Subdiv2D getVertex

List of usage examples for org.opencv.imgproc Subdiv2D getVertex

Introduction

In this page you can find the example usage for org.opencv.imgproc Subdiv2D getVertex.

Prototype

public Point getVertex(int vertex, int[] firstEdge) 

Source Link

Usage

From source file:qupath.opencv.features.DelaunayTriangulation.java

License:Open Source License

void updateNodeMap(Subdiv2D subdiv, final double pixelWidth, final double pixelHeight) {
    if (subdiv == null)
        return;/*from  w w  w.  ja  v a2  s .c om*/

    int[] firstEdgeArray = new int[1];

    //      double distanceThreshold = 0; 
    boolean ignoreDistance = Double.isNaN(distanceThreshold) || Double.isInfinite(distanceThreshold)
            || distanceThreshold <= 0;

    DelaunayNodeFactory factory = new DelaunayNodeFactory(pixelWidth, pixelHeight);
    nodeMap = new HashMap<>(vertexMap.size(), 1f);
    for (Entry<Integer, PathObject> entry : vertexMap.entrySet()) {
        int v = entry.getKey();
        PathObject pathObject = entry.getValue();

        PathClass pathClass = pathObject.getPathClass() == null ? null
                : pathObject.getPathClass().getBaseClass();

        //         // TODO: CHECK INTENSITY DIFFERENT THRESHOLD
        //         String measurementName = "Nucleus: DAB OD mean";
        //         double measurementDiffThreshold = 0.1;
        //         double od = pathObject.getMeasurementList().getMeasurementValue(measurementName);

        subdiv.getVertex(v, firstEdgeArray);
        int firstEdge = firstEdgeArray[0];
        int edge = firstEdge;
        DelaunayNode node = factory.getNode(pathObject);
        while (true) {
            int edgeDest = subdiv.edgeDst(edge);
            PathObject destination = vertexMap.get(edgeDest);
            if (destination == null)
                break;

            boolean distanceOK = ignoreDistance
                    || distance(getROI(pathObject), getROI(destination)) < distanceThreshold;
            boolean classOK = !limitByClass || pathClass == destination.getPathClass()
                    || (destination.getPathClass() != null
                            && destination.getPathClass().getBaseClass() == pathClass);

            if (distanceOK && classOK) {
                // Intensity test (works, but currently commented out)
                //               if (Math.abs(od - destination.getMeasurementList().getMeasurementValue(measurementName)) < measurementDiffThreshold)
                DelaunayNode destinationNode = factory.getNode(destination);
                node.addEdge(destinationNode);

                destinationNode.addEdge(node);
            }

            // Unused code exploring how a similarity test could be included
            //            if (ignoreDistance || distance(pathObject.getROI(), destination.getROI()) < distanceThreshold) {
            //               MeasurementList m1 = pathObject.getMeasurementList();
            //               MeasurementList m2 = destination.getMeasurementList();
            //               double d2 = 0;
            //               for (String name : new String[]{"Nucleus: Area", "Nucleus: DAB OD mean", "Nucleus: Eccentricity"}) {
            //                  double t1 = m1.getMeasurementValue(name);
            //                  double t2 = m2.getMeasurementValue(name);
            //                  double temp = ((t1 - t2) / (t1 + t2)) * 2;
            //                  d2 += temp*temp;
            //               }
            //               if (d2 < 1)
            ////               System.out.println(d2);
            //                  node.addEdge(factory.getNode(destination));
            //            }

            edge = subdiv.getEdge(edge, Subdiv2D.NEXT_AROUND_ORG);
            if (edge == firstEdge)
                break;
        }
        Object previous = nodeMap.put(pathObject, node);
        assert previous == null;
    }
}