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
geometry/surfaces/dvcm-3d.cpp

This example shows the computation of the VCM of a digital surface read from a .vol file. The normal is estimated from the diagonalization of the VCM tensor, while the orientation is deduced from the orientation of the trivial surfel normals. Feature detection is achieved with the eigenvalues of the VCM. A red color indicates a feature. Normals are displayed as black lines.

See also
Voronoi Covariance Measure of a digital surface
$ ./examples/geometry/surfaces/dvcm-3d
Normal vector and feature detection with Voronoi Covariance Measure.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/kernel/BasicPointPredicates.h"
#include "DGtal/math/linalg/EigenDecomposition.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/ImplicitDigitalSurface.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/IntervalForegroundPredicate.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/surfaces/estimation/VoronoiCovarianceMeasureOnDigitalSurface.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/io/readers/GenericReader.h"
#include "ConfigExamples.h"
using namespace std;
using namespace DGtal;
int main( int argc, char** argv )
{
typedef Z3i::Space Space;
typedef Z3i::Point Point;
typedef Z3i::RealVector RealVector;
typedef KSpace::Surfel Surfel;
typedef KSpace::Cell Cell;
typedef ImplicitDigitalSurface< KSpace, ThresholdedImage > DigitalSurfaceContainer;
typedef ExactPredicateLpSeparableMetric<Space, 2> Metric; // L2-metric type
typedef functors::HatPointFunction<Point,double> KernelFunction; // chi function type
typedef VoronoiCovarianceMeasureOnDigitalSurface< DigitalSurfaceContainer, Metric,
KernelFunction > VCMOnSurface;
typedef VCMOnSurface::Surfel2Normals::const_iterator S2NConstIterator;
string inputFilename = examplesPath + "samples/Al.100.vol";
trace.info() << "File = " << inputFilename << std::endl;
int thresholdMin = 0;
trace.info() << "Min image thres. = " << thresholdMin << std::endl;
int thresholdMax = 1;
trace.info() << "Max image thres. = " << thresholdMax << std::endl;
const double R = 20;
trace.info() << "Big radius R = " << R << std::endl;
const double r = 3;
trace.info() << "Small radius r = " << r << std::endl;
const double trivial_r = 3;
trace.info() << "Trivial radius t = " << trivial_r << std::endl; // for orienting the directions given by the tensor.
const double T = 0.1;
trace.info() << "Feature thres. T = " << T << std::endl; // threshold for displaying features as red.
const double size = 1.0; // size of displayed normals.
KSpace ks;
// Reads the volume
trace.beginBlock( "Loading image into memory and build digital surface." );
ThresholdedImage thresholdedImage( image, thresholdMin, thresholdMax );
trace.endBlock();
trace.beginBlock( "Extracting boundary by scanning the space. " );
ks.init( image.domain().lowerBound(),
image.domain().upperBound(), true );
SurfelAdjacency<KSpace::dimension> surfAdj( true ); // interior in all directions.
Surfel bel = Surfaces<KSpace>::findABel( ks, thresholdedImage, 10000 );
DigitalSurfaceContainer* container =
new DigitalSurfaceContainer( ks, thresholdedImage, surfAdj, bel, false );
trace.info() << "Digital surface has " << surface.size() << " surfels." << std::endl;
trace.endBlock();
Surfel2PointEmbedding embType = Pointels; // Could be Pointels|InnerSpel|OuterSpel;
Metric l2; // Euclidean L2 metric
KernelFunction chi( 1.0, r ); // hat function with support of radius r
VCMOnSurface vcm_surface( surface, embType, R, r,
chi, trivial_r, l2, true /* verbose */ );
trace.beginBlock( "Displaying VCM" );
PolyscopeViewer<> viewer( ks );
Cell dummy;
grad.addColor( Color( 128, 128, 255 ) );
grad.addColor( Color( 255, 255, 255 ) );
grad.addColor( Color( 255, 255, 0 ) );
grad.addColor( Color( 255, 0, 0 ) );
RealVector lambda; // eigenvalues of chi-vcm
for ( S2NConstIterator it = vcm_surface.mapSurfel2Normals().begin(),
itE = vcm_surface.mapSurfel2Normals().end(); it != itE; ++it )
{
Surfel s = it->first;
Point kp = ks.sKCoords( s );
RealPoint rp( 0.5 * (double) kp[ 0 ], 0.5 * (double) kp[ 1 ], 0.5 * (double) kp[ 2 ] );
RealVector n = it->second.vcmNormal;
vcm_surface.getChiVCMEigenvalues( lambda, s );
double ratio = lambda[ 1 ] / ( lambda[ 0 ] + lambda[ 1 ] + lambda[ 2 ] );
viewer.drawColor( grad( ratio > T ? T : ratio ) );
viewer << ks.unsigns( s );
n *= size;
viewer.drawLine( rp + n, rp - n );
}
trace.endBlock();
viewer.show();
return 0;
}
// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color Black
Definition Color.h:422
void drawColor(const DGtal::Color &color)
std::string drawLine(const RealPoint &a, const RealPoint &b, const std::string &uname="Line_{i}")
Aim: implements separable l_p metrics with exact predicates.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
void show() override
Starts the event loop and display of elements.
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: This class specializes the Voronoi covariance measure for digital surfaces. It adds notably the ...
Aim: Define a simple Foreground predicate thresholding image values between two constant values (the ...
CountedPtr< SH3::DigitalSurface > surface
SpaceND< 3, Integer > Space
Definition StdDefs.h:144
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Space::RealVector RealVector
Definition StdDefs.h:171
Space::RealPoint RealPoint
Definition StdDefs.h:170
Space::Point Point
Definition StdDefs.h:168
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Surfel2PointEmbedding
Possible embeddings for surfel as point(s)
STL namespace.
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
ImageContainerBySTLVector< Domain, Value > Type
int main()
Definition testBits.cpp:56
MyPointD Point
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain
PointVector< 3, double > RealPoint