protected BallNode buildTreeMiddleOut(int startIdx,int endIdx) throws Exception {
  Instance pivot;
  double radius;
  Vector<TempNode> anchors;
  int numInsts=endIdx - startIdx + 1;
  int numAnchors=(int)Math.round(Math.sqrt(numInsts));
  if (numAnchors > 1) {
    pivot=BallNode.calcCentroidPivot(startIdx,endIdx,m_InstList,m_Instances);
    radius=BallNode.calcRadius(startIdx,endIdx,m_InstList,m_Instances,pivot,m_DistanceFunction);
    if (numInsts <= m_MaxInstancesInLeaf || (rootRadius == 0 ? true : radius / rootRadius < m_MaxRelLeafRadius)) {
      BallNode node=new BallNode(startIdx,endIdx,m_NumNodes,pivot,radius);
      return node;
    }
    anchors=new Vector<TempNode>(numAnchors);
    createAnchorsHierarchy(anchors,numAnchors,startIdx,endIdx);
    BallNode node=mergeNodes(anchors,startIdx,endIdx);
    buildLeavesMiddleOut(node);
    return node;
  }
 else {
    BallNode node=new BallNode(startIdx,endIdx,m_NumNodes,(pivot=BallNode.calcCentroidPivot(startIdx,endIdx,m_InstList,m_Instances)),BallNode.calcRadius(startIdx,endIdx,m_InstList,m_Instances,pivot,m_DistanceFunction));
    return node;
  }
}

protected BallNode buildTreeMiddleOut ( int startIdx , int endIdx ) throws Exception { Instance pivot ; double radius ; Vector < TempNode > anchors ; int numInsts = endIdx - startIdx + 1 ; int numAnchors = ( int ) Math . round ( Math . sqrt ( numInsts ) ) ; if ( numAnchors > 1 ) { pivot = BallNode . calcCentroidPivot ( startIdx , endIdx , m_InstList , m_Instances ) ; radius = BallNode . calcRadius ( startIdx , endIdx , m_InstList , m_Instances , pivot , m_DistanceFunction ) ; if ( numInsts <= m_MaxInstancesInLeaf || ( rootRadius == 0 ? true : radius / rootRadius < m_MaxRelLeafRadius ) ) { BallNode node = new BallNode ( startIdx , endIdx , m_NumNodes , pivot , radius ) ; return node ; } anchors = new Vector < TempNode > ( numAnchors ) ; createAnchorsHierarchy ( anchors , numAnchors , startIdx , endIdx ) ; BallNode node = mergeNodes ( anchors , startIdx , endIdx ) ; buildLeavesMiddleOut ( node ) ; return node ; } else { BallNode node = new BallNode ( startIdx , endIdx , m_NumNodes , ( pivot = BallNode . calcCentroidPivot ( startIdx , endIdx , m_InstList , m_Instances ) ) , BallNode . calcRadius ( startIdx , endIdx , m_InstList , m_Instances , pivot , m_DistanceFunction ) ) ; return node ; } }
builds a ball tree middle out from the portion of the master index array given by supplied start and end index .
