Skip to content

Commit

Permalink
Minor fixes after #25
Browse files Browse the repository at this point in the history
  • Loading branch information
davids91 committed Jun 14, 2024
1 parent c77d6a9 commit 6b41297
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 153 deletions.
16 changes: 8 additions & 8 deletions benches/performance.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use criterion::{criterion_group, criterion_main};
use rand::Rng;
use shocovox_rs::{octree::Octree, octree::V3c};
use shocovox_rs::octree::{Octree, V3c};

#[cfg(feature = "raytracing")]
use shocovox_rs::octree::raytracing::Ray;
use shocovox_rs::octree::{raytracing::Ray, Albedo};

fn criterion_benchmark(c: &mut criterion::Criterion) {
let mut rng = rand::thread_rng();

#[cfg(feature = "raytracing")]
{
let tree_size = 512;
let mut tree = shocovox_rs::octree::Octree::<u32, 8>::new(tree_size)
let mut tree = shocovox_rs::octree::Octree::<Albedo, 8>::new(tree_size)
.ok()
.unwrap();
tree.insert(&V3c::new(1, 3, 3), rng.gen_range(0..500))
tree.insert(&V3c::new(1, 3, 3), rng.gen_range(0..500).into())
.ok()
.unwrap();
for x in 0..100 {
Expand All @@ -25,7 +25,7 @@ fn criterion_benchmark(c: &mut criterion::Criterion) {
|| z < (tree_size / 4)
|| ((tree_size / 2) <= x && (tree_size / 2) <= y && (tree_size / 2) <= z)
{
tree.insert(&V3c::new(x, y, z), rng.gen_range(0..500))
tree.insert(&V3c::new(x, y, z), rng.gen_range(0..500).into())
.ok()
.unwrap();
}
Expand Down Expand Up @@ -74,7 +74,7 @@ fn criterion_benchmark(c: &mut criterion::Criterion) {
}

let tree_size = 64;
let mut tree = shocovox_rs::octree::Octree::<u32>::new(tree_size)
let mut tree = shocovox_rs::octree::Octree::<Albedo>::new(tree_size)
.ok()
.unwrap();

Expand All @@ -86,7 +86,7 @@ fn criterion_benchmark(c: &mut criterion::Criterion) {
rng.gen_range(0..tree_size),
rng.gen_range(0..tree_size),
),
rng.gen_range(0..500),
rng.gen_range(0..500).into(),
)
.ok()
});
Expand Down Expand Up @@ -122,7 +122,7 @@ fn criterion_benchmark(c: &mut criterion::Criterion) {

c.bench_function("octree load", |b| {
b.iter(|| {
let _tree_copy = Octree::<u32>::load("test_junk_octree").ok().unwrap();
let _tree_copy = Octree::<Albedo>::load("test_junk_octree").ok().unwrap();
});
});
}
Expand Down
22 changes: 9 additions & 13 deletions examples/cpu_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,25 @@ fn main() {
const TREE_SIZE: u32 = 64;
let viewport_size_width = 128;
let viewport_size_height = 128;
let mut tree = shocovox_rs::octree::Octree::<Albedo, MATRIX_DIMENSION>::new(tree_size)
let mut tree = shocovox_rs::octree::Octree::<Albedo, MATRIX_DIMENSION>::new(TREE_SIZE)
.ok()
.unwrap();

tree.insert(&V3c::new(1, 3, 3), voxel_color)
.expect("insert of voxel to work");
for x in 0..tree_size {
for y in 0..tree_size {
for z in 0..tree_size {
if ((x < (ARRAY_DIMENSION / 4)
|| y < (ARRAY_DIMENSION / 4)
|| z < (ARRAY_DIMENSION / 4))
for x in 0..TREE_SIZE {
for y in 0..TREE_SIZE {
for z in 0..TREE_SIZE {
if ((x < (TREE_SIZE / 4) || y < (TREE_SIZE / 4) || z < (TREE_SIZE / 4))
&& (0 == x % 2 && 0 == y % 4 && 0 == z % 2))
|| ((ARRAY_DIMENSION / 2) <= x
&& (ARRAY_DIMENSION / 2) <= y
&& (ARRAY_DIMENSION / 2) <= z)
|| ((TREE_SIZE / 2) <= x && (TREE_SIZE / 2) <= y && (TREE_SIZE / 2) <= z)
{
tree.insert(
&V3c::new(x, y, z),
Albedo::default()
.with_red((255 as f32 * x as f32 / tree_size as f32) as u8)
.with_green((255 as f32 * y as f32 / tree_size as f32) as u8)
.with_blue((255 as f32 * z as f32 / tree_size as f32) as u8)
.with_red((255 as f32 * x as f32 / TREE_SIZE as f32) as u8)
.with_green((255 as f32 * y as f32 / TREE_SIZE as f32) as u8)
.with_blue((255 as f32 * z as f32 / TREE_SIZE as f32) as u8)
.with_alpha(255),
)
.ok()
Expand Down
2 changes: 1 addition & 1 deletion src/octree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod update;
pub mod raytracing;

pub use crate::spatial::math::vector::V3c;
pub use types::{Octree, VoxelData};
pub use types::{Albedo, Octree, VoxelData};

use crate::object_pool::{empty_marker, ObjectPool};
use crate::octree::{
Expand Down
Loading

0 comments on commit 6b41297

Please sign in to comment.