DGtal  1.3.beta
exampleIntegralInvariantCurvature3D.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
33 #include "DGtal/base/Common.h"
34 
35 // Shape construction
36 #include "DGtal/io/readers/VolReader.h"
37 #include "DGtal/images/ImageSelector.h"
38 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
39 #include "DGtal/images/SimpleThresholdForegroundPredicate.h"
40 #include "DGtal/topology/helpers/Surfaces.h"
41 #include "DGtal/topology/LightImplicitDigitalSurface.h"
42 #include "DGtal/images/ImageHelper.h"
43 #include "DGtal/topology/DigitalSurface.h"
44 #include "DGtal/graph/DepthFirstVisitor.h"
45 #include "DGtal/graph/GraphVisitorRange.h"
46 
48 #include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
49 #include "DGtal/geometry/surfaces/estimation/IntegralInvariantVolumeEstimator.h"
50 
51 // Drawing
52 #include "DGtal/io/viewers/Viewer3D.h"
53 #include "DGtal/io/colormaps/GradientColorMap.h"
54 
56 
57 using namespace DGtal;
58 
60 
61 int main( int argc, char** argv )
62 {
63  if ( argc != 4 )
64  {
65  trace.error() << "Usage: " << argv[0]
66  << " <fileName.vol> <threshold> <radius>" << std::endl;
67  trace.error() << "Example : "<< argv[0] << " Al.150.vol 0 7" << std::endl;
68  return 0;
69  }
70 
71  trace.beginBlock ( "Example IntegralInvariantCurvature3D" );
72  trace.info() << "Args:";
73  for ( int i = 0; i < argc; ++i )
74  trace.info() << " " << argv[ i ];
75  trace.info() << std::endl;
76 
77  double h = 1.0;
78  unsigned int threshold = std::atoi( argv[ 2 ] );
79 
83  typedef LightImplicitDigitalSurface< Z3i::KSpace, ImagePredicate > MyLightImplicitDigitalSurface;
85 
86  std::string filename = argv[1];
87  Image image = VolReader<Image>::importVol( filename );
88  ImagePredicate predicate = ImagePredicate( image, threshold );
89 
90  Z3i::Domain domain = image.domain();
91 
92  Z3i::KSpace KSpaceShape;
93 
94  bool space_ok = KSpaceShape.init( domain.lowerBound(), domain.upperBound(), true );
95  if (!space_ok)
96  {
97  trace.error() << "Error in the Khalimsky space construction."<<std::endl;
98  return 2;
99  }
100 
102  Z3i::KSpace::Surfel bel = Surfaces< Z3i::KSpace >::findABel( KSpaceShape, predicate, 100000 );
103  MyLightImplicitDigitalSurface LightImplDigSurf( KSpaceShape, predicate, SAdj, bel );
104  MyDigitalSurface digSurf( LightImplDigSurf );
105 
107  typedef GraphVisitorRange< Visitor > VisitorRange;
108  typedef VisitorRange::ConstIterator SurfelConstIterator;
109 
110  VisitorRange range( new Visitor( digSurf, *digSurf.begin() ) );
111  SurfelConstIterator abegin = range.begin();
112  SurfelConstIterator aend = range.end();
113 
116  double radius = std::atof(argv[3]);
117 
118  typedef functors::IIMeanCurvature3DFunctor<Z3i::Space> MyIICurvatureFunctor;
120 
121  // For computing Gaussian curvature instead, for example, change the two typedef above by :
122  // typedef functors::IIGaussianCurvature3DFunctor<Z3i::Space> MyIICurvatureFunctor;
123  // typedef IntegralInvariantCovarianceEstimator< Z3i::KSpace, ImagePredicate, MyIICurvatureFunctor > MyIICurvatureEstimator;
124  // and it's done. The following part is exactly the same.
125 
127 
128  MyIICurvatureFunctor curvatureFunctor; // Functor used to convert volume -> curvature
129  curvatureFunctor.init( h, radius ); // Initialisation for a grid step and a given Euclidean radius of convolution kernel
130 
131  MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
132  curvatureEstimator.attach( KSpaceShape, predicate ); // Setting a KSpace and a predicate on the object to evaluate
133  curvatureEstimator.setParams( radius / h ); // Setting the digital radius of the convolution kernel
134  curvatureEstimator.init( h, abegin, aend ); // Initialisation for a given h, and a range of surfels
135 
136  std::vector< Value > results;
137  std::back_insert_iterator< std::vector< Value > > resultsIt( results ); // output iterator for results of Integral Invariant curvature computation
138  curvatureEstimator.eval( abegin, aend, resultsIt ); // Computation
140 
143  Value max = std::numeric_limits < Value >::min();
144  for ( unsigned int i = 0; i < results.size(); ++i )
145  {
146  if ( results[ i ] < min )
147  {
148  min = results[ i ];
149  }
150  else if ( results[ i ] > max )
151  {
152  max = results[ i ];
153  }
154  }
155 
156  QApplication application( argc, argv );
158  Viewer viewer( KSpaceShape );
159  viewer.setWindowTitle("example Integral Invariant 3D");
160  viewer.show();
161 
162  typedef GradientColorMap< Value > Gradient;
163  Gradient cmap_grad( min, max );
164  cmap_grad.addColor( Color( 50, 50, 255 ) );
165  cmap_grad.addColor( Color( 255, 0, 0 ) );
166  cmap_grad.addColor( Color( 255, 255, 10 ) );
167 
168  VisitorRange range2( new Visitor( digSurf, *digSurf.begin() ) );
169  abegin = range2.begin();
170 
171  Z3i::KSpace::Cell dummy_cell;
172  viewer << SetMode3D( dummy_cell.className(), "Basic" );
173 
174  for ( unsigned int i = 0; i < results.size(); ++i )
175  {
176  viewer << CustomColors3D( Color::Black, cmap_grad( results[ i ] ))
177  << KSpaceShape.unsigns( *abegin );
178  ++abegin;
179  }
180 
181  viewer << Viewer3D<>::updateDisplay;
182 
183  trace.endBlock();
184  return application.exec();
185 }
186 // //
DGtal::KhalimskyCell::className
std::string className() const
Return the style name used for drawing this object.
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::VolReader::importVol
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
max
int max(int a, int b)
Definition: testArithmeticalDSS.cpp:1108
DGtal::GraphVisitorRange
Aim: Transforms a graph visitor into a single pass input range.
Definition: GraphVisitorRange.h:71
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
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition: SurfelAdjacency.h:65
DGtal::Trace::error
std::ostream & error()
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
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
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
main
int main(int argc, char **argv)
Definition: exampleIntegralInvariantCurvature3D.cpp:61
DGtal::Color::Black
static const Color Black
Definition: Color.h:389
Visitor
BreadthFirstVisitor< MyDigitalSurface > Visitor
Definition: greedy-plane-segmentation-ex2.cpp:97
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::IntegralInvariantVolumeEstimator
Aim: This class implement an Integral Invariant estimator which computes for each surfel the volume o...
Definition: IntegralInvariantVolumeEstimator.h:113
DGtal::Viewer3D
Definition: Viewer3D.h:135
DGtal::DigitalSurface::begin
ConstIterator begin() const
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal::Surfaces::findABel
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CustomColors3D
Definition: DrawWithDisplay3DModifier.h:129
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::functors::IIMeanCurvature3DFunctor
Aim: A functor Real -> Real that returns the 3d mean curvature by transforming the given volume....
Definition: IIGeometricFunctors.h:602
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::DepthFirstVisitor
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Definition: DepthFirstVisitor.h:95
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.
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
MyDigitalSurface
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Definition: greedy-plane-segmentation-ex2.cpp:92
DGtal::KhalimskyCell< dim, Integer >
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64
DGtal::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
Definition: SimpleThresholdForegroundPredicate.h:65