Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testNormalVectorEstimatorEmbedder.cpp
Go to the documentation of this file.
1
16
31
33#include <iostream>
34#include <iterator>
35#include "DGtal/base/Common.h"
36#include "ConfigTest.h"
37#include "DGtal/topology/CanonicDigitalSurfaceEmbedder.h"
38#include "DGtal/topology/DigitalSurface.h"
39#include "DGtal/topology/DigitalSetBoundary.h"
40#include "DGtal/topology/ImplicitDigitalSurface.h"
41#include "DGtal/topology/LightImplicitDigitalSurface.h"
42#include "DGtal/topology/ExplicitDigitalSurface.h"
43#include "DGtal/topology/LightExplicitDigitalSurface.h"
44#include "DGtal/graph/BreadthFirstVisitor.h"
45#include "DGtal/topology/helpers/FrontierPredicate.h"
46#include "DGtal/topology/helpers/BoundaryPredicate.h"
47#include "DGtal/graph/CUndirectedSimpleLocalGraph.h"
48#include "DGtal/graph/CUndirectedSimpleGraph.h"
49
50#include "DGtal/io/readers/VolReader.h"
51#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
52
53#include "DGtal/images/ImageSelector.h"
54#include "DGtal/shapes/Shapes.h"
55#include "DGtal/helpers/StdDefs.h"
56#include "DGtal/kernel/CanonicEmbedder.h"
57
58#include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
59#include "DGtal/geometry/surfaces/estimation/DigitalSurfaceEmbedderWithNormalVectorEstimator.h"
60#include "DGtal/geometry/surfaces/estimation/estimationFunctors/ElementaryConvolutionNormalVectorEstimator.h"
61#include "DGtal/geometry/volumes/distance/LpMetric.h"
63
64using namespace std;
65using namespace DGtal;
66using namespace Z3i;
67
69// Functions for testing class LocalConvolutionNormalVectorEstimator.
71
75bool testLocalConvolutionNormalVectorEstimator ( int /*argc*/, char**/*argv*/ )
76{
77 trace.beginBlock ( "Testing convolution neighborhood ..." );
78
79 std::string filename = testPath + "samples/cat10.vol";
80
83 trace.info() <<image<<std::endl;
84 DigitalSet set3d ( image.domain() );
86 0,256 );
87
88 KSpace ks;
89 bool space_ok = ks.init ( image.domain().lowerBound(),
90 image.domain().upperBound(), true );
91 if ( !space_ok )
92 {
93 trace.error() << "Error in the Khamisky space construction."<<std::endl;
94 return 2;
95 }
96 trace.endBlock();
97 typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
98 MySurfelAdjacency surfAdj ( true ); // interior in all directions.
99
100 trace.beginBlock ( "Set up digital surface." );
104 SCell bel = Surfaces<KSpace>::findABel ( ks, set3d, 100000 );
105 MyDigitalSurfaceContainer* ptrSurfContainer =
106 new MyDigitalSurfaceContainer ( ks, set3d, surfAdj, bel );
107 MyDigitalSurface digSurf ( ptrSurfContainer ); // acquired
109 trace.endBlock();
110
111 trace.beginBlock ( "Compute and output surface <cat10-constant.off> with trivial normals." );
112 //Convolution kernel
114 typedef DGtal::functors::ConstValue< double > ConvFunctor;
115
116 LpMetric<Z3i::Space> l1(1.0);
117 CanonicSCellEmbedder<KSpace> embedder(digSurf.container().space());
118
121 Functor, ConvFunctor> MyConstantEstimator;
122 ConvFunctor kernel(1.0);
123 Functor estimator(embedder, 1.0);
124
125 MyConstantEstimator myNormalEstimator;
126 myNormalEstimator.attach(digSurf);
127 myNormalEstimator.setParams(l1, estimator, kernel, 2.0);
128 myNormalEstimator.init(1.0, digSurf.begin(), digSurf.end());
129
130 // Embedder definition
132 SurfaceEmbedder surfaceEmbedder ( digSurf );
134 < SurfaceEmbedder, MyConstantEstimator > SurfaceEmbedderWithTrivialNormal;
135 SurfaceEmbedderWithTrivialNormal mySurfelEmbedder ( surfaceEmbedder,
136 myNormalEstimator );
137
138 MyConstantEstimator::Quantity res = myNormalEstimator.eval ( it );
139 trace.info() << "Normal vector at begin() : "<< res << std::endl;
140
141 ofstream out ( "cat10-constant.off" );
142 if ( out.good() )
143 digSurf.exportAs3DNOFF ( out,mySurfelEmbedder );
144 out.close();
145 trace.endBlock();
146
147 trace.beginBlock ( "Compute and output surface <cat10-gaussian.off> with gaussian convoluted normals." );
148
149 //Convolution kernel
150 typedef DGtal::functors::GaussianKernel ConvFunctorGaussian;
152 Functor, ConvFunctorGaussian> MyGaussianEstimator;
153
154 ConvFunctorGaussian kernelGaussian(4.0);
155 Functor estimatorGaussian(embedder, 1.0); // Passed by alias, can't reuse previous
156
157 MyGaussianEstimator myNormalEstimatorG;
158 myNormalEstimatorG.attach(digSurf);
159 myNormalEstimatorG.setParams(l1, estimatorGaussian, kernelGaussian, 5.0);
160 myNormalEstimatorG.init(1.0, digSurf.begin(), digSurf.end());
161
162 // Embedder definition
164 SurfaceEmbedderWithGaussianNormal mySurfelEmbedderG ( surfaceEmbedder, myNormalEstimatorG );
165
166 MyGaussianEstimator::Quantity res2 = myNormalEstimatorG.eval ( it );
167 trace.info() << "Normal vector at begin() : "<< res2 << std::endl;
168 std::vector<MyGaussianEstimator::Quantity> allNormals;
169 myNormalEstimatorG.evalAll ( std::back_inserter ( allNormals ) );
170 trace.info() << "Normal vector field of size "<< allNormals.size() << std::endl;
171
172 ofstream out2 ( "cat10-gaussian.off" );
173 if ( out2.good() )
174 digSurf.exportAs3DNOFF ( out2 ,mySurfelEmbedderG );
175 out2.close();
176
177 trace.endBlock();
178
179 return true;
180}
181
183// Standard services - public :
184
185int main ( int argc, char** argv )
186{
187 trace.beginBlock ( "Testing class LocalConvolutionNormalVectorEstimator" );
188 trace.info() << "Args:";
189 for ( int i = 0; i < argc; ++i )
190 trace.info() << " " << argv[ i ];
191 trace.info() << endl;
192
193 bool res = testLocalConvolutionNormalVectorEstimator ( argc,argv ); // && ... other tests
194 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
195 trace.endBlock();
196
197 return res ? 0 : 1;
198
199}
200// //
const KSpace & space() const
Aim: Combines a digital surface embedder with a normal vector estimator to get a model of CDigitalSur...
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
void exportAs3DNOFF(std::ostream &out, const SCellEmbedderWithGradientMap &scembedder) const
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.
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
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 digital surfaces, which corresponds to the canonic injection of cell cent...
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())
Aim: defines a functor on double numbers which corresponds to a Gaussian convolution kernel....
int main()
Definition testBits.cpp:56
bool testLocalConvolutionNormalVectorEstimator(int, char **)
Image image(domain)