DGtal  0.9.3
testLocalConvolutionNormalVectorEstimator.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
32 #include "ConfigTest.h"
33 #include "DGtal/base/Common.h"
34 #include "DGtal/topology/DigitalSurface.h"
35 #include "DGtal/topology/DigitalSetBoundary.h"
36 #include "DGtal/topology/ImplicitDigitalSurface.h"
37 #include "DGtal/topology/LightImplicitDigitalSurface.h"
38 #include "DGtal/topology/ExplicitDigitalSurface.h"
39 #include "DGtal/topology/LightExplicitDigitalSurface.h"
40 #include "DGtal/graph/BreadthFirstVisitor.h"
41 #include "DGtal/topology/helpers/FrontierPredicate.h"
42 #include "DGtal/topology/helpers/BoundaryPredicate.h"
43 #include "DGtal/graph/CUndirectedSimpleLocalGraph.h"
44 #include "DGtal/graph/CUndirectedSimpleGraph.h"
45 
46 #include "DGtal/io/readers/VolReader.h"
47 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
48 
49 #include "DGtal/io/viewers/Viewer3D.h"
50 #include "DGtal/images/ImageSelector.h"
51 #include "DGtal/shapes/Shapes.h"
52 #include "DGtal/helpers/StdDefs.h"
53 
54 
55 #include "DGtal/geometry/surfaces/estimation/BasicConvolutionWeights.h"
56 #include "DGtal/geometry/surfaces/estimation/LocalConvolutionNormalVectorEstimator.h"
57 
59 
60 using namespace std;
61 using namespace DGtal;
62 using namespace Z3i;
63 
65 // Functions for testing class LocalConvolutionNormalVectorEstimator.
67 
71 bool testLocalConvolutionNormalVectorEstimator ( int argc, char**argv )
72 {
73  unsigned int nbok = 0;
74  unsigned int nb = 0;
75 
76  trace.beginBlock ( "Testing convolution neighborhood ..." );
77 
78  QApplication application ( argc,argv );
79 
80  std::string filename = testPath + "samples/cat10.vol";
81 
83  Image image = VolReader<Image>::importVol ( filename );
84  trace.info() <<image<<std::endl;
85  DigitalSet set3d ( image.domain() );
87  0,256 );
88 
89  KSpace ks;
90  bool space_ok = ks.init ( image.domain().lowerBound(),
91  image.domain().upperBound(), true );
92  if ( !space_ok )
93  {
94  trace.error() << "Error in the Khamisky space construction."<<std::endl;
95  return true; //2; (return a bool !!!)
96  }
97  trace.endBlock();
98  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
99  MySurfelAdjacency surfAdj ( true ); // interior in all directions.
100 
101  trace.beginBlock ( "Set up digital surface." );
105  SCell bel = Surfaces<KSpace>::findABel ( ks, set3d, 100000 );
106  MyDigitalSurfaceContainer* ptrSurfContainer =
107  new MyDigitalSurfaceContainer ( ks, set3d, surfAdj, bel );
108  MyDigitalSurface digSurf ( ptrSurfContainer ); // acquired
109 
110  MyDigitalSurface::ConstIterator it = digSurf.begin();
111 
112 
113  //Convolution kernel
115 
116  //Estimator definition
119  MyEstimator myNormalEstimator ( digSurf, kernel );
120 
121  myNormalEstimator.init ( 1.0, 5 );
122 
123  MyEstimator::Quantity res = myNormalEstimator.eval ( it );
124  trace.info() << "Normal vector at begin() : "<< res << std::endl;
125 
127  viewer.show();
128 
129  DGtal::Color lineColorSave = viewer.getLineColor();
130  viewer.setLineColor( DGtal::Color ( 20,200,20 ));
131  for ( MyDigitalSurface::ConstIterator itbis = digSurf.begin(),itend=digSurf.end();
132  itbis!=itend; ++itbis )
133  {
134  viewer << ks.unsigns ( *itbis );
135 
136  Point center = ks.sCoords ( *itbis );
137  MyEstimator::Quantity normal = myNormalEstimator.eval ( itbis );
138 
139  viewer.addLine ( center,
140  DGtal::Z3i::RealPoint(center[0]-3*normal[0],
141  center[1]-3*normal[1],
142  center[2]-3*normal[2]) );
143  }
144  viewer.setLineColor( lineColorSave);
145  viewer<< Viewer3D<>::updateDisplay;
146 
147  //Convolution kernel
149 
150  //Estimator definition
153  MyEstimatorGaussian myNormalEstimatorG ( digSurf, Gkernel );
154 
155  myNormalEstimatorG.init ( 1.0, 15 );
156 
157  MyEstimatorGaussian::Quantity res2 = myNormalEstimatorG.eval ( it );
158  trace.info() << "Normal vector at begin() : "<< res2 << std::endl;
159 
160  viewer<< CustomColors3D ( Color ( 200, 0, 0 ),Color ( 200, 0,0 ) );
161  lineColorSave = viewer.getLineColor();
162  viewer.setLineColor( DGtal::Color ( 200,20,20 ));
163  for ( MyDigitalSurface::ConstIterator itbis = digSurf.begin(),itend=digSurf.end();
164  itbis!=itend; ++itbis )
165  {
166  viewer << ks.unsigns ( *itbis );
167 
168  Point center = ks.sCoords ( *itbis );
169  MyEstimatorGaussian::Quantity normal = myNormalEstimatorG.eval ( itbis );
170  viewer.addLine ( center,
171  DGtal::Z3i::RealPoint(center[0]-3*normal[0],
172  center[1]-3*normal[1],
173  center[2]-3*normal[2]) );
174  }
175  viewer.setLineColor( lineColorSave);
176  viewer<< Viewer3D<>::updateDisplay;
177 
178 
179  nbok += true ? 1 : 0;
180  nb++;
181  trace.info() << "(" << nbok << "/" << nb << ") "
182  << "true == true" << std::endl;
183  trace.endBlock();
184 
185  return application.exec();
186 }
187 
189 // Standard services - public :
190 
191 int main ( int argc, char** argv )
192 {
193  trace.beginBlock ( "Testing class LocalConvolutionNormalVectorEstimator" );
194  trace.info() << "Args:";
195  for ( int i = 0; i < argc; ++i )
196  trace.info() << " " << argv[ i ];
197  trace.info() << endl;
198 
199  bool res = testLocalConvolutionNormalVectorEstimator ( argc,argv ); // && ... other tests
200  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
201  trace.endBlock();
202  return true;
203 }
204 // //
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...
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
bool testLocalConvolutionNormalVectorEstimator(int argc, char **argv)
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
STL namespace.
double endBlock()
virtual void setLineColor(DGtal::Color aColor)
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
ConstIterator begin() const
int main(int argc, char **argv)
std::ostream & emphase()
bool init(const Point &lower, const Point &upper, bool isClosed)
virtual DGtal::Color getLineColor()
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
void addLine(const RealPoint &p1, const RealPoint &p2, const double width=0.03)
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...
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
ConstIterator end() const
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
Aim: implement a Gaussian centered convolution kernel.
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)