Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright Contributors to the OpenVDB Project | ||
2 | // SPDX-License-Identifier: MPL-2.0 | ||
3 | |||
4 | /// @file points/AttributeGroup.cc | ||
5 | |||
6 | #include "AttributeGroup.h" | ||
7 | |||
8 | |||
9 | namespace openvdb { | ||
10 | OPENVDB_USE_VERSION_NAMESPACE | ||
11 | namespace OPENVDB_VERSION_NAME { | ||
12 | namespace points { | ||
13 | |||
14 | |||
15 | //////////////////////////////////////// | ||
16 | |||
17 | // GroupHandle implementation | ||
18 | |||
19 | |||
20 | 32219 | GroupHandle::GroupHandle(const GroupAttributeArray& array, const GroupType& offset) | |
21 | : mArray(array) | ||
22 | 32219 | , mBitMask(static_cast<GroupType>(1 << offset)) | |
23 | { | ||
24 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 32219 times.
|
32219 | assert(isGroup(mArray)); |
25 | |||
26 | // load data if delay-loaded | ||
27 | |||
28 | 32219 | mArray.loadData(); | |
29 | 32219 | } | |
30 | |||
31 | |||
32 | 1 | GroupHandle::GroupHandle(const GroupAttributeArray& array, const GroupType& bitMask, | |
33 | 1 | BitMask) | |
34 | : mArray(array) | ||
35 | 1 | , mBitMask(bitMask) | |
36 | { | ||
37 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert(isGroup(mArray)); |
38 | |||
39 | // load data if delay-loaded | ||
40 | |||
41 | 1 | mArray.loadData(); | |
42 | 1 | } | |
43 | |||
44 | |||
45 | 150 | bool GroupHandle::get(Index n) const | |
46 | { | ||
47 | 150 | return (mArray.get(n) & mBitMask) == mBitMask; | |
48 | } | ||
49 | |||
50 | |||
51 | 6019111 | bool GroupHandle::getUnsafe(Index n) const | |
52 | { | ||
53 | 6019111 | return (mArray.getUnsafe(n) & mBitMask) == mBitMask; | |
54 | } | ||
55 | |||
56 | |||
57 | //////////////////////////////////////// | ||
58 | |||
59 | // GroupWriteHandle implementation | ||
60 | |||
61 | |||
62 | 3355 | GroupWriteHandle::GroupWriteHandle(GroupAttributeArray& array, const GroupType& offset) | |
63 | 3355 | : GroupHandle(array, offset) | |
64 | { | ||
65 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 3355 times.
|
6710 | assert(isGroup(mArray)); |
66 | 3355 | } | |
67 | |||
68 | |||
69 | 507203 | void GroupWriteHandle::set(Index n, bool on) | |
70 | { | ||
71 | 507203 | const GroupType& value = mArray.get(n); | |
72 | |||
73 | 507203 | GroupAttributeArray& array(const_cast<GroupAttributeArray&>(mArray)); | |
74 | |||
75 |
2/2✓ Branch 0 taken 507185 times.
✓ Branch 1 taken 18 times.
|
507203 | if (on) array.set(n, value | mBitMask); |
76 | 18 | else array.set(n, value & ~mBitMask); | |
77 | 507203 | } | |
78 | |||
79 | |||
80 | 2 | void GroupWriteHandle::setUnsafe(Index n, bool on) | |
81 | { | ||
82 | 2 | const GroupType& value = mArray.getUnsafe(n); | |
83 | |||
84 | 2 | GroupAttributeArray& array(const_cast<GroupAttributeArray&>(mArray)); | |
85 | |||
86 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (on) array.setUnsafe(n, value | mBitMask); |
87 | ✗ | else array.setUnsafe(n, value & ~mBitMask); | |
88 | 2 | } | |
89 | |||
90 | |||
91 | 172 | bool GroupWriteHandle::collapse(bool on) | |
92 | { | ||
93 | using ValueT = GroupAttributeArray::ValueType; | ||
94 | |||
95 | 172 | GroupAttributeArray& array(const_cast<GroupAttributeArray&>(mArray)); | |
96 | |||
97 | 172 | array.compact(); | |
98 | |||
99 |
2/2✓ Branch 0 taken 142 times.
✓ Branch 1 taken 30 times.
|
172 | if (this->isUniform()) { |
100 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 113 times.
|
142 | if (on) array.collapse(static_cast<ValueT>(array.get(0) | mBitMask)); |
101 | 113 | else array.collapse(static_cast<ValueT>(array.get(0) & ~mBitMask)); | |
102 | 142 | return true; | |
103 | } | ||
104 | |||
105 |
2/2✓ Branch 0 taken 3115 times.
✓ Branch 1 taken 30 times.
|
3145 | for (Index i = 0; i < array.size(); i++) { |
106 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 3082 times.
|
3115 | if (on) array.set(i, static_cast<ValueT>(array.get(i) | mBitMask)); |
107 | 3082 | else array.set(i, static_cast<ValueT>(array.get(i) & ~mBitMask)); | |
108 | } | ||
109 | |||
110 | return false; | ||
111 | } | ||
112 | |||
113 | |||
114 | 3121 | bool GroupWriteHandle::compact() | |
115 | { | ||
116 | 3121 | GroupAttributeArray& array(const_cast<GroupAttributeArray&>(mArray)); | |
117 | |||
118 | 3121 | return array.compact(); | |
119 | } | ||
120 | |||
121 | |||
122 | //////////////////////////////////////// | ||
123 | |||
124 | |||
125 | } // namespace points | ||
126 | } // namespace OPENVDB_VERSION_NAME | ||
127 | } // namespace openvdb | ||
128 |