Class Ransac<Model,Point> 
java.lang.Object
org.ddogleg.fitting.modelset.ransac.Ransac<Model,Point> 
- All Implemented Interfaces:
 InlierThreshold,ModelMatcher<Model,,Point> ModelMatcherPost<Model,Point> 
- Direct Known Subclasses:
 Ransac_MT
public class Ransac<Model,Point> 
extends Object
implements ModelMatcherPost<Model,Point>, InlierThreshold 
RANSAC is an abbreviation for "RANdom SAmple Consensus" and is an iterative algorithm. The model with the largest set of inliers is found by randomly sampling the set of points and fitting a model. The algorithm terminates when the maximum number of iterations has been reached. An inlier is defined as a point which has an error less than a user specified threshold to the estimated model being considered. The algorithm was first published by Fischler and Bolles in 1981."
Sample Points: By default the minimum number of points are sampled. The user to override this default and set it to any number.
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceprotected class - 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Ransac<Model,Point>.@Nullable TrialHelper protected @Nullable Ransac.InitializeModels<Model,Point> Optional function for initializing generator and distance functionsprotected ModelManager<Model>protected intprotected longprotected intprotected double - 
Constructor Summary
ConstructorsConstructorDescriptionRansac(long randSeed, int maxIterations, double thresholdFit, ModelManager<Model> modelManager, Class<Point> pointType) Creates a new instance of the ransac algorithm. - 
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidaddSelect(DogArray_I32 indexes, int numSample, List<T> dataSet, List<T> initialSample) Adds the selected elements to the initialSample list and undoes the shuffling.protected voidIf the maximum number of iterations has changed then re-generate the RNG for each trialdoubleReturns the metric used to evaluate the quality of fit.intgetInputIndex(int matchIndex) For an item in the match set, return the index of the item in the original input set.A set of points which match the provided parameters.intintThis is the minimum number of observations which can be input and produce a valid model.Model for the match setReturns a class for the input point objectReturns a class for the input point objectdoubleReturns the inlier thresholdbooleanFinds a set of points from the provided list that are a good fit for the internal model and computes the fit parameters for the model.static <T> voidrandomDraw(List<T> dataSet, int numSample, List<T> initialSample, Random rand) Performs a random draw in the dataSet.static voidrandomDraw(DogArray_I32 indexes, int size, int numSample, Random rand) Randomly selects a set of points in indexes.voidreset()Resets the model matcher to its original state.voidsetMaxIterations(int maxIterations) voidsetModel(Factory<ModelGenerator<Model, Point>> factoryGenerator, Factory<DistanceFromModel<Model, Point>> factoryDistance) Specifies the internal model.voidsetSampleSize(int sampleSize) Override the number of points that are sampled and used to generate models.voidsetThresholdFit(double thresholdFit) Specifies the "fit" criteria for inlier set as being equal to or less than this 
- 
Field Details
- 
sampleSize
protected int sampleSize - 
thresholdFit
protected double thresholdFit - 
masterModelManager
 - 
randSeed
protected long randSeed - 
trialRNG
 - 
maxIterations
protected int maxIterations - 
helper
 - 
initializeModels
Optional function for initializing generator and distance functions 
 - 
 - 
Constructor Details
- 
Ransac
public Ransac(long randSeed, int maxIterations, double thresholdFit, ModelManager<Model> modelManager, Class<Point> pointType) Creates a new instance of the ransac algorithm. The number of points sampled will default to the minimum number. To override this default invokesetSampleSize(int).- Parameters:
 randSeed- The random seed used by the random number generator.maxIterations- The maximum number of iterations the RANSAC algorithm will perform.thresholdFit- How close of a fit a points needs to be to the model to be considered a fit.
 
 - 
 - 
Method Details
- 
process
Description copied from interface:ModelMatcherFinds a set of points from the provided list that are a good fit for the internal model and computes the fit parameters for the model.- Specified by:
 processin interfaceModelMatcher<Model,Point> - Parameters:
 dataSet- Set of points (with noise) that are to be fit.- Returns:
 - true if it successfully found a solution or false if not.
 
 - 
