How to create a Line and Sphere in the Interactive Views

Hello,

Looking through the SDK Documentation maybe I missed the way to do this.
I am looking for a way to make lines, measurements and spheres appear in the Interactive Views.

Also if it’s possible, be able to click and select a point that has been created, move it around, etc.

Anything that enables that level of interaction?

Thanks!

Hi Jonathan,

I’m sorry to hear that you could not find the feature in the SDK documentation. If you search for the “Visualization and Views” page it will provide you with an overview.

Anyway, let me help you with some concrete pointers and examples:
What you are looking for is the collection of GlAnnotation classes which can be added to views in order show measurements etc. For instance, use the GlLine for a line segment that can also be used for measuring or the GlBall for a simple sphere approximated by three circles.
After creation and configuration you can add them to any view by calling GlView::addObject() so that it will be rendered inside that view. The instance has to remain alive as long as it is part of any view.

auto glLine = std::make_unique<GlLine>();   // store that pointer somewhere to keep it alive
glLine ->setPoints({1, 2, 3}, {4, 5, 6});    // set the two end points of the line in world coordinates
glLine ->setColor({1, 0, 0});                // make it show in red
displayWidget->view2D()->view()->addObject(glLine .get());  // show it in the 2D view

If you want the user to be able to manipulate it with the mouse, you have to pair it with a Manipulator inside an InteractiveObject. For most annotation types you can use the PointBasedAnnotationManipulator:

// create the annotation
auto glLine = std::make_unique<GlLine>();
...
// create a manipulator for it
auto manip = std::make_unique<PointBasedAnnotationManipulator>(*glLine);
manip->setAllowedInteractions({PointBasedAnnotationManipulator::InteractionCreate}); // maybe also other flags like `InteractionMove` depending on use case
manip->setInteractionMode(PointBasedAnnotationManipulator::InteractionCreate, false);

// combine the two into an InteractiveAnnotation
auto interactiveObject = std::make_unique<InteractiveAnnotation>(nullptr, glLine.release(), manip.release());

// add them to the view, note that we call `InteractiveView::addObject()` here and not `GlView::addObject()`
displayWidget->view2D()->addObject(interactiveObject.get());  // show it in the 2D view

I hope this helps. Best,
Christian