DGtal  1.5.beta
viewer3D-7bis-planes.cpp
Go to the documentation of this file.
1 
50 #include <cstdlib>
51 #include <iostream>
52 
53 #include "DGtal/base/Common.h"
54 #include "DGtal/helpers/StdDefs.h"
55 #include "DGtal/geometry/surfaces/ChordNaivePlaneComputer.h"
56 #include "DGtal/io/viewers/Viewer3D.h"
57 
59 
60 using namespace std;
61 using namespace DGtal;
62 
64 // Standard services - public :
65 template <typename Viewer3D, typename Domain, typename Predicate>
66 void
68  const Domain & domain, const Predicate & pred )
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 }
77 
78 int main( int argc, char** argv )
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 }
170 // //
Aim: A class that contains the chord-based algorithm for recognizing pieces of digital planes of give...
void init(Dimension axis, InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Iterator for HyperRectDomain.
const ConstIterator & end() const
const ConstIterator & begin() const
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
int main(int argc, char **argv)
void displayPredicate(Viewer3D &viewer, const Domain &domain, const Predicate &pred)