DGtal  0.9.3
Functions
testLocalConvolutionNormalVectorEstimator.cpp File Reference
#include <iostream>
#include "ConfigTest.h"
#include "DGtal/base/Common.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/DigitalSetBoundary.h"
#include "DGtal/topology/ImplicitDigitalSurface.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/topology/ExplicitDigitalSurface.h"
#include "DGtal/topology/LightExplicitDigitalSurface.h"
#include "DGtal/graph/BreadthFirstVisitor.h"
#include "DGtal/topology/helpers/FrontierPredicate.h"
#include "DGtal/topology/helpers/BoundaryPredicate.h"
#include "DGtal/graph/CUndirectedSimpleLocalGraph.h"
#include "DGtal/graph/CUndirectedSimpleGraph.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/surfaces/estimation/BasicConvolutionWeights.h"
#include "DGtal/geometry/surfaces/estimation/LocalConvolutionNormalVectorEstimator.h"
Include dependency graph for testLocalConvolutionNormalVectorEstimator.cpp:

Go to the source code of this file.

Functions

bool testLocalConvolutionNormalVectorEstimator (int argc, char **argv)
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/03/03

Functions for testing class LocalConvolutionNormalVectorEstimator.

This file is part of the DGtal library.

Definition in file testLocalConvolutionNormalVectorEstimator.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 191 of file testLocalConvolutionNormalVectorEstimator.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testLocalConvolutionNormalVectorEstimator(), and DGtal::trace.

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
bool testLocalConvolutionNormalVectorEstimator(int argc, char **argv)
double endBlock()
std::ostream & emphase()
std::ostream & info()

◆ testLocalConvolutionNormalVectorEstimator()

bool testLocalConvolutionNormalVectorEstimator ( int  argc,
char **  argv 
)

Example of a test. To be completed.

Definition at line 71 of file testLocalConvolutionNormalVectorEstimator.cpp.

References DGtal::Display3D< Space, KSpace >::addLine(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::Image< TImageContainer >::domain(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::end(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Display3D< Space, KSpace >::getLineColor(), image(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::Display3D< Space, KSpace >::setLineColor(), DGtal::Viewer3D< Space, KSpace >::show(), and DGtal::trace.

Referenced by main().

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 }
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...
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
bool init(const Point &lower, const Point &upper, bool isClosed)
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
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
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)