62#include "DGtal/base/Common.h"
63#include "DGtal/io/viewers/Viewer3D.h"
64#include "DGtal/io/DrawWithDisplay3DModifier.h"
65#include "DGtal/io/Color.h"
66#include "DGtal/io/colormaps/SimpleDistanceColorMap.h"
67#include "DGtal/shapes/Shapes.h"
68#include "DGtal/helpers/StdDefs.h"
69#include "DGtal/helpers/Shortcuts.h"
70#include "DGtal/images/ImageContainerBySTLVector.h"
72#include "DGtal/geometry/volumes/TangencyComputer.h"
74#include "ConfigExamples.h"
94 std::cout <<
"Selected surfel=" << *selected << std::endl;
98int main(
int argc,
char** argv )
100 trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <input.vol> <m> <M> <opt>" << std::endl;
101 trace.
info() <<
"\tComputes shortest paths to a source point" << std::endl;
102 trace.
info() <<
"\t- input.vol: choose your favorite shape" << std::endl;
103 trace.
info() <<
"\t- m [==0], M [==255]: used to threshold input vol image" << std::endl;
104 trace.
info() <<
"\t- opt >= sqrt(3): secure shortest paths, 0: fast" << std::endl;
105 string inputFilename = examplesPath +
"samples/Al.100.vol";
106 std::string fn= argc > 1 ? argv[ 1 ] : inputFilename;
107 int m = argc > 2 ? atoi( argv[ 2 ] ) : 0;
108 int M = argc > 3 ? atoi( argv[ 3 ] ) : 255;
109 double opt = argc > 4 ? atof( argv[ 4 ] ) : sqrt(3.0);
111 QApplication application(argc,argv);
113 viewer.setWindowTitle(
"fullConvexityShortestPaths3D");
118 params(
"thresholdMin", m )(
"thresholdMax", M );
119 params(
"surfaceComponents" ,
"All" );
122 trace.
info() <<
"Building set or importing vol ... ";
133 std::vector< Point > points;
134 std::map< SCell, int > surfel2idx;
135 std::map< Point, int > point2idx;
137 for (
auto s : (*surface) )
143 auto it = point2idx.find( p );
144 if ( it == point2idx.end() )
146 points.push_back( p );
147 surfel2idx[ s ] = idx;
148 point2idx [ p ] = idx++;
151 surfel2idx[ s ] = it->second;
153 trace.
info() <<
"Shape has " << points.size() <<
" interior boundary points"
160 for (
int i = 0; i < 2; i++ )
162 MViewer3D viewerCore(
K );
164 Color colSurfel( 200, 200, 255, 255 );
165 Color colStart( 255, 0, 0, 255 );
167 viewerCore <<
SetMode3D( surfels[ 0 ].className(),
"Basic");
168 viewerCore.setFillColor( colSurfel );
169 for (
auto && s : surfels ) viewerCore <<
SetName3D( name++ ) << s;
171 0, surfels.size() - 1 );
172 viewerCore << MViewer3D::updateDisplay;
177 const auto s0 = surfels[ selected_surfels[ 0 ] ];
181 auto start0 = point2idx[ p0 ];
182 std::cout <<
"Start0 index is " << start0 << std::endl;
183 const auto s1 = surfels[ selected_surfels[ 1 ] ];
187 auto start1 = point2idx[ p1 ];
188 std::cout <<
"Start1 index is " << start1 << std::endl;
195 TC.init( points.cbegin(), points.cend() );
196 auto SP = TC.makeShortestPaths( opt );
198 double last_distance = 0.0;
199 while ( ! SP.finished() )
201 last_distance = std::get<2>( SP.current() );
204 std::cout <<
"Max distance is " << last_distance << std::endl;
208 const int nb_repetitions = 10;
209 const double period = last_distance / nb_repetitions;
211 MViewer3D viewerCore;
213 Color colSurfel( 200, 200, 255, 128 );
214 Color colStart( 255, 0, 0, 128 );
216 viewerCore.setUseGLPointForBalls(
true);
217 for (
auto i = 0; i < points.size(); ++i )
219 const double d_s = SP.distance( i );
220 Color c_s = cmap( fmod( d_s, period ) );
221 viewerCore.setFillColor( c_s );
222 viewerCore.addBall(
RealPoint( points[ i ][ 0 ],
224 points[ i ][ 2 ] ), 12.0 );
246 viewerCore << MViewer3D::updateDisplay;
253 auto SP0 = TC.makeShortestPaths( opt );
254 auto SP1 = TC.makeShortestPaths( opt );
257 std::vector< Index > Q;
258 while ( ! SP0.finished() && ! SP1.finished() )
260 auto n0 = SP0.current();
261 auto n1 = SP1.current();
262 auto p0 = std::get<0>( n0 );
263 auto p1 = std::get<0>( n1 );
266 if ( SP0.isVisited( p1 ) )
268 auto c0 = SP0.pathToSource( p1 );
269 auto c1 = SP1.pathToSource( p1 );
270 std::copy(c0.rbegin(), c0.rend(), std::back_inserter(Q));
272 std::copy(c1.begin(), c1.end(), std::back_inserter(Q));
281 const int nb_repetitions = 10;
282 const double period = last_distance / nb_repetitions;
284 MViewer3D viewerCore;
286 Color colSurfel( 200, 200, 255, 128 );
287 Color colStart( 255, 0, 0, 128 );
288 viewerCore.setUseGLPointForBalls(
true);
289 for (
auto i = 0; i < points.size(); ++i )
291 const double d_s0 = SP0.isVisited( i ) ? SP0.distance( i ) : SP0.infinity();
292 const double d_s1 = SP1.isVisited( i ) ? SP1.distance( i ) : SP1.infinity();
293 const double d_s = std::min( d_s0, d_s1 );
294 Color c_s = ( d_s != SP0.infinity() )
295 ? cmap( fmod( d_s, period ) )
297 viewerCore.setFillColor( c_s );
298 viewerCore.addBall(
RealPoint( points[ i ][ 0 ],
300 points[ i ][ 2 ] ), 12 );
303 for (
auto i = 1; i < Q.size(); i++ )
305 Point p1 = TC.point( Q[ i-1 ] );
306 Point p2 = TC.point( Q[ i ] );
307 viewerCore.addLine( p1, p2, 18.0 );
309 viewerCore << MViewer3D::updateDisplay;
315 std::vector< Index > sources;
316 std::vector< Index > dests;
317 for (
int i = 0; i < 20; i++ )
318 sources.push_back( rand() % TC.size() );
319 dests.push_back( start0 );
320 dests.push_back( start1 );
321 auto paths = TC.shortestPaths( sources, dests, opt );
325 MViewer3D viewerCore;
327 Color colSurfel( 200, 200, 255, 128 );
328 Color colStart( 255, 0, 0, 128 );
329 viewerCore.setUseGLPointForBalls(
true);
330 for (
auto i = 0; i < points.size(); ++i )
332 viewerCore.setFillColor(
Color( 150, 150, 150, 255 ) );
333 viewerCore.addBall(
RealPoint( points[ i ][ 0 ],
335 points[ i ][ 2 ] ), 12 );
338 for (
auto path : paths )
340 for (
auto i = 1; i < path.size(); i++ )
342 Point p1 = TC.point( path[ i-1 ] );
343 Point p2 = TC.point( path[ i ] );
344 viewerCore.addLine( p1, p2, 18.0 );
346 trace.
info() <<
"length=" << TC.length( path ) << std::endl;
348 viewerCore << MViewer3D::updateDisplay;
Structure representing an RGB triple with alpha component.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Dimension sOrthDir(const SCell &s) const
Given a signed surfel [s], returns its orthogonal direction (ie, the coordinate where the surfel is c...
Point sCoords(const SCell &c) const
Return its digital coordinates.
bool sDirect(const SCell &p, Dimension k) const
Return 'true' if the direct orientation of [p] along [k] is in the positive coordinate direction.
SCell sIncident(const SCell &c, Dimension k, bool up) const
Return the forward or backward signed cell incident to [c] along axis [k], depending on [up].
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters ¶ms=parametersDigitalSurface())
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters ¶ms=parametersDigitalSurface())
static Parameters defaultParameters()
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Aim: simple blue to red colormap for distance information for instance.
Aim: A class that computes tangency to a given digital set. It provides services to compute all the c...
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
int reaction(void *viewer, DGtal::int32_t name, void *data)
Space::RealPoint RealPoint
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
boost::int32_t int32_t
signed 32-bit integer.
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.