-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Template intersections functions #646
Template intersections functions #646
Conversation
double test_cosine = plane_a.head<3>().dot(plane_b.head<3>()); | ||
double upper_limit = 1 + angular_tolerance; | ||
double lower_limit = 1 - angular_tolerance; | ||
Scalar test_cosine = plane_a.head(3).dot(plane_b.head(3)); |
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 you change <3>
to (3)
?
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.
Its does not compile with <3>()
http://pastebin.com/8zRHGj65
I found this in Eigen documentation (Vector Blocks section):
http://eigen.tuxfamily.org/dox/Eigen2ToEigen3.html
(3)
seems to be an strict equivalent to <3>()
; plus it's compiling
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.
(3)
seems to be an strict equivalent to<3>()
No, when the number is a template parameter it is a compile-time constant. I won't claim that in this particular situation it yields faster/more optimized code, but I do believe that generally it makes sense to give the compiler as much information as possible.
As for the compilation error, you need to add template
keyword, i.e. plane_a.template head<3> ().dot (plane_b.template head<3> ());
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 get the idea; not the syntax. I'll dig this later !
I'm updating the code right now
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.
Do this:
Scalar test_cosine = plane_a.head<3> ().dot(plane_b.head<3> ());
It is faster since you already know how much of the vector you need
@VictorLamoine as is we can't accept I am afraid, you will need to make some changes so that it becomes better (please read Sergey's comments and mine).
It would make the code much more readable and more elegant, |
I would avoid creating such typedefs in |
It still compiles and test is fine |
@taketwo if you put them inside the functions they will be just local anyway it is just a suggestion :) |
@nizar-sallem That's true, putting them into functions is fine. But this means that in the function argument list we still need to spell type names entirely.
That was just a counter-suggestion from my side :) |
@taketwo that is exactly what I meant inside function implementation not declaration I should have mentioned it. |
double angular_tolerance = 0.1); | ||
float angular_tolerance = 0.1) | ||
{ | ||
return ( planeWithPlaneIntersection<float> (plane_a, plane_b, line, angular_tolerance) ); |
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.
We don't put spaces inside parenthesis (also line 107).
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.
Should I always put a space before a parenthesis ?
.normalized ()
or .normalized()
?
.foo (5)
or .foo(5)
?
It's not clear in PCL Style guide: http://pointclouds.org/documentation/advanced/pcl_style_guide.php
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 refered to these spaces:
| |
v v
return ( planeWithPlaneIntersection<float> (plane_a, plane_b, line, angular_tolerance) );
As for your question, yes, always put a space. Excerpt from the guide:
We also include a space before the bracketed list of arguments to a function/method
@taketwo original version was with a double angular_tolerance that is why I said it can break the API and that is why the static cast is done. |
Hm... that is true, |
I commented on this sergey but basically he will need to do this
Or any equivalent form of his choice |
Oh, I see you comment, sorry. Okay, for |
Not sure if it has to be deprecated (I don't know what kind of values are taken by |
Not sure. But if they can, then the best way to be make tolerance a double independently from template scalar. |
I believe that was the main idea behind the double tolerance whereas the planes coefficients were floats so I won't change that and I would keep the tolerance as a double but again I don't believe I used this method before so I would stick with a common agreement ( @jspricke what do you think ?) |
@VictorLamoine a general comment on the unit test : don't bother using |
To summarize: Compiles & test unit is ok. |
I agree with Nizar, let's have double precision tolerance everywhere. |
Ok now all intersections functions uses doubles for precision/tolerance |
Could you also remove newline printing in the unit test so we do not get these gaps in test output:
|
Everything else looks fine for me. If others won't have any further comments I think we can merge. |
Same as for Sergey, looks fine for me except for the new lines. |
Done :
I also removed a useless typename in the |
Neat! Thanks for the effort. |
Template intersections functions
Regression fix for commit #646
It is my first attempt to template C++ functions so please review my code.
planeWithPlaneIntersection
andthreePlanesIntersection
are now templated to allow usage with floats/doubles.I also tested when using an Eclipse project; Eclipse still finds the functions definitions:
Test unit is working (testing both floats/doubles behaviour); the output is :