DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
viewer3D-7-planes.cpp
1 
30 
31 #include <cstdlib>
32 #include <iostream>
33 #include <QtGui/qapplication.h>
34 #include "DGtal/io/viewers/Viewer3D.h"
35 #include "DGtal/base/Common.h"
36 #include "DGtal/helpers/StdDefs.h"
37 #include "DGtal/geometry/surfaces/COBANaivePlane.h"
39 
40 using namespace std;
41 using namespace DGtal;
42 
44 // Standard services - public :
45 template <typename Viewer3D, typename Domain, typename Predicate>
46 void
47 displayPredicate( Viewer3D & viewer,
48  const Domain & domain, const Predicate & pred )
49 {
50  for ( typename Domain::ConstIterator itB = domain.begin(), itE = domain.end();
51  itB != itE; ++itB )
52  {
53  if ( pred( *itB ) )
54  viewer << *itB;
55  }
56 }
57 
58 int main( int argc, char** argv )
59 {
60  using namespace Z3i;
61 
62  QApplication application(argc,argv);
63  trace.beginBlock ( "Testing class COBANaivePlane" );
64 
65  unsigned int nbok = 0;
66  unsigned int nb = 0;
67  typedef BigInteger Integer;
68 
70  plane.init( 2, 100, 1, 1 );
71  Point pt0( 0, 0, 0 );
72  bool pt0_inside = plane.extend( pt0 );
73  trace.info() << "(" << nbok << "/" << nb << ") Plane=" << plane
74  << std::endl;
75  Point pt1( 8, 1, 3 );
76  bool pt1_inside = plane.extend( pt1 );
77  ++nb, nbok += pt1_inside == true ? 1 : 0;
78  trace.info() << "(" << nbok << "/" << nb << ") add " << pt1
79  << " Plane=" << plane << std::endl;
80  Point pt2( 2, 7, 1 );
81  bool pt2_inside = plane.extend( pt2 );
82  ++nb, nbok += pt2_inside == true ? 1 : 0;
83  trace.info() << "(" << nbok << "/" << nb << ") add " << pt2
84  << " Plane=" << plane << std::endl;
85 
86  Point pt3( 0, 5, 12 );
87  bool pt3_inside = plane.extend( pt3 );
88  ++nb, nbok += pt3_inside == false ? 1 : 0;
89  trace.info() << "(" << nbok << "/" << nb << ") add " << pt3
90  << " Plane=" << plane << std::endl;
91 
92  Point pt4( -5, -5, 10 );
93  bool pt4_inside = plane.extend( pt4 );
94  ++nb, nbok += pt4_inside == false ? 1 : 0;
95  trace.info() << "(" << nbok << "/" << nb << ") add " << pt4
96  << " Plane=" << plane << std::endl;
97 
98  Point pt5 = pt0 + pt1 + pt2 + Point( 0, 0, 1 );
99  bool pt5_inside = plane.extend( pt5 );
100  ++nb, nbok += pt5_inside == true ? 1 : 0;
101  trace.info() << "(" << nbok << "/" << nb << ") add " << pt5
102  << " Plane=" << plane << std::endl;
103 
104  trace.emphase() << ( nbok == nb ? "Passed." : "Error." ) << endl;
105  trace.endBlock();
106 
107  Viewer3D viewer;
108  viewer.show();
109  Color red( 255, 0, 0 );
110  Color green( 0, 255, 0 );
111  Color grey( 200, 200, 200 );
112  Domain domain( Point( -5, -5, -5 ), Point( 12, 12, 12 ) );
113  viewer << ( pt0_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt0;
114  viewer << ( pt1_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt1;
115  viewer << ( pt2_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt2;
116  viewer << ( pt3_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt3;
117  viewer << ( pt4_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt4;
118  viewer << ( pt5_inside ? CustomColors3D( green, green ) : CustomColors3D( red, red ) ) << pt5;
119  viewer << CustomColors3D( grey, grey );
120  displayPredicate( viewer, domain, plane );
121 
122  viewer << Viewer3D::updateDisplay;
123 
124 
125  return application.exec();
126 }
127 // //