File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
volDistanceTraversal.cpp File Reference
#include <iostream>
#include <queue>
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/topology/CanonicSCellEmbedder.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/graph/DistanceBreadthFirstVisitor.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/geometry/volumes/distance/LpMetric.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
Include dependency graph for volDistanceTraversal.cpp:

Go to the source code of this file.

Functions

void usage (int, char **argv)
int main (int argc, char **argv)

Detailed Description

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/02/06

An example file named volDistanceTraversal.

This file is part of the DGtal library.

Definition in file volDistanceTraversal.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

[volDistanceTraversal-readVol]

[volDistanceTraversal-readVol]

[volDistanceTraversal-KSpace]

[volDistanceTraversal-KSpace]

[volDistanceTraversal-SurfelAdjacency]

[volDistanceTraversal-SurfelAdjacency]

[volDistanceTraversal-SetUpDigitalSurface]

[volDistanceTraversal-SetUpDigitalSurface]

[volDistanceTraversal-ExtractingSurface]

[volDistanceTraversal-ExtractingSurface]

[volDistanceTraversal-DisplayingSurface]

[volDistanceTraversal-DisplayingSurface]

Definition at line 67 of file volDistanceTraversal.cpp.

68{
69 if ( argc < 4 )
70 {
71 usage( argc, argv );
72 return 1;
73 }
74 std::string inputFilename = argv[ 1 ];
75 unsigned int minThreshold = atoi( argv[ 2 ] );
76 unsigned int maxThreshold = atoi( argv[ 3 ] );
77 unsigned int idxP = (argc <= 4) ? 0 : atoi( argv[ 4 ] );
78
80 trace.beginBlock( "Reading vol file into an image." );
83 DigitalSet set3d (image.domain());
85 minThreshold, maxThreshold);
86 trace.endBlock();
88
89
91 trace.beginBlock( "Construct the Khalimsky space from the image domain." );
92 KSpace ks;
93 bool space_ok = ks.init( image.domain().lowerBound(),
94 image.domain().upperBound(), true );
95 if (!space_ok)
96 {
97 trace.error() << "Error in the Khamisky space construction."<<std::endl;
98 return 2;
99 }
100 trace.endBlock();
102
104 typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
105 MySurfelAdjacency surfAdj( true ); // interior in all directions.
107
109 trace.beginBlock( "Set up digital surface." );
113 SCell bel = Surfaces<KSpace>::findABel( ks, set3d, 100000 );
114 MyDigitalSurfaceContainer* ptrSurfContainer =
115 new MyDigitalSurfaceContainer( ks, set3d, surfAdj, bel );
116 MyDigitalSurface digSurf( ptrSurfContainer ); // acquired
117 trace.endBlock();
118 // Find first bel.
119 MyDigitalSurface::ConstIterator it = digSurf.begin();
120 for ( idxP = idxP % digSurf.size(); idxP != 0; --idxP ) ++it;
121 bel = *it;
123
125 trace.beginBlock( "Extracting boundary by distance tracking from an initial bel." );
126 typedef CanonicSCellEmbedder<KSpace> SCellEmbedder;
127 typedef SCellEmbedder::Value RealPoint;
128 typedef RealPoint::Coordinate Scalar;
129 typedef LpMetric<Space> Distance;
130 using DistanceToPoint = std::function<double(const Space::RealPoint &)>;
133 MyDistanceVisitor;
134 typedef MyDistanceVisitor::Node MyNode;
135 typedef MyDistanceVisitor::Scalar MySize;
136
137 SCellEmbedder embedder( ks );
138 Distance distance(2.0);
139 DistanceToPoint distanceToPoint = std::bind( distance, embedder( bel ), std::placeholders::_1 );
140 VertexFunctor vfunctor( embedder, distanceToPoint );
141 MyDistanceVisitor visitor( digSurf, vfunctor, bel );
142
143 unsigned long nbSurfels = 0;
144 MyNode node;
145 while ( ! visitor.finished() )
146 {
147 node = visitor.current();
148 ++nbSurfels;
149 visitor.expand();
150 }
151 MySize maxDist = node.second;
152 trace.endBlock();
154
156 trace.beginBlock( "Displaying surface in PolyscopeViewer." );
157 PolyscopeViewer<> viewer( ks );
158 HueShadeColorMap<MySize,1> hueShade( 0, maxDist );
159 MyDistanceVisitor visitor2( digSurf, vfunctor, bel );
160 viewer << Color::White << bel;
161 visitor2.expand();
162 std::vector< MyDistanceVisitor::Node > layer;
163 while ( ! visitor2.finished() )
164 {
165 MyNode n = visitor2.current();
166 Color c = hueShade( n.second );
167 viewer << c << n.first;
168 visitor2.expand();
169 }
170 trace.info() << "nb surfels = " << nbSurfels << std::endl;
171 trace.endBlock();
172 viewer.show();
173 return 0;
175}
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color White
Definition Color.h:424
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: This class is useful to perform an exploration of a graph given a starting point or set (called ...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: implements l_p metrics.
Definition LpMetric.h:75
PointVector< dim, double > RealPoint
Definition SpaceND.h:117
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...
Aim: Define a new Functor from the composition of two other functors.
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Space::RealPoint RealPoint
Definition StdDefs.h:170
KSpace::SCell SCell
Definition StdDefs.h:149
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:173
Trace trace
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
ImageContainerBySTLVector< Domain, Value > Type
static void append(Set &aSet, const ForegroundPredicate &isForeground, typename Image::Domain::ConstIterator itBegin, typename Image::Domain::ConstIterator itEnd)
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Image image(domain)

References DGtal::SetFromImage< TSet >::append(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Surfaces< TKSpace >::findABel(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::PolyscopeViewer< Space, KSpace >::show(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::size(), DGtal::trace, usage(), and DGtal::Color::White.

◆ usage()

void usage ( int ,
char ** argv )

Definition at line 60 of file volDistanceTraversal.cpp.

60 {
61 std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT> <idxP>" << std::endl;
62 std::cerr << "\t - displays the Euclidean distance to the specified surfel on the boundary of the shape stored in vol file <fileName.vol>." << std::endl;
63 std::cerr << "\t - the shape is defined implicitly: voxel v belongs to the shape iff its value I(v) follows minT < I(v) <= maxT." << std::endl;
64 std::cerr << "\t - starts from the <idxP>-th surfel or first one if invalid." << std::endl;
65}