public static Plane detectPlane(List<Vector3> points,float distanceThresh,int numIterations,int sufficientSupport){
  int pointCount=points.size();
  boolean[] picked=new boolean[pointCount];
  List<Vector3> supportPointsMax=new LinkedList<>();
  int supportMax=0;
  while (numIterations > 0) {
    numIterations--;
    int[] randomPointIndices=new int[3];
    for (int i=0; i < 3; i++) {
      do {
        randomPointIndices[i]=(int)(Math.random() * pointCount);
      }
 while (picked[randomPointIndices[i]]);
      picked[randomPointIndices[i]]=true;
    }
    picked[randomPointIndices[0]]=false;
    picked[randomPointIndices[1]]=false;
    picked[randomPointIndices[2]]=false;
    Vector3 p0=points.get(randomPointIndices[0]);
    Vector3 p1=points.get(randomPointIndices[1]);
    Vector3 p2=points.get(randomPointIndices[2]);
    Plane plane=Plane.createHessePlane(p0,p1,p2);
    computeSupport(plane,points,distanceThresh);
    int support=supportingPoints.size();
    if (support > supportMax) {
      supportMax=support;
      supportPointsMax=supportingPoints;
    }
    if (supportMax >= sufficientSupport) {
      break;
    }
  }
  Plane plane=planeRegression(supportPointsMax);
  computeSupport(plane,points,distanceThresh);
  return (plane);
}

public static Plane detectPlane ( List < Vector3 > points , float distanceThresh , int numIterations , int sufficientSupport ) { int pointCount = points . size ( ) ; boolean [ ] picked = new boolean [ pointCount ] ; List < Vector3 > supportPointsMax = new LinkedList < > ( ) ; int supportMax = 0 ; while ( numIterations > 0 ) { numIterations -- ; int [ ] randomPointIndices = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { do { randomPointIndices [ i ] = ( int ) ( Math . random ( ) * pointCount ) ; } while ( picked [ randomPointIndices [ i ] ] ) ; picked [ randomPointIndices [ i ] ] = true ; } picked [ randomPointIndices [ 0 ] ] = false ; picked [ randomPointIndices [ 1 ] ] = false ; picked [ randomPointIndices [ 2 ] ] = false ; Vector3 p0 = points . get ( randomPointIndices [ 0 ] ) ; Vector3 p1 = points . get ( randomPointIndices [ 1 ] ) ; Vector3 p2 = points . get ( randomPointIndices [ 2 ] ) ; Plane plane = Plane . createHessePlane ( p0 , p1 , p2 ) ; computeSupport ( plane , points , distanceThresh ) ; int support = supportingPoints . size ( ) ; if ( support > supportMax ) { supportMax = support ; supportPointsMax = supportingPoints ; } if ( supportMax >= sufficientSupport ) { break ; } } Plane plane = planeRegression ( supportPointsMax ) ; computeSupport ( plane , points , distanceThresh ) ; return ( plane ) ; }
detects a plane inside a pointcloud
