DGtal 1.4.0
Loading...
Searching...
No Matches
testArithmeticalDSSComputerOnSurfels.cpp File Reference
#include <iostream>
#include <string>
#include <iterator>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/topology/DigitalSurface2DSlice.h"
#include "ConfigTest.h"
#include "DGtalCatch.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "DGtal/geometry/surfaces/ArithmeticalDSSComputerOnSurfels.h"
#include "DGtal/geometry/curves/SaturatedSegmentation.h"
Include dependency graph for testArithmeticalDSSComputerOnSurfels.cpp:

Go to the source code of this file.

Typedefs

using KSpace = Z3i::KSpace
 
using SH3 = Shortcuts<KSpace>
 
using Surfel = KSpace::SCell
 
using SegmentComputerOnSurfels = ArithmeticalDSSComputerOnSurfels<KSpace, std::vector<Surfel>::const_iterator, int, 4>
 
using SegmentationSurfels = SaturatedSegmentation<SegmentComputerOnSurfels>
 
using SegmentComputer = ArithmeticalDSSComputer<std::vector<Z2i::Point>::const_iterator, int, 4>
 
using Segmentation = SaturatedSegmentation<SegmentComputer>
 

Functions

std::pair< KSpace, Slice > getSlice (std::string const &shape="ellipsoid", double gridstep=1.0)
 
std::vector< Z2i::PointextractPoints (SegmentComputerOnSurfels const &sc, Slice const &slice)
 
 TEST_CASE ("Testing ArithmeticalDSSComputerOnSurfels")
 

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
Jocelyn Meyron (jocel.nosp@m.yn.m.nosp@m.eyron.nosp@m.@lir.nosp@m.is.cn.nosp@m.rs.f.nosp@m.r ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2021/02/12

Functions for testing class DGtal::ArithmeticalDSSComputerOnSurfels.

This file is part of the DGtal library.

Definition in file testArithmeticalDSSComputerOnSurfels.cpp.

Typedef Documentation

◆ KSpace

◆ Segmentation

◆ SegmentationSurfels

◆ SegmentComputer

◆ SegmentComputerOnSurfels

using SegmentComputerOnSurfels = ArithmeticalDSSComputerOnSurfels<KSpace, std::vector<Surfel>::const_iterator, int, 4>

Definition at line 52 of file testArithmeticalDSSComputerOnSurfels.cpp.

◆ SH3

◆ Surfel

Function Documentation

◆ extractPoints()

std::vector< Z2i::Point > extractPoints ( SegmentComputerOnSurfels const & sc,
Slice const & slice )

Definition at line 94 of file testArithmeticalDSSComputerOnSurfels.cpp.

95{
96 std::vector<Z2i::Point> points;
97
98 auto initialPoints = sc.projectSurfel(slice.start);
99 points.push_back(initialPoints.first);
100 points.push_back(initialPoints.second);
101
102 int currentIdx = 0;
103 bool firstIt = true;
104 for (auto sit = slice.contour.begin() + 1; sit != slice.contour.end(); ++sit)
105 {
106 Surfel s = *sit;
107 auto projectedPoints = sc.projectSurfel(s);
108
109 if (firstIt) {
110 if (projectedPoints.first == points[currentIdx]) {
111 points.push_back(projectedPoints.second);
112 } else if (projectedPoints.first == points[currentIdx + 1]) {
113 points.push_back(projectedPoints.second);
114 } else if (projectedPoints.second == points[currentIdx]) {
115 points.push_back(projectedPoints.first);
116 } else if (projectedPoints.second == points[currentIdx + 1]) {
117 points.push_back(projectedPoints.first);
118 } else {
119 assert(false);
120 }
121
122 firstIt = false;
123 } else {
124 if (projectedPoints.first == points[currentIdx]) {
125 points.push_back(projectedPoints.second);
126 } else if (projectedPoints.second == points[currentIdx]) {
127 points.push_back(projectedPoints.first);
128 } else {
129 assert(false);
130 }
131 }
132
133 currentIdx = (int)points.size() - 1;
134 }
135
136 return points;
137}
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.

References DGtal::ArithmeticalDSSComputerOnSurfels< TKSpace, TIterator, TInteger, adjacency >::projectSurfel().

Referenced by TEST_CASE().

◆ getSlice()

std::pair< KSpace, Slice > getSlice ( std::string const & shape = "ellipsoid",
double gridstep = 1.0 )

Definition at line 66 of file testArithmeticalDSSComputerOnSurfels.cpp.

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 Dimension dim1 = *q1, dim2 = kspace.sOrthDir(surfel);
83 auto tracker = surface->container().newTracker(surfel);
84 SurfaceSlice surfaceSlice(tracker, dim1);
85 delete tracker;
86
87 std::vector<Surfel> contour(surfaceSlice.begin(), surfaceSlice.end());
88
89 Slice slice{dim1, dim2, surfel, contour};
90
91 return { kspace, slice };
92}
Aim: Represents a 2-dimensional slice in a DigitalSurface. In a sense, it is a 4-connected contour,...
typename PreCellularGridSpace::DirIterator DirIterator
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
DGtal::uint32_t Dimension
Definition Common.h:136

References binary_image, DGtal::Shortcuts< TKSpace >::defaultParameters(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::Shortcuts< TKSpace >::makeBinaryImage(), DGtal::Shortcuts< TKSpace >::makeDigitalSurface(), DGtal::Shortcuts< TKSpace >::makeDigitizedImplicitShape3D(), DGtal::Shortcuts< TKSpace >::makeImplicitShape3D(), and surface.

Referenced by TEST_CASE().

◆ TEST_CASE()

TEST_CASE ( "Testing ArithmeticalDSSComputerOnSurfels" )

Definition at line 140 of file testArithmeticalDSSComputerOnSurfels.cpp.

141{
142 // Construct and extract a slice of a digital surface
143 KSpace kspace;
144 Slice slice;
145 std::tie(kspace, slice) = getSlice();
146
147 // Do a segmentation using the surfel class
148 SegmentComputerOnSurfels recognitionAlgorithmSurfels(kspace, slice.dim1, slice.dim2);
149 SegmentationSurfels segmentationSurfels(slice.contour.begin(), slice.contour.end(), recognitionAlgorithmSurfels);
150
151 // Extract the projected points
152 std::vector<Z2i::Point> points = extractPoints(recognitionAlgorithmSurfels, slice);
153
154 // Do a segmentation on the projected points
155 SegmentComputer recognitionAlgorithm;
156 Segmentation segmentation(points.begin(), points.end(), recognitionAlgorithm);
157
158 // The two segmentations must be the same
159 bool allEqual = true;
160 auto segIt = segmentation.begin();
161 auto segSurfelIt = segmentationSurfels.begin();
162 while (segIt != segmentation.end() && segSurfelIt != segmentationSurfels.end()) {
163 allEqual = allEqual && (segIt->primitive() == segSurfelIt->primitive());
164
165 ++segIt;
166 ++segSurfelIt;
167 }
168
169 REQUIRE(allEqual);
170}
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
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)
REQUIRE(domain.isInside(aPoint))

References DGtal::SaturatedSegmentation< TSegmentComputer >::begin(), DGtal::SaturatedSegmentation< TSegmentComputer >::end(), extractPoints(), getSlice(), and REQUIRE().