1
- use nalgebra:: point;
2
-
3
1
use crate :: {
4
2
core:: {
5
- index:: { BlockIndex , VoxelIndex } ,
3
+ index:: BlockIndex ,
6
4
layer:: Layer ,
7
5
voxel:: { Esdf , EsdfFlags , Tsdf } ,
8
6
} ,
9
- wgpu_utils:: { self , GpuPropagate , GpuSweep } ,
7
+ wgpu_utils:: { GpuPropagate , GpuSweep } ,
10
8
} ;
11
9
12
10
use std:: { collections:: BTreeSet , time:: Duration } ;
13
11
14
12
#[ derive( Default ) ]
15
13
pub struct EsdfIntegratorConfig { }
16
14
17
- enum OpDir {
18
- XPlus ,
19
- XMinus ,
20
- YPlus ,
21
- YMinus ,
22
- ZPlus ,
23
- ZMinus ,
24
- }
25
-
26
15
pub struct EsdfIntegrator {
27
16
config : EsdfIntegratorConfig ,
28
17
sweep_cache : GpuSweep ,
@@ -42,7 +31,7 @@ impl EsdfIntegrator {
42
31
}
43
32
}
44
33
45
- pub async fn update_blocks <
34
+ pub fn update_blocks <
46
35
const VPS : usize ,
47
36
F : FnMut ( & str , & Layer < Tsdf , VPS > , & Layer < Esdf , VPS > , & [ BlockIndex < VPS > ] , Duration ) ,
48
37
> (
@@ -202,145 +191,11 @@ impl EsdfIntegrator {
202
191
}
203
192
204
193
println ! (
205
- "ESDF update finished in {:?}" ,
194
+ "=> ESDF update finished in {:?}" ,
206
195
std:: time:: Instant :: now( ) . duration_since( start)
207
196
) ;
208
197
}
209
198
210
- fn sweep_block < const VPS : usize > (
211
- dir : OpDir ,
212
- index : & BlockIndex < VPS > ,
213
- esdf_layer : & mut Layer < Esdf , VPS > ,
214
- ) {
215
- let ( step, order) = match dir {
216
- OpDir :: XPlus => ( 1i32 , [ 2 , 1 , 0 ] ) ,
217
- OpDir :: XMinus => ( -1 , [ 2 , 1 , 0 ] ) ,
218
- OpDir :: YPlus => ( 1 , [ 2 , 0 , 1 ] ) ,
219
- OpDir :: YMinus => ( -1 , [ 2 , 0 , 1 ] ) ,
220
- OpDir :: ZPlus => ( 1 , [ 1 , 0 , 2 ] ) ,
221
- OpDir :: ZMinus => ( -1 , [ 1 , 0 , 2 ] ) ,
222
- } ;
223
-
224
- let voxel_size = esdf_layer. voxel_size ( ) ;
225
- let mut lock = esdf_layer. block_by_index ( index) . unwrap ( ) . write ( ) ;
226
-
227
- for u in 0 ..VPS {
228
- for v in 0 ..VPS {
229
- let w_range = if step > 0 {
230
- create_range_chain ( 1 , VPS - 1 )
231
- } else {
232
- create_range_chain ( VPS - 2 , 0 )
233
- } ;
234
-
235
- for w in w_range {
236
- let mut p = point ! [ 0 , 0 , 0 ] ;
237
- p[ order[ 0 ] ] = u;
238
- p[ order[ 1 ] ] = v;
239
- p[ order[ 2 ] ] = w;
240
-
241
- let voxel_index = VoxelIndex ( p) ;
242
-
243
- p[ order[ 2 ] ] = ( w as i32 - step) as usize ;
244
- let parent_voxel_index = VoxelIndex ( p) ;
245
-
246
- let parent_voxel = lock. voxel_from_index ( & parent_voxel_index) ;
247
- let parent_fixed = parent_voxel. flags . contains ( EsdfFlags :: Fixed ) ;
248
- let parent_dist = parent_voxel. distance ;
249
- let parent_site_block_index = parent_voxel. site_block_index ;
250
-
251
- let voxel = lock. voxel_from_index_mut ( & voxel_index) ;
252
-
253
- if parent_fixed && !voxel. flags . contains ( EsdfFlags :: Observed ) {
254
- if !voxel. flags . contains ( EsdfFlags :: Fixed ) {
255
- voxel. distance = parent_dist + voxel_size;
256
- voxel. flags . insert ( EsdfFlags :: Fixed ) ;
257
- voxel. site_block_index = parent_site_block_index;
258
- } else if voxel. distance > parent_dist + voxel_size {
259
- voxel. distance = voxel. distance . min ( parent_dist + voxel_size) ;
260
- voxel. site_block_index = parent_site_block_index;
261
- }
262
- }
263
- }
264
- }
265
- }
266
- }
267
-
268
- fn propagate_to_neighbour < const VPS : usize > (
269
- dir : OpDir ,
270
- pivot_index : & BlockIndex < VPS > ,
271
- esdf_layer : & mut Layer < Esdf , VPS > ,
272
- ) -> Option < BlockIndex < VPS > > {
273
- let voxel_size = esdf_layer. voxel_size ( ) ;
274
-
275
- let nblock_index = match dir {
276
- OpDir :: XPlus => BlockIndex :: new ( pivot_index. x + 1 , pivot_index. y , pivot_index. z ) ,
277
- OpDir :: XMinus => BlockIndex :: new ( pivot_index. x - 1 , pivot_index. y , pivot_index. z ) ,
278
- OpDir :: YPlus => BlockIndex :: new ( pivot_index. x , pivot_index. y + 1 , pivot_index. z ) ,
279
- OpDir :: YMinus => BlockIndex :: new ( pivot_index. x , pivot_index. y - 1 , pivot_index. z ) ,
280
- OpDir :: ZPlus => BlockIndex :: new ( pivot_index. x , pivot_index. y , pivot_index. z + 1 ) ,
281
- OpDir :: ZMinus => BlockIndex :: new ( pivot_index. x , pivot_index. y , pivot_index. z - 1 ) ,
282
- } ;
283
-
284
- let ( n_index, p_index, order) = match dir {
285
- OpDir :: XPlus => ( 0usize , VPS - 1 , [ 2 , 1 , 0 ] ) ,
286
- OpDir :: XMinus => ( VPS - 1 , 0 , [ 2 , 1 , 0 ] ) ,
287
- OpDir :: YPlus => ( 0 , VPS - 1 , [ 2 , 0 , 1 ] ) ,
288
- OpDir :: YMinus => ( VPS - 1 , 0 , [ 2 , 0 , 1 ] ) ,
289
- OpDir :: ZPlus => ( 0 , VPS - 1 , [ 1 , 0 , 2 ] ) ,
290
- OpDir :: ZMinus => ( VPS - 1 , 0 , [ 1 , 0 , 2 ] ) ,
291
- } ;
292
-
293
- let mut dirty = false ;
294
-
295
- if let Some ( neighbour_block) = esdf_layer. block_by_index ( & nblock_index) {
296
- let pivot_block = esdf_layer. block_by_index ( pivot_index) . unwrap ( ) . read ( ) ;
297
-
298
- let mut nlock = neighbour_block. write ( ) ;
299
-
300
- for u in 0 ..VPS {
301
- for v in 0 ..VPS {
302
- let mut p = point ! [ 0 , 0 , 0 ] ;
303
- p[ order[ 0 ] ] = u;
304
- p[ order[ 1 ] ] = v;
305
- p[ order[ 2 ] ] = p_index;
306
-
307
- let p_voxel_index = VoxelIndex ( p) ;
308
-
309
- p[ order[ 2 ] ] = n_index;
310
- let n_voxel_index = VoxelIndex ( p) ;
311
-
312
- // propagate through the sides
313
- let pivot_voxel = pivot_block. voxel_from_index ( & p_voxel_index) ;
314
- let pivot_fixed = pivot_voxel. flags . contains ( EsdfFlags :: Fixed ) ;
315
- let pivot_dist = pivot_voxel. distance ;
316
- let pivot_site_block_index = pivot_voxel. site_block_index ;
317
-
318
- let neighbour_voxel = nlock. voxel_from_index_mut ( & n_voxel_index) ;
319
- let neighbour_fixed = neighbour_voxel. flags . contains ( EsdfFlags :: Fixed ) ;
320
- let neighbour_observed = neighbour_voxel. flags . contains ( EsdfFlags :: Observed ) ;
321
-
322
- if pivot_fixed && !neighbour_observed {
323
- if neighbour_fixed {
324
- // found a shorter distance?
325
- if neighbour_voxel. distance > pivot_dist + voxel_size {
326
- neighbour_voxel. distance = pivot_dist + voxel_size;
327
- neighbour_voxel. site_block_index = pivot_site_block_index;
328
- dirty = true ;
329
- }
330
- } else {
331
- neighbour_voxel. distance = pivot_dist + voxel_size;
332
- neighbour_voxel. flags |= EsdfFlags :: Fixed ;
333
- neighbour_voxel. site_block_index = pivot_site_block_index;
334
- dirty = true ;
335
- }
336
- }
337
- }
338
- }
339
- }
340
-
341
- dirty. then_some ( nblock_index)
342
- }
343
-
344
199
fn sweep_gpu < const VPS : usize > (
345
200
& mut self ,
346
201
esdf_layer : & mut Layer < Esdf , VPS > ,
@@ -428,14 +283,3 @@ impl EsdfIntegrator {
428
283
)
429
284
}
430
285
}
431
-
432
- fn create_range_chain ( a : usize , b : usize ) -> impl Iterator < Item = usize > {
433
- #[ allow( clippy:: reversed_empty_ranges) ]
434
- let ( part1, part2) = if a <= b {
435
- ( a..=b, 1 ..=0 )
436
- } else {
437
- ( 1 ..=0 , b..=a)
438
- } ;
439
-
440
- part1. chain ( part2. rev ( ) )
441
- }
0 commit comments