]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/compress/DuplicatePointAlgorithm.java
Version 11, August 2010
[GpsPrune.git] / tim / prune / function / compress / DuplicatePointAlgorithm.java
1 package tim.prune.function.compress;
2
3 import java.awt.Component;
4 import java.awt.event.ActionListener;
5
6 import tim.prune.data.DataPoint;
7 import tim.prune.data.Track;
8
9 /**
10  * Algorithm for detecting duplicate points to compress
11  */
12 public class DuplicatePointAlgorithm extends CompressionAlgorithm
13 {
14         /** Number of points before this one to consider as duplicates */
15         private static final int NUM_POINTS_TO_BACKTRACK = 20;
16
17         /**
18          * Constructor
19          * @param inTrack track object
20          * @param inDetails track details object
21          * @param inListener listener to attach to activation control
22          */
23         public DuplicatePointAlgorithm(Track inTrack, TrackDetails inDetails, ActionListener inListener)
24         {
25                 super(inTrack, inDetails, inListener);
26         }
27
28         /**
29          * Perform the compression and work out which points should be deleted
30          * @param inFlags deletion flags from previous algorithms
31          * @return number of points deleted
32          */
33         protected int compress(boolean[] inFlags)
34         {
35                 int numPoints = _track.getNumPoints();
36                 int numDeleted = 0;
37                 // Loop over all points looking for duplicates
38                 for (int i=1; i<numPoints; i++)
39                 {
40                         // Don't delete points which are already marked as deleted
41                         if (!inFlags[i])
42                         {
43                                 DataPoint currPoint = _track.getPoint(i);
44                                 // Don't delete any photo points
45                                 if (currPoint.getPhoto() == null)
46                                 {
47                                         // loop over last few points before this one
48                                         for (int j=i-NUM_POINTS_TO_BACKTRACK; j<i; j++)
49                                         {
50                                                 if (j<0) {j=0;} // only look at last few points, but not before 0
51                                                 if (!inFlags[j] && currPoint.isDuplicate(_track.getPoint(j)))
52                                                 {
53                                                         inFlags[i] = true;
54                                                         numDeleted++;
55                                                         break;
56                                                 }
57                                         }
58                                 }
59                         }
60                 }
61                 return numDeleted;
62         }
63
64
65         /**
66          * @return specific gui components for dialog
67          */
68         protected Component getSpecificGuiComponents()
69         {
70                 // no parameters to set, so no gui components
71                 return null;
72         }
73
74         /**
75          * @return title key for box
76          */
77         protected String getTitleTextKey()
78         {
79                 return "dialog.compress.duplicates.title";
80         }
81
82 }