aimsdata 6.0.0
Neuroimaging data handling
structuring_element.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef AIMS_CONNECTIVITY_STRUCTURING_ELEMENT_2_H
35#define AIMS_CONNECTIVITY_STRUCTURING_ELEMENT_2_H
36
37//--- aims -------------------------------------------------------------------
38#include <aims/vector/vector.h> // Point3dl
39//--- carto ------------------------------------------------------------------
40#include <cartobase/smart/rcptr.h> // smart pointers
41#include <cartobase/smart/refwrapper.h> // wrapper to references
42//--- std --------------------------------------------------------------------
43#include <string>
44#include <vector>
45#include <set>
46#include <map>
47//--- forward declarations ---------------------------------------------------
48namespace carto {
49 template <typename T> class Volume;
50}
51//----------------------------------------------------------------------------
52
53namespace aims {
54
55 //==========================================================================
56 // STRUCTURING ELEMENT: BASE CLASS
57 //==========================================================================
90 public:
91 //----------------------------------------------------------------------
92 // TYPEDEF
93 //----------------------------------------------------------------------
95 typedef std::vector<Point3dl>::iterator iterator;
98 typedef std::vector<Point3dl>::const_iterator const_iterator;
99
100 //----------------------------------------------------------------------
101 // CONSTRUCTOR
102 //----------------------------------------------------------------------
104 StructuringElement( const std::vector<Point3dl> & vector ):
105 _vector(vector) {}
107 // Use default compiler-supplied copy constructor and assignment operator
108 // StructuringElement( const StructuringElement & se );
109 // StructuringElement & operator= ( const StructuringElement & se );
110
111 //----------------------------------------------------------------------
112 // ITERATORS
113 //----------------------------------------------------------------------
115 iterator begin() { return _vector.begin(); }
117 iterator end() { return _vector.end(); }
121 const_iterator begin() const { return _vector.begin(); }
125 const_iterator end() const { return _vector.end(); }
126
127
128 //----------------------------------------------------------------------
129 // ACCESSOR
130 //----------------------------------------------------------------------
131 size_t size() const { return _vector.size(); }
135 const std::vector<Point3dl> & getVector() const { return _vector; }
146 std::vector<int> getAmplitude( const Point3dl & origin = Point3dl(0,0,0) ) const;
147
149 virtual StructuringElement* clone() const { return new StructuringElement(*this); }
150 protected:
151 std::vector<Point3dl> _vector;
152 };
153
154 //==========================================================================
155 // STRUCTURED VOLUME
156 //==========================================================================
159 template <typename T>
161 {
162 public:
163 typedef typename std::vector<carto::reference_wrapper<T> >::iterator iterator;
164 typedef typename std::vector<carto::reference_wrapper<T> >::const_iterator const_iterator;
166 const StructuringElement & se ):
167 _vector()
168 {
170 for( i=se.begin(); i!=e; ++i )
171 _vector.push_back( carto::wrap::ref( vol( (*i)[0], (*i)[1], (*i)[2] ) ) );
172 }
174 typename StructuredVolume<T>::iterator begin() { return _vector.begin(); }
175 typename StructuredVolume<T>::iterator end() { return _vector.end(); }
176 typename StructuredVolume<T>::const_iterator begin() const { return _vector.begin(); }
177 typename StructuredVolume<T>::const_iterator end() const { return _vector.end(); }
178 protected:
179 std::vector<carto::reference_wrapper<T> > _vector;
180 };
181
183 template <typename T>
185 {
186 public:
187 typedef typename std::vector<carto::reference_wrapper<const T> >::iterator iterator;
188 typedef typename std::vector<carto::reference_wrapper<const T> >::const_iterator const_iterator;
190 const StructuringElement & se ):
191 _vector()
192 {
194 for( i=se.begin(); i!=e; ++i )
195 _vector.push_back( carto::wrap::cref( vol( (*i)[0], (*i)[1], (*i)[2] ) ) );
196 }
198 typename StructuredConstVolume<T>::iterator begin() { return _vector.begin(); }
199 typename StructuredConstVolume<T>::iterator end() { return _vector.end(); }
200 typename StructuredConstVolume<T>::const_iterator begin() const { return _vector.begin(); }
201 typename StructuredConstVolume<T>::const_iterator end() const { return _vector.end(); }
202 protected:
203 std::vector<carto::reference_wrapper<const T> > _vector;
204 };
205
206 //==========================================================================
207 // STRUCTURING ELEMENT: REFERENCE
208 //==========================================================================
214 class StructuringElementRef: public carto::rc_ptr<StructuringElement>
215 {
216 public:
219
226
232
238
239 iterator begin() { return (*this)->begin(); }
240 iterator end() { return (*this)->end(); }
241 const_iterator begin() const { return (*this)->begin(); }
242 const_iterator end() const { return (*this)->end(); }
243
244 size_t size() const { return (*this)->size(); }
245 const std::vector<Point3dl> & getVector() const
246 { return (*this)->getVector(); }
247 std::vector<int>
248 getAmplitude( const Point3dl & origin = Point3dl(0,0,0) ) const
249 { return (*this)->getAmplitude(origin); }
250 };
251
252 namespace strel {
255
256 //========================================================================
257 // STRUCTURING ELEMENT: SHAPE INTERFACE
258 //========================================================================
270 {
271 friend class ShapeFactory;
272 public:
275 virtual ~Shape() {};
276 virtual Shape* clone() const = 0;
277
278 protected:
279 // Defined methods
280 void setParameters( const double amplitude = 1.,
281 const bool usecenter = false );
282 void setParameters( const Point3dl & origin,
283 const double amplitude = 1.,
284 const bool usecenter = false );
285 void setParameters( const Point3d & origin,
286 const double amplitude = 1,
287 const bool usecenter = false );
288 void setParameters( const std::vector<double> & amplitude,
289 const bool usecenter = false );
290 void setParameters( const Point3d & origin,
291 const std::vector<double> & amplitude,
292 const bool usecenter = false );
293
294 // Pure virtual methods:
295 virtual void setParameters( const Point3dl & origin,
296 const std::vector<double> & amplitude,
297 const bool usecenter = false ) = 0;
298 };
299
300 //========================================================================
301 // STRUCTURING ELEMENT: SHAPE FACTORY
302 //========================================================================
328 public:
329 static Shape* create( const std::string & type,
330 const double amplitude = 1.,
331 const bool usecenter = false );
332 static Shape* create( const std::string & type,
333 const Point3d & origin,
334 const double amplitude = 1.,
335 const bool usecenter = false );
336 static Shape* create( const std::string & type,
337 const Point3dl & origin,
338 const double amplitude = 1.,
339 const bool usecenter = false );
340 static Shape* create( const std::string & type,
341 const std::vector<double> & amplitude,
342 const bool usecenter = false );
343 static Shape* create( const std::string & type,
344 const Point3d & origin,
345 const std::vector<double> & amplitude,
346 const bool usecenter = false );
347 static Shape* create( const std::string & type,
348 const Point3dl & origin,
349 const std::vector<double> & amplitude,
350 const bool usecenter = false );
351 static void registerShape( const std::string & type,
352 const Shape & strel );
353 static std::set<std::string> shapes();
354 protected:
355 static void init();
356 static std::map<std::string,carto::rc_ptr<Shape> > & _map();
357 };
358
359 //========================================================================
360 // STRUCTURING ELEMENT: CONNECTIVITY INTERFACE
361 //========================================================================
371 {
373 public:
376 virtual ~Connectivity() {};
377 virtual Connectivity* clone() const = 0;
378 //--------------------------------------------------------------------
379 // TYPEDEF
380 //--------------------------------------------------------------------
383 typedef const bool (&Matrix3x3x3Const)[3][3][3];
384 //--------------------------------------------------------------------
385 // METHODS
386 //--------------------------------------------------------------------
393 virtual Matrix3x3x3Const getMatrix() const = 0;
394 protected:
395 void setVectorFromMatrix( const Point3dl & origin = Point3dl(0,0,0),
396 const bool usecenter = false );
397 };
398
399 //========================================================================
400 // STRUCTURING ELEMENT: CONNECTIVITY FACTORY
401 //========================================================================
440 {
441 public:
442 static Connectivity* create( const std::string & type,
443 const bool usecenter = false );
444 static Connectivity* create( const std::string & type,
445 const Point3d & origin,
446 const bool usecenter = false );
447 static Connectivity* create( const std::string & type,
448 const Point3dl & origin,
449 const bool usecenter = false );
450 static void registerConnectivity( const std::string & type,
451 const Connectivity & strel );
452 static std::set<std::string> connectivities();
453 protected:
454 static void init();
455 static std::map<std::string,carto::rc_ptr<Connectivity> > & _map();
456 };
457
458 } // namespace strel
459} // namespace aims
460
461
462//============================================================================
463// STRUCTURING ELEMENT: SHAPE DERIVED CLASSES
464//============================================================================
465#define AIMS_DECLARE_STREL_SHAPE( NAME ) \
466 class NAME: public Shape \
467 { \
468 public: \
469 typedef StructuringElement::iterator iterator; \
470 typedef StructuringElement::const_iterator const_iterator; \
471 NAME( const double amplitude = 1., \
472 const bool usecenter = false ): Shape() \
473 { Shape::setParameters( amplitude, usecenter ); } \
474 NAME( const Point3d & origin, \
475 const double amplitude = 1., \
476 const bool usecenter = false ): Shape() \
477 { Shape::setParameters( origin, amplitude, usecenter ); } \
478 NAME( const Point3dl & origin, \
479 const double amplitude = 1., \
480 const bool usecenter = false ): Shape() \
481 { Shape::setParameters( origin, amplitude, usecenter ); } \
482 NAME( const std::vector<double> & amplitude, \
483 const bool usecenter = false ): Shape() \
484 { Shape::setParameters( amplitude, usecenter ); } \
485 NAME( const Point3d & origin, \
486 const std::vector<double> & amplitude, \
487 const bool usecenter = false ): Shape() \
488 { Shape::setParameters( origin, amplitude, usecenter ); } \
489 NAME( const Point3dl & origin, \
490 const std::vector<double> & amplitude, \
491 const bool usecenter = false ): Shape() \
492 { setParameters( origin, amplitude, usecenter ); } \
493 virtual ~NAME() {} \
494 protected: \
495 virtual void setParameters( const Point3dl & origin, \
496 const std::vector<double> & amplitude, \
497 const bool usecenter = false ); \
498 virtual NAME* clone() const { return new NAME(*this); } \
499 };
500
501namespace aims {
502 namespace strel {
515 AIMS_DECLARE_STREL_SHAPE( DiagonalCross );
516 AIMS_DECLARE_STREL_SHAPE( DiagonalCrossXY );
517 AIMS_DECLARE_STREL_SHAPE( DiagonalCrossXZ );
518 AIMS_DECLARE_STREL_SHAPE( DiagonalCrossYZ );
520
521 class ClockWiseCircleXY: public CircleXY
522 {
523 public:
526 ClockWiseCircleXY( const double amplitude = 1.,
527 const bool usecenter = false ): CircleXY()
528 { Shape::setParameters( amplitude, usecenter ); }
529 ClockWiseCircleXY( const Point3d & origin,
530 const double amplitude = 1.,
531 const bool usecenter = false ): CircleXY()
532 { Shape::setParameters( origin, amplitude, usecenter ); }
534 const double amplitude = 1.,
535 const bool usecenter = false ): CircleXY()
536 { Shape::setParameters( origin, amplitude, usecenter ); }
537 ClockWiseCircleXY( const std::vector<double> & amplitude,
538 const bool usecenter = false ): CircleXY()
539 { Shape::setParameters( amplitude, usecenter ); }
540 ClockWiseCircleXY( const Point3d & origin,
541 const std::vector<double> & amplitude,
542 const bool usecenter = false ): CircleXY()
543 { Shape::setParameters( origin, amplitude, usecenter ); }
545 const std::vector<double> & amplitude,
546 const bool usecenter = false ): CircleXY()
547 { setParameters( origin, amplitude, usecenter ); }
549
550 protected:
551 virtual void clockwise_order();
552 virtual void setParameters( const Point3dl & origin,
553 const std::vector<double> & amplitude,
554 const bool usecenter = false );
555 virtual ClockWiseCircleXY* clone() const
556 { return new ClockWiseCircleXY(*this); }
557 };
558
559 } // namespace strel
560} // namespace aims
561
562//============================================================================
563// STRUCTURING ELEMENT: CONNECTIVITY DERIVED CLASSES
564//============================================================================
565#define AIMS_DECLARE_STREL_CONNECTIVITY( NAME ) \
566 class NAME: public Connectivity \
567 { \
568 public: \
569 typedef StructuringElement::iterator iterator; \
570 typedef StructuringElement::const_iterator const_iterator; \
571 NAME(): Connectivity() { setVectorFromMatrix(); } \
572 virtual ~NAME() {} \
573 Connectivity::Matrix3x3x3Const getMatrix() const; \
574 protected: \
575 virtual NAME* clone() const \
576 { return new NAME(*this); } \
577 }
578
579namespace aims {
580 namespace strel {
584 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity4XYDiag );
585 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity4XZDiag );
586 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity4YZDiag );
594 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity9XYZMinus );
595 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity9XYZPlus );
596 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity9XZYMinus );
597 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity9XZYPlus );
598 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity9YZXMinus );
599 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity9YZXPlus );
600 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5XMinusY );
601 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5XPlusY );
602 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5XYMinus );
603 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5XYPlus );
604 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5XMinusZ );
605 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5XPlusZ );
606 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5XZMinus );
607 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5XZPlus );
608 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5YMinusZ );
609 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5YPlusZ );
610 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5YZMinus );
611 AIMS_DECLARE_STREL_CONNECTIVITY( Connectivity5YZPlus );
612 } // namespace strel
613} // namespace aims
614
615#endif
std::vector< carto::reference_wrapper< const T > > _vector
StructuredConstVolume< T >::const_iterator end() const
std::vector< carto::reference_wrapper< constT > >::const_iterator const_iterator
StructuredConstVolume< T >::const_iterator begin() const
StructuredConstVolume< T >::iterator begin()
StructuredConstVolume(const carto::Volume< T > &vol, const StructuringElement &se)
std::vector< carto::reference_wrapper< constT > >::iterator iterator
StructuredConstVolume< T >::iterator end()
StructuredVolume< T >::const_iterator end() const
StructuredVolume< T >::iterator end()
StructuredVolume< T >::const_iterator begin() const
StructuredVolume(carto::Volume< T > &vol, const StructuringElement &se)
std::vector< carto::reference_wrapper< T > >::const_iterator const_iterator
std::vector< carto::reference_wrapper< T > >::iterator iterator
StructuredVolume< T >::iterator begin()
std::vector< carto::reference_wrapper< T > > _vector
Convenient handle for a StructuringElement.
StructuringElementRef()
Default constructor.
StructuringElementRef(StructuringElement *se)
New object constructor.
std::vector< int > getAmplitude(const Point3dl &origin=Point3dl(0, 0, 0)) const
const std::vector< Point3dl > & getVector() const
StructuringElement::iterator iterator
StructuringElementRef(const carto::rc_ptr< StructuringElement > &se)
Copy constructor.
StructuringElement::const_iterator const_iterator
aims::StructuringElement class representing a 3D structuring element.
const_iterator begin() const
Return const_iterator to beginning.
iterator end()
Return iterator to end.
std::vector< int > getAmplitude(const Point3dl &origin=Point3dl(0, 0, 0)) const
Maximum distance to origin in each direction.
iterator begin()
Return iterator to beginning.
std::vector< Point3dl > _vector
const_iterator end() const
Return const_iterator to end.
const std::vector< Point3dl > & getVector() const
Return std::vector<Point3dl>
virtual StructuringElement * clone() const
Clone the StructuringElement.
std::vector< Point3dl >::iterator iterator
std::vector< Point3dl >::const_iterator const_iterator
StructuringElement(const std::vector< Point3dl > &vector)
ClockWiseCircleXY(const Point3d &origin, const std::vector< double > &amplitude, const bool usecenter=false)
virtual void setParameters(const Point3dl &origin, const std::vector< double > &amplitude, const bool usecenter=false)
virtual ClockWiseCircleXY * clone() const
ClockWiseCircleXY(const Point3dl &origin, const std::vector< double > &amplitude, const bool usecenter=false)
ClockWiseCircleXY(const Point3dl &origin, const double amplitude=1., const bool usecenter=false)
ClockWiseCircleXY(const std::vector< double > &amplitude, const bool usecenter=false)
ClockWiseCircleXY(const double amplitude=1., const bool usecenter=false)
StructuringElement::const_iterator const_iterator
ClockWiseCircleXY(const Point3d &origin, const double amplitude=1., const bool usecenter=false)
StructuringElement::iterator iterator
aims::strel::Connectivity generator
static Connectivity * create(const std::string &type, const Point3d &origin, const bool usecenter=false)
static Connectivity * create(const std::string &type, const Point3dl &origin, const bool usecenter=false)
static std::map< std::string, carto::rc_ptr< Connectivity > > & _map()
static std::set< std::string > connectivities()
static Connectivity * create(const std::string &type, const bool usecenter=false)
static void registerConnectivity(const std::string &type, const Connectivity &strel)
aims::strel::Connectivity pure abstract class representing a "connectivity" 3D structuring element.
virtual Matrix3x3x3Const getMatrix() const =0
return the Matrix3x3x3Const representing a structuring element.
virtual Connectivity * clone() const =0
Clone the StructuringElement.
void setVectorFromMatrix(const Point3dl &origin=Point3dl(0, 0, 0), const bool usecenter=false)
StructuringElement::iterator iterator
const bool(& Matrix3x3x3Const)[3][3][3]
StructuringElement::const_iterator const_iterator
aims::strel::Shape generator
static Shape * create(const std::string &type, const Point3d &origin, const std::vector< double > &amplitude, const bool usecenter=false)
static std::map< std::string, carto::rc_ptr< Shape > > & _map()
static Shape * create(const std::string &type, const Point3dl &origin, const std::vector< double > &amplitude, const bool usecenter=false)
static void registerShape(const std::string &type, const Shape &strel)
static Shape * create(const std::string &type, const std::vector< double > &amplitude, const bool usecenter=false)
static Shape * create(const std::string &type, const Point3dl &origin, const double amplitude=1., const bool usecenter=false)
static std::set< std::string > shapes()
static Shape * create(const std::string &type, const Point3d &origin, const double amplitude=1., const bool usecenter=false)
static Shape * create(const std::string &type, const double amplitude=1., const bool usecenter=false)
aims::strel::Shape pure abstract class representing a "shape" 3D structuring element.
void setParameters(const double amplitude=1., const bool usecenter=false)
void setParameters(const Point3d &origin, const std::vector< double > &amplitude, const bool usecenter=false)
virtual Shape * clone() const =0
Clone the StructuringElement.
StructuringElement::const_iterator const_iterator
virtual void setParameters(const Point3dl &origin, const std::vector< double > &amplitude, const bool usecenter=false)=0
void setParameters(const std::vector< double > &amplitude, const bool usecenter=false)
void setParameters(const Point3dl &origin, const double amplitude=1., const bool usecenter=false)
void setParameters(const Point3d &origin, const double amplitude=1, const bool usecenter=false)
StructuringElement::iterator iterator
StructuringElementRef none()
Pointer to an empty aims::StructuringElement.
The class for EcatSino data write operation.
reference_wrapper< T > ref(T &ref)
reference_wrapper< const T > cref(const T &ref)
#define AIMS_DECLARE_STREL_SHAPE(NAME)
#define AIMS_DECLARE_STREL_CONNECTIVITY(NAME)
AimsVector< int16_t, 3 > Point3d
AimsVector< int64_t, 3 > Point3dl