Search in sources :

Example 6 with Point

use of com.google.monitoring.v3.Point in project java-docs-samples by GoogleCloudPlatform.

the class QuickstartSample method main.

public static void main(String... args) throws Exception {
    // Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");
    if (projectId == null) {
        System.err.println("Usage: QuickstartSample -DprojectId=YOUR_PROJECT_ID");
        return;
    }
    // Instantiates a client
    MetricServiceClient metricServiceClient = MetricServiceClient.create();
    // Prepares an individual data point
    TimeInterval interval = TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
    TypedValue value = TypedValue.newBuilder().setDoubleValue(123.45).build();
    Point point = Point.newBuilder().setInterval(interval).setValue(value).build();
    List<Point> pointList = new ArrayList<>();
    pointList.add(point);
    ProjectName name = ProjectName.of(projectId);
    // Prepares the metric descriptor
    Map<String, String> metricLabels = new HashMap<String, String>();
    metricLabels.put("store_id", "Pittsburg");
    Metric metric = Metric.newBuilder().setType("custom.googleapis.com/stores/daily_sales").putAllLabels(metricLabels).build();
    // Prepares the monitored resource descriptor
    Map<String, String> resourceLabels = new HashMap<String, String>();
    resourceLabels.put("project_id", projectId);
    MonitoredResource resource = MonitoredResource.newBuilder().setType("global").putAllLabels(resourceLabels).build();
    // Prepares the time series request
    TimeSeries timeSeries = TimeSeries.newBuilder().setMetric(metric).setResource(resource).addAllPoints(pointList).build();
    List<TimeSeries> timeSeriesList = new ArrayList<>();
    timeSeriesList.add(timeSeries);
    CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder().setName(name.toString()).addAllTimeSeries(timeSeriesList).build();
    // Writes time series data
    metricServiceClient.createTimeSeries(request);
    System.out.printf("Done writing time series data.%n");
    metricServiceClient.close();
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) HashMap(java.util.HashMap) CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest) ArrayList(java.util.ArrayList) MonitoredResource(com.google.api.MonitoredResource) Point(com.google.monitoring.v3.Point) Metric(com.google.api.Metric) TypedValue(com.google.monitoring.v3.TypedValue)

Example 7 with Point

use of com.google.monitoring.v3.Point in project java-docs-samples by GoogleCloudPlatform.

the class BigQueryRunner method prepareMetric.

// Returns a metric time series with a single int64 data point.
private TimeSeries prepareMetric(MetricDescriptor requiredMetric, long metricValue) {
    TimeInterval interval = TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
    TypedValue value = TypedValue.newBuilder().setInt64Value(metricValue).build();
    Point point = Point.newBuilder().setInterval(interval).setValue(value).build();
    List<Point> pointList = Lists.newArrayList();
    pointList.add(point);
    Metric metric = Metric.newBuilder().setType(requiredMetric.getName()).build();
    return TimeSeries.newBuilder().setMetric(metric).addAllPoints(pointList).build();
}
Also used : TimeInterval(com.google.monitoring.v3.TimeInterval) Metric(com.google.api.Metric) Point(com.google.monitoring.v3.Point) TypedValue(com.google.monitoring.v3.TypedValue)

Example 8 with Point

use of com.google.monitoring.v3.Point in project java-mapollage by trixon.

the class Operation method addPolygons.

private void addPolygons(Folder polygonParent, List<Feature> features) {
    for (Feature feature : features) {
        if (feature instanceof Folder) {
            Folder folder = (Folder) feature;
            if (folder != mPathFolder && folder != mPathGapFolder && folder != mPolygonFolder) {
                System.out.println("ENTER FOLDER=" + folder.getName());
                System.out.println("PARENT FOLDER=" + polygonParent.getName());
                Folder polygonFolder = polygonParent.createAndAddFolder().withName(folder.getName()).withOpen(true);
                mFolderPolygonInputs.put(polygonFolder, new ArrayList<>());
                addPolygons(polygonFolder, folder.getFeature());
                System.out.println("POLYGON FOLDER=" + polygonFolder.getName() + " CONTAINS");
                if (mFolderPolygonInputs.get(polygonFolder) != null) {
                    addPolygon(folder.getName(), mFolderPolygonInputs.get(polygonFolder), polygonParent);
                }
                System.out.println("EXIT FOLDER=" + folder.getName());
                System.out.println("");
            }
        }
        if (feature instanceof Placemark) {
            Placemark placemark = (Placemark) feature;
            System.out.println("PLACEMARK=" + placemark.getName() + "(PARENT=)" + polygonParent.getName());
            Point point = (Point) placemark.getGeometry();
            point.getCoordinates().forEach((coordinate) -> {
                mFolderPolygonInputs.get(polygonParent).add(coordinate);
            });
        }
    }
}
Also used : ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) Point(de.micromata.opengis.kml.v_2_2_0.Point) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) ProfileFolder(se.trixon.mapollage.profile.ProfileFolder) Feature(de.micromata.opengis.kml.v_2_2_0.Feature)

