DGtal  1.3.beta
testNormalVectorEstimatorEmbedder.cpp
Go to the documentation of this file.
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  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  }
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
108  MyDigitalSurface::ConstIterator it = digSurf.begin();
109  trace.endBlock();
110 
111  trace.beginBlock ( "Compute and output surface <cat10-constant.off> with trivial normals." );
112  //Convolution kernel
114 
115  //Estimator definition
119  BOOST_CONCEPT_ASSERT ( ( concepts::CNormalVectorEstimator< MyConstantEstimator > ) );
120  MyConstantEstimator myNormalEstimator ( digSurf, kernel );
121 
122  // Embedder definition
123  typedef CanonicDigitalSurfaceEmbedder<MyDigitalSurface> SurfaceEmbedder;
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
146 
147  //Estimator definition
150  BOOST_CONCEPT_ASSERT ( ( concepts::CNormalVectorEstimator< MyGaussianEstimator > ) );
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 
179 int 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 // //
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::deprecated::ConstantConvolutionWeights
Aim: implement a trivial constant convolution kernel which returns 1 to each distance.
Definition: BasicConvolutionWeights.h:67
DGtal::deprecated::GaussianConvolutionWeights
Aim: implement a Gaussian centered convolution kernel.
Definition: BasicConvolutionWeights.h:99
DGtal::deprecated::LocalConvolutionNormalVectorEstimator
Aim: Computes the normal vector at a surface element by convolution of elementary normal vector to ad...
Definition: LocalConvolutionNormalVectorEstimator.h:85
DGtal::DigitalSurface::ConstIterator
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Definition: DigitalSurface.h:163
DGtal::concepts::CNormalVectorEstimator
Aim: Represents the concept of estimator of normal vector along digital surfaces.
Definition: CNormalVectorEstimator.h:94
DGtal::SetFromImage
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
DGtal::Trace::endBlock
double endBlock()
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::Trace::error
std::ostream & error()
DGtal::CanonicDigitalSurfaceEmbedder
Aim: A trivial embedder for digital surfaces, which corresponds to the canonic injection of cell cent...
Definition: CanonicDigitalSurfaceEmbedder.h:65
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::Trace::emphase
std::ostream & emphase()
main
int main(int argc, char **argv)
Definition: testNormalVectorEstimatorEmbedder.cpp:179
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::DigitalSetBoundary
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of a given...
Definition: DigitalSetBoundary.h:69
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::DigitalSurface::exportAs3DNOFF
void exportAs3DNOFF(std::ostream &out, const SCellEmbedderWithGradientMap &scembedder) const
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::Trace::info
std::ostream & info()
DGtal::LightImplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Definition: LightImplicitDigitalSurface.h:115
DGtal::DigitalSurface::begin
ConstIterator begin() const
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::DigitalSurfaceEmbedderWithNormalVectorEstimator
Aim: Combines a digital surface embedder with a normal vector estimator to get a model of CDigitalSur...
Definition: DigitalSurfaceEmbedderWithNormalVectorEstimator.h:74
testLocalConvolutionNormalVectorEstimator
bool testLocalConvolutionNormalVectorEstimator(int, char **)
Definition: testNormalVectorEstimatorEmbedder.cpp:75
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
MyDigitalSurfaceContainer
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
Definition: greedy-plane-segmentation-ex2.cpp:91
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
MyDigitalSurface
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Definition: greedy-plane-segmentation-ex2.cpp:92
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition: DigitalSetByAssociativeContainer.h:89
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64