DGtal 1.4.0
Loading...
Searching...
No Matches
testSphericalAccumulatorQGL.cpp
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/geometry/tools/SphericalAccumulator.h"
35#include "DGtal/io/viewers/Viewer3D.h"
36#include "DGtal/io/boards/Board3D.h"
38
39using namespace std;
40using namespace DGtal;
41using namespace Z3i;
42
44// Functions for testing class SphericalAccumulator.
46bool testSphericalViewer(int argc, char **argv)
47{
48 QApplication application(argc,argv);
49
50 trace.beginBlock ( "Testing Spherical Accumulator Viewer..." );
51
52 typedef Z3i::RealVector Vector;
53
54 SphericalAccumulator<Vector> accumulator(15);
55 trace.info()<< accumulator << std::endl;
56
57 for(unsigned int i=0; i< 10000; i++)
58 accumulator.addDirection( Vector (1+10.0*(rand()-RAND_MAX/2)/(double)RAND_MAX,
59 (1+10.0*(rand()-RAND_MAX/2))/(double)RAND_MAX,
60 (1+10.0*(rand()-RAND_MAX/2))/(double)RAND_MAX));
61
62 Viewer3D<> viewer;
63 Board3D<> board;
64 viewer.show();
65 Vector a,b,c,d;
66 viewer << accumulator;
67
68
69 board << accumulator;
70 board.saveOBJ("testSpherical.obj");
71
72
73 trace.info() << "Bin values: ";
74 for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
75 it != itend;
76 ++it)
77 trace.info() << *it<<" ";
78 trace.info() << std::endl;
79 trace.info() << accumulator<<std::endl;
80
81 viewer << Viewer3D<>::updateDisplay;
82 bool res = application.exec();
83 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
85 return res ? 0 : 1;
86}
87bool testSphericalViewerInteger(int argc, char **argv)
88{
89 QApplication application(argc,argv);
90
91 trace.beginBlock ( "Testing Spherical Accumulator Viewer with Integer numbers..." );
92
93 typedef Z3i::Vector Vector;
94
95 SphericalAccumulator<Vector> accumulator(15);
96 trace.info()<< accumulator << std::endl;
97
98 for(unsigned int i=0; i< 10000; i++)
99 accumulator.addDirection( Vector (1+(rand()-RAND_MAX/2),
100 (1+(rand()-RAND_MAX/2)),
101 (1+(rand()-RAND_MAX/2))));
102
103 Viewer3D<> viewer;
104 viewer.show();
105 Vector a,b,c,d;
106 Display3DFactory<Space,KSpace>::draw(viewer,accumulator, Z3i::RealVector(1.0,1.0,1.0), 3.0);
107
108 trace.info() << "Bin values: ";
109 for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
110 it != itend;
111 ++it)
112 trace.info() << *it<<" ";
113 trace.info() << std::endl;
114 trace.info() << accumulator<<std::endl;
115
116 viewer << Viewer3D<>::updateDisplay;
117 bool res = application.exec();
118 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
119 trace.endBlock();
120 return res ? 0 : 1;
121}
122
124// Standard services - public :
125
126int main( int argc, char** argv )
127{
128 trace.beginBlock ( "Testing class SphericalAccumulator" );
129 trace.info() << "Args:";
130 for ( int i = 0; i < argc; ++i )
131 trace.info() << " " << argv[ i ];
132 trace.info() << endl;
133
134 bool res = testSphericalViewer(argc,argv)
135 && testSphericalViewerInteger(argc,argv);
136 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
137 trace.endBlock();
138 return res ? 0 : 1;
139}
140// //
The class Board3D is a type of Display3D which export the figures in the format OBJ/MTL when calling ...
Definition Board3D.h:82
void saveOBJ(const std::string &filename, const bool isNormalized=false)
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: implements an accumulator (as histograms for 1D scalars) adapted to spherical point samples.
std::vector< Quantity >::const_iterator ConstIterator
Type to iterate on bin values.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Space::Vector Vector
Definition StdDefs.h:169
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
static void draw(Display3D< Space, KSpace > &display, const DGtal::DiscreteExteriorCalculus< dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger > &calculus)
int main()
Definition testBits.cpp:56