DGtal 1.4.0
Loading...
Searching...
No Matches
testNormalVectorEstimatorEmbedder.cpp
Go to the documentation of this file.
1
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/CNormalVectorEstimator.h"
59#include "DGtal/geometry/surfaces/estimation/BasicConvolutionWeights.h"
60#include "DGtal/geometry/surfaces/estimation/LocalConvolutionNormalVectorEstimator.h"
61#include "DGtal/geometry/surfaces/estimation/DigitalSurfaceEmbedderWithNormalVectorEstimator.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
82 Image image = VolReader<Image>::importVol ( filename );
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 }
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
115 //Estimator definition
120 MyConstantEstimator myNormalEstimator ( digSurf, kernel );
121
122 // Embedder definition
124 SurfaceEmbedder surfaceEmbedder ( digSurf );
126 < SurfaceEmbedder, MyConstantEstimator > SurfaceEmbedderWithTrivialNormal;
127 SurfaceEmbedderWithTrivialNormal mySurfelEmbedder ( surfaceEmbedder,
128 myNormalEstimator );
129
130 // Compute normal vector field and displays it.
131 myNormalEstimator.init ( 1.0, 2 );
132
133 MyConstantEstimator::Quantity res = myNormalEstimator.eval ( it );
134 trace.info() << "Normal vector at begin() : "<< res << std::endl;
135
136 ofstream out ( "cat10-constant.off" );
137 if ( out.good() )
138 digSurf.exportAs3DNOFF ( out,mySurfelEmbedder );
139 out.close();
140 trace.endBlock();
141
142 trace.beginBlock ( "Compute and output surface <cat10-gaussian.off> with gaussian convoluted normals." );
143
144 //Convolution kernel
145 deprecated::GaussianConvolutionWeights < MyDigitalSurface::Size > Gkernel ( 4.0 );
146
147 //Estimator definition
151 MyGaussianEstimator myNormalEstimatorG ( digSurf, Gkernel );
152
153 // Embedder definition
155 SurfaceEmbedderWithGaussianNormal mySurfelEmbedderG ( surfaceEmbedder, myNormalEstimatorG );
156
157 // Compute normal vector field and displays it.
158 myNormalEstimatorG.init ( 1.0, 5 );
159
160 MyGaussianEstimator::Quantity res2 = myNormalEstimatorG.eval ( it );
161 trace.info() << "Normal vector at begin() : "<< res2 << std::endl;
162 std::vector<MyGaussianEstimator::Quantity> allNormals;
163 myNormalEstimatorG.evalAll ( std::back_inserter ( allNormals ) );
164 trace.info() << "Normal vector field of size "<< allNormals.size() << std::endl;
165
166 ofstream out2 ( "cat10-gaussian.off" );
167 if ( out2.good() )
168 digSurf.exportAs3DNOFF ( out2 ,mySurfelEmbedderG );
169 out2.close();
170
171 trace.endBlock();
172
173 return true;
174}
175
177// Standard services - public :
178
179int main ( int argc, char** argv )
180{
181 trace.beginBlock ( "Testing class LocalConvolutionNormalVectorEstimator" );
182 trace.info() << "Args:";
183 for ( int i = 0; i < argc; ++i )
184 trace.info() << " " << argv[ i ];
185 trace.info() << endl;
186
187 bool res = testLocalConvolutionNormalVectorEstimator ( argc,argv ); // && ... other tests
188 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
189 trace.endBlock();
190
191 return res ? 0 : 1;
192
193}
194// //
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of a given...
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
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...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
ConstIterator begin() 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
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.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
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 & emphase()
std::ostream & error()
std::ostream & info()
double endBlock()
Aim: implement a trivial constant convolution kernel which returns 1 to each distance.
Aim: implement a Gaussian centered convolution kernel.
Aim: Computes the normal vector at a surface element by convolution of elementary normal vector to ad...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
Aim: A trivial embedder for digital surfaces, which corresponds to the canonic injection of cell cent...
ImageContainerBySTLVector< Domain, Value > Type
static void append(Set &aSet, const ForegroundPredicate &isForeground, typename Image::Domain::ConstIterator itBegin, typename Image::Domain::ConstIterator itEnd)
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Aim: Represents the concept of estimator of normal vector along digital surfaces.
int main()
Definition testBits.cpp:56
bool testLocalConvolutionNormalVectorEstimator(int, char **)
ImageContainerBySTLVector< Domain, Value > Image