Skip to content

Commit

Permalink
Fix refresh of LineSegmentShapeNode (#1381)
Browse files Browse the repository at this point in the history
* Fix refresh of LineSegmentShapeNode

* Update changelog

* Fix element vector update
  • Loading branch information
jslee02 authored Jul 31, 2019
1 parent d8f2636 commit 74317c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

0 comments on commit 74317c5

Please sign in to comment.