コード例 #1
0
ファイル: GraphCycle.java プロジェクト: eyce9000/strontium
 /**
  * Orders the stroke list such that connected strokes are in order of consistency (not time)
  *
  * @param list stroke list
  * @return re-ordered stroke list
  */
 private List<Stroke> orderStrokes(List<Stroke> list) {
   if (list.size() < 3) {
     Collections.sort(list);
     return list;
   }
   List<Stroke> orderedList = new ArrayList<Stroke>();
   orderedList.add(list.get(0));
   list.remove(0);
   while (list.size() > 0) {
     Point curr = orderedList.get(orderedList.size() - 1).getLastPoint();
     Point curr2 = orderedList.get(orderedList.size() - 1).getFirstPoint();
     double closest = Double.MAX_VALUE;
     Stroke closestStr = null;
     for (Stroke s : list) {
       double dist1 = curr.distance(s.getFirstPoint());
       double dist2 = curr.distance(s.getLastPoint());
       double dist3 = curr2.distance(s.getFirstPoint());
       double dist4 = curr2.distance(s.getLastPoint());
       if (dist1 < closest) {
         closest = dist1;
         closestStr = s;
       }
       if (dist2 < closest) {
         closest = dist2;
         closestStr = s;
       }
       if (dist3 < closest) {
         closest = dist3;
         closestStr = s;
       }
       if (dist4 < closest) {
         closest = dist4;
         closestStr = s;
       }
     }
     orderedList.add(closestStr);
     list.remove(closestStr);
   }
   return orderedList;
 }
コード例 #2
0
ファイル: VSegmenter.java プロジェクト: eyce9000/strontium
  /**
   * Perform segmentation
   *
   * @return segmentation interpretation
   */
  private Segmentation doSegmentation() {
    Segmentation seg = new Segmentation();
    ArrayList<Stroke> substrokes = new ArrayList<Stroke>();
    Stroke s1 = new Stroke();
    Stroke s2 = new Stroke();
    for (int i = 0; i < m_features.getNumOrigPoints(); i++) {
      if ((double) i / m_features.getNumOrigPoints() >= 0.5)
        s2.addPoint(m_features.getOrigPoints().get(i));
      else s1.addPoint(m_features.getOrigPoints().get(i));
    }
    substrokes.add(s1);
    substrokes.add(s2);

    // Set the parent
    for (Stroke substroke : substrokes) {
      substroke.setParent(m_features.getOrigStroke());
    }

    seg.setSegmentedStrokes(substrokes);
    seg.setSegmenterName(S_SEGMENTER_NAME);
    return seg;
  }