18
18
19
19
/* *
20
20
* @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
25
25
*
26
26
* @date 2021/01/22
27
27
*
46
46
#include < list>
47
47
#include " DGtal/base/Exceptions.h"
48
48
#include " DGtal/base/Common.h"
49
+ #include " DGtal/kernel/SpaceND.h"
49
50
#include " DGtal/kernel/PointVector.h"
51
+ #include " DGtal/kernel/BasicPointFunctors.h"
50
52
#include " DGtal/kernel/CInteger.h"
51
53
#include " DGtal/base/ReverseIterator.h"
52
54
#include " DGtal/geometry/curves/ArithmeticalDSS.h"
@@ -60,8 +62,10 @@ namespace DGtal
60
62
// class ArithmeticalDSSComputerOnSurfels
61
63
/* *
62
64
* \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).
65
69
*
66
70
* @tparam TKSpace type of Khalimsky space
67
71
* @tparam TIterator type of iterator on 3d surfels,
@@ -77,8 +81,7 @@ namespace DGtal
77
81
* @see ArithmeticalDSS NaiveDSS8 StandardDSS4
78
82
*/
79
83
template <typename TKSpace, typename TIterator,
80
- typename TInteger = typename TKSpace::Space::Integer,
81
- unsigned short adjacency = 8 >
84
+ typename TInteger = typename TKSpace::Space::Integer>
82
85
class ArithmeticalDSSComputerOnSurfels
83
86
{
84
87
BOOST_CONCEPT_ASSERT (( concepts::CCellularGridSpaceND< TKSpace > ));
@@ -97,11 +100,6 @@ namespace DGtal
97
100
*/
98
101
typedef typename KSpace::SCell SCell;
99
102
100
- /* *
101
- * Type of unsigned cell
102
- */
103
- typedef typename KSpace::Cell Cell;
104
-
105
103
/* *
106
104
* Type of iterator, at least readable and forward
107
105
*/
@@ -120,6 +118,11 @@ namespace DGtal
120
118
*/
121
119
typedef PointVector<2 , TInteger> Point;
122
120
121
+ /* *
122
+ * Type of 3d to 2d projector
123
+ */
124
+ typedef functors::Projector<SpaceND<2 ,TInteger> > Projector;
125
+
123
126
/* *
124
127
* Type of coordinate
125
128
*/
@@ -135,7 +138,7 @@ namespace DGtal
135
138
/* *
136
139
* Type of objects that represents DSSs
137
140
*/
138
- typedef ArithmeticalDSS<Coordinate, Integer, adjacency > DSS;
141
+ typedef ArithmeticalDSS<Coordinate, Integer, 4 > DSS;
139
142
// we expect that the iterator type returned DGtal points, used in the DSS representation
140
143
BOOST_STATIC_ASSERT (( concepts::ConceptUtils::SameType< Point, typename DSS::Point >::value ));
141
144
@@ -149,8 +152,32 @@ namespace DGtal
149
152
*/
150
153
typedef Point Vector;
151
154
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;
154
181
155
182
// ----------------------- Standard services ------------------------------
156
183
public:
@@ -164,11 +191,14 @@ namespace DGtal
164
191
/* *
165
192
* Constructor.
166
193
* @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)
169
199
*/
170
- ArithmeticalDSSComputerOnSurfels (const KSpace& aKSpace, Dimension aDim1, Dimension aDim2);
171
-
200
+ ArithmeticalDSSComputerOnSurfels (const KSpace& aKSpace, Dimension aDim1, Dimension aDim2, bool aFlagToReverse = false );
201
+
172
202
/* *
173
203
* Initialisation.
174
204
* @param it an iterator on 3D surfels
@@ -227,6 +257,9 @@ namespace DGtal
227
257
* Tests whether the current DSS can be extended at the front.
228
258
*
229
259
* @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.
230
263
*/
231
264
bool isExtendableFront ();
232
265
@@ -240,7 +273,11 @@ namespace DGtal
240
273
/* *
241
274
* Tests whether the current DSS can be extended at the front.
242
275
* Computes the parameters of the extended DSS if yes.
276
+ *
243
277
* @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.
244
281
*/
245
282
bool extendFront ();
246
283
@@ -265,6 +302,32 @@ namespace DGtal
265
302
*/
266
303
bool retractBack ();
267
304
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 ;
268
331
269
332
// ------------------------- Accessors ------------------------------
270
333
/* *
@@ -329,92 +392,77 @@ namespace DGtal
329
392
*/
330
393
bool isValid () const ;
331
394
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 ;
337
395
338
396
// ------------------------- Hidden services ------------------------------
339
397
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);
347
398
348
399
/* *
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.
351
405
*/
352
- Point projectInPlane (Point3 const & aPoint ) const ;
353
-
406
+ std::pair< Point,Point> getProjectedPointsFromLinel (SCell const & aLinel ) const ;
407
+
354
408
/* *
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
360
413
*/
361
- bool getOtherPointFromSurfel (ConstIterator const & it, Point& aPoint, bool aIsFront, bool aUpdatePrevious);
362
-
414
+ Dimension dimNotIn (Dimension const & aDim1, Dimension const & aDim2) const ;
415
+
363
416
// ------------------------- Protected Datas ------------------------------
364
417
protected:
365
418
366
419
/* *
367
- * Khalimsky space
420
+ * (Pointer to) Khalimsky space
368
421
*/
369
422
const KSpace* myKSpace;
370
423
371
424
/* *
372
- * The first projection dimension.
425
+ * A first direction that describes the projection plane
373
426
*/
374
- Dimension myDim1 ;
375
-
427
+ Dimension mySliceAxis1 ;
428
+
376
429
/* *
377
- * The second projection dimension.
430
+ * A second direction that describes the projection plane
378
431
*/
379
- Dimension myDim2 ;
380
-
432
+ Dimension mySliceAxis2 ;
433
+
381
434
/* *
382
- * The first projection direction.
435
+ * A direction along which the points are projected
436
+ * (and orthogonal to the projection plane)
383
437
*/
384
- Point3 myProjection1 ;
438
+ Dimension myProjectionAxis ;
385
439
386
440
/* *
387
- * The second projection direction.
441
+ * Functor that projects a 3D point to a 2D point along myProjectionAxis
388
442
*/
389
- Point3 myProjection2;
443
+ Projector my2DProjector;
390
444
391
445
/* *
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
393
448
*/
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
+
408
451
/* *
409
452
* DSS representation
410
453
*/
411
454
DSS myDSS;
455
+
412
456
/* *
413
457
* begin iterator
414
458
*/
415
459
ConstIterator myBegin;
460
+
416
461
/* *
417
462
* end iterator
463
+ *
464
+ * @warning the user must be sure that it can be safely dereferenced
465
+ * before calling 'isExtendableFront' and 'extendFront'.
418
466
*/
419
467
ConstIterator myEnd;
420
468
@@ -438,9 +486,9 @@ namespace DGtal
438
486
* @param object the object of class 'ArithmeticalDSSComputerOnSurfels' to write.
439
487
* @return the output stream after the writing.
440
488
*/
441
- template <typename TKSpace, typename TIterator, typename TInteger, unsigned short adjacency >
489
+ template <typename TKSpace, typename TIterator, typename TInteger>
442
490
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 )
444
492
{
445
493
object.selfDisplay ( out);
446
494
return out;
0 commit comments