setModel
public void setModel(Factory<ModelGenerator<Model, Point>> factoryGenerator, Factory<DistanceFromModel<Model, Point>> factoryDistance) Description copied from interface:ModelMatcherPostSpecifies the internal model. Factories are provided since each thread might need its own unique instance of the generator and distance function if they are not thread safe.- Specified by:
 setModelin interfaceModelMatcherPost<Model,Point> - Parameters:
 factoryGenerator-ModelGeneratorfactoryDistance-DistanceFromModel
 - 
checkTrialGenerators
protected void checkTrialGenerators()If the maximum number of iterations has changed then re-generate the RNG for each trial - 
randomDraw
public static <T> void randomDraw(List<T> dataSet, int numSample, List<T> initialSample, Random rand) Performs a random draw in the dataSet. When an element is selected it is moved to the end of the list so that it can't be selected again.- Parameters:
 dataSet- List that points are to be selected from. Modified.
 - 
randomDraw
Randomly selects a set of points in indexes. The selects points are put at the end of the array - 
addSelect
public static <T> void addSelect(DogArray_I32 indexes, int numSample, List<T> dataSet, List<T> initialSample) Adds the selected elements to the initialSample list and undoes the shuffling. There is probably a slightly more elegant way to do this... - 
getMatchSet
Description copied from interface:ModelMatcherA set of points which match the provided parameters.- Specified by:
 getMatchSetin interfaceModelMatcher<Model,Point> - Returns:
 - List of points in the match set.
 
 - 
getInputIndex
public int getInputIndex(int matchIndex) Description copied from interface:ModelMatcherFor an item in the match set, return the index of the item in the original input set.- Specified by:
 getInputIndexin interfaceModelMatcher<Model,Point> - Parameters:
 matchIndex- Index of an element in the match set.- Returns:
 - Index of the same element in the original input list.
 
 - 
getModelParameters
Description copied from interface:ModelMatcherModel for the match set- Specified by:
 getModelParametersin interfaceModelMatcher<Model,Point> - Returns:
 - model.
 
 - 
getFitQuality
public double getFitQuality()Description copied from interface:ModelMatcherReturns the metric used to evaluate the quality of fit. Meaning is implementation specific. Larger or smaller values could be preferred depending on implementation..- Specified by:
 getFitQualityin interfaceModelMatcher<Model,Point> - Returns:
 - Quality of fit to matched set of points
 
 - 
getMaxIterations
public int getMaxIterations() - 
setMaxIterations
public void setMaxIterations(int maxIterations)  - 
getMinimumSize
public int getMinimumSize()Description copied from interface:ModelMatcherThis is the minimum number of observations which can be input and produce a valid model.- Specified by:
 getMinimumSizein interfaceModelMatcher<Model,Point> - Returns:
 - Minimum number of sample points
 
 - 
reset
public void reset()Description copied from interface:ModelMatcherResets the model matcher to its original state. This means that given identical inputs it would produce the same outputs- Specified by:
 resetin interfaceModelMatcher<Model,Point> 
 - 
setSampleSize
public void setSampleSize(int sampleSize) Override the number of points that are sampled and used to generate models. If this value is not set it defaults to the minimum number.- Parameters:
 sampleSize- Number of sample points.
 - 
getThresholdFit
public double getThresholdFit()Description copied from interface:InlierThresholdReturns the inlier threshold- Specified by:
 getThresholdFitin interfaceInlierThreshold
 - 
setThresholdFit
public void setThresholdFit(double thresholdFit) Description copied from interface:InlierThresholdSpecifies the "fit" criteria for inlier set as being equal to or less than this- Specified by:
 setThresholdFitin interfaceInlierThreshold- Parameters:
 thresholdFit- inlier threshold
 - 
getPointType
Description copied from interface:ModelMatcherReturns a class for the input point object- Specified by:
 getPointTypein interfaceModelMatcher<Model,Point> 
 - 
getModelType
Description copied from interface:ModelMatcherReturns a class for the input point object- Specified by:
 getModelTypein interfaceModelMatcher<Model,Point> 
 
 -