Example of a test. To be completed.
123{
124 unsigned int nbok = 0;
125 unsigned int nb = 0;
126
127
128 using namespace Z3i;
129
130
137
138
140 double p1[] = {-2,-2,-2};
141 double p2[] = { 2, 2, 2};
142 std::string poly_str = "x*x+y*y+z*z-1";
143 double step = 0.4;
146 std::string::const_iterator iter
147 = reader.
read( P, poly_str.begin(), poly_str.end() );
148 if ( iter != poly_str.end() )
149 {
150 std::cerr << "ERROR: I read only <"
151 << poly_str.substr( 0, iter - poly_str.begin() )
152 << ">, and I built P=" << P << std::endl;
153 return 1;
154 }
155 trace.
info() <<
"- P = " << P << std::endl;
162
163
164 trace.
beginBlock (
"Construct the Khalimsky space from the image domain ..." );
168 );
169 if (!space_ok)
170 {
171 trace.
error() <<
"Error in the Khamisky space construction."<<std::endl;
172 return false;
173 }
175
183
184 MySurfelAdjacency surfAdj( true );
185 MySetOfSurfels theSetOfSurfels(
K, surfAdj );
189 dshape, bel );
191 trace.
info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
192 << std::endl;
194
197 typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
198 typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
199 typedef boost::graph_traits<Graph>::vertices_size_type vertices_size_type;
200 typedef boost::graph_traits<Graph>::vertex_iterator vertex_iterator;
201 typedef boost::graph_traits<Graph>::out_edge_iterator out_edge_iterator;
202 typedef boost::graph_traits<Graph>::edge_iterator edge_iterator;
203
208
210
211 trace.
beginBlock (
"Testing IncidenceGraph interface with breadth_first_visit ..." );
212
213 typedef std::map< vertex_descriptor, boost::default_color_type > StdColorMap;
214 StdColorMap colorMap;
215 boost::associative_property_map< StdColorMap > propColorMap( colorMap );
216
217 typedef std::map< vertex_descriptor, uint64_t > StdDistanceMap;
218 StdDistanceMap distanceMap;
219 boost::associative_property_map< StdDistanceMap > propDistanceMap( distanceMap );
220 boost::queue< vertex_descriptor > Q;
221 vertex_descriptor start = *( digSurf.begin() );
222 boost::breadth_first_visit
223 ( digSurf,
224 start,
225 Q,
226 boost::make_bfs_visitor( boost::record_distances( propDistanceMap, boost::on_tree_edge() ) ),
227 propColorMap
228 );
230
231
234 vertex_descriptor furthest = start;
236 for ( std::pair<vertex_iterator, vertex_iterator>
237 vp =
boost::vertices( digSurf ); vp.first != vp.second; ++vp.first, ++nbV )
238 {
239 uint64_t d = boost::get( propDistanceMap, *vp.first );
240 if ( d > maxD )
241 {
242 maxD = d;
243 furthest = *vp.first;
244 }
245 }
246 trace.
info() <<
"- d[ " << start <<
" ] = " << boost::get( propDistanceMap, start ) << std::endl;
247 trace.
info() <<
"- d[ " << furthest <<
" ] = " << maxD << std::endl;
248 ++nb; nbok += ( nbV == digSurf.size() ) ? 1 : 0;
249 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
250 << "nb vertices is ok" << std::endl;
251 ++nb; nbok += ( maxD == 12 ) ? 1 : 0;
252 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
253 << "maxD == 12" << std::endl;
255
256 trace.
beginBlock (
"Testing VertexListGraph interface with connected_components ..." );
257
258 typedef std::map< vertex_descriptor, vertices_size_type > StdComponentMap;
259 StdComponentMap componentMap;
260 boost::associative_property_map< StdComponentMap > propComponentMap( componentMap );
261 vertices_size_type nbComp =
262 boost::connected_components
263 ( digSurf,
264 propComponentMap,
265 boost::color_map( propColorMap )
266 );
267 trace.
info() <<
"- nbComponents = " << nbComp << std::endl;
268 ++nb; nbok += ( nbComp == 1 ) ? 1 : 0;
269 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
270 << "nbComp == 1" << std::endl;
272
273 trace.
beginBlock (
"Testing UndirectedGraph interface with Wagner-Stoer min cut ..." );
274
275 typedef double weight_type;
276 typedef std::map< edge_descriptor, weight_type > StdWeightMap;
277 StdWeightMap weightMap;
278 boost::associative_property_map< StdWeightMap > propWeightMap( weightMap );
279 typedef std::map< vertex_descriptor, vertices_size_type > StdVertexIndexMap;
280 StdVertexIndexMap vertexIndexMap;
281 boost::associative_property_map< StdVertexIndexMap > propVertexIndexMap( vertexIndexMap );
282 vertices_size_type idxV = 0;
283
284
285 for ( std::pair<vertex_iterator, vertex_iterator>
286 vp =
boost::vertices( digSurf ); vp.first != vp.second; ++vp.first, ++idxV )
287 {
288 vertex_descriptor v1 = *vp.first;
289 vertexIndexMap[ v1 ] = idxV;
290 for ( std::pair<out_edge_iterator, out_edge_iterator>
292 {
294 if ( v1 < v2 )
295 {
297 weight_type weight = (
K.
sKCoord( sep, 2 ) == 0 ) ? 0.01 : 1.0;
298 weightMap[ *ve.first ] = weight;
299 weightMap[ digSurf.opposite( *ve.first ) ] = weight;
300 }
301 }
302 }
303
304 typedef std::map< vertex_descriptor, bool > StdParityMap;
305 StdParityMap parityMap;
306 boost::associative_property_map< StdParityMap > propParityMap( parityMap );
307
308 weight_type total_weight =
309 boost::stoer_wagner_min_cut
310 ( digSurf,
311 propWeightMap,
312 boost::parity_map( propParityMap )
313 .vertex_index_map( propVertexIndexMap )
314 );
315 trace.
info() <<
"- total weight = " << total_weight << std::endl;
318 for ( std::pair<vertex_iterator, vertex_iterator>
319 vp =
boost::vertices( digSurf ); vp.first != vp.second; ++vp.first, ++idxV )
320 {
321 vertex_descriptor v1 = *vp.first;
322
323 if ( parityMap[ v1 ] ) ++nb1;
324 else ++nb0;
325 }
326 ++nb; nbok += ( total_weight < 1.0 ) ? 1 : 0;
327 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
328 << "total_weight < 1.0"
329 << ", nb0=" << nb0 << " nb1=" << nb1 << std::endl;
330 trace.
info() <<
"- parity[ " << start <<
" ] = " << parityMap[ start ] << std::endl;
331 trace.
info() <<
"- parity[ " << furthest <<
" ] = " << parityMap[ furthest ] << std::endl;
332 ++nb; nbok += ( parityMap[ start ] != parityMap[ furthest ] ) ? 1 : 0;
333 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
334 << "parityMap[ start ] != parityMap[ furthest ]" << std::endl;
336
337 trace.
beginBlock (
"Testing EdgeListGraph and IncidenceGraph interfaces with Boykov-Kolmogorov max flow ..." );
338 typedef double capacity_type;
339
340 typedef std::map< edge_descriptor, weight_type > StdEdgeCapacityMap;
341 StdEdgeCapacityMap edgeCapacityMap;
342 boost::associative_property_map< StdEdgeCapacityMap > propEdgeCapacityMap( edgeCapacityMap );
343
344 typedef std::map< edge_descriptor, weight_type > StdEdgeResidualCapacityMap;
345 StdEdgeResidualCapacityMap edgeResidualCapacityMap;
346 boost::associative_property_map< StdEdgeResidualCapacityMap > propEdgeResidualCapacityMap( edgeResidualCapacityMap );
347
348 typedef std::map< edge_descriptor, edge_descriptor > StdReversedEdgeMap;
349 StdReversedEdgeMap reversedEdgeMap;
350 boost::associative_property_map< StdReversedEdgeMap > propReversedEdgeMap( reversedEdgeMap );
351
352 typedef std::map< vertex_descriptor, edge_descriptor > StdPredecessorMap;
353 StdPredecessorMap predecessorMap;
354 boost::associative_property_map< StdPredecessorMap > propPredecessorMap( predecessorMap );
355
357
358
359 for ( std::pair<edge_iterator, edge_iterator>
360 ve =
boost::edges( digSurf ); ve.first != ve.second; ++ve.first, ++nbEdges )
361 {
362 edge_descriptor e = *ve.first;
363 edge_descriptor rev_e = digSurf.opposite( e );
368 if ( v1 < v2 )
369 {
371 capacity_type capacity = (
K.
sKCoord( sep, 2 ) == 0 ) ? 0.01 : 1.0;
372 edgeCapacityMap[ e ] = capacity;
373 edgeCapacityMap[ digSurf.opposite( e ) ] = capacity;
374 reversedEdgeMap[ e ] = digSurf.opposite( e );
375 reversedEdgeMap[ digSurf.opposite( e ) ] = e;
376 }
377 }
378 trace.
info() <<
"- nb edges = " << nbEdges << std::endl;
379 distanceMap.clear();
380 colorMap.clear();
381 capacity_type max_flow =
382 boost::boykov_kolmogorov_max_flow
383 ( digSurf,
384 propEdgeCapacityMap, propEdgeResidualCapacityMap,
385 propReversedEdgeMap, propPredecessorMap, propColorMap, propDistanceMap, propVertexIndexMap,
386 start, furthest );
387 trace.
info() <<
"- max flow = " << max_flow << std::endl;
388 ++nb; nbok += (
abs( max_flow - total_weight ) < 0.0000001 ) ? 1 : 0;
389 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
390 << "max_flow == min_cut, Duality max-flow/min-cut." << std::endl;
392
394 typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, VertexProperties > BGraph;
395 BGraph bG;
396 boost::copy_graph( digSurf, bG,
397 boost::vertex_copy( my_vertex_copier<Graph,BGraph,StdVertexIndexMap>( digSurf, bG, vertexIndexMap ) )
398 .edge_copy( my_edge_copier<Graph,BGraph>( digSurf, bG ) )
399 .vertex_index_map( propVertexIndexMap )
400 );
401 typedef boost::graph_traits< BGraph >::vertex_descriptor vertex_descriptor_2;
402 typedef boost::graph_traits< BGraph >::vertex_iterator vertex_iterator_2;
403 typedef boost::property_map< BGraph, surfel_position_t>::type GraphSurfelPositionMap;
404 GraphSurfelPositionMap surfelPos( boost::get( surfel_position_t(), bG) );
405 for ( std::pair<vertex_iterator_2, vertex_iterator_2>
407 {
408 vertex_descriptor_2 v1 = *vp.first;
409 surfel_position pos = boost::get( surfelPos, v1 );
410 trace.
info() <<
"- " << v1 <<
" was at " << pos.myP << std::endl;
411 }
413 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
415 << " vertices." << std::endl;
417
418 return nbok == nb;
419}
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
void attach(ConstAlias< EuclideanShape > shape)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
const Point & lowerBound() const
const Point & upperBound() const
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Integer sKCoord(const SCell &c, Dimension k) const
Return its Khalimsky coordinate along [k].
Aim: This class converts a string polynomial expression in a multivariate polynomial.
Iterator read(Polynomial &p, Iterator begin, Iterator end)
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
static void trackBoundary(SCellSet &surface, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::SurfelSet SurfelSet
boost::uint64_t uint64_t
unsigned 64-bit integer.
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator > edges(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertices_size_type num_vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_descriptor source(typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_descriptor edge, const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::out_edge_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::out_edge_iterator > out_edges(typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_descriptor u, const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_descriptor target(typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_descriptor edge, const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Go to http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/AdjacencyGraph.html.
Go to http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/EdgeListGraph.html.
Go to http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/IncidenceGraph.html.
Go to http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/VertexListGraph.html.
PointVector< 3, double > RealPoint