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