DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testSphericalAccumulatorQGL.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/geometry/tools/SphericalAccumulator.h"
36 
37 using namespace std;
38 using namespace DGtal;
39 
41 // Functions for testing class SphericalAccumulator.
43 
44 
45 
46 #include <QtGui/qapplication.h>
47 #include "DGtal/io/viewers/Viewer3D.h"
48 bool testSphericalViewer(int argc, char **argv)
49 {
50  QApplication application(argc,argv);
51 
52  trace.beginBlock ( "Testing Spherical Accumulator Viewer..." );
53 
54  typedef Z3i::RealVector Vector;
55 
56  SphericalAccumulator<Vector> accumulator(15);
57  trace.info()<< accumulator << std::endl;
58 
59  for(unsigned int i=0; i< 10000; i++)
60  accumulator.addDirection( Vector (1+10.0*(rand()-RAND_MAX/2)/(double)RAND_MAX,
61  (1+10.0*(rand()-RAND_MAX/2))/(double)RAND_MAX,
62  (1+10.0*(rand()-RAND_MAX/2))/(double)RAND_MAX));
63 
64  Viewer3D viewer;
65  viewer.show();
66  Vector a,b,c,d;
67  viewer << accumulator;
68 
69  trace.info() << "Bin values: ";
70  for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
71  it != itend;
72  ++it)
73  trace.info() << *it<<" ";
74  trace.info() << std::endl;
75  trace.info() << accumulator<<std::endl;
76 
77  viewer << Viewer3D::updateDisplay;
78  bool res = application.exec();
79  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
80  trace.endBlock();
81  return res ? 0 : 1;
82 }
83 bool testSphericalViewerInteger(int argc, char **argv)
84 {
85  QApplication application(argc,argv);
86 
87  trace.beginBlock ( "Testing Spherical Accumulator Viewer with Integer numbers..." );
88 
89  typedef Z3i::Vector Vector;
90 
91  SphericalAccumulator<Vector> accumulator(15);
92  trace.info()<< accumulator << std::endl;
93 
94  for(unsigned int i=0; i< 10000; i++)
95  accumulator.addDirection( Vector (1+(rand()-RAND_MAX/2),
96  (1+(rand()-RAND_MAX/2)),
97  (1+(rand()-RAND_MAX/2))));
98 
99  Viewer3D viewer;
100  viewer.show();
101  Vector a,b,c,d;
102  Display3DFactory::draw(viewer,accumulator, Z3i::RealVector(1.0,1.0,1.0), 3.0);
103 
104  trace.info() << "Bin values: ";
105  for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
106  it != itend;
107  ++it)
108  trace.info() << *it<<" ";
109  trace.info() << std::endl;
110  trace.info() << accumulator<<std::endl;
111 
112  viewer << Viewer3D::updateDisplay;
113  bool res = application.exec();
114  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
115  trace.endBlock();
116  return res ? 0 : 1;
117 }
118 
120 // Standard services - public :
121 
122 int main( int argc, char** argv )
123 {
124  trace.beginBlock ( "Testing class SphericalAccumulator" );
125  trace.info() << "Args:";
126  for ( int i = 0; i < argc; ++i )
127  trace.info() << " " << argv[ i ];
128  trace.info() << endl;
129 
130  bool res = testSphericalViewer(argc,argv)
131  && testSphericalViewerInteger(argc,argv);
132  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
133  trace.endBlock();
134  return res ? 0 : 1;
135 }
136 // //