DGtal 1.4.0
Loading...
Searching...
No Matches
exampleMaximalSegmentSliceEstimation.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "ConfigExamples.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/base/Common.h"
35#include "DGtal/geometry/surfaces/estimation/MaximalSegmentSliceEstimation.h"
36#include "DGtal/helpers/Shortcuts.h"
37#include "DGtal/io/viewers/Viewer3D.h"
39
40using namespace std;
41using namespace DGtal;
42
49
51{
52 auto pointels = SH3::getPrimalVertices(K, s, true);
53
54 Point p = K.uCoords(pointels[0]),
55 u = K.uCoords(pointels[1]) - p,
56 v = K.uCoords(pointels[3]) - p;
57
58 static const RealPoint shift(-0.5, -0.5, -0.5);
59
60 return p + 0.5 * u + 0.5 * v + shift;
61}
62
64
65int main(int argc, char** argv)
66{
67 QApplication application(argc, argv);
68
69 auto params = SH3::defaultParameters();
70 params("polynomial", "ellipsoid")("gridstep", "1.0");
71 auto implicit_shape = SH3::makeImplicitShape3D ( params );
72 auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
73 auto K = SH3::getKSpace( params );
74 auto binary_image = SH3::makeBinaryImage( digitized_shape, params );
76 auto surfels = SH3::getSurfelRange(surface);
77
78 double gridstep = params["gridstep"].as<double>();
79
80 Viewer3D<> viewer(K);
81 viewer << SetMode3D(Surfel().className(), "Basic");
82 viewer.show();
83
85 // Instantiation
87 Estimator estimator;
88 estimator.init(gridstep, surfels.begin(), surfels.end());
89 estimator.attach(surface);
90
91 // Usage
92 std::vector<Estimator::Quantity> quantities;
93 estimator.eval(surfels.begin(), surfels.end(), std::back_inserter(quantities));
95
96 Color fillColor = viewer.getFillColor();
97
98 for (std::size_t i = 0; i < surfels.size(); ++i)
99 {
100 const Surfel& s = surfels[i];
101 const Estimator::Quantity& normal = quantities[i];
102
103 const RealPoint& n = normal.getNormalized();
104 RealPoint origin = centerSurfel(K, s);
105
106 viewer.setFillColor(fillColor);
107 viewer << s;
108
109 viewer.setLineColor(Color::Green);
110 viewer.addLine(origin, origin + 1.5 * n, 0.3);
111 }
112
113 viewer << Viewer3D<>::updateDisplay;
114 application.exec();
115
116 return 0;
117}
118// //
Structure representing an RGB triple with alpha component.
Definition Color.h:68
static const Color Green
Definition Color.h:417
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::Surfel Surfel
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Point uCoords(const Cell &c) const
Return its digital coordinates.
PointVector< dim, double, std::array< double, dim > > getNormalized() const
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition Shortcuts.h:105
Space::RealPoint RealPoint
Point with floating-point coordinates.
Definition Shortcuts.h:123
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition Shortcuts.h:332
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition Shortcuts.h:523
Space::Point Point
Point with integer coordinates.
Definition Shortcuts.h:117
static CellRange getPrimalVertices(const KSpace &K, const SCell &s)
Definition Shortcuts.h:3180
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1547
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1209
::DGtal::DigitalSurface< ExplicitSurfaceContainer > DigitalSurface
defines an arbitrary digital surface over a binary image.
Definition Shortcuts.h:158
static Parameters defaultParameters()
Definition Shortcuts.h:203
LightDigitalSurface::SCell SCell
Definition Shortcuts.h:163
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition Shortcuts.h:561
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition Shortcuts.h:282
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
Surface::Surfel Surfel
RealPoint centerSurfel(KSpace const &K, SH3::SCell const &s)
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
int main()
Definition testBits.cpp:56
MyPointD Point
KSpace K