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

Iterator by Node ID #268

Merged
merged 14 commits into from
Jun 6, 2019
Merged

Iterator by Node ID #268

merged 14 commits into from
Jun 6, 2019

Conversation

catevita
Copy link
Contributor

@catevita catevita commented May 21, 2019

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

@catevita
Copy link
Contributor Author

PTAL @feuerste @nnmm

@catevita catevita changed the title Iterator by Node ID and computing "tight" Aabb estimate (backward compatible) Iterator by Node ID May 21, 2019
@@ -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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

src/octree/octree_test.rs Outdated Show resolved Hide resolved
@nnmm
Copy link
Contributor

nnmm commented May 21, 2019

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?

@catevita
Copy link
Contributor Author

hi nikolai,

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?

in another branch I am currently implementing the parallelization... PR comes soon.
Either should par_iter from rayon be directly used, or should the candidate nodes be gathered and then should the threads reading memory be parallelized.

@catevita
Copy link
Contributor Author

#273 here the PR

Copy link

@feuerste feuerste left a 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/mod.rs Show resolved Hide resolved
type Item = NodeId;

fn next(&mut self) -> Option<NodeId> {
loop {
Copy link

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)(&current, &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;

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -130,3 +130,42 @@ pub fn intersecting_node_ids(
}
node_ids
}

pub struct NodeIdIterator<'a> {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

type Item = NodeId;

fn next(&mut self) -> Option<NodeId> {
loop {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nonetheless can be optimized!


pub struct NodeIdIterator<'a> {
octree: &'a Octree,
filter_func: Box<Fn(&NodeId, &Octree) -> bool + 'a>,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@catevita
Copy link
Contributor Author

catevita commented Jun 5, 2019

Can we actually also apply/use the new NodeIdIterator inside FilteredPointsIterator and AllPointsIterator?

I removed these in #273, or better, I unified these with the implementation of the trait.
this PR is just implementing the NodeIdsIterator

Copy link

@feuerste feuerste left a 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.

}

#[test]
//#[ignore]
Copy link

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same above

Copy link
Contributor Author

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

Copy link
Contributor

@nnmm nnmm left a 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

@catevita
Copy link
Contributor Author

catevita commented Jun 6, 2019

@wally-the-cartographer merge

1 similar comment
@catevita
Copy link
Contributor Author

catevita commented Jun 6, 2019

@wally-the-cartographer merge

@catevita
Copy link
Contributor Author

catevita commented Jun 6, 2019

@pifon2a Hi, sorry to bother you, Wally does not seem to be responsive, can you please restart it?

@pifon2a pifon2a merged commit a9d0179 into master Jun 6, 2019
@pifon2a
Copy link

pifon2a commented Jun 6, 2019

@catevita The Wally is not run by me anymore. I have also left the project. Merging manually...

@pifon2a
Copy link

pifon2a commented Jun 6, 2019

@catevita Wolfgang and Holger know more about that.

@catevita
Copy link
Contributor Author

catevita commented Jun 6, 2019

Thanks, for all your recent and previuos help! next time I am asking to someone else, all the best

@catevita catevita deleted the cvitadello/nodeiditerator branch July 4, 2019 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants