DGtal  0.9.3
Functions
testNormalVectorEstimatorEmbedder.cpp File Reference
#include <iostream>
#include <iterator>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtal/topology/CanonicDigitalSurfaceEmbedder.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/DigitalSetBoundary.h"
#include "DGtal/topology/ImplicitDigitalSurface.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/topology/ExplicitDigitalSurface.h"
#include "DGtal/topology/LightExplicitDigitalSurface.h"
#include "DGtal/graph/BreadthFirstVisitor.h"
#include "DGtal/topology/helpers/FrontierPredicate.h"
#include "DGtal/topology/helpers/BoundaryPredicate.h"
#include "DGtal/graph/CUndirectedSimpleLocalGraph.h"
#include "DGtal/graph/CUndirectedSimpleGraph.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/kernel/CanonicEmbedder.h"
#include "DGtal/geometry/surfaces/estimation/CNormalVectorEstimator.h"
#include "DGtal/geometry/surfaces/estimation/BasicConvolutionWeights.h"
#include "DGtal/geometry/surfaces/estimation/LocalConvolutionNormalVectorEstimator.h"
#include "DGtal/geometry/surfaces/estimation/DigitalSurfaceEmbedderWithNormalVectorEstimator.h"
Include dependency graph for testNormalVectorEstimatorEmbedder.cpp:

Go to the source code of this file.

Functions

bool testLocalConvolutionNormalVectorEstimator (int, char **)
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/04/08

Functions for testing class NormalVectorEstimatorEmbedder.

This file is part of the DGtal library.

Definition in file testNormalVectorEstimatorEmbedder.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 186 of file testNormalVectorEstimatorEmbedder.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testLocalConvolutionNormalVectorEstimator(), and DGtal::trace.

