DGtal  0.9.2
viewer3D-10-interaction.cpp
1 
33 #include <iostream>
35 
36 #include "DGtal/base/Common.h"
37 #include "DGtal/helpers/StdDefs.h"
38 #include "DGtal/io/viewers/Viewer3D.h"
39 
41 
42 using namespace std;
43 using namespace DGtal;
44 using namespace Z3i;
45 
47 typedef MyViewer::SelectCallbackFct SelectCallbackFct;
48 typedef KSpace::SCell SCell;
49 
50 struct BigDataCells
51 {
52  KSpace K;
53  std::map< DGtal::int32_t, Z3i::SCell > cells;
54 };
55 
56 struct BigDataVoxels
57 {
58  std::map< DGtal::int32_t, Z3i::Point > voxels;
59 };
60 
61 int reaction1( void* viewer, DGtal::int32_t name, void* data )
62 {
63  BigDataCells* bg = (BigDataCells*) data;
64  stringstream ssMessage;
65  ssMessage << "Reaction1 with name " << name << " cell " << bg->K.sKCoords( bg->cells[ name ] ) ;
66  ((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
67  trace.info() << ssMessage.str() << std::endl;
68  return 0;
69 }
70 int reaction23( void* viewer, DGtal::int32_t name, void* data )
71 {
72  BigDataCells* bg = (BigDataCells*) data;
73  stringstream ssMessage;
74  ssMessage << "Reaction23 with name " << name << " cell " << bg->K.sKCoords( bg->cells[ name ] );
75  ((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
76  trace.info() << ssMessage.str() << std::endl;
77  return 0;
78 }
79 int reaction4( void* viewer, DGtal::int32_t name, void* data )
80 {
81  BigDataVoxels* bg = (BigDataVoxels*) data;
82  stringstream ssMessage;
83  ssMessage << "Reaction4 with name " << name << " Voxel " << bg->voxels[name] ;
84  ((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
85  trace.info() << ssMessage.str() << std::endl;
86  return 0;
87 }
89 // Standard services - public :
90 
91 int main( int argc, char** argv )
92 {
93  QApplication application(argc,argv);
94  BigDataCells data;
95  BigDataVoxels dataV;
96  Point p1( 0, 0, 0 );
97  Point p2( 5, 5 ,5 );
98  Point p3( 2, 3, 4 );
99  KSpace & K = data.K;
100  K.init( p1, p2, true );
101  Point v1 = Z3i::Point(10, 10,10);
102  Point v2 = Z3i::Point(9, 9, 9);
103  Point v3 = Z3i::Point(11, 11,11);
104 
105  dataV.voxels[4001] = v1;
106  dataV.voxels[4002] = v2;
107  dataV.voxels[4003] = v3;
108 
109 
110  MyViewer viewer( K );
111  viewer.show();
112  viewer.displayMessage(QString("You can use [shift + click right] on surfels or voxel to interact ..."), 100000);
113  Z3i::SCell surfel1 = K.sCell( Point( 1, 1, 2 ), KSpace::POS );
114  Z3i::SCell surfel2 = K.sCell( Point( 3, 3, 4 ), KSpace::NEG );
115  Z3i::SCell surfel3 = K.sCell( Point( 5, 6, 5 ), KSpace::POS );
116  data.cells[ 10001 ] = surfel1;
117  data.cells[ 10002 ] = surfel2;
118  data.cells[ 10003 ] = surfel3;
119  viewer << SetMode3D( surfel1.className(), "Basic" );
120  viewer << SetName3D( 10001 ) << CustomColors3D( Color::Red, Color::Red ) << surfel1;
121  viewer << SetName3D( 10002 ) << CustomColors3D( Color::Green, Color::Green ) << surfel2;
122  viewer << SetName3D( 10003 ) << CustomColors3D( Color::Blue, Color::Blue ) << surfel3;
123  viewer << SetSelectCallback3D( reaction1, &data, 10001, 10001 );
124  viewer << SetSelectCallback3D( reaction23, &data, 10002, 10003 );
125 
126  // example by using voxel interaction:
127  viewer << SetName3D( 4001 ) << v1;
128  viewer << SetName3D( 4002 ) << v2;
129  viewer << SetName3D( 4003 ) << v3;
130  viewer << SetSelectCallback3D( reaction4, &dataV, 4001,4003 );
131  viewer<< MyViewer::updateDisplay;
132  return application.exec();
133 }
134 // //
std::string className() const
Trace trace
Definition: Common.h:130
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
Display::SelectCallbackFct SelectCallbackFct
Definition: Viewer3D.h:143
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.