public void reset() { id = -1; externalIndex = -1; internalIndexes.reset(); }
public void init( int segment ) { this.segment = segment; edges.reset(); }
synchronized public void clearCloud() { cloudXyz.reset(); cloudColor.reset(); }
/** * Very fast histogram based sorting. Index of each pixel is placed inside a list for its intensity level. */ protected void sortPixels(GrayU8 input) { // initialize histogram for( int i = 0; i < histogram.length; i++ ) { histogram[i].reset(); } // sort by creating a histogram for( int y = 0; y < input.height; y++ ) { int index = input.startIndex + y*input.stride; int indexOut = (y+1)*output.stride + 1; for (int x = 0; x < input.width; x++ , index++ , indexOut++) { int value = input.data[index] & 0xFF; histogram[value].add(indexOut); } } }
/** * Does much of the work needed to remove the redundant segments that are being merged into their root node. * The list of member count is updated. mergeList is updated with the new segment IDs. */ protected void setToRootNodeNewID( GrowQueue_I32 regionMemberCount ) { tmpMemberCount.reset(); for( int i = 0; i < mergeList.size; i++ ) { int p = mergeList.data[i]; if( p == i ) { mergeList.data[i] = rootID.data[i]; tmpMemberCount.add( regionMemberCount.data[i] ); } else { mergeList.data[i] = rootID.data[mergeList.data[i]]; } } regionMemberCount.reset(); regionMemberCount.addAll(tmpMemberCount); }
/** * Converts the list of shapes into the output format */ private void convertIntoOuput(List<FoundShape> schnabelShapes) { output.reset(); for (int i = 0; i < schnabelShapes.size(); i++) { FoundShape fs = schnabelShapes.get(i); Shape os = output.grow(); os.parameters = fs.modelParam; os.type = shapeList.get(fs.whichShape); os.points.clear(); os.indexes.reset(); // add the points to it for (int j = 0; j < fs.points.size(); j++) { PointVectorNN pv = fs.points.get(j); os.points.add(pv.p); os.indexes.add(pv.index); } } }
/** * Splits a line in two if there is a point that is too far away * @return true for change */ protected boolean splitSegments() { boolean change = false; work.reset(); for( int i = 0; i < splits.size-1; i++ ) { change |= checkSplit(change, i,i+1); } change |= checkSplit(change, splits.size - 1, 0); // swap the two lists GrowQueue_I32 tmp = work; work = splits; splits = tmp; return change; }
private void addShapeToOutput(List<PointVectorNN> inliers) { ModelFitter<Object, PointVectorNN> fitter = fitters.get(ransac.getModelIndex()); Object shapeParam = models.get(ransac.getModelIndex()); fitter.fitModel(inliers, ransac.getModelParameters(), shapeParam); // convert the results into output format Shape os = output.grow(); os.parameters = modelManagers.get(ransac.getModelIndex()).createModelInstance(); modelManagers.get(ransac.getModelIndex()).copyModel(shapeParam,os.parameters); os.type = shapeList.get(ransac.getModelIndex()); os.points.clear(); os.indexes.reset(); // add the points to it for (int j = 0; j < inliers.size(); j++) { PointVectorNN pv = inliers.get(j); os.points.add(pv.p); os.indexes.add(pv.index); } }
public GrowQueue_I32 checkSource( FastQueue<AssociatedIndex> matches , int num ) { matched.resize(num); for( int i = 0; i < matched.size; i++ ) { matched.data[i] = 0; } for( int i = 0; i < matches.size; i++ ) { matched.data[matches.get(i).src] = 1; } unassociatedSrc.reset(); for( int i = 0; i < matched.size; i++ ) { if( matched.data[i] == 0 ) { unassociatedSrc.add(i); } } return unassociatedSrc; }
public GrowQueue_I32 checkDestination( FastQueue<AssociatedIndex> matches , int num ) { matched.resize(num); for( int i = 0; i < matched.size; i++ ) { matched.data[i] = 0; } for( int i = 0; i < matches.size; i++ ) { matched.data[matches.get(i).dst] = 1; } unassociatedDst.reset(); for( int i = 0; i < matched.size; i++ ) { if( matched.data[i] == 0 ) { unassociatedDst.add(i); } } return unassociatedDst; } }
@Override public boolean process(List<Point2D_I32> list) { splits.reset(); this.contour = list; if( list.size() <= 2 ) { // can't do anything with two or less points return false; } this.minimumSideLengthPixel = (int)Math.ceil(contour.size()* minimumSideLengthFraction); // initial segmentation splits.add(0); splitPixels(0, list.size() - 1); splits.add(list.size()-1); for( int i = 0; i < maxIterations; i++ ) { boolean changed = mergeSegments(); if( !changed && !splitSegments() ) break; if( splits.size() <= 2 || splits.size() >= abortSplits ) break; } return true; }
/** * Recycles and initializes all internal data structures */ private void init(List<EllipseRotated_F64> ellipses) { searchPoints.resize(ellipses.size()); nodes.resize(ellipses.size()); clusters.reset(); for (int i = 0; i < ellipses.size(); i++) { EllipseRotated_F64 e = ellipses.get(i); double[] p = searchPoints.get(i); p[0] = e.center.x; p[1] = e.center.y; Node n = nodes.get(i); n.connections.reset(); n.which = i; n.cluster = -1; } search.setPoints(searchPoints.toList(),nodes.toList()); }
private void findBestPoints(int x, int y, List<Point2D_F64> pts , List<Integer> selected ) { double bestDist = clickDistance*clickDistance; GrowQueue_I32 bestIndexes = new GrowQueue_I32(20); for( int i = 0; i < pts.size(); i++ ) { if( !isValidPoint(i) ) continue; Point2D_F64 p = pts.get(i); double d = UtilPoint2D_F64.distanceSq(p.x, p.y, x, y); if( d < bestDist ) { bestDist = d; bestIndexes.reset(); bestIndexes.add(i); } else if( Math.abs(d - bestDist) < 0.01 ) { bestIndexes.add(i); } } if( bestIndexes.size() > 0 ) { int indexRight = bestIndexes.get(0); } for (int i = 0; i < bestIndexes.size(); i++) { selected.add(bestIndexes.get(i)); } }
@Override public void findNearest(P point, double maxDistance, int numNeighbors, FastQueue<NnData<P>> results) { results.reset(); if( maxDistance < 0 ) maxDistance = Double.MAX_VALUE; outputIndex.reset(); outputDistance.reset(); alg.findClosestN(point,maxDistance,numNeighbors,outputIndex,outputDistance); for( int i = 0; i < outputIndex.size; i++ ) { int index = outputIndex.get(i); NnData<P> r = results.grow(); r.distance = outputDistance.get(i); r.point = points.get(index); r.index = index; } } }
@Override public void associate() { if( listSrc == null ) throw new IllegalArgumentException("source features not specified"); if( listDst == null ) throw new IllegalArgumentException("destination features not specified"); unassocSrc.reset(); alg.associate(listSrc,listDst); int pairs[] = alg.getPairs(); double score[] = alg.getFitQuality(); matches.reset(); for( int i = 0; i < listSrc.size; i++ ) { int dst = pairs[i]; if( dst >= 0 ) matches.grow().setAssociation(i,dst,score[i]); else unassocSrc.add(i); } }
@Override public void findNearest(P point, double maxDistance, int numNeighbors, FastQueue<NnData<P>> results) { results.reset(); if( maxDistance < 0 ) maxDistance = Double.MAX_VALUE; outputIndex.reset(); outputDistance.reset(); alg.findClosestN(point,maxDistance,numNeighbors,outputIndex,outputDistance); for( int i = 0; i < outputIndex.size; i++ ) { int index = outputIndex.get(i); NnData<P> r = results.grow(); r.distance = outputDistance.get(i); r.point = points.get(index); r.index = index; } } }
/** * Given the disparity image compute the 3D location of valid points and save pixel colors * at that point * * @param disparity Disparity image * @param color Color image of left camera */ public void process(ImageGray disparity , BufferedImage color ) { cloudRgb.setMaxSize(disparity.width*disparity.height); cloudXyz.setMaxSize(disparity.width*disparity.height*3); cloudRgb.reset(); cloudXyz.reset(); if( disparity instanceof GrayU8) process((GrayU8)disparity,color); else process((GrayF32)disparity,color); }
@Test public void reset() { GrowQueue_I32 alg = new GrowQueue_I32(10); alg.push(1); alg.push(3); alg.push(-2); assertTrue(1.0 == alg.get(0)); assertEquals(3,alg.size); alg.reset(); assertEquals(0,alg.size); }
/** * Make sure it works after multiple calls */ @Test public void findClosestN_multiple_calls() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4 , 4,5, 6,7 , 8,9 ); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{4.1, 4.9}, 10, 3, outputIndex, outputDistance); outputIndex.reset(); outputDistance.reset(); alg.findClosestN(new double[]{4.1, 4.9}, 10, 3, outputIndex, outputDistance); assertEquals(3,outputIndex.size); assertEquals(3,outputDistance.size); checkContains(1,outputIndex); checkContains(2,outputIndex); checkContains(3,outputIndex); }