Skip to content

Commit

Permalink
Add container member function to DigitalSets and ImageContainers
Browse files Browse the repository at this point in the history
`container()` returns a reference (might be const) to the underlying
container holding the data.
It might point to an instance of Self type, Parent type, or to a protected/private
data member, depending on the type.
  • Loading branch information
phcerdan committed Nov 19, 2020
1 parent 9302899 commit 9ea6a08
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- *General*
- Only set CMAKE_CXX_STANDARD if not defined already
(Pablo Hernandez-Cerdan [#1526](https://github.com/DGtal-team/DGtal/pull/1526))
- Add `container()` member function to DigitalSets and ImageContainers
(Pablo Hernandez-Cerdan [#1532](https://github.com/DGtal-team/DGtal/pull/1532))

- *Arithmetic*
- Add default constructor to ClosedIntegerHalfSpace
Expand Down
15 changes: 15 additions & 0 deletions src/DGtal/images/ImageContainerByHashTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,21 @@ namespace DGtal
*/
Range range() ;

/**
* Give access to the underlying container.
* @return a (might be const) reference to the container.
*/
const Self & container() const { return *this; };
/** @copydoc container() */
Self & container() { return *this; };

/**
* Give access to the underlying data.
* @return a (might be const) reference to the data.
*/
const Node** & data() const noexcept { return myData; };
/** @copydoc data() */
Node** & data() noexcept { return myData; };

/**
* Returns the value corresponding to a key.
Expand Down
15 changes: 15 additions & 0 deletions src/DGtal/images/ImageContainerByITKImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace DGtal

typedef typename itk::Image< TValue, dimension> ITKImage;
typedef typename ITKImage::Pointer ITKImagePointer;
typedef typename ITKImage::PixelContainer Container;
typedef typename itk::ImageRegionConstIterator< ITKImage > ConstIterator;
typedef typename itk::ImageRegionIterator< ITKImage > Iterator;

Expand Down Expand Up @@ -190,6 +191,20 @@ namespace DGtal
return Range(*this);
}

/**
* Give access to the underlying container.
* @return a (might be const) reference to the container.
*/
const Container & container() const
{
return *(myITKImagePointer->GetPixelContainer());
}
/** @copydoc container() */
Container & container()
{
return *(myITKImagePointer->GetPixelContainer());
}

/**
* Get the value of an image at a given position.
*
Expand Down
9 changes: 9 additions & 0 deletions src/DGtal/images/ImageContainerBySTLMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace DGtal

typedef ImageContainerBySTLMap<TDomain,TValue> Self;
typedef std::map<typename TDomain::Point, TValue > Parent;
typedef Parent Container;

/// domain
BOOST_CONCEPT_ASSERT(( concepts::CDomain<TDomain> ));
Expand Down Expand Up @@ -216,6 +217,14 @@ namespace DGtal
*/
Range range();

/**
* Give access to the underlying container.
* @return a (might be const) reference to the container.
*/
const Container & container() const { return static_cast<Parent>(*this); };
/** @copydoc container() */
Container & container() { return static_cast<Parent>(*this); };

/**
* Writes/Displays the object on an output stream.
* @param out the output stream where the object is written.
Expand Down
10 changes: 10 additions & 0 deletions src/DGtal/images/ImageContainerBySTLVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ namespace DGtal
public:

typedef ImageContainerBySTLVector<TDomain, TValue> Self;
typedef std::vector<TValue> Parent;
typedef Parent Container;

/// domain
BOOST_CONCEPT_ASSERT ( ( concepts::CDomain<TDomain> ) );
Expand Down Expand Up @@ -284,6 +286,14 @@ namespace DGtal
*/
Range range();

/**
* Give access to the underlying container.
* @return a (might be const) reference to the container.
*/
const Container & container() const { return static_cast<Parent>(*this); };
/** @copydoc container() */
Container & container() { return static_cast<Parent>(*this); };


/////////////////////////// Custom Iterator ///////////////
/**
Expand Down
3 changes: 2 additions & 1 deletion src/DGtal/kernel/PointVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -972,11 +972,12 @@ namespace DGtal
ConstReverseIterator rend() const;

/**
* PointVector data() access to raw data of a std container
* PointVector data() (const and non-const) access to raw data of a std container
*
* @return container.data()
*/
inline const Component* data() const noexcept;
/** @copydoc data() */
inline Component* data() noexcept;

// ----------------------- Array services ------------------------------
Expand Down
8 changes: 8 additions & 0 deletions src/DGtal/kernel/sets/DigitalSetByAssociativeContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ namespace DGtal
*/
Iterator end();

/**
* Give access to the underlying container.
* @return a (might be const) reference to the stored container.
*/
const Container & container() const;
/** @copydoc container() */
Container & container();

/**
* set union to left.
* @param aSet any other set.
Expand Down
16 changes: 16 additions & 0 deletions src/DGtal/kernel/sets/DigitalSetByAssociativeContainer.ih
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,22 @@ DGtal::DigitalSetByAssociativeContainer<Domain, Container>::end()
return mySet.end();
}

template <typename Domain, typename Container>
inline
const typename DGtal::DigitalSetByAssociativeContainer<Domain, Container>::Container &
DGtal::DigitalSetByAssociativeContainer<Domain, Container>::container() const
{
return mySet;
}

template <typename Domain, typename Container>
inline
typename DGtal::DigitalSetByAssociativeContainer<Domain, Container>::Container &
DGtal::DigitalSetByAssociativeContainer<Domain, Container>::container()
{
return mySet;
}

/**
* set union to left.
* @param aSet any other set.
Expand Down
9 changes: 9 additions & 0 deletions src/DGtal/kernel/sets/DigitalSetBySTLSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace DGtal
typedef typename Domain::Space Space;
typedef typename Domain::Point Point;
typedef typename Domain::Size Size;
typedef std::set<Point> Container;
typedef typename std::set<Point>::iterator Iterator;
typedef typename std::set<Point>::const_iterator ConstIterator;

Expand Down Expand Up @@ -254,6 +255,14 @@ namespace DGtal
*/
Iterator end();

/**
* Give access to the underlying container.
* @return a (might be const) reference to the stored container.
*/
const Container & container() const;
/** @copydoc container() */
Container & container();

/**
* set union to left.
* @param aSet any other set.
Expand Down
16 changes: 16 additions & 0 deletions src/DGtal/kernel/sets/DigitalSetBySTLSet.ih
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,22 @@ DGtal::DigitalSetBySTLSet<Domain, Compare>::end()
return mySet.end();
}

template <typename Domain, typename Compare>
inline
const typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Container &
DGtal::DigitalSetBySTLSet<Domain, Compare>::container() const
{
return mySet;
}

template <typename Domain, typename Compare>
inline
typename DGtal::DigitalSetBySTLSet<Domain, Compare>::Container &
DGtal::DigitalSetBySTLSet<Domain, Compare>::container()
{
return mySet;
}

/**
* set union to left.
* @param aSet any other set.
Expand Down
10 changes: 9 additions & 1 deletion src/DGtal/kernel/sets/DigitalSetBySTLVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ namespace DGtal
typedef typename Domain::Space Space;
typedef typename Domain::Point Point;
typedef typename Domain::Size Size;
typedef typename std::vector<Point>::const_iterator Iterator;
typedef std::vector<Point> Container;
typedef typename std::vector<Point>::iterator Iterator;
typedef typename std::vector<Point>::const_iterator ConstIterator;
typedef typename std::vector<Point>::iterator MutableIterator;

Expand Down Expand Up @@ -253,6 +254,13 @@ namespace DGtal
*/
Iterator end();

/**
* Give access to the underlying container.
* @return a (might be const) reference to the stored container.
*/
const Container & container() const;
Container & container();

/**
* set union to left.
* @param aSet any other set.
Expand Down
16 changes: 16 additions & 0 deletions src/DGtal/kernel/sets/DigitalSetBySTLVector.ih
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,22 @@ DGtal::DigitalSetBySTLVector<Domain>::end()
return myVector.end();
}

template <typename Domain>
inline
const typename DGtal::DigitalSetBySTLVector<Domain>::Container &
DGtal::DigitalSetBySTLVector<Domain>::container() const
{
return myVector;
}

template <typename Domain>
inline
typename DGtal::DigitalSetBySTLVector<Domain>::Container &
DGtal::DigitalSetBySTLVector<Domain>::container()
{
return myVector;
}

/**
* set union to left.
* @param aSet any other set.
Expand Down
9 changes: 9 additions & 0 deletions src/DGtal/kernel/sets/DigitalSetFromMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace DGtal
public:

typedef TMapImage Image;
typedef Image Container;
typedef std::pair<const typename Image::Point,
typename Image::Value> Pair;
typedef DigitalSetFromMap<Image> Self;
Expand Down Expand Up @@ -269,6 +270,14 @@ namespace DGtal
*/
Iterator end();

/**
* Give access to the underlying container.
* @return a (might be const) reference to the stored container.
*/
const Container & container() const { return *myImgPtr;};
/** @copydoc container() */
Container & container(){ return *myImgPtr;};

/**
* set union to left.
* @param aSet any other set.
Expand Down
3 changes: 3 additions & 0 deletions tests/images/testITKImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ bool testITKImage()
trace.warning() << myImage(it) << " ";
trace.info() << endl;

auto & container = myImage.container();
(void)container;


trace.info() << "(" << nbok << "/" << nb << ") "
<< "true == true" << std::endl;
Expand Down
4 changes: 4 additions & 0 deletions tests/kernel/testDigitalSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ bool testDigitalSet( const DigitalSetType& aSet1, const DigitalSetType& aSet2 )
trace.info() << "Iterate: (" << nbok << "/" << nb << ") "
<< std::endl;

// access to underlying container
auto & container = set1.container();
(void)container; // remove unused warning

//erasure
set1.erase( b );
nbok += ( (set1.size() == 2)
Expand Down

0 comments on commit 9ea6a08

Please sign in to comment.