187 {
188  trace.beginBlock ( "Testing class LocalConvolutionNormalVectorEstimator" );
189  trace.info() << "Args:";
190  for ( int i = 0; i < argc; ++i )
191  trace.info() << " " << argv[ i ];
192  trace.info() << endl;
193 
194  bool res = testLocalConvolutionNormalVectorEstimator ( argc,argv ); // && ... other tests
195  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
196  trace.endBlock();
197 
198  return res ? 0 : 1;
199 
200 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
std::ostream & emphase()
std::ostream & info()
bool testLocalConvolutionNormalVectorEstimator(int, char **)

◆ testLocalConvolutionNormalVectorEstimator()

bool testLocalConvolutionNormalVectorEstimator ( int  ,
char **   
)

Example of a test. To be completed.

Definition at line 75 of file testNormalVectorEstimatorEmbedder.cpp.

References DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::Image< TImageContainer >::domain(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::exportAs3DNOFF(), image(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), and DGtal::trace.

Referenced by main().

76 {
77  unsigned int nbok = 0;
78  unsigned int nb = 0;
79 
80  trace.beginBlock ( "Testing convolution neighborhood ..." );
81 
82  std::string filename = testPath + "samples/cat10.vol";
83 
85  Image image = VolReader<Image>::importVol ( filename );
86  trace.info() <<image<<std::endl;
87  DigitalSet set3d ( image.domain() );
89  0,256 );
90 
91  KSpace ks;
92  bool space_ok = ks.init ( image.domain().lowerBound(),
93  image.domain().upperBound(), true );
94  if ( !space_ok )
95  {
96  trace.error() << "Error in the Khamisky space construction."<<std::endl;
97  return 2;
98  }
99  trace.endBlock();
100  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
101  MySurfelAdjacency surfAdj ( true ); // interior in all directions.
102 
103  trace.beginBlock ( "Set up digital surface." );
107  SCell bel = Surfaces<KSpace>::findABel ( ks, set3d, 100000 );
108  MyDigitalSurfaceContainer* ptrSurfContainer =
109  new MyDigitalSurfaceContainer ( ks, set3d, surfAdj, bel );
110  MyDigitalSurface digSurf ( ptrSurfContainer ); // acquired
111  MyDigitalSurface::ConstIterator it = digSurf.begin();
112  trace.endBlock();
113 
114  trace.beginBlock ( "Compute and output surface <cat10-constant.off> with trivial normals." );
115  //Convolution kernel
117 
118  //Estimator definition
122  BOOST_CONCEPT_ASSERT ( ( concepts::CNormalVectorEstimator< MyConstantEstimator > ) );
123  MyConstantEstimator myNormalEstimator ( digSurf, kernel );
124 
125  // Embedder definition
126  typedef CanonicDigitalSurfaceEmbedder<MyDigitalSurface> SurfaceEmbedder;
127  SurfaceEmbedder surfaceEmbedder ( digSurf );
129  < SurfaceEmbedder, MyConstantEstimator > SurfaceEmbedderWithTrivialNormal;
130  SurfaceEmbedderWithTrivialNormal mySurfelEmbedder ( surfaceEmbedder,
131  myNormalEstimator );
132 
133  // Compute normal vector field and displays it.
134  myNormalEstimator.init ( 1.0, 2 );
135 
136  MyConstantEstimator::Quantity res = myNormalEstimator.eval ( it );
137  trace.info() << "Normal vector at begin() : "<< res << std::endl;
138 
139  ofstream out ( "cat10-constant.off" );
140  if ( out.good() )
141  digSurf.exportAs3DNOFF ( out,mySurfelEmbedder );
142  out.close();
143  trace.endBlock();
144 
145  trace.beginBlock ( "Compute and output surface <cat10-gaussian.off> with gaussian convoluted normals." );
146 
147  //Convolution kernel
149 
150  //Estimator definition
153  BOOST_CONCEPT_ASSERT ( ( concepts::CNormalVectorEstimator< MyGaussianEstimator > ) );
154  MyGaussianEstimator myNormalEstimatorG ( digSurf, Gkernel );
155 
156  // Embedder definition
158  SurfaceEmbedderWithGaussianNormal mySurfelEmbedderG ( surfaceEmbedder, myNormalEstimatorG );
159 
160  // Compute normal vector field and displays it.
161  myNormalEstimatorG.init ( 1.0, 5 );
162 
163  MyGaussianEstimator::Quantity res2 = myNormalEstimatorG.eval ( it );
164  trace.info() << "Normal vector at begin() : "<< res2 << std::endl;
165  std::vector<MyGaussianEstimator::Quantity> allNormals;
166  myNormalEstimatorG.evalAll ( std::back_inserter ( allNormals ) );
167  trace.info() << "Normal vector field of size "<< allNormals.size() << std::endl;
168 
169  ofstream out2 ( "cat10-gaussian.off" );
170  if ( out2.good() )
171  digSurf.exportAs3DNOFF ( out2 ,mySurfelEmbedderG );
172  out2.close();
173 
174  nbok += true ? 1 : 0;
175  nb++;
176  trace.info() << "(" << nbok << "/" << nb << ") "
177  << "true == true" << std::endl;
178  trace.endBlock();
179 
180  return true;
181 }
void beginBlock(const std::string &keyword="")
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Trace trace
Definition: Common.h:137
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: Computes the normal vector at a surface element by convolution of elementary normal vector to ad...
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: A trivial embedder for digital surfaces, which corresponds to the canonic injection of cell cent...
bool init(const Point &lower, const Point &upper, bool isClosed)
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
std::ostream & info()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
ImageContainerBySTLVector< Domain, Value > Image
Aim: implement a trivial constant convolution kernel which returns 1 to each distance.
const Domain & domain() const
Definition: Image.h:192
Aim: Represents the concept of estimator of normal vector along digital surfaces. ...
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
Aim: implement a Gaussian centered convolution kernel.
Aim: Combines a digital surface embedder with a normal vector estimator to get a model of CDigitalSur...
std::ostream & error()
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Image image(domain)