Exemple #1
0
 /**
  * Get the {@code grid} as sample indices.
  *
  * @param s Sampling that this {@code grid} subsamples.
  * @param grid the subsample locations defined in terms of Sampling {@code s}.
  * @return the {@code grid} as sample indices.
  * @throws IllegalArgumentException if any of the grid locations are not valid with the given
  *     Sampling {@code s}.
  */
 public static int[] gridCoordsToSamples(Sampling s, float[] grid) {
   Almost a = new Almost();
   float f = (float) s.getFirst();
   float l = (float) s.getLast();
   int ng = grid.length;
   int[] t = new int[ng]; // temp sample indices
   int count = 0;
   int is = -1; // save last index
   for (int ig = 0; ig < ng; ig++) {
     float v = grid[ig];
     if (a.ge(v, f) && a.le(v, l)) {
       int i = s.indexOfNearest(v);
       if (i != is) { // no duplicate entries
         t[count] = i;
         count++;
       }
       is = i;
     } else {
       print("Error: value " + v + " is out of bounds! First=" + f + ", Last=" + l);
     }
   }
   if (count != ng) {
     print("Grid values:");
     dump(grid);
     throw new IllegalArgumentException(
         "Error: Only "
             + count
             + " of "
             + ng
             + " input grid coordinates are valid "
             + "with the specified sampling "
             + s.toString());
   }
   return copy(count, t);
 }
Exemple #2
0
 private static float[] getValues(Sampling s) {
   int n = s.getCount();
   double f = s.getFirst();
   double d = s.getDelta();
   float[] x = new float[n];
   for (int i = 0; i < n; i++) x[i] = (float) (f + i * d);
   return x;
 }