DGtal  0.9.3
viewer3D-10-interaction.cpp
1 
59 #include <iostream>
61 
62 #include "DGtal/base/Common.h"
63 #include "DGtal/helpers/StdDefs.h"
64 #include "DGtal/io/viewers/Viewer3D.h"
65 
67 
68 using namespace std;
69 using namespace DGtal;
70 using namespace Z3i;
71 
73 typedef MyViewer::SelectCallbackFct SelectCallbackFct;
74 typedef KSpace::SCell SCell;
75 
76 struct BigDataCells
77 {
78  KSpace K;
79  std::map< DGtal::int32_t, Z3i::SCell > cells;
80 };
81 
82 struct BigDataVoxels
83 {
84  std::map< DGtal::int32_t, Z3i::Point > voxels;
85 };
86 
87 int reaction1( void* viewer, DGtal::int32_t name, void* data )
88 {
89  BigDataCells* bg = (BigDataCells*) data;
90  stringstream ssMessage;
91  ssMessage << "Reaction1 with name " << name << " cell " << bg->K.sKCoords( bg->cells[ name ] ) ;
92  ((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
93  trace.info() << ssMessage.str() << std::endl;
94  return 0;
95 }
96 int reaction23( void* viewer, DGtal::int32_t name, void* data )
97 {
98  BigDataCells* bg = (BigDataCells*) data;
99  stringstream ssMessage;
100  ssMessage << "Reaction23 with name " << name << " cell " << bg->K.sKCoords( bg->cells[ name ] );
101  ((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
102  trace.info() << ssMessage.str() << std::endl;
103  return 0;
104 }
105 int reaction4( void* viewer, DGtal::int32_t name, void* data )
106 {
107  BigDataVoxels* bg = (BigDataVoxels*) data;
108  stringstream ssMessage;
109  ssMessage << "Reaction4 with name " << name << " Voxel " << bg->voxels[name] ;
110  ((MyViewer *) viewer)->displayMessage(QString(ssMessage.str().c_str()), 100000);
111  trace.info() << ssMessage.str() << std::endl;
112  return 0;
113 }
115 // Standard services - public :
116 
117 int main( int argc, char** argv )
118 {
119  QApplication application(argc,argv);
120  BigDataCells data;
121  BigDataVoxels dataV;
122  Point p1( 0, 0, 0 );
123  Point p2( 5, 5 ,5 );
124  Point p3( 2, 3, 4 );
125  KSpace & K = data.K;
126  K.init( p1, p2, true );
127  Point v1 = Z3i::Point(10, 10,10);
128  Point v2 = Z3i::Point(9, 9, 9);
129  Point v3 = Z3i::Point(11, 11,11);
130 
131  dataV.voxels[4001] = v1;
132  dataV.voxels[4002] = v2;
133  dataV.voxels[4003] = v3;
134 
135 
136  MyViewer viewer( K );
137  viewer.show();
138  viewer.displayMessage(QString("You can use [shift + click right] on surfels or voxel to interact ..."), 100000);
139  Z3i::SCell surfel1 = K.sCell( Point( 1, 1, 2 ), KSpace::POS );
140  Z3i::SCell surfel2 = K.sCell( Point( 3, 3, 4 ), KSpace::NEG );
141  Z3i::SCell surfel3 = K.sCell( Point( 5, 6, 5 ), KSpace::POS );
142  data.cells[ 10001 ] = surfel1;
143  data.cells[ 10002 ] = surfel2;
144  data.cells[ 10003 ] = surfel3;
145  viewer << SetMode3D( surfel1.className(), "Basic" );
146  viewer << SetName3D( 10001 ) << CustomColors3D( Color::Red, Color::Red ) << surfel1;
147  viewer << SetName3D( 10002 ) << CustomColors3D( Color::Green, Color::Green ) << surfel2;
148  viewer << SetName3D( 10003 ) << CustomColors3D( Color::Blue, Color::Blue ) << surfel3;
149  viewer << SetSelectCallback3D( reaction1, &data, 10001, 10001 );
150  viewer << SetSelectCallback3D( reaction23, &data, 10002, 10003 );
151 
152  // example by using voxel interaction:
153  viewer << SetName3D( 4001 ) << v1;
154  viewer << SetName3D( 4002 ) << v2;
155  viewer << SetName3D( 4003 ) << v3;
156  viewer << SetSelectCallback3D( reaction4, &dataV, 4001,4003 );
157  viewer<< MyViewer::updateDisplay;
158  return application.exec();
159 }
160 // //
Trace trace
Definition: Common.h:137
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
Display::SelectCallbackFct SelectCallbackFct
Definition: Viewer3D.h:143
std::string className() const
int main(int argc, char **argv)
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
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
KSpace K
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.