Changeset 6949 in osm


Ignore:
Timestamp:
2008-02-22T09:49:07+01:00 (17 years ago)
Author:
jrreid
Message:

Update lakewalker to use new preference value, switch shortcut to fire java based tracer, handle cases when no, or only a single node, are found

Location:
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/Lakewalker.java

    r6923 r6949  
    223223        public ArrayList<double[]> duplicateNodeRemove(ArrayList<double[]> nodes){
    224224               
     225                if(nodes.size() <= 1){
     226                        return nodes;
     227                }
     228               
    225229                double lastnode[] = new double[] {nodes.get(0)[0], nodes.get(0)[1]};
    226230               
     
    251255               
    252256                // Check if node list is empty
    253                 if(nodes.size()==0){
     257                if(nodes.size()<=1){
    254258                        return nodes;
    255259                }
     
    286290        }
    287291       
     292        public ArrayList<double[]> douglasPeuckerNR(ArrayList<double[]> nodes, double epsilon){
     293                /*
     294                command_stack = [(0, len(nodes) - 1)]
     295                                 
     296                Vector result_stack = new Vector();
     297
     298        while(command_stack.size() > 0){
     299                cmd = command_stack.pop();
     300                if(type(cmd) == tuple){
     301                        (start, end) = cmd
     302                        (node, dist) = dp_findpoint(nodes, start, end)
     303                        if(dist > epsilon){
     304                                command_stack.append("+")
     305                                command_stack.append((start, node))
     306                                command_stack.append((node, end))
     307                        } else {
     308                                result_stack.append((start, end))
     309                        }
     310                } elseif(cmd == "+"){
     311                        first = result_stack.pop()
     312                        second = result_stack.pop()
     313                        if(first[-1] == second[0]){
     314                                result_stack.append(first + second[1:])
     315                                //print "Added %s and %s; result is %s" % (first, second, result_stack[-1])
     316                        }else {
     317                                error("ERROR: Cannot connect nodestrings!")
     318                                #print first
     319                                #print second
     320                                return;
     321                        }
     322                } else {
     323                        error("ERROR: Can't understand command \"%s\"" % (cmd,))
     324                        return
     325 
     326                if(len(result_stack) == 1){
     327                        return [nodes[x] for x in result_stack[0]];
     328                } else {
     329                        error("ERROR: Command stack is empty but result stack has %d nodes!" % len(result_stack));
     330                        return;
     331                }
     332                       
     333                farthest_node = None
     334                farthest_dist = 0
     335                first = nodes[0]
     336                last = nodes[-1]
     337             
     338                for(i in xrange(1, len(nodes) - 1){
     339                        d = point_line_distance(nodes[i], first, last)
     340                        if(d > farthest_dist){
     341                                farthest_dist = d
     342                                farthest_node = i
     343                }
     344                }
     345                if(farthest_dist > epsilon){
     346                        seg_a = douglas_peucker(nodes[0:farthest_node+1], epsilon)
     347                        seg_b = douglas_peucker(nodes[farthest_node:-1], epsilon)
     348                        //print "Minimized %d nodes to %d + %d nodes" % (len(nodes), len(seg_a), len(seg_b))
     349                        nodes = seg_a[:-1] + seg_b
     350                } else {
     351                        return [nodes[0], nodes[-1]];
     352                }
     353                */
     354                return nodes;
     355        }
     356       
    288357        public ArrayList<double[]> douglasPeucker(ArrayList<double[]> nodes, double epsilon){
    289358               
    290359                // Check if node list is empty
    291                 if(nodes.size()==0){
     360                if(nodes.size()<=1){
    292361                        return nodes;
    293362                }
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java

    r6923 r6949  
    106106        final int waylen = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_MAX_SEG, "500"));
    107107        final int maxnode = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_MAX_NODES, "50000"));
    108         final int threshold = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_THRESHOLD, "35"));
     108        final int threshold = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_THRESHOLD_VALUE, "90"));
    109109        final double epsilon = Double.parseDouble(Main.pref.get(LakewalkerPreferences.PREF_EPSILON, "0.0003"));
    110110        final int resolution = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_LANDSAT_RES, "4000"));
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerActionOld.java

    r6910 r6949  
    4040 
    4141  public LakewalkerActionOld(String name) {
    42     super(name, "lakewalker-sml", tr("Lake Walker."), KeyEvent.VK_L, KeyEvent.CTRL_MASK
    43         | KeyEvent.SHIFT_MASK, true);
     42    super(name, "lakewalker-sml", tr("Lake Walker (Old)"), KeyEvent.VK_L, KeyEvent.ALT_MASK | KeyEvent.CTRL_MASK
     43        | KeyEvent.SHIFT_MASK, false);
    4444    this.name = name;
    4545    setEnabled(true);
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPlugin.java

    r6910 r6949  
    3636    if (toolsMenu == null) {
    3737      toolsMenu = new JMenu(name);
     38      toolsMenu.add(new JMenuItem(new LakewalkerActionOld(name2)));
    3839      toolsMenu.add(new JMenuItem(new LakewalkerAction(name)));
    3940      Main.main.menu.add(toolsMenu, 2);
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPreferences.java

    r6874 r6949  
    2121  public static final String PREF_MAX_NODES = "lakewalker.max_nodes";
    2222  public static final String PREF_THRESHOLD = "lakewalker.threshold";
     23  public static final String PREF_THRESHOLD_VALUE = "lakewalker.thresholdvalue";
    2324  public static final String PREF_EPSILON = "lakewalker.epsilon";
    2425  public static final String PREF_LANDSAT_RES = "lakewalker.landsat_res";
     
    3738  protected JLabel maxNodesLabel = new JLabel(tr("Maximum number of nodes in initial trace"));
    3839  protected IntConfigurer thresholdConfig = new IntConfigurer();
    39   protected JLabel thresholdLabel = new JLabel(tr("Maximum gray value to count as water (0-255)"));
     40  protected JLabel thresholdLabel = new JLabel(tr("Maximum gray value to count as water (0-255) [For old script]"));
     41  protected IntConfigurer thresholdConfigNew = new IntConfigurer();
     42  protected JLabel thresholdLabelNew = new JLabel(tr("Maximum gray value to count as water (0-255)"));
    4043  protected DoubleConfigurer epsilonConfig = new DoubleConfigurer();
    4144  protected JLabel epsilonLabel = new JLabel(tr("Line simplification accuracy (degrees)"));
     
    6063    maxNodesConfig.setToolTipText(tr("Maximum number of nodes to generate before bailing out (before simplifying lines). Default 50000."));
    6164    thresholdConfig.setToolTipText(tr("Maximum gray value to accept as water (based on Landsat IR-1 data). Can be in the range 0-255. Default 35."));
     65    thresholdConfigNew.setToolTipText(tr("Maximum gray value to accept as water (based on Landsat IR-1 data). Can be in the range 0-255. Default 90."));
    6266    epsilonConfig.setToolTipText(tr("Accuracy of Douglas-Peucker line simplification, measured in degrees.<br>Lower values give more nodes, and more accurate lines. Default 0.0003."));
    6367    landsatResConfig.setToolTipText(tr("Resolution of Landsat tiles, measured in pixels per degree. Default 4000."));
     
    7781    maxNodesConfig.setValue(Main.pref.get(PREF_MAX_NODES, "50000"));
    7882    thresholdConfig.setValue(Main.pref.get(PREF_THRESHOLD, "35"));
     83    thresholdConfigNew.setValue(Main.pref.get(PREF_THRESHOLD_VALUE, "90"));   
    7984    epsilonConfig.setValue(Main.pref.get(PREF_EPSILON, "0.0003"));
    8085    landsatResConfig.setValue(Main.pref.get(PREF_LANDSAT_RES, "4000"));
     
    99104    prefPanel.add(thresholdLabel, labelConstraints);
    100105    prefPanel.add(thresholdConfig.getControls(), dataConstraints);
     106    prefPanel.add(thresholdLabelNew, labelConstraints);
     107    prefPanel.add(thresholdConfigNew.getControls(), dataConstraints);
    101108    prefPanel.add(epsilonLabel, labelConstraints);
    102109    prefPanel.add(epsilonConfig.getControls(), dataConstraints);
     
    125132    Main.pref.put(PREF_MAX_NODES, maxNodesConfig.getValueString());
    126133    Main.pref.put(PREF_THRESHOLD, thresholdConfig.getValueString());
     134    Main.pref.put(PREF_THRESHOLD_VALUE, thresholdConfigNew.getValueString());
    127135    Main.pref.put(PREF_EPSILON, epsilonConfig.getValueString());
    128136    Main.pref.put(PREF_LANDSAT_RES, landsatResConfig.getValueString());
Note: See TracChangeset for help on using the changeset viewer.