Displays the Euclidean distance to a starting surfel on the boundary of a vol shape (traversal by mix distance/breadth-first, see DGtal::DistanceBreadthFirstVisitor).
#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"
void usage(
int,
char** argv ) {
std::cerr << "Usage: " << argv[ 0 ] << " <fileName.vol> <minT> <maxT> <idxP>" << std::endl;
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;
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;
std::cerr << "\t - starts from the <idxP>-th surfel or first one if invalid." << std::endl;
}
int main(
int argc,
char** argv )
{
if ( argc < 4 )
{
return 1;
}
std::string inputFilename = argv[ 1 ];
unsigned int minThreshold = atoi( argv[ 2 ] );
unsigned int maxThreshold = atoi( argv[ 3 ] );
unsigned int idxP = (argc <= 4) ? 0 : atoi( argv[ 4 ] );
trace.beginBlock(
"Reading vol file into an image." );
typedef ImageSelector < Domain, int>::Type
Image;
minThreshold, maxThreshold);
trace.beginBlock(
"Construct the Khalimsky space from the image domain." );
bool space_ok = ks.init(
image.domain().lowerBound(),
image.domain().upperBound(),
true );
if (!space_ok)
{
trace.error() <<
"Error in the Khamisky space construction."<<std::endl;
return 2;
}
MySurfelAdjacency surfAdj( true );
trace.beginBlock(
"Set up digital surface." );
MyDigitalSurface::ConstIterator it = digSurf.begin();
for ( idxP = idxP % digSurf.size(); idxP != 0; --idxP ) ++it;
bel = *it;
trace.beginBlock(
"Extracting boundary by distance tracking from an initial bel." );
typedef RealPoint::Coordinate Scalar;
MyDistanceVisitor;
typedef MyDistanceVisitor::Node MyNode;
typedef MyDistanceVisitor::Scalar MySize;
SCellEmbedder embedder( ks );
Distance distance(2.0);
DistanceToPoint distanceToPoint = std::bind( distance, embedder( bel ), std::placeholders::_1 );
VertexFunctor vfunctor( embedder, distanceToPoint );
MyDistanceVisitor visitor( digSurf, vfunctor, bel );
unsigned long nbSurfels = 0;
MyNode node;
while ( ! visitor.finished() )
{
node = visitor.current();
++nbSurfels;
visitor.expand();
}
MySize maxDist = node.second;
trace.beginBlock(
"Displaying surface in PolyscopeViewer." );
PolyscopeViewer<> viewer( ks );
MyDistanceVisitor visitor2( digSurf, vfunctor, bel );
visitor2.expand();
std::vector< MyDistanceVisitor::Node > layer;
while ( ! visitor2.finished() )
{
MyNode n = visitor2.current();
Color c = hueShade( n.second );
viewer << c << n.first;
visitor2.expand();
}
trace.info() <<
"nb surfels = " << nbSurfels << std::endl;
viewer.show();
return 0;
}
Structure representing an RGB triple with alpha component.
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
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: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: implements l_p metrics.
PointVector< dim, double > RealPoint
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
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
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())
ImageContainerBySTLVector< Domain, Value > Image
PointVector< 3, double > RealPoint
Z2i::DigitalSet DigitalSet