Example 9 with Point

use of com.google.monitoring.v3.Point in project imagej-ops by imagej.

the class WatershedSeeded method compute.

@SuppressWarnings("unchecked")
@Override
public void compute(final RandomAccessibleInterval<T> in, final ImgLabeling<Integer, IntType> out) {
    // extend border to be able to do a quick check, if a voxel is inside
    final LabelingType<Integer> oustide = out.firstElement().copy();
    oustide.clear();
    oustide.add(OUTSIDE);
    final ExtendedRandomAccessibleInterval<LabelingType<Integer>, ImgLabeling<Integer, IntType>> outExt = Views.extendValue(out, oustide);
    final OutOfBounds<LabelingType<Integer>> raOut = outExt.randomAccess();
    // if no mask provided, set the mask to the whole image
    if (mask == null) {
        mask = (RandomAccessibleInterval<B>) ops().create().img(in, new BitType());
        for (B b : Views.flatIterable(mask)) {
            b.set(true);
        }
    }
    // initialize output labels
    final Cursor<B> maskCursor = Views.flatIterable(mask).cursor();
    while (maskCursor.hasNext()) {
        maskCursor.fwd();
        if (maskCursor.get().get()) {
            raOut.setPosition(maskCursor);
            raOut.get().clear();
            raOut.get().add(INIT);
        }
    }
    // RandomAccess for Mask, Seeds and Neighborhoods
    final RandomAccess<B> raMask = mask.randomAccess();
    final RandomAccess<LabelingType<Integer>> raSeeds = seeds.randomAccess();
    final Shape shape;
    if (useEightConnectivity) {
        shape = new RectangleShape(1, true);
    } else {
        shape = new DiamondShape(1);
    }
    final RandomAccessible<Neighborhood<T>> neighborhoods = shape.neighborhoodsRandomAccessible(in);
    final RandomAccess<Neighborhood<T>> raNeigh = neighborhoods.randomAccess();
    /*
		 * Carry over the seeding points to the new label and adds them to a
		 * voxel priority queue
		 */
    final PriorityQueue<WatershedVoxel> pq = new PriorityQueue<>();
    // Only iterate seeds that are not excluded by the mask
    final IterableRegion<B> maskRegions = Regions.iterable(mask);
    final IterableInterval<LabelingType<Integer>> seedsMasked = Regions.sample(maskRegions, seeds);
    final Cursor<LabelingType<Integer>> cursorSeeds = seedsMasked.localizingCursor();
    while (cursorSeeds.hasNext()) {
        final Set<Integer> l = cursorSeeds.next();
        if (l.isEmpty()) {
            continue;
        }
        if (l.size() > 1) {
            throw new IllegalArgumentException("Seeds must have exactly one label!");
        }
        final Integer label = l.iterator().next();
        if (label < 0) {
            throw new IllegalArgumentException("Seeds must have positive integers as labels!");
        }
        raNeigh.setPosition(cursorSeeds);
        final Cursor<T> neighborhood = raNeigh.get().cursor();
        // Add unlabeled neighbors to priority queue
        while (neighborhood.hasNext()) {
            neighborhood.fwd();
            raSeeds.setPosition(neighborhood);
            raMask.setPosition(neighborhood);
            raOut.setPosition(neighborhood);
            final Integer labelNeigh = raOut.get().iterator().next();
            if (labelNeigh != INQUEUE && labelNeigh != OUTSIDE && !raOut.isOutOfBounds() && raMask.get().get() && raSeeds.get().isEmpty()) {
                raOut.setPosition(neighborhood);
                pq.add(new WatershedVoxel(IntervalIndexer.positionToIndex(neighborhood, in), neighborhood.get().getRealDouble()));
                raOut.get().clear();
                raOut.get().add(INQUEUE);
            }
        }
        // Overwrite label in output with the seed label
        raOut.setPosition(cursorSeeds);
        raOut.get().clear();
        raOut.get().add(label);
    }
    /*
		 * Pop the head of the priority queue, label and push all unlabeled
		 * neighbored pixels.
		 */
    // list to store neighbor labels
    final ArrayList<Integer> neighborLabels = new ArrayList<>();
    // list to store neighbor voxels
    final ArrayList<WatershedVoxel> neighborVoxels = new ArrayList<>();
    // iterate the queue
    final Point pos = new Point(in.numDimensions());
    while (!pq.isEmpty()) {
        IntervalIndexer.indexToPosition(pq.poll().getPos(), out, pos);
        // reset list of neighbor labels
        neighborLabels.clear();
        // reset list of neighbor voxels
        neighborVoxels.clear();
        // iterate the neighborhood of the pixel
        raNeigh.setPosition(pos);
        final Cursor<T> neighborhood = raNeigh.get().cursor();
        while (neighborhood.hasNext()) {
            neighborhood.fwd();
            // Unlabeled neighbors go into the queue if they are not there
            // yet
            raOut.setPosition(neighborhood);
            raMask.setPosition(raOut);
            if (!raOut.get().isEmpty()) {
                final Integer label = raOut.get().iterator().next();
                if (label == INIT && raMask.get().get()) {
                    neighborVoxels.add(new WatershedVoxel(IntervalIndexer.positionToIndex(neighborhood, out), neighborhood.get().getRealDouble()));
                } else {
                    if (label > WSHED && (!drawWatersheds || !neighborLabels.contains(label))) {
                        // store labels of neighbors in a list
                        neighborLabels.add(label);
                    }
                }
            }
        }
        if (drawWatersheds) {
            // if the neighbors of the extracted voxel that have already
            // been labeled
            // all have the same label, then the voxel is labeled with their
            // label.
            raOut.setPosition(pos);
            raOut.get().clear();
            if (neighborLabels.size() == 1) {
                raOut.get().add(neighborLabels.get(0));
                // list
                for (final WatershedVoxel v : neighborVoxels) {
                    IntervalIndexer.indexToPosition(v.getPos(), out, raOut);
                    raOut.get().clear();
                    raOut.get().add(INQUEUE);
                    pq.add(v);
                }
            } else if (neighborLabels.size() > 1)
                raOut.get().add(WSHED);
        } else {
            if (neighborLabels.size() > 0) {
                raOut.setPosition(pos);
                raOut.get().clear();
                // take the label which most of the neighbors have
                if (neighborLabels.size() > 2) {
                    final Map<Integer, Long> countLabels = neighborLabels.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting()));
                    final Integer keyMax = Collections.max(countLabels.entrySet(), Comparator.comparingLong(Map.Entry::getValue)).getKey();
                    raOut.get().add(keyMax);
                } else {
                    raOut.get().add(neighborLabels.get(0));
                }
                // list
                for (final WatershedVoxel v : neighborVoxels) {
                    IntervalIndexer.indexToPosition(v.getPos(), out, raOut);
                    raOut.get().clear();
                    raOut.get().add(INQUEUE);
                    pq.add(v);
                }
            }
        }
    }
    /*
		 * Merge already present labels before calculation of watershed
		 */
    if (out() != null) {
        final Cursor<LabelingType<Integer>> cursor = out().cursor();
        while (cursor.hasNext()) {
            cursor.fwd();
            raOut.setPosition(cursor);
            final List<Integer> labels = new ArrayList<>();
            cursor.get().iterator().forEachRemaining(labels::add);
            raOut.get().addAll(labels);
        }
    }
}
Also used : DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) IterableRegion(net.imglib2.roi.IterableRegion) PriorityQueue(java.util.PriorityQueue) Contingent(net.imagej.ops.Contingent) Point(net.imglib2.Point) OutOfBounds(net.imglib2.outofbounds.OutOfBounds) ArrayList(java.util.ArrayList) Intervals(net.imglib2.util.Intervals) Cursor(net.imglib2.Cursor) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) BooleanType(net.imglib2.type.BooleanType) Map(java.util.Map) AbstractUnaryHybridCF(net.imagej.ops.special.hybrid.AbstractUnaryHybridCF) Functions(net.imagej.ops.special.function.Functions) Views(net.imglib2.view.Views) ExtendedRandomAccessibleInterval(net.imglib2.view.ExtendedRandomAccessibleInterval) BitType(net.imglib2.type.logic.BitType) RandomAccess(net.imglib2.RandomAccess) Shape(net.imglib2.algorithm.neighborhood.Shape) Regions(net.imglib2.roi.Regions) Parameter(org.scijava.plugin.Parameter) Set(java.util.Set) IntervalIndexer(net.imglib2.util.IntervalIndexer) IntType(net.imglib2.type.numeric.integer.IntType) Collectors(java.util.stream.Collectors) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) AtomicLong(java.util.concurrent.atomic.AtomicLong) Plugin(org.scijava.plugin.Plugin) CreateImgLabelingFromInterval(net.imagej.ops.create.imgLabeling.CreateImgLabelingFromInterval) List(java.util.List) Neighborhood(net.imglib2.algorithm.neighborhood.Neighborhood) LabelingType(net.imglib2.roi.labeling.LabelingType) UnaryFunctionOp(net.imagej.ops.special.function.UnaryFunctionOp) ImgLabeling(net.imglib2.roi.labeling.ImgLabeling) Ops(net.imagej.ops.Ops) Interval(net.imglib2.Interval) RandomAccessible(net.imglib2.RandomAccessible) Comparator(java.util.Comparator) RealType(net.imglib2.type.numeric.RealType) Collections(java.util.Collections) IterableInterval(net.imglib2.IterableInterval) DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) Shape(net.imglib2.algorithm.neighborhood.Shape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) ArrayList(java.util.ArrayList) BitType(net.imglib2.type.logic.BitType) LabelingType(net.imglib2.roi.labeling.LabelingType) ImgLabeling(net.imglib2.roi.labeling.ImgLabeling) DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) Point(net.imglib2.Point) PriorityQueue(java.util.PriorityQueue) Neighborhood(net.imglib2.algorithm.neighborhood.Neighborhood) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 10 with Point

