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

Function Documentation

◆ displayPredicate()

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

Definition at line 67 of file viewer3D-7bis-planes.cpp.

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

Referenced by main().

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 78 of file viewer3D-7bis-planes.cpp.

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

79 {
80  using namespace Z3i;
81 
82  QApplication application(argc,argv);
83  trace.beginBlock ( "Testing class ChordNaivePlaneComputer" );
84 
85  unsigned int nbok = 0;
86  unsigned int nb = 0;
87  typedef ChordNaivePlaneComputer<Z3, Z3::Point, int> PlaneComputer;
88  typedef PlaneComputer::Primitive Primitive;
89 
90  PlaneComputer plane;
91  plane.init( 2, 1, 1 );
92  Point pt0( 0, 0, 0 );
93  bool pt0_inside = plane.extend( pt0 );
94  trace.info() << "(" << nbok << "/" << nb << ") Plane=" << plane
95  << std::endl;
96  Point pt1( 8, 1, 3 );
97  bool pt1_inside = plane.extend( pt1 );
98  ++nb, nbok += pt1_inside == true ? 1 : 0;
99  trace.info() << "(" << nbok << "/" << nb << ") add " << pt1
100  << " Plane=" << plane << std::endl;
101  Point pt2( 2, 7, 1 );
102  bool pt2_inside = plane.extend( pt2 );
103  ++nb, nbok += pt2_inside == true ? 1 : 0;
104  trace.info() << "(" << nbok << "/" << nb << ") add " << pt2
105  << " Plane=" << plane << std::endl;
106 
107  Point pt3( 0, 5, 12 );
108  bool pt3_inside = plane.extend( pt3 );
109  ++nb, nbok += pt3_inside == false ? 1 : 0;
110  trace.info() << "(" << nbok << "/" << nb << ") add " << pt3
111  << " Plane=" << plane << std::endl;
112 
113  Point pt4( -5, -5, 10 );
114  bool pt4_inside = plane.extend( pt4 );
115  ++nb, nbok += pt4_inside == false ? 1 : 0;
116  trace.info() << "(" << nbok << "/" << nb << ") add " << pt4
117  << " Plane=" << plane << std::endl;
118 
119  Point pt5 = pt0 + pt1 + pt2 + Point( 0, 0, 1 );
120  bool pt5_inside = plane.extend( pt5 );
121  ++nb, nbok += pt5_inside == true ? 1 : 0;
122  trace.info() << "(" << nbok << "/" << nb << ") add " << pt5
123  << " Plane=" << plane << std::endl;
124 
125  Point pt6 = Point( 1, 0, 1 );
126  bool pt6_inside = plane.extend( pt6 );
127  ++nb, nbok += pt6_inside == true ? 1 : 0;
128  trace.info() << "(" << nbok << "/" << nb << ") add " << pt5
129  << " Plane=" << plane << std::endl;
130 
131  Primitive strip = plane.primitive();
132  trace.info() << "strip=" << strip
133  << " axis=" << strip.mainAxis()
134  << " axiswidth=" << strip.axisWidth()
135  << " diag=" << strip.mainDiagonal()
136  << " diagwidth=" << strip.diagonalWidth()
137  << std::endl;
138  ++nb, nbok += strip.axisWidth() < 1.0 ? 1 : 0;
139  trace.info() << "(" << nbok << "/" << nb << ") axiswidth < 1 "
140  << std::endl;
141  ++nb, nbok += strip.diagonalWidth() < sqrt(3.0) ? 1 : 0;
142  trace.info() << "(" << nbok << "/" << nb << ") axiswidth < sqrt(3) "
143  << std::endl;
144 
145  trace.emphase() << ( nbok == nb ? "Passed." : "Error." ) << endl;
146  trace.endBlock();
147 
148  typedef Viewer3D<> MyViewer;
149  MyViewer viewer;
150  viewer.show();
151  Color red( 255, 0, 0 );
152  Color green( 0, 255, 0 );
153  Color grey( 200, 200, 200 );
154  Domain domain( Point( -5, -5, -5 ), Point( 12, 12, 12 ) );
155  viewer << ( pt0_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt0;
156  viewer << ( pt1_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt1;
157  viewer << ( pt2_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt2;
158  viewer << ( pt3_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt3;
159  viewer << ( pt4_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt4;
160  viewer << ( pt5_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt5;
161  viewer << ( pt6_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt6;
162  viewer << CustomColors3D( grey, grey );
163  displayPredicate( viewer, domain, plane );
164 
165  viewer << MyViewer::updateDisplay;
166 
167 
168  return application.exec();
169 }
void beginBlock(const std::string &keyword="")
void displayPredicate(Viewer3D &viewer, const Domain &domain, const Predicate &pred)
const Domain domain(Point(1, 2), Point(6, 5))
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...
Aim: A class that contains the chord-based algorithm for recognizing pieces of digital planes of give...
double endBlock()
std::ostream & emphase()
MyPointD Point
Definition: testClone2.cpp:383
void init(Dimension axis, InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
std::ostream & info()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66