15 #ifdef KERNEL_INTEGRATE_TRAJECTORY 50 float2 *dxy1_vec, float2 *dxy2_vec,
51 float2 *vec, float2 *prev_vec,
53 uint *n_steps, uint *idx, uint *prev_idx,
54 __global char2 *trajectory_vec)
56 const float step_error = fast_length((*dxy2_vec-*dxy1_vec)/
GRID_SCALE);
58 *dl = fast_length(*dxy2_vec);
60 *next_vec = *vec+*dxy1_vec;
61 *dl = fast_length(*dxy1_vec);
70 isequal(step_error,0.0f) );
79 #ifdef KERNEL_INTEGRATE_TRAJECTORY 104 float *l_trajectory,
const float2 uv_vec,
105 float2 *vec,
const float2 prev_vec,
106 uint *n_steps, __global char2 *trajectory_vec)
112 *dt = minmag(dt_x,dt_y);
113 *vec += sgnd_uv_vec*(*dt);
115 *vec = (float2)( fmin(fmax((*vec)[0],-0.5f),
X_MAX),
116 fmin(fmax((*vec)[1],-0.5f),
Y_MAX) );
117 *dl = fast_length(*vec-prev_vec);
122 #ifdef KERNEL_INTEGRATE_TRAJECTORY 163 float *dt,
float *dl,
float *l_trajectory,
164 float2 *dxy1_vec, float2 *dxy2_vec,
165 float2 *vec, float2 *prev_vec,
const float2 next_vec,
166 uint *n_steps, uint *idx, uint *prev_idx,
167 __global
const bool *mask_array,
168 __global uint *slt_array, __global uint *slc_array)
170 const float step_error = fast_length((*dxy2_vec-*dxy1_vec)/
GRID_SCALE);
172 *dl = fast_length(*dxy2_vec);
176 idx, prev_idx, mask_array, slt_array, slc_array);
180 isequal(step_error,0.0f) );
182 idx, prev_idx, mask_array, slt_array, slc_array);
188 #ifdef KERNEL_INTEGRATE_TRAJECTORY 221 const float2 uv_vec, float2 *vec,
222 const float2 prev_vec,
224 uint *idx, uint *prev_idx,
225 __global
const bool *mask_array,
226 __global uint *slt_array,
227 __global uint *slc_array)
229 __private float2 sgnd_uv_vec;
230 __private
float dt_x, dt_y;
235 *dt = minmag(dt_x,dt_y);
236 *vec += sgnd_uv_vec*(*dt);
238 *vec = (float2)( fmin(fmax((*vec)[0],-0.5f),
X_MAX),
239 fmin(fmax((*vec)[1],-0.5f),
Y_MAX) );
240 *dl = fast_length(*vec-prev_vec);
242 idx, prev_idx, mask_array, slt_array, slc_array);
246 #ifdef KERNEL_CONNECT_CHANNELS 282 float2 *dxy1_vec, float2 *dxy2_vec,
283 float2 *vec, float2 *prev_vec,
286 uint *idx, uint *prev_idx,
287 __private char2 *trajectory_vec)
289 const float step_error = fast_length((*dxy2_vec-*dxy1_vec)/
GRID_SCALE);
291 *dl = fast_length(*dxy2_vec);
293 *next_vec = *vec+*dxy1_vec;
294 *dl = fast_length(*dxy1_vec);
304 isequal(step_error,0.0f) );
312 #ifdef KERNEL_MAP_CHANNEL_HEADS 336 float2 *dxy1_vec, float2 *dxy2_vec,
337 float2 *vec, float2 *next_vec,
338 uint *n_steps, uint *idx)
340 const float step_error = fast_length((*dxy2_vec-*dxy1_vec)/
GRID_SCALE);
342 *dl = fast_length(*dxy2_vec);
344 *next_vec = *vec+*dxy1_vec;
345 *dl = fast_length(*dxy1_vec);
351 isequal(step_error,0.0f) );
356 #if defined(KERNEL_COUNT_DOWNCHANNELS) || defined(KERNEL_LINK_HILLSLOPES) 383 float2 *dxy1_vec, float2 *dxy2_vec,
384 float2 *vec, float2 *next_vec, uint *idx,
385 __global uint *mapping_array)
387 const float step_error = fast_length((*dxy2_vec-*dxy1_vec)/
GRID_SCALE);
389 *dl = fast_length(*dxy2_vec);
391 *next_vec = *vec+*dxy1_vec;
392 *dl = fast_length(*dxy1_vec);
397 printf(
"Count-link @ %g,%g: stuck\n",(*vec)[0],(*vec)[1]);
398 atomic_or(&mapping_array[*idx],
IS_STUCK);
402 isequal(step_error,0.0f) );
407 #if defined(KERNEL_SEGMENT_HILLSLOPES) || defined(KERNEL_SUBSEGMENT_FLANKS) 433 float2 *dxy1_vec, float2 *dxy2_vec,
434 float2 *vec, float2 *next_vec,
435 uint *n_steps, uint *idx)
437 const float step_error = fast_length((*dxy2_vec-*dxy1_vec)/
GRID_SCALE);
439 *dl = fast_length(*dxy2_vec);
441 *next_vec = *vec+*dxy1_vec;
442 *dl = fast_length(*dxy1_vec);
448 printf(
"Segment @ %g,%g: stuck\n",(*vec)[0],(*vec)[1]);
452 isequal(step_error,0.0f) );
457 #ifdef KERNEL_HILLSLOPE_LENGTHS 488 float2 *dxy1_vec, float2 *dxy2_vec,
489 float2 *vec, float2 *prev_vec,
491 uint *n_steps, uint *idx)
493 const float step_error = fast_length((*dxy2_vec-*dxy1_vec)/
GRID_SCALE);
495 *dl = fast_length(*dxy2_vec);
497 *next_vec = *vec+*dxy1_vec;
498 *dl = fast_length(*dxy1_vec);
507 isequal(step_error,0.0f) );
static void euler_step_record(float *dt, float *dl, float *l_trajectory, const float2 uv_vec, float2 *vec, const float2 prev_vec, uint *n_steps, __global char2 *trajectory_vec)
Compute a single Euler integration step of of a streamline.
static void update_trajectory(float dl, float *l_trajectory, uint *n_steps)
Update variables tracking trajectory length and integration step counter.
static void update_trajectory_write_sl_data(float dl, float *l_trajectory, float2 vec, float2 prev_vec, uint *n_steps, uint *idx, uint *prev_idx, __global const bool *mask_array, __global uint *slt_array, __global uint *slc_array)
Update variables tracking trajectory length and integration step counter.
static void update_record_private_trajectory(float dl, float *l_trajectory, float2 vec, float2 prev_vec, uint *n_steps, __private char2 *trajectory_vec)
Update variables tracking trajectory length and integration step counter.
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...
#define INTEGRATION_HALT_THRESHOLD
static bool runge_kutta_step_record(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, uint *prev_idx, __global char2 *trajectory_vec)
Compute a single step of 2nd-order Runge-Kutta numerical integration of a streamline given precompute...
static float dt_to_nearest_edge(float x, float u)
In Euler streamline integration (which is the last step), this function provides the delta time requi...
static float2 approximate(float2 raw_position)
Approximate a float vector at the resolution provided by a scaled byte vector.
static bool runge_kutta_step_write_sl_data(float *dt, float *dl, float *l_trajectory, float2 *dxy1_vec, float2 *dxy2_vec, float2 *vec, float2 *prev_vec, const float2 next_vec, uint *n_steps, uint *idx, uint *prev_idx, __global const bool *mask_array, __global uint *slt_array, __global uint *slc_array)
Compute a single step of 2nd-order Runge-Kutta numerical integration of a streamline given precompute...
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 ...
static bool segment_runge_kutta_step(float *dt, float *dl, float2 *dxy1_vec, float2 *dxy2_vec, float2 *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 euler_step_write_sl_data(float *dt, float *dl, float *l_trajectory, const float2 uv_vec, float2 *vec, const float2 prev_vec, uint *n_steps, uint *idx, uint *prev_idx, __global const bool *mask_array, __global uint *slt_array, __global uint *slc_array)
Compute a single Euler integration step of of a streamline.
#define ADJUSTED_MAX_ERROR
static void update_record_trajectory(float dl, float *l_trajectory, float2 vec, float2 prev_vec, uint *n_steps, __global char2 *trajectory_vec)
Update variables tracking trajectory length and integration step counter.
static bool countlink_runge_kutta_step(float *dt, float *dl, float2 *dxy1_vec, float2 *dxy2_vec, float2 *vec, float2 *next_vec, uint *idx, __global uint *mapping_array)
Compute a single step of 2nd-order Runge-Kutta numerical integration of a streamline given precompute...
static void channelheads_runge_kutta_step(float *dt, float *dl, float2 *dxy1_vec, float2 *dxy2_vec, float2 *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 bool connect_runge_kutta_step_record(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, uint *prev_idx, __private char2 *trajectory_vec)
Compute a single step of 2nd-order Runge-Kutta numerical integration of a streamline given precompute...