Example #1
0
PRIVATE void stack_adjust_zpos(const Stack *stack, int x, int y, int *z)
{
    int old_z = *z;
    int new_z = *z;
    double value[5];
    double points[15];
    int i;
    for (i = 0; i <= 5; i++) {
        points[i*3] = x;
        points[i*3+1] = y;
        points[i*3+2] = *z + i - 2;
    }

    do {
        old_z = new_z;
        Stack_Points_Sampling(stack, points, 5, value);
        if (!(isnan(value[0]) || isnan(value[1]) || isnan(value[2]) ||
                isnan(value[3]) || isnan(value[4]))) {
            if ((dmax2(value[0], value[1]) < value[2]) && (value[2] < dmin2(value[3],
                    value[4]))) {
                new_z++;
            } else if ((dmin2(value[0], value[1]) > value[2]) &&
                       (value[2] > dmax2(value[3], value[4]))) {
                new_z--;
            }
        }

        if (new_z == old_z) {
            double w = 0.0;
            double zw = 0.0;
            for (i = 0; i < 5; i++) {
                if (!isnan(value[i])) {
                    w += value[i];
                    zw += value[i] * points[3*i+2];
                }
            }

            if (w == 0.0) {
                break;
            } else {
                new_z = iround(zw / w);
            }
        }

        for (i = 0; i < 5; i++) {
            points[i*3+2] += new_z - old_z;
        }
    } while (old_z != new_z);

    *z = new_z;
}
Example #2
0
int main(int argc, char *argv[])
{
  Stack *stack = Make_Stack(GREY, 3, 3, 3);
  int i;
  for (i = 0; i < Stack_Voxel_Number(stack); i++) {
    stack->array[i] = i;
  }
  Print_Stack(stack);

  
  printf("%g\n", Stack_Point_Sampling(stack, 1.1, 1.5, 1.0));
  printf("%g\n", Stack_Point_Sampling(stack, 1.1, 1.0, 1.5));
  printf("%g\n", Stack_Point_Sampling(stack, 1.1, 1.0, 1.0));
  printf("%g\n", Stack_Point_Sampling(stack, 1.0, 1.5, 1.3));
  printf("%g\n", Stack_Point_Sampling(stack, 1.0, 1.5, 1.0));
  printf("%g\n", Stack_Point_Sampling(stack, 1.0, 1.0, 1.3));
  printf("%g\n", Stack_Point_Sampling(stack, 1.0, 1.5, 1.0));

  DMatrix *dm;
  dim_type dim[3];
  dim[0] = 10;
  dim[1] = 4;
  dim[2] = 5;
  dm = Make_DMatrix(dim, 3);

  int j, k;
  int offset = 0;
  double x, y, z;

  dim[0] = matrix_size(dm->dim, dm->ndim);
  dim[1] = 3;
  DMatrix *points = Make_DMatrix(dim, 2);

  for (k = 0; k < dm->dim[2]; k++) {
    z = (double) (k ) * (stack->depth - 1) / (dm->dim[2] - 1);
    for (j = 0; j < dm->dim[1]; j++) {
      y = (double) (j ) * (stack->height - 1) / (dm->dim[1] - 1);
      for (i = 0; i < dm->dim[0]; i++) {
	x = (double) (i ) * (stack->width - 1) / (dm->dim[0] - 1);
	points->array[offset++] = x;
	points->array[offset++] = y;
	points->array[offset++] = z;
      }
    }
  }

  tic();
  for (j = 0; j < 100; j++) {
    Stack_Points_Sampling(stack, points->array, points->dim[0], dm->array);
  }
  printf("%llu\n", toc());

  DMatrix_Print(dm);
  Kill_Stack(stack);
  
  stack = Scale_Double_Stack(dm->array, dm->dim[0], dm->dim[1], dm->dim[2],
			     GREY);
  Write_Stack("../data/test.tif", stack);

  Kill_Stack(stack);
  Kill_DMatrix(dm);
  Kill_DMatrix(points);

  return 0;
}