-
Notifications
You must be signed in to change notification settings - Fork 98
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
Iterator by Node ID #268
Iterator by Node ID #268
Conversation
src/octree/octree_iterator.rs
Outdated
@@ -7,7 +7,7 @@ use collision::Aabb3; | |||
use std::collections::VecDeque; | |||
|
|||
/// returns an Iterator over the points of the current node | |||
fn get_node_iterator(octree: &Octree, node_id: &NodeId) -> NodeIterator { | |||
pub fn get_node_iterator(octree: &Octree, node_id: &NodeId) -> NodeIterator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this become public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here i forgot to remove some previous changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and, most importantly, pushed to origin
I think abstracting away traversal of the nodes into an iterator is potentially a good idea, we do that a lot. However, it's currently unused – could you comment a bit more on how this should be used? |
hi nikolai,
in another branch I am currently implementing the parallelization... PR comes soon. |
#273 here the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we actually also apply/use the new NodeIdIterator
inside FilteredPointsIterator
and AllPointsIterator
?
src/octree/octree_iterator.rs
Outdated
type Item = NodeId; | ||
|
||
fn next(&mut self) -> Option<NodeId> { | ||
loop { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about shortening this to
while let Some(current) = self.node_ids.pop_front() {
if (self.filter_func)(¤t, &self.octree) {
for child_index in 0..8 {
let child_id = current.get_child_id(ChildIndex::from_u8(child_index));
if self.octree.nodes.contains_key(&child_id) {
self.node_ids.push_back(child_id);
}
}
return Some(current);
}
}
return None;
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/octree/octree_iterator.rs
Outdated
@@ -130,3 +130,42 @@ pub fn intersecting_node_ids( | |||
} | |||
node_ids | |||
} | |||
|
|||
pub struct NodeIdIterator<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: How about naming it NodeIdsIterator? The pluralization matches the other iterators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/octree/octree_iterator.rs
Outdated
type Item = NodeId; | ||
|
||
fn next(&mut self) -> Option<NodeId> { | ||
loop { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does there need to be a loop in here? next()
only gets one node, so I'd think all the state is encapsulated in the node_ids
queue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the loop is necessary to guarantee that next() returns Some(item) if the filter fuction is successful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nonetheless can be optimized!
src/octree/octree_iterator.rs
Outdated
|
||
pub struct NodeIdIterator<'a> { | ||
octree: &'a Octree, | ||
filter_func: Box<Fn(&NodeId, &Octree) -> bool + 'a>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first preference would be to integrate this directly with PointCulling instead of functions, and to use the more optimized distinction between Inside, Crossing and Outside to automatically add child nodes. If we use functions, how about making this a template parameter instead of a trait object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned offline, the iterator is more generic than the filtering of the point culling. This distinction occurs for Frustum and a specific method returns the node ids.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but can we make this a parameter of the struct, I.e. struct NodeIdsIterator<F>
and filter_func: F
, and restrict it to Fn(&NodeId, &Octree) -> bool
in the impl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, seems like you can directly embed the trait bound into the struct definition (where F: Fn(&NodeId, &Octree) -> bool
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I removed these in #273, or better, I unified these with the implementation of the trait. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with one nit.
src/octree/octree_test.rs
Outdated
} | ||
|
||
#[test] | ||
//#[ignore] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please delete this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
|
||
impl<'a, F> Iterator for NodeIdsIterator<'a, F> | ||
where | ||
F: Fn(&NodeId, &Octree) -> bool + 'a, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need that here when it's already in the struct definition, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it does not work removing that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one nit
@wally-the-cartographer merge |
1 similar comment
@wally-the-cartographer merge |
@pifon2a Hi, sorry to bother you, Wally does not seem to be responsive, can you please restart it? |
@catevita The Wally is not run by me anymore. I have also left the project. Merging manually... |
@catevita Wolfgang and Holger know more about that. |
Thanks, for all your recent and previuos help! next time I am asking to someone else, all the best |
The node file id iterator allows traversal by accessing node id an meta. This is a pre step useful for node parallelization (using e.g. rayon and par_iter())
Test were moved into a single file to allow for less code duplication