DGtal  1.1.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.

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/viewers/Viewer3D.h"
#include "ConfigExamples.h"
using namespace std;
using namespace DGtal;
int main( int argc, char** argv )
{
QApplication application(argc,argv);
typedef Z3i::Space Space;
typedef Z3i::Point Point;
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;
ThresholdedImage thresholdedImage( image, thresholdMin, thresholdMax );
trace.beginBlock( "Extracting boundary by scanning the space. " );
ks.init( image.domain().lowerBound(),
image.domain().upperBound(), true );
Surfel bel = Surfaces<KSpace>::findABel( ks, thresholdedImage, 10000 );
DigitalSurfaceContainer* container =
new DigitalSurfaceContainer( ks, thresholdedImage, surfAdj, bel, false );
DigitalSurface< DigitalSurfaceContainer > surface( container ); //acquired
trace.info() << "Digital surface has " << surface.size() << " surfels." << std::endl;
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" );
Viewer3D<> viewer( ks );
Cell dummy;
viewer.setWindowTitle("3D VCM viewer");
viewer << SetMode3D( dummy.className(), "Basic" );
viewer.show();
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.setFillColor( grad( ratio > T ? T : ratio ) );
viewer << ks.unsigns( s );
n *= size;
viewer.setLineColor( Color::Black );
viewer.addLine( rp + n, rp - n, 0.1 );
}
viewer << Viewer3D<>::updateDisplay;
application.exec();
return 0;
}
// //
DGtal::KhalimskyCell::className
std::string className() const
Return the style name used for drawing this object.
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
KSpace
Z3i::KSpace KSpace
Definition: sphereCotangentLaplaceOperator.cpp:70
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:140
DGtal::VoronoiCovarianceMeasureOnDigitalSurface
Aim: This class specializes the Voronoi covariance measure for digital surfaces. It adds notably the ...
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
RealVector
Z3i::RealVector RealVector
Definition: sphereCotangentLaplaceOperator.cpp:71
DGtal::DigitalSurface::size
Size size() const
DGtal::trace
Trace trace
Definition: Common.h:150
DGtal::ImplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Definition: ImplicitDigitalSurface.h:72
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Surfel2PointEmbedding
Surfel2PointEmbedding
Possible embeddings for surfel as point(s)
Aim: Provide a mechanism to load with the bestloader according to an image (2D or 3D) filename (by pa...
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:209
DGtal::SpaceND
Definition: SpaceND.h:96
DGtal::Trace::info
std::ostream & info()
DGtal::Viewer3D
Definition: Viewer3D.h:133
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::KhalimskySpaceND::sKCoords
const Point & sKCoords(const SCell &c) const
Return its Khalimsky coordinates.
DGtal::Pointels
@ Pointels
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:74
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Display3D< SpaceND< 3 >, KhalimskySpaceND< 3 > >::addLine
void addLine(const RealPoint &p1, const RealPoint &p2, const double width=0.03)
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
DGtal::Display3D< SpaceND< 3 >, KhalimskySpaceND< 3 > >::setFillColor
virtual void setFillColor(DGtal::Color aColor)
DGtal::Display3D< SpaceND< 3 >, KhalimskySpaceND< 3 > >::setLineColor
virtual void setLineColor(DGtal::Color aColor)
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition: ExactPredicateLpSeparableMetric.h:88
DGtal::PointVector< dim, Integer >
DGtal::Viewer3D::show
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Space
SpaceND< 2 > Space
Definition: testSimpleRandomAccessRangeFromPoint.cpp:42
Cell
KSpace::Cell Cell
Definition: testCubicalComplex.cpp:56
DGtal::ImageSelector
Aim: Automatically defines an adequate image type according to the hints given by the user.
Definition: ImageSelector.h:67
DGtal::KhalimskySpaceND::unsigns
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
DGtal::functors::IntervalForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values between two constant values (the ...
Definition: IntervalForegroundPredicate.h:65
Point
MyPointD Point
Definition: testClone2.cpp:383
RealPoint
Z2i::RealPoint RealPoint
Definition: testAstroid2D.cpp:46