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

PointCloud in YARP #1597

Merged
merged 55 commits into from Apr 5, 2018
Merged

PointCloud in YARP #1597

merged 55 commits into from Apr 5, 2018

Conversation

Nicogene
Copy link
Member

@Nicogene Nicogene commented Mar 15, 2018

This PR introduces the PointCloud type in YARP 🎉

A nice documentation page has been added under "YARP tutorials"

image

Probably the most important feature is the total compatibility with the PCL PointCloud.
In this sense in the documentation has been added a section where is explained how to convert a yarp cloud in a pcl cloud and viceversa.

image

Please review code.

@Nicogene Nicogene added PR Type: Feat/Enh This PR adds some new feature or enhances some part of YARP Component: Library - YARP_sig PR Status: Changelog - OK This PR has a proper changelog entry Target: YARP v3.0.0 labels Mar 15, 2018
template< class T1, class T2 >
inline bool toPCL(yarp::sig::PointCloud< T1 > &yarpCloud, ::pcl::PointCloud< T2 > &pclCloud)
{
yAssert(sizeof(T1) == sizeof(T2));
Copy link
Member

Choose a reason for hiding this comment

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

static_assert ?
As you are directly copyng the raw memory, perhaps it is even safer to just defined the template to operate on one consistent type.

Copy link
Member Author

@Nicogene Nicogene Mar 15, 2018

Choose a reason for hiding this comment

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

The problem here is that we can't have any control on T2 because it is a pcl's type, the only thing that I can check is that the sizeof of the yarp type and the pcl type are the same.

I used static_assert inside the yarp PointCloud for defining which T1 are allowed and supported for now, the problem is that with the static_assert we can add the corresponding list of pcl supported types but inside these conversion functions (toPcl and fromPcl) we cannot check the correspondence between the yarp type and pcl type (e.g. yarp::sig::XYZ_DATA and pcl::PointXYZ)

Note that it is possible that sizeof(T1)==sizeof(T2) but the two types can be incompatible.
Example:
sizeof(yarp::sig::XYZ_DATA) is equal to sizeof(pcl::Normal) but they have different fields.

This check is not sufficient to be 100% safe but better than nothing 😅
I hope that the user will these functions with the correct types and not try some exotic conversions like yarp XYZ to pcl NxNyNz (Normals):sweat_smile:

Copy link
Member

Choose a reason for hiding this comment

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

I see, T1 is something like struct vec3 { double x; double y; double z; } and in memcpy you are relying of the memory structure of the two types to be the same, I get it.
However, I think it is is desirable to transform this in static_assert(sizeof(T1) == sizeof(T2)).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah ok now I get your point, yes probably is better static_assert in this case 👍

Copy link
Collaborator

@claudiofantacci claudiofantacci left a comment

Choose a reason for hiding this comment

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

LGTM!
Just noticed some minor (picky) typos.

}

/**
* Convert a pcl::PointCloud to a yarp::sig::PointCloud object
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is an extra space before and after pcl::PointCloud and after yarp::sig::PointCloud.

}


/** \brief Concatenate a point cloud to the current cloud.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably missing a newline after /**?

return (*this);
}

/** \brief Concatenate a point cloud to another cloud.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably missing a newline after /**?

class yarp::sig::PointCloudNetworkHeader
{
public:
PointCloudNetworkHeader() : width(10),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and the following lines the indentation seems somwhat wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems ok 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is how I see it.
schermata 2018-03-15 alle 19 40 08
There are extra spaces here and there after the default constructor semicolon 😄

Copy link
Member Author

@Nicogene Nicogene Mar 15, 2018

Choose a reason for hiding this comment

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

Ah ok I see, I thought was referred to the indentation of public 😅

@traversaro
Copy link
Member

Why XY_DATA and all the other data structures are named using ALL_CAPITAL_LETTERS_WITH_UNDERSCORE style (typically used for macros in C/C++) while the rest of classes in YARP are named using the CamelCaseClassName style?

@Nicogene
Copy link
Member Author

Nicogene commented Mar 15, 2018

@traversaro because they are struct and not class (?).
The names have been chosen by @barbalberto 😅

@Nicogene Nicogene force-pushed the pointCloud_typeTRUE branch 2 times, most recently from 1b1be65 to be5e191 Compare March 16, 2018 09:54
@Nicogene Nicogene changed the title [WIP] PointCloud in YARP PointCloud in YARP Mar 16, 2018
@pattacini
Copy link
Member

Thanks @Nicogene and @barbalberto for this awesome integration 💖

We have the urge to merge this PR in order to start testing an online viewer of point clouds.
Any outstanding point still to discuss?

@Nicogene
Copy link
Member Author

Nicogene commented Mar 19, 2018

All tests passed, for me the PR is ready to be merged.

@@ -49,6 +49,7 @@ Using YARP devices:
\li \subpage yarp_config_files

More software tutorials:
\li \subpage yarp_pointcloud
Copy link
Member

Choose a reason for hiding this comment

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

I would add this page also on the Interoperability and advanced use section in the main page of YARP.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it possible to do it without restarting all the tests ? 😬

Copy link
Member

Choose a reason for hiding this comment

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

@Nicogene let's be flexible and add this change after the merge 😉 (if you like to have the green lights within the PR)

Copy link
Member

Choose a reason for hiding this comment

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

Please fix this as suggested by @traversaro in next iteration

Copy link
Member Author

@Nicogene Nicogene Apr 4, 2018

Choose a reason for hiding this comment

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

DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/yarp)

set_property(GLOBAL APPEND PROPERTY YARP_LIBS YARP_pcl)
#set_property(TARGET YARP_pcl PROPERTY FOLDER "Libraries")
Copy link
Member

Choose a reason for hiding this comment

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

This line can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it is a copy-paste from the CMakeLists.txt of libYARP_eigen.
(If you uncomment this line the CMake complaints, so I think it is better to remove it 🤔)


/**
* Convert a yarp::sig::PointCloud to a pcl::PointCloud object
* @param yarpCloud yarp::sig::PointCloud input
Copy link
Member

Choose a reason for hiding this comment

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

@param[in] ?

* @return a pcl PointCloud filled with data contained in the yarp cloud.
*/
template< class T1, class T2 >
inline bool toPCL(yarp::sig::PointCloud< T1 > &yarpCloud, ::pcl::PointCloud< T2 > &pclCloud)
Copy link
Member

