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

PointCulling Trait and Iterator cleanup #278

Merged
merged 1 commit into from
Jun 19, 2019

Conversation

catevita
Copy link
Contributor

@catevita catevita commented Jun 7, 2019

The iterator are splitted on
-iterator that retrieve nodes
-iterator that scan points on a single node

The PointLocation in which the Points that have to be retrieved has been streamlined,
the methods contains and intersects are part of the trait PointCulling.
This works for an Aabb3, Obb, OrientedBeam and Frustum

@catevita
Copy link
Contributor Author

catevita commented Jun 7, 2019

still quite a big PR, I tried my best to remove some other additional changes
PTAL @nnmm @feuerste

@@ -276,19 +301,43 @@ impl<S: BaseFloat> Obb<S> {
}
}

impl<S> PointCulling<S> for Obb<S>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Why was this moved?

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 methods have been moved to implement the trait - I hope to understand the question

pub enum PointCulling {
Any(),
#[derive(Debug, Clone)]
pub enum GeoFence {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be clearer if we name this PointLocation, and what's currently called PointLocation can become PointQuery. GeoFence has a specific meaning: https://en.wikipedia.org/wiki/Geo-fence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, I was running short on names!

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!

};
iterator.try_for_each(|point: Point| point_stream.push_point_and_callback(point))?;
point_stream.callback()
//todo (catevita) mutable function parallelization
Copy link
Contributor

@nnmm nnmm Jun 7, 2019

Choose a reason for hiding this comment

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

I'm not sure I understand and/or we need this. In the end, the user calls try_for_each_batch. Are you proposing the callbacks should happen on several threads in parallel? I suspect that's not super useful, since it requires synchronization on the user side again, and I'd prefer to (as a user) e.g. request points in non-overlapping boxes from several threads.

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 told offline, this PR only takes care of implementing the trait, the parallelization follows up next

}

pub fn points_in_frustum<'a>(
/// Returns the ids of all nodes that cut or are fully contained in 'aabb'.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Let's be consistent with two vs three slashes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was meant to be a minimal doc comment for the method points_in_node, do we use doc comment at all?

