DGtal 1.4.2
Loading...
Searching...
No Matches
testArithmeticalDSSComputerOnSurfels.cpp
Go to the documentation of this file.
1
30#include <iostream>
31#include <string>
32#include <iterator>
33
34#include "DGtal/base/Common.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/helpers/Shortcuts.h"
37#include "DGtal/topology/DigitalSurface2DSlice.h"
38#include "ConfigTest.h"
39#include "DGtalCatch.h"
40
41#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
42#include "DGtal/geometry/surfaces/ArithmeticalDSSComputerOnSurfels.h"
43#include "DGtal/geometry/curves/SaturatedSegmentation.h"
44
45using namespace std;
46using namespace DGtal;
47
51
54
57
58struct Slice
59{
60 Dimension dim1;
61 Dimension dim2;
62 Surfel start;
63 std::vector<Surfel> contour;
64};
65
66std::pair<KSpace, Slice> getSlice (std::string const& shape = "ellipsoid", double gridstep = 1.0)
67{
69
70 auto params = SH3::defaultParameters();
71 params("polynomial", shape)("gridstep", gridstep);
72
73 auto implicit_shape = SH3::makeImplicitShape3D(params);
74 auto digitized_shape = SH3::makeDigitizedImplicitShape3D(implicit_shape, params);
75 auto binary_image = SH3::makeBinaryImage(digitized_shape, params);
76 auto kspace = SH3::getKSpace(binary_image, params);
77 auto surface = SH3::makeDigitalSurface(binary_image, kspace, params);
78
79 Surfel surfel = Surfaces<KSpace>::findABel(kspace, *binary_image, 10000);
80
81 KSpace::DirIterator q1 = kspace.sDirs(surfel);
82 KSpace::DirIterator q2 = kspace.sOrthDirs(surfel);
83 Dimension dim1 = *q1, dim2 = *q2;
84 auto tracker = surface->container().newTracker(surfel);
85 SurfaceSlice surfaceSlice(tracker, dim1);
86 delete tracker;
87
88 std::vector<Surfel> contour(surfaceSlice.begin(), surfaceSlice.end());
89
90 Slice slice{dim1, dim2, surfel, contour};
91
92 return { kspace, slice };
93}
94
95std::vector<Z2i::Point> extractPoints (SegmentComputerOnSurfels const& sc, Slice const& slice)
96{
97 std::vector<Z2i::Point> points;
98
99 auto initialPoints = sc.getProjectedPointsFromSurfel(slice.start);
100 points.push_back(initialPoints.first);
101 points.push_back(initialPoints.second);
102
103 for (auto sit = slice.contour.begin() + 1; sit != slice.contour.end(); ++sit)
104 {
105 Surfel s = *sit;
106 auto pt = sc.getNextProjectedPoint(s);
107 points.push_back(pt);
108 }
109
110 return points;
111}
112
114TEST_CASE("Testing ArithmeticalDSSComputerOnSurfels")
115{
116 // Construct and extract a slice of a digital surface
117 KSpace kspace;
118 Slice slice;
119 std::tie(kspace, slice) = getSlice();
120
121 // Do a segmentation using the surfel class
122 SegmentComputerOnSurfels recognitionAlgorithmSurfels(kspace, slice.dim1, slice.dim2);
123 SegmentationSurfels segmentationSurfels(slice.contour.begin(), slice.contour.end(), recognitionAlgorithmSurfels);
124
125 // Extract the projected points
126 std::vector<Z2i::Point> points = extractPoints(recognitionAlgorithmSurfels, slice);
127
128 // Do a segmentation on the projected points
129 SegmentComputer recognitionAlgorithm;
130 Segmentation segmentation(points.begin(), points.end(), recognitionAlgorithm);
131
132 // The two segmentations must be the same
133 bool allEqual = true;
134 auto segIt = segmentation.begin();
135 auto segSurfelIt = segmentationSurfels.begin();
136 while (segIt != segmentation.end() && segSurfelIt != segmentationSurfels.end()) {
137
138 allEqual = allEqual && (segIt->primitive() == segSurfelIt->primitive());
139 ++segIt;
140 ++segSurfelIt;
141 }
142
143 REQUIRE(allEqual);
144}
145
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
std::pair< Point, Point > getProjectedPointsFromSurfel(SCell const &aSurfel) const
Point getNextProjectedPoint(SCell const &aSurfel) const
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: Represents a 2-dimensional slice in a DigitalSurface. In a sense, it is a 4-connected contour,...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
SignedKhalimskyCell< dim, Integer > SCell
typename PreCellularGridSpace::DirIterator DirIterator
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
SaturatedSegmentation::SegmentComputerIterator end() const
SaturatedSegmentation::SegmentComputerIterator begin() const
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition Shortcuts.h:105
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
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition Shortcuts.h:1209
static Parameters defaultParameters()
Definition Shortcuts.h:203
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition Shortcuts.h:561
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition Shortcuts.h:282
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition Common.h:136
STL namespace.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
std::pair< KSpace, Slice > getSlice(std::string const &shape="ellipsoid", double gridstep=1.0)
std::vector< Z2i::Point > extractPoints(SegmentComputerOnSurfels const &sc, Slice const &slice)
TEST_CASE("Testing ArithmeticalDSSComputerOnSurfels")
REQUIRE(domain.isInside(aPoint))