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

Fix refresh of LineSegmentShapeNode #1381

Merged
merged 3 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Fixed memory leaks from dart::gui::osg::Viewer: [#1349](https://github.com/dartsim/dart/pull/1349)
* Added point rendering mode to PointCloudShape: [#1351](https://github.com/dartsim/dart/pull/1351), [#1355](https://github.com/dartsim/dart/pull/1355)
* Updated ImGui to 1.71: [#1362](https://github.com/dartsim/dart/pull/1362)
* Fixed refresh of LineSegmentShapeNode: [#1381](https://github.com/dartsim/dart/pull/1381)

* dartpy

Expand Down
16 changes: 9 additions & 7 deletions dart/gui/osg/render/LineSegmentShapeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class LineSegmentShapeDrawable : public ::osg::Geometry

::osg::ref_ptr<::osg::Vec3Array> mVertices;
::osg::ref_ptr<::osg::Vec4Array> mColors;
::osg::ref_ptr<::osg::DrawElementsUInt> mElements;
};

//==============================================================================
Expand Down Expand Up @@ -187,8 +188,10 @@ LineSegmentShapeDrawable::LineSegmentShapeDrawable(
: mLineSegmentShape(shape),
mVisualAspect(visualAspect),
mVertices(new ::osg::Vec3Array),
mColors(new ::osg::Vec4Array)
mColors(new ::osg::Vec4Array),
mElements(new ::osg::DrawElementsUInt(::osg::PrimitiveSet::LINES))
{
addPrimitiveSet(mElements);
refresh(true);
}

Expand All @@ -207,18 +210,17 @@ void LineSegmentShapeDrawable::refresh(bool firstTime)
const common::aligned_vector<Eigen::Vector2i>& connections
= mLineSegmentShape->getConnections();

::osg::ref_ptr<::osg::DrawElementsUInt> elements
= new ::osg::DrawElementsUInt(::osg::PrimitiveSet::LINES);
elements->reserve(2 * connections.size());
mElements->clear();
mElements->reserve(2 * connections.size());

for (std::size_t i = 0; i < connections.size(); ++i)
{
const Eigen::Vector2i& c = connections[i];
elements->push_back(c[0]);
elements->push_back(c[1]);
mElements->push_back(static_cast<unsigned int>(c[0]));
mElements->push_back(static_cast<unsigned int>(c[1]));
}

addPrimitiveSet(elements);
setPrimitiveSet(0, mElements);
}

if (mLineSegmentShape->checkDataVariance(
Expand Down