DGtal  1.5.beta
testLocalConvolutionNormalVectorEstimator.cpp
Go to the documentation of this file.
1 
31 #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  trace.beginBlock ( "Testing convolution neighborhood ..." );
74 
75  QApplication application ( argc,argv );
76 
77  std::string filename = testPath + "samples/cat10.vol";
78 
80  Image image = VolReader<Image>::importVol ( filename );
81  trace.info() <<image<<std::endl;
82  DigitalSet set3d ( image.domain() );
84  0,256 );
85 
86  KSpace ks;
87  bool space_ok = ks.init ( image.domain().lowerBound(),
88  image.domain().upperBound(), true );
89  if ( !space_ok )
90  {
91  trace.error() << "Error in the Khamisky space construction."<<std::endl;
92  return true; //2; (return a bool !!!)
93  }
94  trace.endBlock();
95  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
96  MySurfelAdjacency surfAdj ( true ); // interior in all directions.
97 
98  trace.beginBlock ( "Set up digital surface." );
102  SCell bel = Surfaces<KSpace>::findABel ( ks, set3d, 100000 );
103  MyDigitalSurfaceContainer* ptrSurfContainer =
104  new MyDigitalSurfaceContainer ( ks, set3d, surfAdj, bel );
105  MyDigitalSurface digSurf ( ptrSurfContainer ); // acquired
106 
107  MyDigitalSurface::ConstIterator it = digSurf.begin();
108 
109 
110  //Convolution kernel
112 
113  //Estimator definition
116  MyEstimator myNormalEstimator ( digSurf, kernel );
117 
118  myNormalEstimator.init ( 1.0, 5 );
119 
120  MyEstimator::Quantity res = myNormalEstimator.eval ( it );
121  trace.info() << "Normal vector at begin() : "<< res << std::endl;
122 
124  viewer.show();
125 
126  DGtal::Color lineColorSave = viewer.getLineColor();
127  viewer.setLineColor( DGtal::Color ( 20,200,20 ));
128  for ( MyDigitalSurface::ConstIterator itbis = digSurf.begin(),itend=digSurf.end();
129  itbis!=itend; ++itbis )
130  {
131  viewer << ks.unsigns ( *itbis );
132 
133  Point center = ks.sCoords ( *itbis );
134  MyEstimator::Quantity normal = myNormalEstimator.eval ( itbis );
135 
136  viewer.addLine ( center,
137  DGtal::Z3i::RealPoint(center[0]-3*normal[0],
138  center[1]-3*normal[1],
139  center[2]-3*normal[2]) );
140  }
141  viewer.setLineColor( lineColorSave);
142  viewer<< Viewer3D<>::updateDisplay;
143 
144  //Convolution kernel
146 
147  //Estimator definition
150  MyEstimatorGaussian myNormalEstimatorG ( digSurf, Gkernel );
151 
152  myNormalEstimatorG.init ( 1.0, 15 );
153 
154  MyEstimatorGaussian::Quantity res2 = myNormalEstimatorG.eval ( it );
155  trace.info() << "Normal vector at begin() : "<< res2 << std::endl;
156 
157  viewer<< CustomColors3D ( Color ( 200, 0, 0 ),Color ( 200, 0,0 ) );
158  lineColorSave = viewer.getLineColor();
159  viewer.setLineColor( DGtal::Color ( 200,20,20 ));
160  for ( MyDigitalSurface::ConstIterator itbis = digSurf.begin(),itend=digSurf.end();
161  itbis!=itend; ++itbis )
162  {
163  viewer << ks.unsigns ( *itbis );
164 
165  Point center = ks.sCoords ( *itbis );
166  MyEstimatorGaussian::Quantity normal = myNormalEstimatorG.eval ( itbis );
167  viewer.addLine ( center,
168  DGtal::Z3i::RealPoint(center[0]-3*normal[0],
169  center[1]-3*normal[1],
170  center[2]-3*normal[2]) );
171  }
172  viewer.setLineColor( lineColorSave);
173  viewer<< Viewer3D<>::updateDisplay;
174 
175  return application.exec();
176 }
177 
179 // Standard services - public :
180 
181 int main ( int argc, char** argv )
182 {
183  trace.beginBlock ( "Testing class LocalConvolutionNormalVectorEstimator" );
184  trace.info() << "Args:";
185  for ( int i = 0; i < argc; ++i )
186  trace.info() << " " << argv[ i ];
187  trace.info() << endl;
188 
189  bool res = testLocalConvolutionNormalVectorEstimator ( argc,argv ); // && ... other tests
190  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
191  trace.endBlock();
192 
193  return (res ? 0:1);
194 }
195 // //
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
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: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
ConstIterator begin() const
ConstIterator end() const
virtual DGtal::Color getLineColor()
virtual void setLineColor(DGtal::Color aColor)
void addLine(const RealPoint &p1, const RealPoint &p2, const double width=0.03)
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.
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
Point sCoords(const SCell &c) const
Return its digital coordinates.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
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
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
int main(int argc, char **argv)
bool testLocalConvolutionNormalVectorEstimator(int argc, char **argv)
ImageContainerBySTLVector< Domain, Value > Image