Example usage for org.apache.commons.math3.geometry.partitioning BSPTree getAttribute

List of usage examples for org.apache.commons.math3.geometry.partitioning BSPTree getAttribute

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.partitioning BSPTree getAttribute.

Prototype

public Object getAttribute() 

Source Link

Document

Get the attribute associated with the instance.

Usage

From source file:edu.stanford.cfuller.imageanalysistools.util.VoronoiDiagram.java

/**
* Gets the number of the region in which a supplied point lies.
* 
* @param point a Vector2D describing the point whose region is being queried.
* @return an int that is the label of the region in which the supplied vector lies.
*          this label corresponds to the (1-indexed) order in which the points were supplied
*          to the constructor./*from   w  w  w  .j av a 2  s .  c  o m*/
*/
public int getRegionNumber(Vector2D point) {
    final int unlabeledValue = 100;
    try {
        BSPTree<Euclidean2D> node = this.diagram.getCell(point);

        while (node.getAttribute() == null) {
            if (isLeaf(node)) {
                Integer value = findClosestRegion(point);
                node.setAttribute(value);
                break;
            }
            final double eps = 1e-6; // bump it slightly if it's exactly on an edge.
            Vector2D newpoint = point.add(new Vector2D(eps, 0));
            node = this.diagram.getCell(newpoint);

            if (node.getAttribute() != null)
                break;

            if (isLeaf(node)) {
                Integer value = findClosestRegion(point);
                node.setAttribute(value);
                break;
            }

            newpoint = point.add(new Vector2D(0, eps));
            node = this.diagram.getCell(newpoint);
        }

        return ((Integer) node.getAttribute());
        //return (node.hashCode());
    } catch (ClassCastException e) {
        return 0;
    }
}

From source file:org.orekit.models.earth.tessellation.EllipsoidTessellator.java

/** Check if an arc meets the inside of a zone.
 * <p>/*from ww  w.j av a 2s .c  om*/
 * This method is heavily based on the Characterization class from
 * Apache Commons Math library, also distributed under the terms
 * of the Apache Software License V2.
 * </p>
 * @param node spherical zone node
 * @param sub arc to characterize
 * @return true if the arc meets the inside of the zone
 */
private boolean recurseMeetInside(final BSPTree<Sphere2D> node, final SubHyperplane<Sphere2D> sub) {

    if (node.getCut() == null) {
        // we have reached a leaf node
        if (sub.isEmpty()) {
            return false;
        } else {
            return (Boolean) node.getAttribute();
        }
    } else {
        final Hyperplane<Sphere2D> hyperplane = node.getCut().getHyperplane();
        final SubHyperplane.SplitSubHyperplane<Sphere2D> split = sub.split(hyperplane);
        switch (split.getSide()) {
        case PLUS:
            return recurseMeetInside(node.getPlus(), sub);
        case MINUS:
            return recurseMeetInside(node.getMinus(), sub);
        case BOTH:
            if (recurseMeetInside(node.getPlus(), split.getPlus())) {
                return true;
            } else {
                return recurseMeetInside(node.getMinus(), split.getMinus());
            }
        default:
            // this should not happen
            throw new OrekitInternalError(null);
        }
    }
}

From source file:org.orekit.models.earth.tessellation.InsideFinder.java

/** {@inheritDoc} */
@Override/*from www  . j  a va  2  s .  co  m*/
public void visitLeafNode(final BSPTree<Sphere2D> node) {

    // we have already found a good point
    if (insidePointFirstChoice != null) {
        return;
    }

    if ((Boolean) node.getAttribute()) {

        // transform this inside leaf cell into a simple convex polygon
        final SphericalPolygonsSet convex = new SphericalPolygonsSet(
                node.pruneAroundConvexCell(Boolean.TRUE, Boolean.FALSE, null), zone.getTolerance());

        // extract the start of the single loop boundary of the convex cell
        final List<Vertex> boundary = convex.getBoundaryLoops();
        final Vertex start = boundary.get(0);
        int n = 0;
        Vector3D sumB = Vector3D.ZERO;
        for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) {
            sumB = new Vector3D(1, sumB, e.getLength(), e.getCircle().getPole());
            n++;
        }

        final S2Point candidate = new S2Point(sumB);

        // check the candidate point is really considered inside
        // it may appear outside if the current leaf cell is very thin
        // and checkPoint selects another (very close) tree leaf node
        if (zone.checkPoint(candidate) == Location.INSIDE) {
            insidePointFirstChoice = candidate;
        } else {
            insidePointSecondChoice = candidate;
        }

    }

}