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

Addes TSR visualizer to aikido/rviz. #136

Merged
merged 13 commits into from
Apr 4, 2017
Merged

Addes TSR visualizer to aikido/rviz. #136

merged 13 commits into from
Apr 4, 2017

Conversation

gilwoolee
Copy link
Contributor

@gilwoolee gilwoolee commented Mar 10, 2017

This change is Reviewable

@gilwoolee gilwoolee requested a review from ClintLiddick March 10, 2017 23:40
@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.288% when pulling 48e929c on rviz/visualizeTSR into 6a94d4b on master.

Copy link
Member

@mkoval mkoval left a comment

Choose a reason for hiding this comment

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

🎉 Thanks for adding this. This is very useful.

I added a few minor comments, but am happy to merge this once they are addressed.


for(int i = 0; i < nSamples && sampler->canSample(); ++i)
{
sampler->sample(state);
Copy link
Member

Choose a reason for hiding this comment

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

Check the return value of sample. In principle it should not return false if canSample() returned true, so an assertion would be fine.

sampler->sample(state);

std::stringstream sstm;
sstm << "tsr" << i;
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Make the base name a std::string parameter. I suggest making it default to something that includes the &tsr (or, even better, the memory address of the return value) to avoid name collisions.

auto tsrFrame = std::make_shared<SimpleFrame>(
Frame::World(), sstm.str(), state.getIsometry());
mSimpleFrames.push_back(tsrFrame);
this->addFrame(tsrFrame.get());
Copy link
Member

Choose a reason for hiding this comment

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

Nit: We don't typically explicitly specify this-> unless there is a name conflict.

Also, I'd prefer to aggregate all of the FrameMarkerPtrs returned by addFrame into an RAII object (perhaps TSRMarker 😉) that we return from this function. That would also make clearTSRs and the mSimpleFrames member variable superfluous, since they could be replaced by the RAII object.

@@ -32,6 +33,10 @@ class InteractiveMarkerViewer {
SkeletonMarkerPtr CreateSkeletonMarker(
dart::dynamics::SkeletonPtr const &skeleton);

/// Visualizes tsr with at most n samples
void visualizeTSR(const aikido::constraint::TSR& _tsr, int nSamples = 10);
Copy link
Member

Choose a reason for hiding this comment

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

Please add a full docstring.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.288% when pulling 929f988 on rviz/visualizeTSR into 67747e1 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.391% when pulling a68bdae on rviz/visualizeTSR into 963a5d7 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.391% when pulling 09ca6c9 on rviz/visualizeTSR into 963a5d7 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.391% when pulling 09ca6c9 on rviz/visualizeTSR into 963a5d7 on master.

@@ -49,6 +50,42 @@ FrameMarkerPtr InteractiveMarkerViewer::addFrame(
return marker;
}

TSRMarkerPtr InteractiveMarkerViewer::visualizeTSR(
Copy link
Member

Choose a reason for hiding this comment

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

Rename this to addTSRMarker to be consistent with addFrameMarker.

TSRMarkerPtr InteractiveMarkerViewer::visualizeTSR(
aikido::constraint::TSR const &_tsr,
int nSamples,
std::string basename)
Copy link
Member

Choose a reason for hiding this comment

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

Take basename by const std::string&.

if (basename == "")
{
std::ostringstream ost;
ost << &tsrMarker;
Copy link
Member

Choose a reason for hiding this comment

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

tsrMarker is a smart_ptr, so this should be tsrMarker.get() to get the memory address of the heap memory. It's possible that repeated calls of this function in a loop could allocate tsrMarker itself at the same memory address on the stack.

auto state = _tsr.getSE3()->createState();
auto tsrMarker = std::make_shared<TSRMarker>();

if (basename == "")
Copy link
Member

Choose a reason for hiding this comment

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

Nit: basename.empty().

assert(sampler->sample(state));

std::stringstream ss;
ss << "Marker[" << basename << "].frame[" << i << "]";
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Marker -> TSRMarker to avoid collisions with other markers we add in the future.

TSRMarker();
~TSRMarker(){};

void addFrameMarker(FrameMarkerPtr const &marker);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should be part of the public API. The simplest option would be to modify TSRMarker's constructor to directly accept the std::set<FrameMarkerPtr>.

class TSRMarker {
public:
TSRMarker();
~TSRMarker(){};
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Use ~TSRMarker = default instead.

namespace aikido {
namespace rviz {

class TSRMarker {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Either mark this as final or mark the destructor as virtual.

void addFrameMarker(FrameMarkerPtr const &marker);

private:
std::set<FrameMarkerPtr> mFrameMarkers;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Why does this need to be an std::set? I'd prefer an std::vector here, since linear memory is a lot simpler than a red-black tree, if we don't require uniqueness.

@gilwoolee
Copy link
Contributor Author

@mkoval I think I addressed all of your comments. Please take a look. Thanks for the help!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.391% when pulling e964439 on rviz/visualizeTSR into 963a5d7 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.391% when pulling e964439 on rviz/visualizeTSR into 963a5d7 on master.

Copy link
Member

@mkoval mkoval left a comment

Choose a reason for hiding this comment

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

LGTM. I left one minor comment, but feel free to ignore.

auto tsrFrame = std::make_shared<SimpleFrame>(
Frame::World(), ss.str(), state.getIsometry());
auto frameMarker = addFrame(tsrFrame.get());
tsrFrames.emplace_back(tsrFrame);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could we use unique_ptr instead of shared_ptr here?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.391% when pulling 4e62ebc on rviz/visualizeTSR into 4cd2795 on master.

@gilwoolee
Copy link
Contributor Author

@mkoval Would you mind taking a last look before I merge this? It just changes shared_ptr to unique_ptr, taking your last suggestion. :)

Copy link
Member

@mkoval mkoval left a comment

Choose a reason for hiding this comment

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

Looks good to me! @gilwoolee feel free to merge.

@@ -17,6 +17,10 @@ class SkeletonMarker;
typedef std::shared_ptr<SkeletonMarker> SkeletonMarkerPtr;
typedef std::shared_ptr<SkeletonMarker const> SkeletonMarkerConstPtr;

class TSRMarker;
typedef std::shared_ptr<TSRMarker> TSRMarkerPtr;
typedef std::shared_ptr<TSRMarker const> TSRMarkerConstPtr;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Prefer using aliases to typedefs.

Copy link
Member

Choose a reason for hiding this comment

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

Please place const before type. See above.

Copy link
Member

@jslee02 jslee02 left a comment

Choose a reason for hiding this comment

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

Commented some style related nitpicks.

namespace aikido {
namespace rviz {

TSRMarker::TSRMarker(std::vector<std::unique_ptr<SimpleFrame>> tsrFrames)
Copy link
Member

Choose a reason for hiding this comment

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

We could use rvalue reference (std::vector<std::unique_ptr<SimpleFrame>>&& tsrFrames) here to prevent unnecessary copy.

Copy link
Member

Choose a reason for hiding this comment

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

This already doesn't make any copies if the caller uses std::move, e.g.:

// Caller std::move's from local variable to argument:
std::vector<std::unique_ptr<SimpleFrame>> frames = /* ... */;
auto marker = TSRMarker{std::move(frames)};

// Constructor std::moves from argument to member variable:
TSRMarker::TSRMarker(std::vector<std::unique_ptr<SimpleFrame>> frames)
  : markers{std::move(frames)} {}

Note that std::vector<std::unique_ptr<...>> is not copyable, so we already must not be introducing an extra copy. 😉

My general understanding is that rvalue references are only useful for: (1) move constructors and (2) perfect forwarding in templates due to reference collapsing.

Copy link
Member

Choose a reason for hiding this comment

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

This already doesn't make any copies if the caller uses std::move

That is true, but the explicit rvalue argument could prevent passing lvalue by accident (if I'm missing something here). For example:

class TSRMarker
{
public:
  TSRMarker(std::vector<std::unique_ptr<SimpleFrame>>&& tsrFrames);
  // ...
};
std::vector<std::unique_ptr<SimpleFrame>> frames = /* ... */;
auto marker1 = TSRMarker{frames}; // error
auto marker2 = TSRMarker{std::move(frames)}; // okay

Copy link
Member

@jslee02 jslee02 Apr 3, 2017

Choose a reason for hiding this comment

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

Note that std::vector<std::unique_ptr<...>> is not copyable, so we already must not be introducing an extra copy.

Hm, this is what I missed. It still prevents passing lvalue even without making it rvalue reference but in a different way (we get different error messages).

I still prefer to make the argument explicitly rvalue reference because we always expect to pass rvalue here. However, I am not strongly against leaving it as it is since it works as we intend anyway.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree! 😬 I prefer to leave copy versus move up to the caller (i.e. leave the code as it is).

I don't feel particularly strongly either way, so let's leave it up to @gilwoolee to decide. 😄

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel particularly strongly either way, so let's leave it up to @gilwoolee to decide.

👍

My only concern is that the caller is not able to pass lvalue anyway (whether or not the argument is rvalue reference because copy assignment of std::unique_ptr is not defined), but explicit rvalue reference argument could give us hint why the caller cannot pass lvalue.

Alright, let's pass the baton to @gilwoolee. 😈

/// \param basename Basename for markers
/// \return TSRMarkerPtr contains sampled frames of TSR.
TSRMarkerPtr addTSRMarker(
aikido::constraint::TSR const &tsr,
Copy link
Member

Choose a reason for hiding this comment

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

I believe the convention is to place const before type and space after & as const aikido::constraint::TSR& tsr.

/// \return TSRMarkerPtr contains sampled frames of TSR.
TSRMarkerPtr addTSRMarker(
aikido::constraint::TSR const &tsr,
int nSamples = 10, const std::string &basename = "");
Copy link
Member

Choose a reason for hiding this comment

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

Please put a space after & not not before. See above.

@@ -17,6 +17,10 @@ class SkeletonMarker;
typedef std::shared_ptr<SkeletonMarker> SkeletonMarkerPtr;
typedef std::shared_ptr<SkeletonMarker const> SkeletonMarkerConstPtr;

class TSRMarker;
typedef std::shared_ptr<TSRMarker> TSRMarkerPtr;
typedef std::shared_ptr<TSRMarker const> TSRMarkerConstPtr;
Copy link
Member

Choose a reason for hiding this comment

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

Please place const before type. See above.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.391% when pulling 7fd58e1 on rviz/visualizeTSR into 4cd2795 on master.

@jslee02 jslee02 added this to the Aikido 0.1.0 milestone Apr 4, 2017
@gilwoolee gilwoolee merged commit 9c977e3 into master Apr 4, 2017
@gilwoolee gilwoolee deleted the rviz/visualizeTSR branch April 4, 2017 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants