DGtal  0.9.3
Functions
viewer3D-7bis-stdplane.cpp File Reference
#include <cstdlib>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/surfaces/ChordGenericStandardPlaneComputer.h"
#include "DGtal/io/viewers/Viewer3D.h"
Include dependency graph for viewer3D-7bis-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 ChordNaivePlaneComputer.

This file is part of the DGtal library.

Definition in file viewer3D-7bis-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 70 of file viewer3D-7bis-stdplane.cpp.

References DGtal::HyperRectDomain< TSpace >::begin(), and DGtal::HyperRectDomain< TSpace >::end().

Referenced by main().

72 {
73  for ( typename Domain::ConstIterator itB = domain.begin(), itE = domain.end();
74  itB != itE; ++itB )
75  {
76  if ( pred( *itB ) )
77  viewer << *itB;
78  }
79 }
const ConstIterator & end() const
const ConstIterator & begin() const

◆ displayRange()

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

Definition at line 85 of file viewer3D-7bis-stdplane.cpp.

References pointsInStandardPlane().

Referenced by main().

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 120 of file viewer3D-7bis-stdplane.cpp.

References DGtal::Trace::beginBlock(), displayPredicate(), displayRange(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::ChordGenericStandardPlaneComputer< TSpace, TInputPoint, TInternalScalar >::init(), pointsInStandardPlane(), DGtal::Viewer3D< Space, KSpace >::show(), DGtal::trace, and DGtal::Display3D< Space, KSpace >::updateDisplay.

121 {
122  using namespace Z3i;
123  unsigned int nb = 0;
124  unsigned int nbok = 0;
125 
126  QApplication application(argc,argv);
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 ChordGenericStandardPlaneComputer" );
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 
141  typedef int64_t Integer;
143  typedef PlaneComputer::Primitive Primitive;
144  PlaneComputer plane;
145  plane.init( 1, 1 );
146 
147  std::vector<Point> recognized = pointsInStandardPlane( domain1,
148  a, b , c, mu );
149  ++nb, nbok += plane.extend( recognized.begin(), recognized.end() ) ? 1 : 0;
150  trace.info() << "(" << nbok << "/" << nb
151  << ") All points are recognized." << std::endl;
152  trace.info() << " - Plane=" << plane
153  << std::endl;
154  Primitive strip = plane.primitive();
155  trace.info() << "strip=" << strip
156  << " axis=" << strip.mainAxis()
157  << " axiswidth=" << strip.axisWidth()
158  << " diag=" << strip.mainDiagonal()
159  << " diagwidth=" << strip.diagonalWidth()
160  << std::endl;
161  ++nb, nbok += ( strip.diagonalWidth() < sqrt(3.0) ) ? 1 : 0;
162  trace.info() << "(" << nbok << "/" << nb
163  << ") Diagonal width < sqrt(3)." << std::endl;
164  trace.emphase() << ( (nb == nbok) ? "Passed." : "Error." ) << endl;
165  trace.endBlock();
166 
167  typedef Viewer3D<> MyViewer;
168  MyViewer viewer;
169  viewer.show();
170  Color red( 255, 0, 0 );
171  Color green( 0, 255, 0 );
172  Color grey( 200, 200, 200 );
173  Domain domain2( Point( -2*diameter, -2*diameter, -2*diameter ),
174  Point( 2*diameter, 2*diameter, 2*diameter ) );
175  viewer << CustomColors3D( red, red );
176  for ( std::vector<Point>::const_iterator it = recognized.begin(),
177  itE = recognized.end(); it != itE; ++it )
178  if ( ! strip( *it ) ) viewer << *it;
179  viewer << CustomColors3D( green, green );
180  displayRange( viewer, plane.begin(), plane.end() );
181  viewer << CustomColors3D( grey, grey );
182  displayPredicate( viewer, domain2, strip );
183  viewer << MyViewer::updateDisplay;
184  trace.info() << "- Points in green have been recognized as belonging to this standard plane." << std::endl;
185  trace.info() << "- Points in grey belongs also to the parallel strip of the recognized standard plane." << std::endl;
186  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;
187 
188  return application.exec();
189 }
void beginBlock(const std::string &keyword="")
DGtal::int32_t Integer
Definition: StdDefs.h:74
void displayPredicate(Viewer3D &viewer, const Domain &domain, const Predicate &pred)
Trace trace
Definition: Common.h:137
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
double endBlock()
std::ostream & emphase()
void displayRange(Viewer3D &viewer, InputIterator it, InputIterator itE)
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
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 init(InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
Aim: A class that recognizes pieces of digital planes of given diagonal width. When the width is ...

◆ 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 97 of file viewer3D-7bis-stdplane.cpp.

References DGtal::HyperRectDomain< TSpace >::begin(), and DGtal::HyperRectDomain< TSpace >::end().

Referenced by displayRange(), and main().

102 {
103  typedef typename Domain::Integer Integer;
104  typedef typename Domain::Point Point;
105  typedef typename Domain::ConstIterator ConstIterator;
106  std::vector<Point> pts;
107  Integer mup = mu + abs(a) + abs(b) + abs(c);
108  for ( ConstIterator it = domain.begin(), itE = domain.end();
109  it != itE; ++it )
110  {
111  Point p = *it;
112  Integer r = a * p[ 0 ] + b * p[ 1 ] + c * p[ 2 ];
113  if ( ( mu <= r ) && ( r < mup ) )
114  pts.push_back( p );
115  }
116  return pts;
117 }
DGtal::int32_t Integer
Definition: StdDefs.h:74
const ConstIterator & end() const
MyDigitalSurface::ConstIterator ConstIterator
const ConstIterator & begin() const
MyPointD Point
Definition: testClone2.cpp:383