DGtal  1.4.beta
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 // //
DGtal::Viewer3D< Space, KSpace >::SelectCallbackFct
Display::SelectCallbackFct SelectCallbackFct
Definition: Viewer3D.h:144
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
SCell
Z3i::SCell SCell
Definition: digitalPolyhedronBuilder3D.cpp:79
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