DGtal 2.1.0
Loading...
Searching...
No Matches
dvcm-3d.cpp
1
50#include <iostream>
51
52#include "DGtal/base/Common.h"
53#include "DGtal/helpers/StdDefs.h"
54#include "DGtal/kernel/BasicPointPredicates.h"
55#include "DGtal/math/linalg/EigenDecomposition.h"
56#include "DGtal/topology/helpers/Surfaces.h"
57#include "DGtal/topology/DigitalSurface.h"
58#include "DGtal/topology/ImplicitDigitalSurface.h"
59#include "DGtal/images/ImageSelector.h"
60#include "DGtal/images/IntervalForegroundPredicate.h"
61#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
62#include "DGtal/geometry/surfaces/estimation/VoronoiCovarianceMeasureOnDigitalSurface.h"
63#include "DGtal/io/colormaps/GradientColorMap.h"
64#include "DGtal/io/viewers/PolyscopeViewer.h"
65#include "DGtal/io/readers/GenericReader.h"
66#include "ConfigExamples.h"
67
68
70
71using namespace std;
72using namespace DGtal;
73
75int main()
76{
77 typedef Z3i::Space Space;
78 typedef Z3i::KSpace KSpace;
79 typedef Z3i::Point Point;
83 typedef KSpace::Surfel Surfel;
84 typedef KSpace::Cell Cell;
85
87 typedef functors::IntervalForegroundPredicate<Image> ThresholdedImage;
88 typedef ImplicitDigitalSurface< KSpace, ThresholdedImage > DigitalSurfaceContainer;
89
91 typedef ExactPredicateLpSeparableMetric<Space, 2> Metric; // L2-metric type
92 typedef functors::HatPointFunction<Point,double> KernelFunction; // chi function type
93 typedef VoronoiCovarianceMeasureOnDigitalSurface< DigitalSurfaceContainer, Metric,
94 KernelFunction > VCMOnSurface;
95 typedef VCMOnSurface::Surfel2Normals::const_iterator S2NConstIterator;
97
98 string inputFilename = examplesPath + "samples/Al.100.vol";
99 trace.info() << "File = " << inputFilename << std::endl;
100 int thresholdMin = 0;
101 trace.info() << "Min image thres. = " << thresholdMin << std::endl;
102 int thresholdMax = 1;
103 trace.info() << "Max image thres. = " << thresholdMax << std::endl;
104 const double R = 20;
105 trace.info() << "Big radius R = " << R << std::endl;
106 const double r = 3;
107 trace.info() << "Small radius r = " << r << std::endl;
108 const double trivial_r = 3;
109 trace.info() << "Trivial radius t = " << trivial_r << std::endl; // for orienting the directions given by the tensor.
110 const double T = 0.1;
111 trace.info() << "Feature thres. T = " << T << std::endl; // threshold for displaying features as red.
112
113 const double size = 1.0; // size of displayed normals.
114
115 KSpace ks;
116 // Reads the volume
117 trace.beginBlock( "Loading image into memory and build digital surface." );
118 Image image = GenericReader<Image>::import(inputFilename );
119 ThresholdedImage thresholdedImage( image, thresholdMin, thresholdMax );
120 trace.endBlock();
121 trace.beginBlock( "Extracting boundary by scanning the space. " );
122 ks.init( image.domain().lowerBound(),
123 image.domain().upperBound(), true );
124 SurfelAdjacency<KSpace::dimension> surfAdj( true ); // interior in all directions.
125 Surfel bel = Surfaces<KSpace>::findABel( ks, thresholdedImage, 10000 );
126 DigitalSurfaceContainer* container =
127 new DigitalSurfaceContainer( ks, thresholdedImage, surfAdj, bel, false );
129 trace.info() << "Digital surface has " << surface.size() << " surfels." << std::endl;
130 trace.endBlock();
131
133 Surfel2PointEmbedding embType = Pointels; // Could be Pointels|InnerSpel|OuterSpel;
134 Metric l2; // Euclidean L2 metric
135 KernelFunction chi( 1.0, r ); // hat function with support of radius r
136 VCMOnSurface vcm_surface( surface, embType, R, r,
137 chi, trivial_r, l2, true /* verbose */ );
139
140 trace.beginBlock( "Displaying VCM" );
141 PolyscopeViewer<> viewer( ks );
142 Cell dummy;
143
144 GradientColorMap<double> grad( 0, T );
145 grad.addColor( Color( 128, 128, 255 ) );
146 grad.addColor( Color( 255, 255, 255 ) );
147 grad.addColor( Color( 255, 255, 0 ) );
148 grad.addColor( Color( 255, 0, 0 ) );
149 RealVector lambda; // eigenvalues of chi-vcm
150 for ( S2NConstIterator it = vcm_surface.mapSurfel2Normals().begin(),
151 itE = vcm_surface.mapSurfel2Normals().end(); it != itE; ++it )
152 {
153 Surfel s = it->first;
154 Point kp = ks.sKCoords( s );
155 RealPoint rp( 0.5 * (double) kp[ 0 ], 0.5 * (double) kp[ 1 ], 0.5 * (double) kp[ 2 ] );
156 RealVector n = it->second.vcmNormal;
157 vcm_surface.getChiVCMEigenvalues( lambda, s );
158 double ratio = lambda[ 1 ] / ( lambda[ 0 ] + lambda[ 1 ] + lambda[ 2 ] );
159 viewer.drawColor( grad( ratio > T ? T : ratio ) );
160 viewer << ks.unsigns( s );
161
162 n *= size;
163
164 viewer.drawColor( Color::Black );
165 viewer.drawLine( rp + n, rp - n );
166 }
167
168 trace.endBlock();
169 viewer.show();
170 return 0;
171}
172// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color Black
Definition Color.h:422
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
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...
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
const Domain & domain() const
Definition Image.h:192
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
const Point & sKCoords(const SCell &c) const
Return its Khalimsky coordinates.
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...
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
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
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 >())
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
MyPointD Point
KSpace::Cell Cell
int main(int, char **)
Image image(domain)
HyperRectDomain< Space > Domain
PointVector< 3, double > RealPoint