DGtal  1.3.beta
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  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 // //
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::SetFromImage
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
DGtal::Trace::endBlock
double endBlock()
DGtal::Display3D::getLineColor
virtual DGtal::Color getLineColor()
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::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
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()
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::KhalimskySpaceND::sCoords
Point sCoords(const SCell &c) const
Return its digital coordinates.
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
main
int main(int argc, char **argv)
Definition: testLocalConvolutionNormalVectorEstimator.cpp:181
DGtal::Viewer3D< Space, KSpace >
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::CustomColors3D
Definition: DrawWithDisplay3DModifier.h:129
DGtal::Display3D::addLine
void addLine(const RealPoint &p1, const RealPoint &p2, const double width=0.03)
DGtal::DigitalSurface::end
ConstIterator end() const
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::Display3D::setLineColor
virtual void setLineColor(DGtal::Color aColor)
MyDigitalSurfaceContainer
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
Definition: greedy-plane-segmentation-ex2.cpp:91
DGtal::PointVector< dim, Integer >
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::Viewer3D::show
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DGtal::KhalimskySpaceND::unsigns
Cell unsigns(const SCell &p) const
Creates an unsigned cell from a signed one.
testLocalConvolutionNormalVectorEstimator
bool testLocalConvolutionNormalVectorEstimator(int argc, char **argv)
Definition: testLocalConvolutionNormalVectorEstimator.cpp:71
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