File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
viewer3D-7-stdplane.cpp File Reference
#include <cstdlib>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/geometry/surfaces/COBAGenericStandardPlaneComputer.h"
Include dependency graph for viewer3D-7-stdplane.cpp:

Go to the source code of this file.

Functions

template<typename Viewer3D, typename Domain, typename Predicate>
void displayPredicate (Viewer3D &viewer, const Domain &domain, const Predicate &pred)
template<typename Viewer3D, typename InputIterator>
void displayRange (Viewer3D &viewer, InputIterator it, InputIterator itE)
template<typename Domain>
std::vector< typename Domain::PointpointsInStandardPlane (const Domain &domain, typename Domain::Integer a, typename Domain::Integer b, typename Domain::Integer c, typename Domain::Integer mu)
int main (int argc, char **argv)

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/03/05

Functions for testing class COBANaivePlaneComputer.

This file is part of the DGtal library.

Definition in file viewer3D-7-stdplane.cpp.

Function Documentation

◆ displayPredicate()

template<typename Viewer3D, typename Domain, typename Predicate>
void displayPredicate ( Viewer3D & viewer,
const Domain & domain,
const Predicate & pred )

Definition at line 72 of file viewer3D-7-stdplane.cpp.

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}
Domain domain

References domain.

Referenced by main().

◆ displayRange()

template<typename Viewer3D, typename InputIterator>
void displayRange ( Viewer3D & viewer,
InputIterator it,
InputIterator itE )

Definition at line 87 of file viewer3D-7-stdplane.cpp.

88{
89 for ( ; it != itE; ++it )
90 viewer << *it;
91}

Referenced by main().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 122 of file viewer3D-7-stdplane.cpp.

123{
124 using namespace Z3i;
125 unsigned int nb = 0;
126 unsigned int nbok = 0;
127
128 unsigned int diameter = argc > 1 ? atoi( argv[ 1 ] ) : 10;
129 int a = argc > 2 ? atoi( argv[ 2 ] ) : 2;
130 int b = argc > 3 ? atoi( argv[ 3 ] ) : 3;
131 int c = argc > 4 ? atoi( argv[ 4 ] ) : 5;
132 int mu = argc > 5 ? atoi( argv[ 5 ] ) : 0;
133 trace.beginBlock ( "Testing class COBAGenericStandardPlaneComputer" );
134 trace.info() << "Recognizing plane "
135 << mu << " <= " << a << " * x + "
136 << b << " * y + " << c << " * z < "
137 << (mu+abs(a)+abs(b)+abs(c)) << std::endl;
138 Domain domain1( Point( -diameter, -diameter, -diameter ),
139 Point( diameter, diameter, diameter ) );
140
142 typedef PlaneComputer::Primitive Primitive;
143 PlaneComputer plane;
144 plane.init( 2*diameter, 1, 1 );
145
146 std::vector<Point> recognized = pointsInStandardPlane( domain1,
147 a, b , c, mu );
148 ++nb, nbok += plane.extend( recognized.begin(), recognized.end() ) ? 1 : 0;
149 trace.info() << "(" << nbok << "/" << nb
150 << ") All points are recognized." << std::endl;
151 trace.info() << " - Plane=" << plane
152 << std::endl;
153 Primitive strip = plane.primitive();
154 trace.info() << "strip=" << strip
155 << " axis=" << strip.mainAxis()
156 << " axiswidth=" << strip.axisWidth()
157 << " diag=" << strip.mainDiagonal()
158 << " diagwidth=" << strip.diagonalWidth()
159 << std::endl;
160 ++nb, nbok += ( strip.diagonalWidth() < sqrt(3.0) ) ? 1 : 0;
161 trace.info() << "(" << nbok << "/" << nb
162 << ") Diagonal width < sqrt(3)." << std::endl;
163 trace.emphase() << ( (nb == nbok) ? "Passed." : "Error." ) << endl;
164 trace.endBlock();
165
166 PolyscopeViewer viewer;
167 Color red( 255, 0, 0 );
168 Color green( 0, 255, 0 );
169 Color grey( 200, 200, 200 );
170 Domain domain2( Point( -2*diameter, -2*diameter, -2*diameter ),
171 Point( 2*diameter, 2*diameter, 2*diameter ) );
172 viewer << red;
173 for ( std::vector<Point>::const_iterator it = recognized.begin(),
174 itE = recognized.end(); it != itE; ++it )
175 if ( ! strip( *it ) ) viewer << *it;
176
177 viewer << green;
178 displayRange( viewer, plane.begin(), plane.end() );
179
180 viewer << grey;
181 displayPredicate( viewer, domain2, strip );
182
183 trace.info() << "- Points in green have been recognized as belonging to this standard plane." << std::endl;
184 trace.info() << "- Points in grey belongs also to the parallel strip of the recognized standard plane." << std::endl;
185 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;
186
187 viewer.show();
188 return 0;
189}
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:77
void show() override
Starts the event loop and display of elements.
Z3i this namespace gathers the standard of types for 3D imagery.
Trace trace
MyPointD Point
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)

References displayPredicate(), displayRange(), DGtal::COBAGenericStandardPlaneComputer< TSpace, TInternalInteger >::init(), pointsInStandardPlane(), DGtal::PolyscopeViewer< Space, KSpace >::show(), and DGtal::trace.

◆ pointsInStandardPlane()

template<typename Domain>
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 )

Definition at line 98 of file viewer3D-7-stdplane.cpp.

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}

References domain.

Referenced by main().