OpenVDB
12.1.1
Loading...
Searching...
No Matches
MorphologyHelpers.h
Go to the documentation of this file.
1
// Copyright Contributors to the OpenVDB Project
2
// SPDX-License-Identifier: Apache-2.0
3
4
/*!
5
\file MorphologyHelpers.h
6
7
\author Efty Sifakis
8
9
\date March 17, 2025
10
11
\brief This file implements helper methods used in morphology operations
12
13
*/
14
15
#ifndef NANOVDB_TOOLS_CUDA_MORPHOLOGYHELPERS_H_HAS_BEEN_INCLUDED
16
#define NANOVDB_TOOLS_CUDA_MORPHOLOGYHELPERS_H_HAS_BEEN_INCLUDED
17
18
#include <
nanovdb/NanoVDB.h
>
19
20
namespace
nanovdb::tools
{
21
22
namespace
morphology
{
23
24
enum
NearestNeighbors
{
NN_FACE
= 6,
NN_FACE_EDGE
= 18,
NN_FACE_EDGE_VERTEX
= 26 };
25
26
template
<
int
di,
int
dj,
int
dk>
27
struct
NearestNeighborBitMask
{
28
static_assert
( (di>=-1) && (di<=1) && (dj>=-1) && (dj<=1) && (dk>=-1) && (dk<=1) );
29
static
constexpr
uint32_t
value
= 1u << (di+1)*9+(dj+1)*3+dk+1;
30
};
31
32
template
<NearestNeighbors nnType>
33
__hostdev__
34
uint32_t
neighborMaskStencil
(
const
nanovdb::Mask<3>
& mask)
35
{
36
uint32_t result = 0;
37
auto
words = mask.
words
();
38
uint64_t allWordsOr = 0;
39
for
(
int
i = 0; i < 8; i++)
40
allWordsOr |= words[i];
41
// Center
42
if
( allWordsOr ) result |=
NearestNeighborBitMask< 0, 0, 0>::value
;
43
// Neighbors across faces
44
if
constexpr
(nnType ==
NN_FACE
|| nnType ==
NN_FACE_EDGE
|| nnType ==
NN_FACE_EDGE_VERTEX
) {
45
if
( words[0] ) result |=
NearestNeighborBitMask
<-1, 0, 0>::value;
46
if
( words[7] ) result |=
NearestNeighborBitMask< 1, 0, 0>::value
;
47
if
( allWordsOr & 0x00000000000000ffUL ) result |=
NearestNeighborBitMask
< 0,-1, 0>::value;
48
if
( allWordsOr & 0xff00000000000000UL ) result |=
NearestNeighborBitMask< 0, 1, 0>::value
;
49
if
( allWordsOr & 0x0101010101010101UL ) result |=
NearestNeighborBitMask
< 0, 0,-1>::value;
50
if
( allWordsOr & 0x8080808080808080UL ) result |=
NearestNeighborBitMask< 0, 0, 1>::value
; }
51
// Neighbors across edges
52
if
constexpr
(nnType ==
NN_FACE_EDGE
|| nnType ==
NN_FACE_EDGE_VERTEX
) {
53
if
( words[0] & 0x00000000000000ffUL ) result |=
NearestNeighborBitMask
<-1,-1, 0>::value;
54
if
( words[0] & 0xff00000000000000UL ) result |=
NearestNeighborBitMask
<-1, 1, 0>::value;
55
if
( words[0] & 0x0101010101010101UL ) result |=
NearestNeighborBitMask
<-1, 0,-1>::value;
56
if
( words[0] & 0x8080808080808080UL ) result |=
NearestNeighborBitMask
<-1, 0, 1>::value;
57
if
( allWordsOr & 0x0000000000000001UL ) result |=
NearestNeighborBitMask
< 0,-1,-1>::value;
58
if
( allWordsOr & 0x0000000000000080UL ) result |=
NearestNeighborBitMask
< 0,-1, 1>::value;
59
if
( allWordsOr & 0x0100000000000000UL ) result |=
NearestNeighborBitMask
< 0, 1,-1>::value;
60
if
( allWordsOr & 0x8000000000000000UL ) result |=
NearestNeighborBitMask< 0, 1, 1>::value
;
61
if
( words[7] & 0x00000000000000ffUL ) result |=
NearestNeighborBitMask
< 1,-1, 0>::value;
62
if
( words[7] & 0xff00000000000000UL ) result |=
NearestNeighborBitMask< 1, 1, 0>::value
;
63
if
( words[7] & 0x0101010101010101UL ) result |=
NearestNeighborBitMask
< 1, 0,-1>::value;
64
if
( words[7] & 0x8080808080808080UL ) result |=
NearestNeighborBitMask< 1, 0, 1>::value
; }
65
// Neighbors across vertices
66
if
constexpr
(nnType ==
NN_FACE_EDGE_VERTEX
) {
67
if
( words[0] & 0x0000000000000001UL ) result |=
NearestNeighborBitMask
<-1,-1,-1>::value;
68
if
( words[0] & 0x0000000000000080UL ) result |=
NearestNeighborBitMask
<-1,-1, 1>::value;
69
if
( words[0] & 0x0100000000000000UL ) result |=
NearestNeighborBitMask
<-1, 1,-1>::value;
70
if
( words[0] & 0x8000000000000000UL ) result |=
NearestNeighborBitMask
<-1, 1, 1>::value;
71
if
( words[7] & 0x0000000000000001UL ) result |=
NearestNeighborBitMask
< 1,-1,-1>::value;
72
if
( words[7] & 0x0000000000000080UL ) result |=
NearestNeighborBitMask
< 1,-1, 1>::value;
73
if
( words[7] & 0x0100000000000000UL ) result |=
NearestNeighborBitMask
< 1, 1,-1>::value;
74
if
( words[7] & 0x8000000000000000UL ) result |=
NearestNeighborBitMask< 1, 1, 1>::value
; }
75
return
result;
76
}
77
78
}
// namespace morphology
79
80
}
// namespace nanovdb::tools
81
82
#if defined(__CUDACC__)
83
#include <nanovdb/util/cuda/MorphologyHelpers.cuh>
84
#endif
// defined(__CUDACC__)
85
86
#endif
// NANOVDB_TOOLS_CUDA_MORPHOLOGYHELPERS_H_HAS_BEEN_INCLUDED
87
NanoVDB.h
Implements a light-weight self-contained VDB data-structure in a single file! In other words,...
nanovdb::Mask
Bit-mask to encode active states and facilitate sequential iterators and a fast codec for I/O compres...
Definition
NanoVDB.h:1028
nanovdb::Mask::words
__hostdev__ uint64_t * words()
Return a pointer to the list of words of the bit mask.
Definition
NanoVDB.h:1152
nanovdb::tools::morphology
Definition
MorphologyHelpers.h:22
nanovdb::tools::morphology::NearestNeighbors
NearestNeighbors
Definition
MorphologyHelpers.h:24
nanovdb::tools::morphology::NN_FACE_EDGE_VERTEX
@ NN_FACE_EDGE_VERTEX
Definition
MorphologyHelpers.h:24
nanovdb::tools::morphology::NN_FACE_EDGE
@ NN_FACE_EDGE
Definition
MorphologyHelpers.h:24
nanovdb::tools::morphology::NN_FACE
@ NN_FACE
Definition
MorphologyHelpers.h:24
nanovdb::tools::morphology::neighborMaskStencil
__hostdev__ uint32_t neighborMaskStencil(const nanovdb::Mask< 3 > &mask)
Definition
MorphologyHelpers.h:34
nanovdb::tools
Definition
MorphologyHelpers.h:20
__hostdev__
#define __hostdev__
Definition
Util.h:73
nanovdb::tools::morphology::NearestNeighborBitMask
Definition
MorphologyHelpers.h:27
nanovdb::tools::morphology::NearestNeighborBitMask::value
static constexpr uint32_t value
Definition
MorphologyHelpers.h:29
nanovdb
util
MorphologyHelpers.h
Generated by
1.14.0