S: BaseFloat + Sync + Send,
{
fn contains(&self, point: &Point3<S>) -> bool;
fn intersects(&self, aabb: &Aabb3<S>) -> bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a TODO here to return Relation?

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

Choose a reason for hiding this comment

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

Nit: Our formatting convention for TODOs is:

// TODO(username): Do something.

Can you please adjust it everywhere in this PR?

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

Choose a reason for hiding this comment

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

Supernit: Still not in the format

// TODO(username): Do something.

everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I just paid attention to the caps! now it should be finally fixed!

{
fn contains(&self, point: &Point3<S>) -> bool;
fn intersects(&self, aabb: &Aabb3<S>) -> bool;
fn transform(&self, isometry: &Isometry3<S>) -> Box<PointCulling<S>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can probably be impl PointCulling, I'd think.

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 this does not work inside a trait, from rfcs

"impl Trait may only be written within the return type of a freestanding or inherent-impl function, not in trait definitions or any non-return type position. "


#[derive(Debug, Clone)]
pub struct Frustum<S: BaseFloat> {
pub matrix: Matrix4<S>,
Copy link
Contributor

@nnmm nnmm Jun 7, 2019

Choose a reason for hiding this comment

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

Could you remind me why this contains the second matrix? I forgot. Also, the fields probably do not need to be public and I'd have expected this to be in math.rs.

Copy link
Contributor Author

@catevita catevita Jun 7, 2019

Choose a reason for hiding this comment

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

i moved it in math, the matrix is used by the contains function

// TODO(ksavinash9) update after https://github.com/rustgd/collision-rs/issues/101 is resolved.
pub fn contains<S: BaseFloat>(projection_matrix: &Matrix4<S>, point: &Point3<S>) -> bool {

the issue in collision is not resolved yet

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 you please remove the file .DS_Store?
Did you actually check the runtime performance with all the new changes?

S: BaseFloat + Sync + Send,
{
fn contains(&self, point: &Point3<S>) -> bool;
fn intersects(&self, aabb: &Aabb3<S>) -> bool;

Choose a reason for hiding this comment

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

Nit: Our formatting convention for TODOs is:

// TODO(username): Do something.

Can you please adjust it everywhere in this PR?

@@ -54,8 +53,8 @@ fn main() {
let num_points = args.num_points;
let point_cloud_client = PointCloudClient::new(&args.locations, OctreeFactory::new())
.expect("Couldn't create octree client.");
let point_location = PointLocation {
culling: PointCulling::Aabb(Aabb3::new(args.min, args.max)),

Choose a reason for hiding this comment

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

Any specific reason to remove the min/max restriction?
Then the whole point of having min/max arguments goes away...

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think it also was a copy-paste error

global_from_local: None,
};
let mut batch_iterator = BatchIterator::new(&octree, &all_points, 1_000_000);
let mut num_batches = 0;

Choose a reason for hiding this comment

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

Nit: How about having a const variable BATCH_SIZE, removing num_batches, and just working on counter?

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

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

location: octree::PointLocation::Frustum(frustum_matrix),
global_from_local: None,
};
self.stream_points_back_to_sink(point_location, &req.octree_id, &ctx, resp)

Choose a reason for hiding this comment

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

It seems global_from_local is None whenever calling self.stream_points_back_to_sink. How about just passing a location and constructing the PointQuery inside stream_points_back_to_sink?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if it is ok for you i'd like to leave this pieces of code as is, as the grpc server is not intensively used, so if we have to support query with local/global transforms the PointQuery struct is already prepared to support that.

.iter()
.map(|p| {
let mut v = point_viewer::proto::Color::new();
v.set_red(f32::from(p.x) / 255.);

Choose a reason for hiding this comment

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

How about using Color::to_f32 to perform the conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it, it adds some lines but the performance seems not to be affected from that

src/math.rs Outdated
fn transform(&self, isometry: &Isometry3<S>) -> Box<PointCulling<S>>;
}

// PointCulling for Aabb3

Choose a reason for hiding this comment

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

Nit: remove comment, this is clear

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

src/math.rs Outdated
@@ -150,22 +199,6 @@ impl<'a, S: BaseFloat> Mul<&'a Vector3<S>> for &'a Isometry3<S> {
}
}

impl<S: BaseFloat> Into<Decomposed<Vector3<S>, Quaternion<S>>> for Isometry3<S> {

Choose a reason for hiding this comment

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

Any reason why the generics were removed here and instead having an f64 implementation only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this there is indeed some automatic or manual merging gone wrong! I am restoring them

Choose a reason for hiding this comment

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

It would be clearer to move them back exactly where they were before, so they don't show up as diff...

src/math.rs Outdated
let corner_from = |x, y| {
isometry
.rotation
.rotate_point(Point3::new(x, y, S::from(0.0).unwrap()))

Choose a reason for hiding this comment

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

Nit: Use S::zero() instead of S:from(0.0)

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

src/math.rs Outdated
}

fn transform(&self, isometry: &Isometry3<S>) -> Box<PointCulling<S>> {
let matrix = Matrix4::from(Decomposed {

Choose a reason for hiding this comment

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

Here we could nicely make use of the conversion methods between Decomposed and Isometry3, which were deleted 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.

done

for node_id in node_id_iterator {
let point_iterator = self.octree.points_in_node(self.point_location, node_id);
for point in point_iterator {
if let Err(err) = point_stream.push_point_and_callback(point) {

Choose a reason for hiding this comment

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

Can we just do point_stream.push_point_and_callback(point)?; instead?

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

I did some benchmarking running time (./target/release/octree_benchmark ~/octree_marco/ --no-client) on my workstation. Results are quite aligned, typically these

new:
real 0m3.662s user 0m3.500s sys 0m0.160s

old
real 0m3.563s user 0m3.408s sys 0m0.152s

@feuerste
Copy link

Can you please remove the .DS_Store file?


impl<S> PointCulling<S> for Aabb3<S>
where
S: 'static + BaseFloat + Sync + Send,

Choose a reason for hiding this comment

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

What do we 'static need for?

S: BaseFloat + Sync + Send,
{
fn contains(&self, point: &Point3<S>) -> bool;
fn intersects(&self, aabb: &Aabb3<S>) -> bool;

Choose a reason for hiding this comment

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

Supernit: Still not in the format

// TODO(username): Do something.

everywhere.

src/math.rs Outdated
@@ -150,22 +199,6 @@ impl<'a, S: BaseFloat> Mul<&'a Vector3<S>> for &'a Isometry3<S> {
}
}

impl<S: BaseFloat> Into<Decomposed<Vector3<S>, Quaternion<S>>> for Isometry3<S> {

Choose a reason for hiding this comment

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

It would be clearer to move them back exactly where they were before, so they don't show up as diff...

@catevita
Copy link
Contributor Author

Can you please remove the .DS_Store file?

Indeed it shows up in the list, but it as removed file

@feuerste
Copy link

Can you please remove the .DS_Store file?

Indeed it shows up in the list, but it as removed file

Ah, I see, thanks, I overlooked this...

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

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

☹️ Sorry, but only Googlers may change the label cla: yes.

@catevita catevita force-pushed the cvitadello/pointculling_trait branch from 6e01dbd to 897ebfd Compare June 19, 2019 08:34
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@catevita
Copy link
Contributor Author

@wally-the-cartographer merge

2 similar comments
@catevita
Copy link
Contributor Author

@wally-the-cartographer merge

@feuerste
Copy link

@wally-the-cartographer merge

@catevita
Copy link
Contributor Author

@gaschler sorry to bother you, Wally seems to be down again, could you help me merging this branch or pointing to the right person that mantains Wally?

@gaschler gaschler merged commit 616b957 into master Jun 19, 2019
@catevita
Copy link
Contributor Author

thanks!

@catevita catevita deleted the cvitadello/pointculling_trait branch July 4, 2019 04:16
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