DGtal  0.9.3beta
viewer3D-7bis-planes.cpp
1 
30 #include <cstdlib>
32 #include <iostream>
33 
34 #include "DGtal/base/Common.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/geometry/surfaces/ChordNaivePlaneComputer.h"
37 #include "DGtal/io/viewers/Viewer3D.h"
38 
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 // Standard services - public :
46 template <typename Viewer3D, typename Domain, typename Predicate>
47 void
48 displayPredicate( Viewer3D & viewer,
49  const Domain & domain, const Predicate & pred )
50 {
51  for ( typename Domain::ConstIterator itB = domain.begin(), itE = domain.end();
52  itB != itE; ++itB )
53  {
54  if ( pred( *itB ) )
55  viewer << *itB;
56  }
57 }
58 
59 int main( int argc, char** argv )
60 {
61  using namespace Z3i;
62 
63  QApplication application(argc,argv);
64  trace.beginBlock ( "Testing class ChordNaivePlaneComputer" );
65 
66  unsigned int nbok = 0;
67  unsigned int nb = 0;
68  typedef ChordNaivePlaneComputer<Z3, Z3::Point, int> PlaneComputer;
69  typedef PlaneComputer::Primitive Primitive;
70 
71  PlaneComputer plane;
72  plane.init( 2, 1, 1 );
73  Point pt0( 0, 0, 0 );
74  bool pt0_inside = plane.extend( pt0 );
75  trace.info() << "(" << nbok << "/" << nb << ") Plane=" << plane
76  << std::endl;
77  Point pt1( 8, 1, 3 );
78  bool pt1_inside = plane.extend( pt1 );
79  ++nb, nbok += pt1_inside == true ? 1 : 0;
80  trace.info() << "(" << nbok << "/" << nb << ") add " << pt1
81  << " Plane=" << plane << std::endl;
82  Point pt2( 2, 7, 1 );
83  bool pt2_inside = plane.extend( pt2 );
84  ++nb, nbok += pt2_inside == true ? 1 : 0;
85  trace.info() << "(" << nbok << "/" << nb << ") add " << pt2
86  << " Plane=" << plane << std::endl;
87 
88  Point pt3( 0, 5, 12 );
89  bool pt3_inside = plane.extend( pt3 );
90  ++nb, nbok += pt3_inside == false ? 1 : 0;
91  trace.info() << "(" << nbok << "/" << nb << ") add " << pt3
92  << " Plane=" << plane << std::endl;
93 
94  Point pt4( -5, -5, 10 );
95  bool pt4_inside = plane.extend( pt4 );
96  ++nb, nbok += pt4_inside == false ? 1 : 0;
97  trace.info() << "(" << nbok << "/" << nb << ") add " << pt4
98  << " Plane=" << plane << std::endl;
99 
100  Point pt5 = pt0 + pt1 + pt2 + Point( 0, 0, 1 );
101  bool pt5_inside = plane.extend( pt5 );
102  ++nb, nbok += pt5_inside == true ? 1 : 0;
103  trace.info() << "(" << nbok << "/" << nb << ") add " << pt5
104  << " Plane=" << plane << std::endl;
105 
106  Point pt6 = Point( 1, 0, 1 );
107  bool pt6_inside = plane.extend( pt6 );
108  ++nb, nbok += pt6_inside == true ? 1 : 0;
109  trace.info() << "(" << nbok << "/" << nb << ") add " << pt5
110  << " Plane=" << plane << std::endl;
111 
112  Primitive strip = plane.primitive();
113  trace.info() << "strip=" << strip
114  << " axis=" << strip.mainAxis()
115  << " axiswidth=" << strip.axisWidth()
116  << " diag=" << strip.mainDiagonal()
117  << " diagwidth=" << strip.diagonalWidth()
118  << std::endl;
119  ++nb, nbok += strip.axisWidth() < 1.0 ? 1 : 0;
120  trace.info() << "(" << nbok << "/" << nb << ") axiswidth < 1 "
121  << std::endl;
122  ++nb, nbok += strip.diagonalWidth() < sqrt(3.0) ? 1 : 0;
123  trace.info() << "(" << nbok << "/" << nb << ") axiswidth < sqrt(3) "
124  << std::endl;
125 
126  trace.emphase() << ( nbok == nb ? "Passed." : "Error." ) << endl;
127  trace.endBlock();
128 
129  typedef Viewer3D<> MyViewer;
130  MyViewer viewer;
131  viewer.show();
132  Color red( 255, 0, 0 );
133  Color green( 0, 255, 0 );
134  Color grey( 200, 200, 200 );
135  Domain domain( Point( -5, -5, -5 ), Point( 12, 12, 12 ) );
136  viewer << ( pt0_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt0;
137  viewer << ( pt1_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt1;
138  viewer << ( pt2_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt2;
139  viewer << ( pt3_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt3;
140  viewer << ( pt4_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt4;
141  viewer << ( pt5_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt5;
142  viewer << ( pt6_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt6;
143  viewer << CustomColors3D( grey, grey );
144  displayPredicate( viewer, domain, plane );
145 
146  viewer << MyViewer::updateDisplay;
147 
148 
149  return application.exec();
150 }
151 // //
void beginBlock(const std::string &keyword="")
const ConstIterator & begin() const
const ConstIterator & end() const
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...
STL namespace.
double endBlock()
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
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