Skip to content

Commit

Permalink
Merge pull request #1023 from dcoeurjo/Hashdigitalset
Browse files Browse the repository at this point in the history
DigitalSetByAssociativeContainer
  • Loading branch information
JacquesOlivierLachaud committed Oct 1, 2015
2 parents 169304e + 3d92f4c commit 03da2c8
Show file tree
Hide file tree
Showing 48 changed files with 2,074 additions and 195 deletions.
15 changes: 15 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
[#1042](https:/DGtal-team/DGtal/pull/1042)


- *Kernel*
- New template class DigitalSetlByAssociativeContainer allows to
define digital sets from any associative container of the STL. For
instance, using std::unordered_set (c++11) or boost::unordered_set (hash
function based containers), speed-up up to 40% can be measured when
processing digital sets. (David Coeurjolly,
[#1023](https:/DGtal-team/DGtal/pull/1023)
- By default, Z2i::DigitalSet, Z3i::DigitalSet and digital set from
DigitalSetSelector use the new hash function based
container. (David Coeurjolly,
[#1023](https:/DGtal-team/DGtal/pull/1023)
- Specializations of std::hash (c++11) and boost::hash to define a hash
functions on DGtal points. (David Coeurjolly,
[#1023](https:/DGtal-team/DGtal/pull/1023)

## Changes

- *DEC Package*
Expand Down
11 changes: 11 additions & 0 deletions src/DGtal/base/BasicArchetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ namespace DGtal
/////////////////////////////////////////////////////////////////////////////
// List of basic archetypes, grouped in this file.


/**
Description of \b archetype '\b CSinglePassIteratorArchetype' <p>
@ingroup Archetypes
@brief An archetype of SingePassIterator.
*/
template <typename T>
struct CSinglePassIteratorArchetype :
public boost::input_iterator_archetype<T>
{};

/**
Description of \b archetype '\b CBidirectionalIteratorArchetype' <p>
@ingroup Archetypes
Expand Down
154 changes: 154 additions & 0 deletions src/DGtal/base/CSTLAssociativeContainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* 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/>.
*
**/

#pragma once

/**
* @file CSTLAssociativeContainer.h
* @author David Coeurjolly
* Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
*
* @date 2015/07/06
*
* Header file for concept CSTLAssociativeContainer
*
* This file is part of the DGtal library.
*/

#if defined(CSTLAssociativeContainer_RECURSES)
#error Recursive header files inclusion detected in CSTLAssociativeContainer.h
#else // defined(CSTLAssociativeContainer_RECURSES)
/** Prevents recursive inclusion of headers. */
#define CSTLAssociativeContainer_RECURSES

#if !defined CSTLAssociativeContainer_h
/** Prevents repeated inclusion of headers. */
#define CSTLAssociativeContainer_h

//////////////////////////////////////////////////////////////////////////////
// Inclusions
#include <iostream>
//////////////////////////////////////////////////////////////////////////////

namespace DGtal
{
namespace concepts
{
/////////////////////////////////////////////////////////////////////////////
// class CSTLAssociativeContainer
/**
DescriptionDescription of \b concept '\b CSTLAssociativeContainer'
@ingroup Concepts
\brief Aim: Defines the concept describing an Associative
Container of the STL
(https://www.sgi.com/tech/stl/AssociativeContainer.html).
@note This concept can also be found in the boost library under
the name boost::AssociativeContainer. However, there is a
issue in this concept (problem in boost 1.58 but present in
several releases) which requires the container to be "sorted". As
a consequence, boost::unordered_set does not satisfy the concept.
### Refinement of
- boost::ForwardContainer
- boost::DefaultConstructible
### Provided types:
- value_type: the value type
- key_type: the key type
- iterator: the iterator type
- const_iterator: a const iterator type
- size_type: a size type
### Notation:
- x an object of a model of CSTLAssociativeContainer.
- val an object of type value_type
- key and object of type key_type
- p, q two instances of type iterator
For a complete desccription of this concept, please check https://www.sgi.com/tech/stl/AssociativeContainer.html.
### Invariants
### Models
std::set, std::unordered_set (c++11), boost::unordered_set.
### Notes
@tparam T the type that is checked. T should be a model of CSTLAssociativeContainer.
*/
template <typename T>
struct CSTLAssociativeContainer : boost::ForwardContainer<T>, boost::DefaultConstructible<T>
{
// ----------------------- Concept checks ------------------------------
public:
typedef typename T::iterator iterator;
typedef typename T::value_type value_type;
typedef typename T::key_type key_type;
typedef typename T::size_type size_type;
typedef typename T::const_iterator const_iterator;

BOOST_CONCEPT_USAGE(CSTLAssociativeContainer)
{
x.erase(key);
x.erase(p);
x.erase(p, q);
x.clear();
p = x.find(key);
r = x.equal_range(key);
n = x.count(key);
};

private:
void const_constraints(const T& cc)
{
ci = cc.find(key);
n = cc.count(key);
cr = cc.equal_range(key);
}


private:
T x;
iterator p,q;
const_iterator ci;
value_type val;
key_type key;
size_type n;
std::pair<iterator,iterator> r;
std::pair<const_iterator,const_iterator> cr;

}; // end of concept CSTLAssociativeContainer
} // namespace concept
} // namespace DGtal



// //
///////////////////////////////////////////////////////////////////////////////

#endif // !defined CSTLAssociativeContainer_h

#undef CSTLAssociativeContainer_RECURSES
#endif // else defined(CSTLAssociativeContainer_RECURSES)
1 change: 0 additions & 1 deletion src/DGtal/dec/DiscreteExteriorCalculus.ih
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ DGtal::DiscreteExteriorCalculus<dimEmbedded, dimAmbient, TLinearAlgebraBackend,
if (iter_property == myCellProperties.end())
return false;

const DGtal::Dimension cell_dim = myKSpace.uDim(_cell);
const Index index = iter_property->second.index;
myCellProperties.erase(iter_property);

Expand Down
2 changes: 1 addition & 1 deletion src/DGtal/geometry/volumes/distance/FMM.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace DGtal
typedef std::pair<Point, Value> PointValue;
typedef std::set<PointValue,
detail::PointValueCompare<PointValue> > CandidatePointSet;
typedef unsigned long Area;
typedef DGtal::uint64_t Area;

// ------------------------- Private Datas --------------------------------
private:
Expand Down
3 changes: 2 additions & 1 deletion src/DGtal/graph/BreadthFirstVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ namespace DGtal
typedef Size Data; ///< Data attached to each Vertex is the topological distance to the seed.

// Cannot check this since some types using it are incomplete.
//BOOST_CONCEPT_ASSERT(( CUndirectedSimpleLocalGraph< Graph > ));
///FIXME
// BOOST_CONCEPT_ASSERT(( concepts::CUndirectedSimpleLocalGraph< Graph > ));
// BOOST_CONCEPT_ASSERT(( CSet< MarkSet, Vertex > ));

// ----------------------- defined types ------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/DGtal/graph/doc/moduleBoostGraphWrapping.dox
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ for ( std::pair<vertex_iterator, vertex_iterator> vp = boost::vertices( g );
it works.

@code
unsigned long nbEdges = 0;
unsigned int nbEdges = 0;
for ( std::pair<edge_iterator, edge_iterator> ve = boost::edges( g );
ve.first != ve.second; ++ve.first, ++nbEdges )
{
Expand Down Expand Up @@ -244,7 +244,7 @@ creating your property map, as follows.

@code
// get the property map for storing distances
typedef std::map< vertex_descriptor, unsigned long > StdDistanceMap;
typedef std::map< vertex_descriptor, unsigned int > StdDistanceMap;
StdDistanceMap distanceMap;
boost::associative_property_map< StdDistanceMap > propDistanceMap( distanceMap );
boost::queue< vertex_descriptor > Q; // std::queue does not have top().
Expand All @@ -262,12 +262,12 @@ creating your property map, as follows.
possible from \c start.

@code
unsigned long maxD = 0;
unsigned int maxD = 0;
vertex_descriptor furthest = start;
for ( std::pair<vertex_iterator, vertex_iterator> vp = boost::vertices( g );
vp.first != vp.second; ++vp.first )
{
unsigned long d = boost::get( propDistanceMap, *vp.first );
unsigned int d = boost::get( propDistanceMap, *vp.first );
if ( d > maxD )
{
maxD = d;
Expand Down
4 changes: 1 addition & 3 deletions src/DGtal/images/ImageContainerBySTLMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace DGtal
* Note that the default value (returned for points that are not
* stored in the underlying STL map) can be chosen by the user.
*
* As a model of CImage, this class provides two ways of accessing values:
* As a model of concepts::CImage, this class provides two ways of accessing values:
* - through the range of points returned by the domain() method
* combined with the operator() that takes a point and returns its associated value.
* - through the range of values returned by the range() method,
Expand Down Expand Up @@ -121,8 +121,6 @@ namespace DGtal
/// range of values
BOOST_CONCEPT_ASSERT(( CLabel<TValue> ));
typedef TValue Value;
//obsolete:
//typedef ConstRangeAdapter<typename Domain::ConstIterator, Self, Value > ConstRange;
typedef DefaultConstImageRange<Self> ConstRange;
typedef DefaultImageRange<Self> Range;

Expand Down
2 changes: 1 addition & 1 deletion src/DGtal/images/ImageContainerBySTLVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace DGtal
typedef typename Domain::Dimension Dimension;
typedef Point Vertex;

BOOST_STATIC_CONSTANT( Dimension, dimension = Domain::dimension );
BOOST_STATIC_CONSTANT( Dimension, dimension = Domain::Space::dimension );

/// domain should be rectangular
BOOST_STATIC_ASSERT ( ( boost::is_same< Domain,
Expand Down
2 changes: 1 addition & 1 deletion src/DGtal/images/imagesSetsUtils/ImageFromSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace DGtal
typedef typename TImage::Value Value;


//BOOST_CONCEPT_ASSERT(( CImage<Image> ));
BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));


/**
Expand Down
4 changes: 2 additions & 2 deletions src/DGtal/images/imagesSetsUtils/ImageFromSet.ih
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DGtal::ImageFromSet<Image>::create(const Set &aSet, const Value &defaultValue,
typename Set::ConstIterator itBegin,
typename Set::ConstIterator itEnd)
{
// BOOST_CONCEPT_ASSERT(( CDigitalSet<Set> ));
BOOST_CONCEPT_ASSERT(( concepts::CDigitalSet<Set> ));

typename Set::Point lower,upper;
typename Set::Point dec;
Expand All @@ -71,7 +71,7 @@ DGtal::ImageFromSet<Image>::append(Image &aImage, const Value &defaultValue,
typename Set::ConstIterator itBegin,
typename Set::ConstIterator itEnd)
{
// BOOST_CONCEPT_ASSERT(( CDigitalSet<Set> ));
BOOST_CONCEPT_ASSERT(( concepts::CDigitalSet<Set> ));

typename Image::Domain domain = aImage.domain();

Expand Down
13 changes: 11 additions & 2 deletions src/DGtal/io/Display2DFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

#include "DGtal/base/Common.h"

#include "DGtal/kernel/sets/DigitalSetByAssociativeContainer.h"
#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
#include "DGtal/kernel/sets/DigitalSetBySTLVector.h"

#include "DGtal/math/AngleLinearMinimizer.h"
#include "DGtal/geometry/curves/ArithmeticalDSS.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
Expand Down Expand Up @@ -71,7 +75,6 @@
#include "DGtal/dec/KForm.h"
#include "DGtal/dec/DiscreteExteriorCalculus.h"

//#include "DGtal/io/boards/Board2D.h"
#include "DGtal/helpers/StdDefs.h"

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -181,7 +184,13 @@ static void draw(Board2D & aBoard, const DGtal::CircleFrom3Points<TPoint> & );
template<typename Domain, typename Compare>
static void draw( DGtal::Board2D & board, const DGtal::DigitalSetBySTLSet<Domain, Compare> & );
// DigitalSetBySTLSet



// DigitalSetByAssociativeContainer
template<typename Domain, typename Container>
static void draw( DGtal::Board2D & board, const DGtal::DigitalSetByAssociativeContainer<Domain,Container> & );
// DigitalSetByAssociativeContainer


// DigitalSetBySTLVector
template<typename Domain>
Expand Down
15 changes: 15 additions & 0 deletions src/DGtal/io/Display2DFactory.ih
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,21 @@ void DGtal::Display2DFactory::draw( DGtal::Board2D & board,
// DigitalSetBySTLSet


// DigitalSetByAssociativeContainer
template<typename Domain, typename Container>
inline
void DGtal::Display2DFactory::draw( DGtal::Board2D & board,
const DGtal::DigitalSetByAssociativeContainer<Domain,Container> & s )
{
typedef typename DigitalSetByAssociativeContainer<Domain,Container>::ConstIterator ConstIterator;

BOOST_STATIC_ASSERT(Domain::Space::dimension == 2);
for(ConstIterator it = s.begin(); it != s.end(); ++it)
draw(board, *it);
}
// DigitalSetByAssociativeContainer


// DigitalSetBySTLVector
template<typename Domain>
inline
Expand Down
Loading

0 comments on commit 03da2c8

Please sign in to comment.