MarkerExample demonstrates how to use the fiducial markers with MultiTouch cells and Cornerstone SDK. This example shows how marker information can be queried from the tracker and does simple visualization based on that information.
You can use virtual markers to try and run this application without actual MultiTouch Cell or printed marker. Press 'y' twice to change virtual input type to markers, and after that mouse press generates a dummy marker on screen.
The heart of the example is a custom widget, MarkerVisualizer, that we use to extend the functionality of the basic MultiWidgets::Widget class. MarkerVisualizer will render rectangles whenever a marker is placed on the widget. We define our custom widget by inheriting from MultiWidgets::Widget:
Because input handling and rendering are done at separately in Cornerstone, we need to store some marker information in our input handling so we can later reference it during rendering. Namely, we need a list of markers affecting the widget and the input transformation that is used to convert the marker location from screen coordinates to widget coordinates. We store this information in two private member variables in MarkerVisualizer:
Since we are interested in markers, we override the MultiWidgets::Widget::processMarkers function. In our own implementation, we store the list of markers affecting the widget and the input transformation used to convert the marker coordinates from screen coordinates to widget coordinates:
In order to visualize the markers, we override the renderContent function with our own implementation:
In our implementation, we first query the number of detected markers and iterate over all of them:
For every marker, we will render a rectangle and some text information about the marker in its location:
The transformation of Luminous::RenderContext is local to the widget coordinates inside the renderContent function. So to draw the marker, we transform the RenderContext to the marker's location using its location and rotation and then draw a rectangle and render some text.
The application itself consist of just creating an application instance and adding a fullscreen MarkerVisualizer widget to it.
The full source code for the example is listed below: