Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testLocalConvolutionNormalVectorEstimator.cpp
Go to the documentation of this file.
1
16
29
31#include <iostream>
32#include "ConfigTest.h"
33#include "DGtal/base/Common.h"
34#include "DGtal/topology/DigitalSurface.h"
35#include "DGtal/topology/DigitalSetBoundary.h"
36#include "DGtal/topology/ImplicitDigitalSurface.h"
37#include "DGtal/topology/LightImplicitDigitalSurface.h"
38#include "DGtal/topology/ExplicitDigitalSurface.h"
39#include "DGtal/topology/LightExplicitDigitalSurface.h"
40#include "DGtal/graph/BreadthFirstVisitor.h"
41#include "DGtal/topology/helpers/FrontierPredicate.h"
42#include "DGtal/topology/helpers/BoundaryPredicate.h"
43#include "DGtal/graph/CUndirectedSimpleLocalGraph.h"
44#include "DGtal/graph/CUndirectedSimpleGraph.h"
45
46#include "DGtal/io/readers/VolReader.h"
47#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
48
49#include "DGtal/io/viewers/PolyscopeViewer.h"
50#include "DGtal/images/ImageSelector.h"
51#include "DGtal/shapes/Shapes.h"
52#include "DGtal/helpers/StdDefs.h"
53
54#include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
55#include "DGtal/geometry/surfaces/estimation/estimationFunctors/ElementaryConvolutionNormalVectorEstimator.h"
56#include "DGtal/geometry/volumes/distance/LpMetric.h"
57
59
60using namespace std;
61using namespace DGtal;
62using namespace Z3i;
63
65// Functions for testing class LocalConvolutionNormalVectorEstimator.
67
71bool testLocalConvolutionNormalVectorEstimator ( int argc, char**argv )
72{
73 trace.beginBlock ( "Testing convolution neighborhood ..." );
74
75 std::string filename = testPath + "samples/cat10.vol";
76
79 trace.info() <<image<<std::endl;
80 DigitalSet set3d ( image.domain() );
82 0,256 );
83
84 KSpace ks;
85 bool space_ok = ks.init ( image.domain().lowerBound(),
86 image.domain().upperBound(), true );
87 if ( !space_ok )
88 {
89 trace.error() << "Error in the Khamisky space construction."<<std::endl;
90 return true; //2; (return a bool !!!)
91 }
92 trace.endBlock();
93 typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
94 MySurfelAdjacency surfAdj ( true ); // interior in all directions.
95
96 trace.beginBlock ( "Set up digital surface." );
100 SCell bel = Surfaces<KSpace>::findABel ( ks, set3d, 100000 );
101 MyDigitalSurfaceContainer* ptrSurfContainer =
102 new MyDigitalSurfaceContainer ( ks, set3d, surfAdj, bel );
103 MyDigitalSurface digSurf ( ptrSurfContainer ); // acquired
104
106
107
108 //Convolution kernel
110 typedef DGtal::functors::ConstValue< double > ConvFunctor;
111
112 LpMetric<Z3i::Space> l1(1.0);
113 CanonicSCellEmbedder<KSpace> embedder(digSurf.container().space());
114
117 Functor, ConvFunctor> MyEstimator;
118 ConvFunctor kernel(1.0);
119 Functor estimator(embedder, 1.0);
120
121 MyEstimator myNormalEstimator;
122 myNormalEstimator.attach(digSurf);
123 myNormalEstimator.setParams(l1, estimator, kernel, 5.0);
124 myNormalEstimator.init(1.0, digSurf.begin(), digSurf.end());
125
126 MyEstimator::Quantity res = myNormalEstimator.eval ( it );
127 trace.info() << "Normal vector at begin() : "<< res << std::endl;
128
130 viewer.allowReuseList = true; // Enable auto grouping, which is to some extend, way better
131
132 // KCell will be rendered as quads (not signed)
133 viewer.newQuadList("Constant estimator");
134 for ( MyDigitalSurface::ConstIterator itbis = digSurf.begin(),itend=digSurf.end();
135 itbis!=itend; ++itbis )
136 {
137 Point center = ks.sCoords ( *itbis );
138 MyEstimator::Quantity normal = myNormalEstimator.eval ( itbis );
139 viewer << Color(200, 0, 0) << WithQuantity(ks.unsigns( *itbis ), "normal", -normal);
140 }
141
142 //Convolution kernel
143 typedef DGtal::functors::GaussianKernel ConvFunctorGaussian;
145 Functor, ConvFunctorGaussian> MyEstimatorGaussian;
146
147 ConvFunctorGaussian kernelGaussian(14.0);
148 Functor estimatorGaussian(embedder, 1.0); // Passed by alias, can't reuse previous
149
150 MyEstimatorGaussian myNormalEstimatorG;
151 myNormalEstimatorG.attach(digSurf);
152 myNormalEstimatorG.setParams(l1, estimatorGaussian, kernelGaussian, 15.0);
153 myNormalEstimatorG.init(1.0, digSurf.begin(), digSurf.end());
154
155 MyEstimatorGaussian::Quantity res2 = myNormalEstimatorG.eval ( it );
156 trace.info() << "Normal vector at begin() : "<< res2 << std::endl;
157
158 // KCell will be rendered as quads (not signed)
159 viewer.newQuadList("Gaussian estimator");
160 for ( MyDigitalSurface::ConstIterator itbis = digSurf.begin(),itend=digSurf.end();
161 itbis!=itend; ++itbis )
162 {
163 Point center = ks.sCoords ( *itbis );
164 MyEstimatorGaussian::Quantity normal = myNormalEstimatorG.eval ( itbis );
165 viewer << Color(200, 0, 0) << WithQuantity(ks.unsigns( *itbis ), "normal", -normal);
166 }
167
168 viewer.show();
169 return 0;
170}
171
173// Standard services - public :
174
175int main ( int argc, char** argv )
176{
177 trace.beginBlock ( "Testing class LocalConvolutionNormalVectorEstimator" );
178 trace.info() << "Args:";
179 for ( int i = 0; i < argc; ++i )
180 trace.info() << " " << argv[ i ];
181 trace.info() << endl;
182
183 bool res = testLocalConvolutionNormalVectorEstimator ( argc,argv ); // && ... other tests
184 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
185 trace.endBlock();
186
187 return (res ? 0:1);
188}
189// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
const KSpace & space() const
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
const DigitalSurfaceContainer & container() const
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
ConstIterator begin() const
ConstIterator end() const
std::string newQuadList(const std::string &name)
Definition Display3D.h:532
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.
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
Point sCoords(const SCell &c) const
Return its digital coordinates.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: this class adapts any local functor on digital surface element to define a local estimator....
Aim: implements l_p metrics.
Definition LpMetric.h:75
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: Define a simple functor that returns a constant value (0 by default).
Aim: Estimates normal vector by convolution of elementary normal vector to adjacent surfel.
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
Z3i this namespace gathers the standard of types for 3D imagery.
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
KSpace::SCell SCell
Definition StdDefs.h:149
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:173
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
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())
Attach a property to an element.
Definition Display3D.h:327
Aim: defines a functor on double numbers which corresponds to a Gaussian convolution kernel....
int main()
Definition testBits.cpp:56
bool testLocalConvolutionNormalVectorEstimator(int argc, char **argv)
Image image(domain)