@Override public void run(){
  amIActive=true;
  String inputHeader=null;
  String outputHeader=null;
  WhiteboxRaster image;
  WhiteboxRaster output;
  int cols, rows;
  int progress=0;
  int col, row;
  int i;
  int numSamplePoints=0;
  if (args.length <= 0) {
    showFeedback("Plugin parameters have not been set.");
    return;
  }
  inputHeader=args[0];
  outputHeader=args[1];
  numSamplePoints=Integer.parseInt(args[2]);
  if ((inputHeader == null) || (outputHeader == null)) {
    showFeedback("One or more of the input parameters have not been set properly.");
    return;
  }
  try {
    image=new WhiteboxRaster(inputHeader,"r");
    rows=image.getNumberRows();
    cols=image.getNumberColumns();
    if (rows * cols < numSamplePoints) {
      showFeedback("The number of samples cannot exceed the number of cells.");
      return;
    }
    output=new WhiteboxRaster(outputHeader,"rw",inputHeader,WhiteboxRaster.DataType.FLOAT,0);
    output.setPreferredPalette("qual.pal");
    output.setDataScale(WhiteboxRaster.DataScale.CATEGORICAL);
    image.close();
    NonDuplicatingPriorityQueue queue=new NonDuplicatingPriorityQueue(numSamplePoints);
    Random generator=new Random();
    GridCell gc;
    i=0;
    do {
      row=generator.nextInt(rows);
      col=generator.nextInt(cols);
      gc=new GridCell(row,col);
      if (queue.add(gc)) {
        i++;
        progress=(int)(100f * i / numSamplePoints);
        updateProgress("Loop 1 of 2:",progress);
      }
    }
 while (i < numSamplePoints);
    Iterator<GridCell> it=queue.iterator();
    i=1;
    do {
      gc=queue.poll();
      output.setValue(gc.row,gc.col,i);
      i++;
      progress=(int)(100f * i / numSamplePoints);
      updateProgress("Loop 2 of 2:",progress);
    }
 while (i < numSamplePoints);
    output.addMetadataEntry("Created by the " + getDescriptiveName() + " tool.");
    output.addMetadataEntry("Created on " + new Date());
    output.close();
    returnData(outputHeader);
  }
 catch (  OutOfMemoryError oe) {
    myHost.showFeedback("An out-of-memory error has occurred during operation.");
  }
catch (  Exception e) {
    myHost.showFeedback("An error has occurred during operation. See log file for details.");
    myHost.logException("Error in " + getDescriptiveName(),e);
  }
 finally {
    updateProgress("Progress: ",0);
    amIActive=false;
    myHost.pluginComplete();
  }
}

@ Override public void run ( ) { amIActive = true ; String inputHeader = null ; String outputHeader = null ; WhiteboxRaster image ; WhiteboxRaster output ; int cols , rows ; int progress = 0 ; int col , row ; int i ; int numSamplePoints = 0 ; if ( args . length <= 0 ) { showFeedback ( "Plugin parameters have not been set." ) ; return ; } inputHeader = args [ 0 ] ; outputHeader = args [ 1 ] ; numSamplePoints = Integer . parseInt ( args [ 2 ] ) ; if ( ( inputHeader == null ) || ( outputHeader == null ) ) { showFeedback ( "One or more of the input parameters have not been set properly." ) ; return ; } try { image = new WhiteboxRaster ( inputHeader , "r" ) ; rows = image . getNumberRows ( ) ; cols = image . getNumberColumns ( ) ; if ( rows * cols < numSamplePoints ) { showFeedback ( "The number of samples cannot exceed the number of cells." ) ; return ; } output = new WhiteboxRaster ( outputHeader , "rw" , inputHeader , WhiteboxRaster . DataType . FLOAT , 0 ) ; output . setPreferredPalette ( "qual.pal" ) ; output . setDataScale ( WhiteboxRaster . DataScale . CATEGORICAL ) ; image . close ( ) ; NonDuplicatingPriorityQueue queue = new NonDuplicatingPriorityQueue ( numSamplePoints ) ; Random generator = new Random ( ) ; GridCell gc ; i = 0 ; do { row = generator . nextInt ( rows ) ; col = generator . nextInt ( cols ) ; gc = new GridCell ( row , col ) ; if ( queue . add ( gc ) ) { i ++ ; progress = ( int ) ( 100f * i / numSamplePoints ) ; updateProgress ( "Loop 1 of 2:" , progress ) ; } } while ( i < numSamplePoints ) ; Iterator < GridCell > it = queue . iterator ( ) ; i = 1 ; do { gc = queue . poll ( ) ; output . setValue ( gc . row , gc . col , i ) ; i ++ ; progress = ( int ) ( 100f * i / numSamplePoints ) ; updateProgress ( "Loop 2 of 2:" , progress ) ; } while ( i < numSamplePoints ) ; output . addMetadataEntry ( "Created by the " + getDescriptiveName ( ) + " tool." ) ; output . addMetadataEntry ( "Created on " + new Date ( ) ) ; output . close ( ) ; returnData ( outputHeader ) ; } catch ( OutOfMemoryError oe ) { myHost . showFeedback ( "An out-of-memory error has occurred during operation." ) ; } catch ( Exception e ) { myHost . showFeedback ( "An error has occurred during operation. See log file for details." ) ; myHost . logException ( "Error in " + getDescriptiveName ( ) , e ) ; } finally { updateProgress ( "Progress: " , 0 ) ; amIActive = false ; myHost . pluginComplete ( ) ; } }
used to execute this plugin tool .
