Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node mask compression #57

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/data_structure.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::coordinates::{GlobalCoord, Index, LocalCoord};
use crate::transform::Map;
use crate::OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION;
use bitflags::bitflags;
use bitvec::prelude::*;
use bitvec::slice::IterOnes;
Expand Down Expand Up @@ -93,7 +94,19 @@ where
{
return Some((
node_4.offset_to_global_coord(Index(idx as u32)).0.as_vec3(),
node_4.data[idx],
if self.grid.descriptor.file_version
< OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
{
let node_mask_compression_idx = node_4
.child_mask
.iter()
.by_vals()
.take(idx)
.fold(0, |old, val| old + (!val as usize)); // count 0's before idx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you could have .map(|v| !v as usize).sum()'ed this 😬

node_4.data[node_mask_compression_idx]
} else {
node_4.data[idx]
},
VdbLevel::Node3,
));
}
Expand Down Expand Up @@ -130,6 +143,7 @@ where
#[derive(Debug, Clone)]
pub struct GridDescriptor {
pub name: String,
pub file_version: u32,
/// If not empty, the name of another grid that shares this grid's tree
pub instance_parent: String,
pub grid_type: String,
Expand Down
1 change: 1 addition & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ impl<R: Read + Seek> VdbReader<R> {

let mut gd = GridDescriptor {
name: name.clone(),
file_version: header.file_version,
grid_type,
instance_parent,
grid_pos,
Expand Down