commit 59831938eed74e099aaedc84004084fdd79e0b99
parent c4b26621003d07f850ea646a3d5784a124d34e7f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 27 Feb 2018 11:34:58 +0100
Upd how #voxels are managed
Do not explicitly count each emitted voxels : recompute it from
the `in use' memory in the buffer of leaves.
Diffstat:
2 files changed, 11 insertions(+), 23 deletions(-)
diff --git a/src/htvox_scene.c b/src/htvox_scene.c
@@ -52,7 +52,6 @@ struct octree_builder {
int octree_depth;
uint64_t mcode; /* Morton code of the last registered voxels */
- size_t nvoxels; /* Number of voxels, i.e. leaves, */
};
/*******************************************************************************
@@ -151,15 +150,13 @@ static res_T
stack_write
(struct stack* stack, /* Node to write */
struct octree_buffer* buffer, /* Buffer where nodes are written */
- struct octree_index* out_index, /* Index of the first written node */
- size_t* nvoxels) /* Number of written voxels */
+ struct octree_index* out_index) /* Index of the first written node */
{
struct octree_index nodes_id = OCTREE_INDEX_NULL;
struct octree_node* node = NULL;
- size_t nvoxs = 0;
int inode;
res_T res = RES_OK;
- ASSERT(stack && buffer && out_index && nvoxels);
+ ASSERT(stack && buffer && out_index);
/* No registered nodes, this means that the nodes were merged in an higher
* level */
@@ -188,7 +185,6 @@ stack_write
if(node->is_leaf & BIT(ileaf)) leaves[nvoxs_node++] = node->data[ileaf];
}
ASSERT(nvoxs_node == nleaves);
- nvoxs += nleaves;
}
do {
@@ -258,7 +254,6 @@ stack_write
exit:
/* Return the index toward the first writen nodes */
*out_index = nodes_id;
- *nvoxels = nvoxs;
return res;
error:
goto exit;
@@ -293,7 +288,6 @@ octree_builder_init
bldr->merge = merge;
bldr->context = context;
bldr->buffer = buffer;
- bldr->nvoxels = 0;
exit:
return res;
@@ -330,7 +324,6 @@ octree_builder_add_voxel
* levels contain all the voxels and can be skipped */
FOR_EACH(ilvl, 0, bldr->octree_depth-2/*The 2 last leaves contain all voxels*/) {
struct octree_node* stack_node;
- size_t nvoxels;
uint64_t mcode_max_lvl;
/* Compute the maximum morton code value for the current octree level */
@@ -350,11 +343,9 @@ octree_builder_add_voxel
/* Write the nodes of the stack of the current octree level into the buf */
res = stack_write
- (&bldr->stacks[ilvl], bldr->buffer, &stack_node->ichild_node, &nvoxels);
+ (&bldr->stacks[ilvl], bldr->buffer, &stack_node->ichild_node);
if(res != RES_OK) goto error;
- bldr->nvoxels += nvoxels; /* TODO remove this */
-
/* Reset the current stack */
stack_clear(&bldr->stacks[ilvl]);
}
@@ -384,7 +375,6 @@ octree_builder_finalize
(struct octree_builder* bldr,
struct octree_index* root_id)
{
- size_t nvoxels;
size_t inode;
int ilvl;
res_T res = RES_OK;
@@ -410,19 +400,15 @@ octree_builder_finalize
/* Write the stacked nodes of the current level */
res = stack_write
- (&bldr->stacks[ilvl], bldr->buffer, &parent_node->ichild_node, &nvoxels);
+ (&bldr->stacks[ilvl], bldr->buffer, &parent_node->ichild_node);
if(res != RES_OK) goto error;
-
- bldr->nvoxels += nvoxels; /* TODO remove this */
}
/* Write the root node */
ilvl = bldr->octree_depth-1; /* Root level */
- res = stack_write(&bldr->stacks[ilvl], bldr->buffer, root_id, &nvoxels);
+ res = stack_write(&bldr->stacks[ilvl], bldr->buffer, root_id);
if(res != RES_OK) goto error;
- bldr->nvoxels += nvoxels; /* TODO remove this */
-
exit:
return res;
error:
@@ -538,8 +524,6 @@ htvox_scene_create
res = octree_builder_finalize(&bldr, &scn->root);
if(res != RES_OK) goto error;
- scn->nvoxels = bldr.nvoxels;
-
#ifndef NDEBUG
check_octree(&scn->buffer, scn->root);
#endif
@@ -600,8 +584,13 @@ htvox_scene_get_aabb
res_T
htvox_scene_get_voxels_count(const struct htvox_scene* scn, size_t* nvoxels)
{
+ size_t nvoxs = 0;
+ size_t nvoxs_per_page = 0;
if(!scn || !nvoxels) return RES_BAD_ARG;
- *nvoxels = scn->nvoxels;
+ nvoxs_per_page = scn->buffer.pagesize / sizeof(double);
+ nvoxs = scn->buffer.leaf_head.ipage * nvoxs_per_page
+ + scn->buffer.leaf_head.inode;
+ *nvoxels = nvoxs;
return RES_OK;
}
diff --git a/src/htvox_scene.h b/src/htvox_scene.h
@@ -21,7 +21,6 @@
struct htvox_scene {
size_t definition; /* Definition of the octree */
- size_t nvoxels; /* Overall #voxels effectively stored in the octree */
double lower[3], upper[3]; /* World space AABB of the scene */
double oclow[3], ocupp[3]; /* World space AABB of the octree */