use of com.google.monitoring.v3.Point in project imagej-ops by imagej.

the class DefaultDetectRidges method getNextPoint.

/**
 * Recursively determines the next line point and adds it to the running list
 * of line points.
 *
 * @param gradientRA - the {@link RandomAccess} of the gradient image.
 * @param pRA - the {@link RandomAccess} of the eigenvector image.
 * @param nRA - the {@link RandomAccess} of the subpixel line location image.
 * @param points - the {@link ArrayList} containing the line points.
 * @param octant - integer denoting the octant of the last gradient vector,
 *          oriented with 1 being 0 degrees and increasing in the
 *          counterclockwise direction.
 * @param lastnx - the x component of the gradient vector of the last line
 *          point.
 * @param lastny - the y component of the gradient vector of the last line
 *          point.
 * @param lastpx - the x component of the subpixel line location of the last
 *          line point.
 * @param lastpy - the y component of the subpixel line location of the last
 *          line point.
 */
private void getNextPoint(RandomAccess<DoubleType> gradientRA, RandomAccess<DoubleType> pRA, RandomAccess<DoubleType> nRA, List<RealPoint> points, int octant, double lastnx, double lastny, double lastpx, double lastpy) {
    Point currentPos = new Point(gradientRA);
    // variables for the best line point of the three.
    Point salientPoint = new Point(gradientRA);
    double salientnx = 0;
    double salientny = 0;
    double salientpx = 0;
    double salientpy = 0;
    double bestSalience = Double.MAX_VALUE;
    boolean lastPointInLine = true;
    // check the three possible points that could continue the line, starting at
    // the octant after the given octant and rotating clockwise around the
    // current pixel.
    double lastAngle = RidgeDetectionUtils.getAngle(lastnx, lastny);
    for (int i = 1; i < 4; i++) {
        int[] modifier = RidgeDetectionUtils.getOctantCoords(octant + i);
        gradientRA.move(modifier[0], 0);
        gradientRA.move(modifier[1], 1);
        // there.
        if (gradientRA.get().get() > lowerThreshold) /*&& isMaxRA.get().get() > 0*/
        {
            long[] vectorArr = { gradientRA.getLongPosition(0), gradientRA.getLongPosition(1), 0 };
            nRA.setPosition(vectorArr);
            double nx = nRA.get().get();
            nRA.fwd(2);
            double ny = nRA.get().get();
            pRA.setPosition(vectorArr);
            double px = pRA.get().get();
            pRA.fwd(2);
            double py = pRA.get().get();
            double currentAngle = RidgeDetectionUtils.getAngle(nx, ny);
            double subpixelDiff = Math.sqrt(Math.pow(px - lastpx, 2) + Math.pow(py - lastpy, 2));
            double angleDiff = Math.abs(currentAngle - lastAngle);
            lastPointInLine = false;
            // numbers relative to other potential line points.
            if (subpixelDiff + angleDiff < bestSalience) {
                // record the values of the new most salient pixel
                salientPoint = new Point(gradientRA);
                salientnx = nx;
                salientny = ny;
                salientpx = px;
                salientpy = py;
                bestSalience = subpixelDiff + angleDiff;
            }
            // set the values to zero so that they are not added to another line.
            gradientRA.get().set(0);
        }
        // reset our randomAccess for the next check
        gradientRA.setPosition(currentPos);
    }
    // set the current pixel to 0 in the first slice of eigenRA!
    gradientRA.get().setReal(0);
    // find the next line point as long as there is one to find
    if (!lastPointInLine) {
        // take the most salient point
        gradientRA.setPosition(salientPoint);
        points.add(RidgeDetectionUtils.get2DRealPoint(gradientRA.getDoublePosition(0) + salientpx, gradientRA.getDoublePosition(1) + salientpy));
        // the gradient vector itself refers to the greatest change in intensity,
        // and for a pixel on a line this vector will be perpendicular to the
        // direction of the line. But this vector can point to either the left or
        // the right of the line from the perspective of the detector, and there
        // is no guarantee that the vectors at line point will point off the same
        // side of the line. So if they point off different sides, set the current
        // vector by 180 degrees for the purposes of this detector. We set the
        // threshold for angle fixing just above 90 degrees since any lower would
        // prevent ridges curving.
        double potentialGradient = RidgeDetectionUtils.getAngle(salientnx, salientny);
        // even though they are close enough to satisfy.
        if (lastAngle < angleThreshold)
            lastAngle += 360;
        if (potentialGradient < angleThreshold)
            potentialGradient += 360;
        if (Math.abs(potentialGradient - lastAngle) > angleThreshold) {
            salientnx = -salientnx;
            salientny = -salientny;
        }
        // perform the operation again on the new end of the line being formed.
        getNextPoint(gradientRA, pRA, nRA, points, RidgeDetectionUtils.getOctant(salientnx, salientny), salientnx, salientny, salientpx, salientpy);
    }
}
Also used : RealPoint(net.imglib2.RealPoint) Point(net.imglib2.Point) RealPoint(net.imglib2.RealPoint) Point(net.imglib2.Point)

Aggregations

Point (net.imglib2.Point)8 Point (com.google.monitoring.v3.Point)4 HyperSphere (net.imglib2.algorithm.region.hypersphere.HyperSphere)4 FloatType (net.imglib2.type.numeric.real.FloatType)4 Metric (com.google.api.Metric)3 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)3 TimeInterval (com.google.monitoring.v3.TimeInterval)3 TimeSeries (com.google.monitoring.v3.TimeSeries)3 TypedValue (com.google.monitoring.v3.TypedValue)3 ArrayList (java.util.ArrayList)3 MonitoredResource (com.google.api.MonitoredResource)2 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)2 ProjectName (com.google.monitoring.v3.ProjectName)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Interval (net.imglib2.Interval)2 Collections2 (com.google.common.collect.Collections2)1