Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
viewer3D-7-planes.cpp
Go to the documentation of this file.
1
16
29
47
49#include <cstdlib>
50#include <iostream>
51#include "DGtal/base/Common.h"
52#include "DGtal/helpers/StdDefs.h"
53#include "DGtal/io/viewers/PolyscopeViewer.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
64displayPredicate( Viewer3D & viewer,
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 trace.beginBlock ( "Testing class COBANaivePlaneComputer" );
80
81 unsigned int nbok = 0;
82 unsigned int nb = 0;
83
84 typedef COBANaivePlaneComputer<Z3, BigInteger> PlaneComputer;
85 typedef PlaneComputer::Primitive Primitive;
86 PlaneComputer plane;
87
88 plane.init( 2, 100, 1, 1 );
89 Point pt0( 0, 0, 0 );
90 bool pt0_inside = plane.extend( pt0 );
91 trace.info() << "(" << nbok << "/" << nb << ") Plane=" << plane
92 << std::endl;
93 Point pt1( 8, 1, 3 );
94 bool pt1_inside = plane.extend( pt1 );
95 ++nb, nbok += pt1_inside == true ? 1 : 0;
96 trace.info() << "(" << nbok << "/" << nb << ") add " << pt1
97 << " Plane=" << plane << std::endl;
98 Point pt2( 2, 7, 1 );
99 bool pt2_inside = plane.extend( pt2 );
100 ++nb, nbok += pt2_inside == true ? 1 : 0;
101 trace.info() << "(" << nbok << "/" << nb << ") add " << pt2
102 << " Plane=" << plane << std::endl;
103
104 Point pt3( 0, 5, 12 );
105 bool pt3_inside = plane.extend( pt3 );
106 ++nb, nbok += pt3_inside == false ? 1 : 0;
107 trace.info() << "(" << nbok << "/" << nb << ") add " << pt3
108 << " Plane=" << plane << std::endl;
109
110 Point pt4( -5, -5, 10 );
111 bool pt4_inside = plane.extend( pt4 );
112 ++nb, nbok += pt4_inside == false ? 1 : 0;
113 trace.info() << "(" << nbok << "/" << nb << ") add " << pt4
114 << " Plane=" << plane << std::endl;
115
116 Point pt5 = pt0 + pt1 + pt2 + Point( 0, 0, 1 );
117 bool pt5_inside = plane.extend( pt5 );
118 ++nb, nbok += pt5_inside == true ? 1 : 0;
119 trace.info() << "(" << nbok << "/" << nb << ") add " << pt5
120 << " Plane=" << plane << std::endl;
121
122 Point pt6 = Point( 1, 0, 1 );
123 bool pt6_inside = plane.extend( pt6 );
124 ++nb, nbok += pt6_inside == true ? 1 : 0;
125 trace.info() << "(" << nbok << "/" << nb << ") add " << pt5
126 << " Plane=" << plane << std::endl;
127
128 Primitive strip = plane.primitive();
129 trace.info() << "strip=" << strip
130 << " axis=" << strip.mainAxis()
131 << " axiswidth=" << strip.axisWidth()
132 << " diag=" << strip.mainDiagonal()
133 << " diagwidth=" << strip.diagonalWidth()
134 << std::endl;
135 ++nb, nbok += strip.axisWidth() < 1.0 ? 1 : 0;
136 trace.info() << "(" << nbok << "/" << nb << ") axiswidth < 1 "
137 << std::endl;
138 ++nb, nbok += strip.diagonalWidth() < sqrt(3.0) ? 1 : 0;
139 trace.info() << "(" << nbok << "/" << nb << ") axiswidth < sqrt(3) "
140 << std::endl;
141 trace.emphase() << ( nbok == nb ? "Passed." : "Error." ) << endl;
142 trace.endBlock();
143
144 PolyscopeViewer viewer;
145 Color red( 255, 0, 0 );
146 Color green( 0, 255, 0 );
147 Color grey( 200, 200, 200 );
148 Domain domain( Point( -5, -5, -5 ), Point( 12, 12, 12 ) );
149 viewer << grey;
150 viewer << ( pt0_inside ? green : red ) << pt0;
151 viewer << ( pt1_inside ? green : red ) << pt1;
152 viewer << ( pt2_inside ? green : red ) << pt2;
153 viewer << ( pt3_inside ? green : red ) << pt3;
154 viewer << ( pt4_inside ? green : red ) << pt4;
155 viewer << ( pt5_inside ? green : red ) << pt5;
156 viewer << ( pt6_inside ? green : red ) << pt6;
157 viewer << grey;
158 displayPredicate( viewer, domain, strip );
159
160 viewer.show();
161 return 0;
162}
163// //
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:77
void show() override
Starts the event loop and display of elements.
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
int main()
Definition testBits.cpp:56
MyPointD Point
Domain domain
void displayPredicate(Viewer3D &viewer, const Domain &domain, const Predicate &pred)