DGtal  0.9.2
testNormalVectorEstimatorEmbedder.cpp
1 
32 #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 
64 using namespace std;
65 using namespace DGtal;
66 using namespace Z3i;
67 
69 // Functions for testing class LocalConvolutionNormalVectorEstimator.
71 
75 bool testLocalConvolutionNormalVectorEstimator ( int /*argc*/, char**/*argv*/ )
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() );
88  SetFromImage<DigitalSet>::append<Image> ( set3d, image,
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
120  < MyDigitalSurface,
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
151  typedef deprecated::LocalConvolutionNormalVectorEstimator < MyDigitalSurface,
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 }
182 
184 // Standard services - public :
185 
186 int main ( int argc, char** argv )
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 }
201 // //
void beginBlock(const std::string &keyword="")
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:130
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
STL namespace.
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of a given...
Aim: A trivial embedder for digital surfaces, which corresponds to the canonic injection of cell cent...
std::ostream & emphase()
bool init(const Point &lower, const Point &upper, bool isClosed)
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
DGtal is the top-level namespace which contains all DGtal functions and types.
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...
Aim: implement a trivial constant convolution kernel which returns 1 to each distance.
Aim: Represents the concept of estimator of normal vector along digital surfaces. ...
const Domain & domain() const
Definition: Image.h:192
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...