Choose a reason for hiding this comment

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

If yarpCloud is just an input argument, perhaps we can have const yarp::sig::PointCloud< T1 > &yarpCloud?


/**
* Convert a pcl::PointCloud to a yarp::sig::PointCloud object
* @param pclCloud pcl::PointCloud input
Copy link
Member

Choose a reason for hiding this comment

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

@param[in]

/**
* Convert a pcl::PointCloud to a yarp::sig::PointCloud object
* @param pclCloud pcl::PointCloud input
* @return a yarp cloud filled with data contained in the pcl cloud.
Copy link
Member

Choose a reason for hiding this comment

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

Missing yarpCloud docs.

inline PointCloud<T>&
operator+=(const PointCloud<T>& rhs)
{
//TODO: take the newest timestamp
Copy link
Member

Choose a reason for hiding this comment

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

If this is an actual TODO, can you open a issue in the YARP issue tracker?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that I can remove it, in PCL the operator+= takes the newest timestamp because the timestamp is in the pointcloud header, but in YARP is handled on another level.

{
//TODO: take the newest timestamp

yAssert(getPointType() == rhs.getPointType());
Copy link
Member

Choose a reason for hiding this comment

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

Some gentler error, or perhaps document this behavior in the docs?

}

inline void push_back (const T& pt)
{
Copy link
Member

Choose a reason for hiding this comment

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

The indentation of this method is different.

*/
virtual void fromExternalPC(const char* source, int type, size_t width, size_t height, bool isDense = true)
{
yAssert(source);
Copy link
Member

Choose a reason for hiding this comment

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

As before, are you sure that crashing is a sensible behavior (especially if not documented) for wrong parameters?

Copy link
Member Author

Choose a reason for hiding this comment

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

yarp::sig::Image* classes are plenty of these yAssert 😅
I think that the assert is necessary in these cases, but probably it is better to document it

Copy link
Member

Choose a reason for hiding this comment

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

I see, then it is a discussion worth having on another place.

// yarp::sig::Vector orientation; // orientation wrt origin -- could be an Eigen::Quaternion for better PCL compatibility if yarp can afford to depend from it

// YARPish fileds
// char *data; // actual pointCloud data.
Copy link
Member

Choose a reason for hiding this comment

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

If all this commented line are not necessary, can we remove them?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that it is better to keep it for the future improvements

Copy link
Member

Choose a reason for hiding this comment

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

if you leave them here with no comment at all, just commented out, nobody will never know what are those lines and why they are here. Hence I agree with @traversaro

@traversaro
Copy link
Member

Added some comments but:

  • I was not able to review all the PR
  • Comments are quite picky, can be ignored if the mantainer is ok, or can be addressed after the merge

@Nicogene
Copy link
Member Author

I can do the changes requested by @traversaro, and I think that tomorrow should be ready.
I know that @pattacini needs it, I don't know how much it is urgent!
@drdanz any comment?

@Nicogene Nicogene force-pushed the pointCloud_typeTRUE branch 2 times, most recently from 352bc27 to 8b7fe66 Compare March 19, 2018 16:52
@Nicogene Nicogene added this to To do in YARP v3.0.0 (2018-06-11) via automation Mar 20, 2018
@Nicogene Nicogene moved this from To do to In progress in YARP v3.0.0 (2018-06-11) Mar 20, 2018
Copy link
Collaborator

@barbalberto barbalberto left a comment

Choose a reason for hiding this comment

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

👍

@Nicogene
Copy link
Member Author

Rebased over last devel, waiting that passes all tests...

@drdanz
Copy link
Member

drdanz commented Apr 5, 2018

Fixed copyright headers, renamed structures to "DataXxx" in order to have some kind of "namespacing", and cleanup... Now LGTM

@drdanz drdanz merged commit 808e674 into robotology:devel Apr 5, 2018
YARP v3.0.0 (2018-06-11) automation moved this from In progress to Done Apr 5, 2018
@drdanz
Copy link
Member

drdanz commented Apr 5, 2018

Merged, thanks.

@drdanz drdanz added Resolution: Merged and removed PR Status: Commits - Not OK Commits in this PR needs to be squashed or re-organized labels Apr 5, 2018
@Nicogene Nicogene deleted the pointCloud_typeTRUE branch April 5, 2018 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Library - YARP_sig PR Status: Changelog - OK This PR has a proper changelog entry PR Type: Feat/Enh This PR adds some new feature or enhances some part of YARP Resolution: Merged Target: YARP v3.0.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

8 participants