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