slm: OpenCL code base  0.1
lengths.cl
Go to the documentation of this file.
1 
14 
15 
16 #ifdef KERNEL_HILLSLOPE_LENGTHS
17 __kernel void hillslope_lengths(
38  __global const float2 *seed_point_array,
39  __global const bool *mask_array,
40  __global const float2 *uv_array,
41  __global const uint *mapping_array,
42  __global const uint *label_array,
43  __global float *traj_length_array
44  )
45 {
46  // For every non-thin-channel pixel
47 
48  const uint global_id = get_global_id(0u)+get_global_id(1u)*get_global_size(0u);
49  __private uint idx, hillslope_idx, n_steps=0u;
50  __private float dl=0.0f, dt=DT_MAX, l_trajectory=0.0f;
51  __private float2 uv1_vec, uv2_vec, dxy1_vec, dxy2_vec,
52  vec = seed_point_array[global_id], prev_vec, next_vec;
53 
54  // Remember here
55  idx = get_array_idx(vec);
56  hillslope_idx = idx;
57  // Integrate downstream until a channel pixel (or masked pixel) is reached
58  while (((~mapping_array[idx])&IS_THINCHANNEL) && !mask_array[idx]
59  && n_steps<(MAX_N_STEPS-1)) {
60  compute_step_vec(dt, uv_array, &dxy1_vec, &dxy2_vec, &uv1_vec, &uv2_vec,
61  vec, &next_vec, &idx);
62  if (lengths_runge_kutta_step(&dt, &dl, &l_trajectory, &dxy1_vec, &dxy2_vec,
63  &vec, &prev_vec, &next_vec, &n_steps, &idx)) {
64  break;
65  }
66  }
67  if (mapping_array[idx]&IS_THINCHANNEL) {
68  // We've reached a (thin) channel, so save this trajectory length
69  // No need for atomic here since we're writing to the source pixel
70  traj_length_array[global_id] = l_trajectory;
71  }
72  return;
73 }
74 #endif
#define DT_MAX
Definition: info.h:48
__kernel void hillslope_lengths(__global const float2 *seed_point_array, __global const bool *mask_array, __global const float2 *uv_array, __global const uint *mapping_array, __global const uint *label_array, __global float *traj_length_array)
TBD.
Definition: lengths.cl:37
static bool lengths_runge_kutta_step(float *dt, float *dl, float *l_trajectory, float2 *dxy1_vec, float2 *dxy2_vec, float2 *vec, float2 *prev_vec, float2 *next_vec, uint *n_steps, uint *idx)
Compute a single step of 2nd-order Runge-Kutta numerical integration of a streamline given precompute...
static void compute_step_vec(const float dt, const __global float2 *uv_array, float2 *dxy1_vec, float2 *dxy2_vec, float2 *uv1_vec, float2 *uv2_vec, const float2 vec, float2 *next_vec, uint *idx)
Compute a 2nd-order Runge-Kutta integration step along a streamline.
Definition: computestep.cl:41
static uint get_array_idx(float2 vec)
Compute the array index of the padded grid pixel pointed to by a float2 grid position vector (choice ...
Definition: essentials.cl:62
#define IS_THINCHANNEL
Definition: info.h:97
#define MAX_N_STEPS
Definition: info.h:49