DGtal  1.3.beta
io/viewers/viewer3D-10-interaction.cpp

Simple selection of a surfel (with shift + left click) with the QGLViewer proposed by DGtal (Viewer3D). You may associates names (i.e. integers) to surfels or to group of surfels. You may associate reactions or callback functions to named graphical objects (surfels in DGtal 0.9).

The red surfel is given the name 10001, the green 10002 and the blue

  1. A specific reaction is associated with surfel 10001, while a common reaction is associated with surfels 10002 and 10003. The reactions simply display the clicked surfel.
See also
Limited interaction when using selection with QGLViewer Viewer3D stream mechanism
* $ ./examples/io/viewers/viewer3D-10-interaction
* 
Example of viewer3D interaction with the selection of surfels.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/viewers/Viewer3D.h"
using namespace std;
using namespace DGtal;
using namespace Z3i;
typedef MyViewer::SelectCallbackFct SelectCallbackFct;
struct BigDataCells
{
std::map< DGtal::int32_t, Z3i::SCell > cells;
};
struct BigDataVoxels
{
std::map< DGtal::int32_t, Z3i::Point > voxels;
};
int reaction1( void* viewer, DGtal::int32_t name, void* data )
{
BigDataCells* bg = (BigDataCells*) data;
stringstream ssMessage;
ssMessage << "Reaction1 with name " << name << " cell " << bg->K.sKCoords( bg->cells[ name ] ) ;
((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
trace.info() << ssMessage.str() << std::endl;
return 0;
}
int reaction23( void* viewer, DGtal::int32_t name, void* data )
{
BigDataCells* bg = (BigDataCells*) data;
stringstream ssMessage;
ssMessage << "Reaction23 with name " << name << " cell " << bg->K.sKCoords( bg->cells[ name ] );
((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
trace.info() << ssMessage.str() << std::endl;
return 0;
}
int reaction4( void* viewer, DGtal::int32_t name, void* data )
{
BigDataVoxels* bg = (BigDataVoxels*) data;
stringstream ssMessage;
ssMessage << "Reaction4 with name " << name << " Voxel " << bg->voxels[name] ;
((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
trace.info() << ssMessage.str() << std::endl;
return 0;
}
// Standard services - public :
int main( int argc, char** argv )
{
QApplication application(argc,argv);
BigDataCells data;
BigDataVoxels dataV;
Point p1( 0, 0, 0 );
Point p2( 5, 5 ,5 );
Point p3( 2, 3, 4 );
KSpace & K = data.K;
K.init( p1, p2, true );
Point v1 = Z3i::Point(10, 10,10);
Point v2 = Z3i::Point(9, 9, 9);
Point v3 = Z3i::Point(11, 11,11);
dataV.voxels[4001] = v1;
dataV.voxels[4002] = v2;
dataV.voxels[4003] = v3;
MyViewer viewer( K );
viewer.show();
viewer.displayMessage(QString("You can use [shift + click right] on surfels or voxel to interact ..."), 100000);
Z3i::SCell surfel1 = K.sCell( Point( 1, 1, 2 ), KSpace::POS );
Z3i::SCell surfel2 = K.sCell( Point( 3, 3, 4 ), KSpace::NEG );
Z3i::SCell surfel3 = K.sCell( Point( 5, 6, 5 ), KSpace::POS );
data.cells[ 10001 ] = surfel1;
data.cells[ 10002 ] = surfel2;
data.cells[ 10003 ] = surfel3;
viewer << SetMode3D( surfel1.className(), "Basic" );
viewer << SetName3D( 10001 ) << CustomColors3D( Color::Red, Color::Red ) << surfel1;
viewer << SetName3D( 10002 ) << CustomColors3D( Color::Green, Color::Green ) << surfel2;
viewer << SetName3D( 10003 ) << CustomColors3D( Color::Blue, Color::Blue ) << surfel3;
viewer << SetSelectCallback3D( reaction1, &data, 10001, 10001 );
viewer << SetSelectCallback3D( reaction23, &data, 10002, 10003 );
// example by using voxel interaction:
viewer << SetName3D( 4001 ) << v1;
viewer << SetName3D( 4002 ) << v2;
viewer << SetName3D( 4003 ) << v3;
viewer << SetSelectCallback3D( reaction4, &dataV, 4001,4003 );
return application.exec();
}
// //
DGtal::Viewer3D< Space, KSpace >::SelectCallbackFct
Display::SelectCallbackFct SelectCallbackFct
Definition: Viewer3D.h:148
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::int32_t
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
DGtal::KhalimskySpaceND::sCell
SCell sCell(const SPreCell &c) const
From a signed cell, returns a signed cell lying into this Khalismky space.
DGtal::trace
Trace trace
Definition: Common.h:154
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Display3D::updateDisplay
@ updateDisplay
Definition: Display3D.h:249
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::SetName3D
Definition: DrawWithDisplay3DModifier.h:242
DGtal::Trace::info
std::ostream & info()
DGtal::SignedKhalimskyCell::className
std::string className() const
Return the style name used for drawing this object.
DGtal::Viewer3D< Space, KSpace >
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::KhalimskySpaceND::POS
static const constexpr Sign POS
Definition: KhalimskySpaceND.h:432
DGtal::CustomColors3D
Definition: DrawWithDisplay3DModifier.h:129
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::SetSelectCallback3D
Definition: DrawWithDisplay3DModifier.h:257
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::KhalimskySpaceND::NEG
static const constexpr Sign NEG
Definition: KhalimskySpaceND.h:433
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64