Skip to content

Commit f74ed72

Browse files
authored
Merge pull request #1742 from troussil/testArithmeticalDSSOnSurfelsFix
Bugfix in TestArithmeticalDSSOnSurfels
2 parents cc6e213 + 662226d commit f74ed72

File tree

6 files changed

+347
-415
lines changed

6 files changed

+347
-415
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# DGtal 1.5beta
22

3+
## Bug fixes
4+
- *Geometry*
5+
- Bug fix in ArithmeticalDSSComputerOnSurfels (Tristan Roussillon, [#1742](https://github.com/DGtal-team/DGtal/pull/1742))
36

47
# DGtal 1.4.1
58

src/DGtal/geometry/doc/moduleMaximalSegmentSliceEstimation.dox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ using Surfel = KSpace::SCell;
6969
using Container = std::vector<Surfel>;
7070
using Integer = int;
7171
short adjacency = 4;
72-
using SegmentComputerOnSurfels = ArithmeticalDSSComputerOnSurfels<KSpace, Container::const_iterator, Integer, adjacency>;
72+
using SegmentComputerOnSurfels = ArithmeticalDSSComputerOnSurfels<KSpace, Container::const_iterator, Integer>;
7373

7474
// Instantiation
7575
SegmentComputerOnSurfels computer(kspace, // A 3D Khalimsky space

src/DGtal/geometry/surfaces/ArithmeticalDSSComputerOnSurfels.h

Lines changed: 119 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
/**
2020
* @file ArithmeticalDSSComputerOnSurfels.h
21-
* @author Jocelyn Meyron (\c
22-
* [email protected] ) Laboratoire d'InfoRmatique en
23-
* Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS,
24-
* France
21+
* @author Jocelyn Meyron (\c [email protected] )
22+
* Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
23+
* @author Tristan Roussillon (\c [email protected] )
24+
* Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
2525
*
2626
* @date 2021/01/22
2727
*
@@ -46,7 +46,9 @@
4646
#include <list>
4747
#include "DGtal/base/Exceptions.h"
4848
#include "DGtal/base/Common.h"
49+
#include "DGtal/kernel/SpaceND.h"
4950
#include "DGtal/kernel/PointVector.h"
51+
#include "DGtal/kernel/BasicPointFunctors.h"
5052
#include "DGtal/kernel/CInteger.h"
5153
#include "DGtal/base/ReverseIterator.h"
5254
#include "DGtal/geometry/curves/ArithmeticalDSS.h"
@@ -60,8 +62,10 @@ namespace DGtal
6062
// class ArithmeticalDSSComputerOnSurfels
6163
/**
6264
* \brief Aim: This class is a wrapper around ArithmeticalDSS that is devoted
63-
* to the dynamic recognition of digital straight segments (DSS) along any
64-
* sequence of 3D surfels.
65+
* to the dynamic recognition of digital straight segments (DSS) along a
66+
* sequence of surfels lying on a slice of the digital surface (i.e., the
67+
* orthogonal direction of all surfels belong to a same plane, most pairs
68+
* of consecutive surfels share a common linel).
6569
*
6670
* @tparam TKSpace type of Khalimsky space
6771
* @tparam TIterator type of iterator on 3d surfels,
@@ -77,8 +81,7 @@ namespace DGtal
7781
* @see ArithmeticalDSS NaiveDSS8 StandardDSS4
7882
*/
7983
template <typename TKSpace, typename TIterator,
80-
typename TInteger = typename TKSpace::Space::Integer,
81-
unsigned short adjacency = 8>
84+
typename TInteger = typename TKSpace::Space::Integer>
8285
class ArithmeticalDSSComputerOnSurfels
8386
{
8487
BOOST_CONCEPT_ASSERT(( concepts::CCellularGridSpaceND< TKSpace > ));
@@ -97,11 +100,6 @@ namespace DGtal
97100
*/
98101
typedef typename KSpace::SCell SCell;
99102

100-
/**
101-
* Type of unsigned cell
102-
*/
103-
typedef typename KSpace::Cell Cell;
104-
105103
/**
106104
* Type of iterator, at least readable and forward
107105
*/
@@ -120,6 +118,11 @@ namespace DGtal
120118
*/
121119
typedef PointVector<2, TInteger> Point;
122120

121+
/**
122+
* Type of 3d to 2d projector
123+
*/
124+
typedef functors::Projector<SpaceND<2,TInteger> > Projector;
125+
123126
/**
124127
* Type of coordinate
125128
*/
@@ -135,7 +138,7 @@ namespace DGtal
135138
/**
136139
* Type of objects that represents DSSs
137140
*/
138-
typedef ArithmeticalDSS<Coordinate, Integer, adjacency> DSS;
141+
typedef ArithmeticalDSS<Coordinate, Integer, 4> DSS;
139142
//we expect that the iterator type returned DGtal points, used in the DSS representation
140143
BOOST_STATIC_ASSERT(( concepts::ConceptUtils::SameType< Point, typename DSS::Point >::value ));
141144

@@ -149,8 +152,32 @@ namespace DGtal
149152
*/
150153
typedef Point Vector;
151154

152-
typedef ArithmeticalDSSComputerOnSurfels<KSpace,ConstIterator,TInteger,adjacency> Self;
153-
typedef ArithmeticalDSSComputerOnSurfels<KSpace,ReverseIterator<ConstIterator>,TInteger,adjacency> Reverse;
155+
/**
156+
* Alias of this class
157+
*/
158+
typedef ArithmeticalDSSComputerOnSurfels<KSpace,ConstIterator,TInteger> Self;
159+
160+
/**
161+
* Helpers used to extract relevant points from a pair of points
162+
*/
163+
struct DirectPairExtractor {
164+
165+
virtual Point first(const std::pair<Point,Point>& aPair) const { return aPair.first; }
166+
virtual Point second(const std::pair<Point,Point>& aPair) const { return aPair.second; }
167+
168+
};
169+
struct IndirectPairExtractor : public DirectPairExtractor {
170+
171+
Point first(const std::pair<Point,Point>& aPair) const { return aPair.second; }
172+
Point second(const std::pair<Point,Point>& aPair) const { return aPair.first; }
173+
174+
};
175+
typedef std::shared_ptr<DirectPairExtractor> PairExtractor;
176+
177+
/**
178+
* Reversed version of this class (using reverse iterators)
179+
*/
180+
typedef ArithmeticalDSSComputerOnSurfels<KSpace,ReverseIterator<ConstIterator>,TInteger> Reverse;
154181

155182
// ----------------------- Standard services ------------------------------
156183
public:
@@ -164,11 +191,14 @@ namespace DGtal
164191
/**
165192
* Constructor.
166193
* @param aKSpace a Khalimsky space
167-
* @param aDim1 the first direction to project
168-
* @param aDim2 the second direction to project
194+
* @param aDim1 a first direction that describes the projection plane
195+
* @param aDim2 a second direction that describes the projection plane
196+
* @param aFlagToReverse a boolean telling whether one has to reverse
197+
* the orientation of the points associated to a surfel or not
198+
* ('false' by default)
169199
*/
170-
ArithmeticalDSSComputerOnSurfels(const KSpace& aKSpace, Dimension aDim1, Dimension aDim2);
171-
200+
ArithmeticalDSSComputerOnSurfels(const KSpace& aKSpace, Dimension aDim1, Dimension aDim2, bool aFlagToReverse = false);
201+
172202
/**
173203
* Initialisation.
174204
* @param it an iterator on 3D surfels
@@ -227,6 +257,9 @@ namespace DGtal
227257
* Tests whether the current DSS can be extended at the front.
228258
*
229259
* @return 'true' if yes, 'false' otherwise.
260+
*
261+
* @warning the caller must be sure that the iterator returned
262+
* by 'end()' can be safely dereferenced.
230263
*/
231264
bool isExtendableFront();
232265

@@ -240,7 +273,11 @@ namespace DGtal
240273
/**
241274
* Tests whether the current DSS can be extended at the front.
242275
* Computes the parameters of the extended DSS if yes.
276+
*
243277
* @return 'true' if yes, 'false' otherwise.
278+
*
279+
* @warning the caller must be sure that the iterator returned
280+
* by 'end()' can be safely dereferenced.
244281
*/
245282
bool extendFront();
246283

@@ -265,6 +302,32 @@ namespace DGtal
265302
*/
266303
bool retractBack();
267304

305+
/**
306+
* Returns the ends of a unit segment corresponding
307+
* to the projection of a given signed surfel.
308+
*
309+
* @param aSurfel any signed surfel.
310+
* @return a pair of 2D points.
311+
*/
312+
std::pair<Point,Point> getProjectedPointsFromSurfel(SCell const& aSurfel) const;
313+
314+
/**
315+
* Front end of the projection of a given surfel.
316+
*
317+
* @param aSurfel any signed surfel.
318+
* @return the second 2D point.
319+
* @see getProjectedPointsFromSurfel
320+
*/
321+
Point getNextProjectedPoint(SCell const& aSurfel) const;
322+
323+
/**
324+
* Back end of the projection of a given surfel.
325+
*
326+
* @param aSurfel any signed surfel.
327+
* @return the second 2D point.
328+
* @see getProjectedPointsFromSurfel
329+
*/
330+
Point getPreviousProjectedPoint(SCell const& aSurfel) const;
268331

269332
// ------------------------- Accessors ------------------------------
270333
/**
@@ -329,92 +392,77 @@ namespace DGtal
329392
*/
330393
bool isValid() const;
331394

332-
/**
333-
* @param aSCell a surfel.
334-
* @return the pair of 2D points projected on the plane defined by \ref myProjection1, \ref myProjection2.
335-
*/
336-
std::pair<Point, Point> projectSurfel(SCell const& aSCell) const;
337395

338396
// ------------------------- Hidden services ------------------------------
339397
private:
340-
/**
341-
* @param aSurfel1 the first unsigned surfel.
342-
* @param aSurfel2 the second unsigned surfel.
343-
* @param aLinel the common unsigned linel if it exists.
344-
* @return 'true' if we found a common linel, 'false' otherwise.
345-
*/
346-
bool commonLinel (Cell const& aSurfel1, Cell const& aSurfel2, Cell& aLinel);
347398

348399
/**
349-
* @param aPoint a digital 3D point.
350-
* @return the 2D orthogonal projection on the plane defined by \ref myProjection1, \ref myProjection2
400+
* Returns the ends of a unit segment corresponding
401+
* to the projection of a given signed linel.
402+
*
403+
* @param aLinel any signed linel.
404+
* @return a pair of 2D points.
351405
*/
352-
Point projectInPlane (Point3 const& aPoint) const;
353-
406+
std::pair<Point,Point> getProjectedPointsFromLinel(SCell const& aLinel) const;
407+
354408
/**
355-
* @param it an iterator on a surfel.
356-
* @param aPoint the new 2D point of 'it' that is not common to the previous surfel (if the update is possible).
357-
* @param aUpdatePrevious a boolean that indicates whether to update myPreviousSurfel or not.
358-
* @param aIsFront a boolean indicating we want to update in the front or in the back direction.
359-
* @return 'true' if the update is possible, 'false' otherwise.
409+
* Returns the unique dimension in {0,1,2} \ {aDim1, aDim2}.
410+
*
411+
* @param aDim1 a dimension
412+
* @param aDim2 a dimension
360413
*/
361-
bool getOtherPointFromSurfel (ConstIterator const& it, Point& aPoint, bool aIsFront, bool aUpdatePrevious);
362-
414+
Dimension dimNotIn(Dimension const& aDim1, Dimension const& aDim2) const;
415+
363416
// ------------------------- Protected Datas ------------------------------
364417
protected:
365418

366419
/**
367-
* Khalimsky space
420+
* (Pointer to) Khalimsky space
368421
*/
369422
const KSpace* myKSpace;
370423

371424
/**
372-
* The first projection dimension.
425+
* A first direction that describes the projection plane
373426
*/
374-
Dimension myDim1;
375-
427+
Dimension mySliceAxis1;
428+
376429
/**
377-
* The second projection dimension.
430+
* A second direction that describes the projection plane
378431
*/
379-
Dimension myDim2;
380-
432+
Dimension mySliceAxis2;
433+
381434
/**
382-
* The first projection direction.
435+
* A direction along which the points are projected
436+
* (and orthogonal to the projection plane)
383437
*/
384-
Point3 myProjection1;
438+
Dimension myProjectionAxis;
385439

386440
/**
387-
* The second projection direction.
441+
* Functor that projects a 3D point to a 2D point along myProjectionAxis
388442
*/
389-
Point3 myProjection2;
443+
Projector my2DProjector;
390444

391445
/**
392-
* The direction that is orthogonal to the two projection directions.
446+
* Smart pointer on an object used to extract relevant points
447+
* from a pair of points
393448
*/
394-
Point3 myProjectionNormal;
395-
396-
/**
397-
* We store the previous surfel in the 'front' direction to compute the common linel.
398-
* Used in \ref getOtherPointFromSurfel.
399-
*/
400-
ConstIterator myPreviousSurfelFront;
401-
402-
/**
403-
* We store the previous surfel in the 'back' direction to compute the common linel.
404-
* Used in \ref getOtherPointFromSurfel.
405-
*/
406-
ConstIterator myPreviousSurfelBack;
407-
449+
PairExtractor myExtractor;
450+
408451
/**
409452
* DSS representation
410453
*/
411454
DSS myDSS;
455+
412456
/**
413457
* begin iterator
414458
*/
415459
ConstIterator myBegin;
460+
416461
/**
417462
* end iterator
463+
*
464+
* @warning the user must be sure that it can be safely dereferenced
465+
* before calling 'isExtendableFront' and 'extendFront'.
418466
*/
419467
ConstIterator myEnd;
420468

@@ -438,9 +486,9 @@ namespace DGtal
438486
* @param object the object of class 'ArithmeticalDSSComputerOnSurfels' to write.
439487
* @return the output stream after the writing.
440488
*/
441-
template <typename TKSpace, typename TIterator, typename TInteger, unsigned short adjacency>
489+
template <typename TKSpace, typename TIterator, typename TInteger>
442490
std::ostream&
443-
operator<< ( std::ostream & out, const ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger,adjacency> & object )
491+
operator<< ( std::ostream & out, const ArithmeticalDSSComputerOnSurfels<TKSpace,TIterator,TInteger> & object )
444492
{
445493
object.selfDisplay( out);
446494
return out;

0 commit comments

Comments
 (0)