DGtal 1.3.0
Loading...
Searching...
No Matches
viewer3D-7-stdplane.cpp
Go to the documentation of this file.
1
52#include <cstdlib>
53#include <iostream>
54#include "DGtal/base/Common.h"
55#include "DGtal/helpers/StdDefs.h"
56#include "DGtal/io/viewers/Viewer3D.h"
57#include "DGtal/geometry/surfaces/COBAGenericStandardPlaneComputer.h"
59
60using namespace std;
61using namespace DGtal;
62
64// Standard services - public :
65
66/*
67 Displays in the \a viewer all the points in the \a domain that
68 satisfies the predicate \a pred.
69*/
70template <typename Viewer3D, typename Domain, typename Predicate>
71void
73 const Domain & domain, const Predicate & pred )
74{
75 for ( typename Domain::ConstIterator itB = domain.begin(), itE = domain.end();
76 itB != itE; ++itB )
77 {
78 if ( pred( *itB ) )
79 viewer << *itB;
80 }
81}
82/*
83 Displays in the \a viewer all the points in the range [it,itE).
84*/
85template <typename Viewer3D, typename InputIterator>
86void
87displayRange( Viewer3D & viewer, InputIterator it, InputIterator itE )
88{
89 for ( ; it != itE; ++it )
90 viewer << *it;
91}
92
93/*
94 Returns all the points in the \a domain that belongs to the standard
95 plane mu <= a*x+b*y+c*z < mu+|a|+|b|+|c|.
96*/
97template <typename Domain>
98std::vector<typename Domain::Point> pointsInStandardPlane
99( const Domain & domain,
100 typename Domain::Integer a,
101 typename Domain::Integer b,
102 typename Domain::Integer c,
103 typename Domain::Integer mu )
104{
105 typedef typename Domain::Integer Integer;
106 typedef typename Domain::Point Point;
107 typedef typename Domain::ConstIterator ConstIterator;
108 std::vector<Point> pts;
109 Integer mup = mu + abs(a) + abs(b) + abs(c);
110 for ( ConstIterator it = domain.begin(), itE = domain.end();
111 it != itE; ++it )
112 {
113 Point p = *it;
114 Integer r = a * p[ 0 ] + b * p[ 1 ] + c * p[ 2 ];
115 if ( ( mu <= r ) && ( r < mup ) )
116 pts.push_back( p );
117 }
118 return pts;
119}
120
121
122int main( int argc, char** argv )
123{
124 using namespace Z3i;
125 unsigned int nb = 0;
126 unsigned int nbok = 0;
127
128 QApplication application(argc,argv);
129
130 unsigned int diameter = argc > 1 ? atoi( argv[ 1 ] ) : 10;
131 int a = argc > 2 ? atoi( argv[ 2 ] ) : 2;
132 int b = argc > 3 ? atoi( argv[ 3 ] ) : 3;
133 int c = argc > 4 ? atoi( argv[ 4 ] ) : 5;
134 int mu = argc > 5 ? atoi( argv[ 5 ] ) : 0;
135 trace.beginBlock ( "Testing class COBAGenericStandardPlaneComputer" );
136 trace.info() << "Recognizing plane "
137 << mu << " <= " << a << " * x + "
138 << b << " * y + " << c << " * z < "
139 << (mu+abs(a)+abs(b)+abs(c)) << std::endl;
140 Domain domain1( Point( -diameter, -diameter, -diameter ),
141 Point( diameter, diameter, diameter ) );
142
144 typedef PlaneComputer::Primitive Primitive;
145 PlaneComputer plane;
146 plane.init( 2*diameter, 1, 1 );
147
148 std::vector<Point> recognized = pointsInStandardPlane( domain1,
149 a, b , c, mu );
150 ++nb, nbok += plane.extend( recognized.begin(), recognized.end() ) ? 1 : 0;
151 trace.info() << "(" << nbok << "/" << nb
152 << ") All points are recognized." << std::endl;
153 trace.info() << " - Plane=" << plane
154 << std::endl;
155 Primitive strip = plane.primitive();
156 trace.info() << "strip=" << strip
157 << " axis=" << strip.mainAxis()
158 << " axiswidth=" << strip.axisWidth()
159 << " diag=" << strip.mainDiagonal()
160 << " diagwidth=" << strip.diagonalWidth()
161 << std::endl;
162 ++nb, nbok += ( strip.diagonalWidth() < sqrt(3.0) ) ? 1 : 0;
163 trace.info() << "(" << nbok << "/" << nb
164 << ") Diagonal width < sqrt(3)." << std::endl;
165 trace.emphase() << ( (nb == nbok) ? "Passed." : "Error." ) << endl;
166 trace.endBlock();
167
168 typedef Viewer3D<> MyViewer;
169 MyViewer viewer;
170 viewer.show();
171 Color red( 255, 0, 0 );
172 Color green( 0, 255, 0 );
173 Color grey( 200, 200, 200 );
174 Domain domain2( Point( -2*diameter, -2*diameter, -2*diameter ),
175 Point( 2*diameter, 2*diameter, 2*diameter ) );
176 viewer << CustomColors3D( red, red );
177 for ( std::vector<Point>::const_iterator it = recognized.begin(),
178 itE = recognized.end(); it != itE; ++it )
179 if ( ! strip( *it ) ) viewer << *it;
180 viewer << CustomColors3D( green, green );
181 displayRange( viewer, plane.begin(), plane.end() );
182 viewer << CustomColors3D( grey, grey );
183 displayPredicate( viewer, domain2, strip );
184 viewer << MyViewer::updateDisplay;
185 trace.info() << "- Points in green have been recognized as belonging to this standard plane." << std::endl;
186 trace.info() << "- Points in grey belongs also to the parallel strip of the recognized standard plane." << std::endl;
187 trace.info() << "- Points in red belongs to the parallel strip of the recognized standard plane but not to the input standard plane: NONE should be red." << std::endl;
188
189 return application.exec();
190}
191// //
Aim: A class that recognizes pieces of digital planes of given axis width. When the diagonal width is...
void init(InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
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...
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
void displayRange(Viewer3D &viewer, InputIterator it, InputIterator itE)
std::vector< typename Domain::Point > pointsInStandardPlane(const Domain &domain, typename Domain::Integer a, typename Domain::Integer b, typename Domain::Integer c, typename Domain::Integer mu)
void displayPredicate(Viewer3D &viewer, const Domain &domain, const Predicate &pred)