Example of extension of Viewer3D interface by deriving the class Viewer3D::Extension. Here we have added a callback to the "Shift+R" keypressed event, which adds a point randomly in the domain.
- See also
- moduleQGLExtension
Extending the Viewer3D interface: just press
Shift+R and you have new points added randomly in the scene."
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/viewers/Viewer3D.h"
using namespace Z3i;
struct RandomPointKeyExtension :
public Viewer3D<Space, KSpace>::Extension
{
RandomPointKeyExtension()
{
}
virtual bool keyPressEvent(
Viewer & viewer, QKeyEvent * event )
{
bool handled = false;
const Qt::KeyboardModifiers modifiers = event->modifiers();
if ( ( event->key() == Qt::Key_R ) && ( modifiers == Qt::ShiftModifier ) )
{
Point a( ( rand() % d[ 0 ] ) + p[ 0 ], ( rand() % d[ 1 ] ) + p[ 1 ],
( rand() % d[ 2 ] ) + p[ 2 ] );
viewer << a;
trace.
info() <<
"Adding point " << a << std::endl;
handled = true;
}
return handled;
}
{
viewer.setKeyDescription( Qt::ShiftModifier + Qt::Key_R,
"Creates a random digital point." );
}
virtual QString helpString(
const Viewer & )
const
{
QString text( "<h2> Random point Viewer3D </h2>" );
text += "Press Shift+R to add points.";
return text;
}
};
int main(
int argc,
char ** argv )
{
QApplication application( argc, argv );
viewer.setExtension( new RandomPointKeyExtension );
viewer.show();
viewer << p1 << p2 << p3;
viewer << MyViewer::updateDisplay;
return application.exec();
}
const KSpace & space() const
DGtal is the top-level namespace which contains all DGtal functions and types.
K init(Point(0, 0, 0), Point(512, 512, 512), true)
HyperRectDomain< Space > Domain