Digital sets are sets of digital points within some domain of a digital space. They are thus subsets of a given domain (e.g. see Domains and HyperRectDomains). As such, their elements can be enumerated with iterators through the range [begin(),end()). Furthermore, digital sets can be complemented within their domain. Last, a digital set is also a predicate on point, returning true whenever the points lies inside the set.
There are several ways for defining concretely a digital set, this is why digital sets are specified through the concept concepts::CDigitalSet. All types and required methods are specified in the documentation of CDigitalSet. It is worthy to note that a digital set is also associated to a digital domain, i.e. any model of concepts::CDomain.
There exists several models for concepts::CDigitalSet; their difference lies in the way elements are stored (let n be the number of points in the set).
std::set(a model of boost::SimpleAssociativeContainer). All find, insertion and deletion requests are \( O(\log n) \) complexity. Internal order can be changed by specifiing another Compare functor as template parameter.
std::vector(a model of boost::Sequence). All find, insertion and deletion requests are \( O(n) \) complexity.
std::set, this class exactly matches with DigitalSetBySTLSet. The main advantage of this container is its ability to adapt hash function based containers such as
std::unordered_set(for C++11 enabled build) or
boost::unordered_set. Compared to DigitalSetBySTLSet, DigitalSetByAssociativeContainer on
std::unordered_setis expected to be 20% - 50% faster when accessing or inserting points in the set.
You may choose yourself your representation of digital set, or let DGtal chooses for you the best suited representation with the class DigitalSetSelector. This is done by choosing among the following properties:
HIGH_VAR_DS) or not (
LOW_ITER_DS, many times is
LOW_BEL_DS, many times is
The following lines selects a rather generic representation for digital sets, since the set may be big, will be iterated many times and points will be tested many times:
The following snippet shows how to define a digital set in space Z2, within a rectangular domain, then how to insert points, how to visit them and how to test if a point belongs to the set.
Other methods may be found in the concept definition of digital sets (CDigitalSet).
Since 0.6, any digital set is also a model of concepts::CPointPredicate. You may thus use a digital set directly in functions and methods requiring a predicate on points. However, the class deprecated::SetPredicate, which builds a predicate on points around a digital set, is deprecated since 0.6. You may still used it by referecing it with DGtal::deprecated::SetPredicate, but it will no longer be maintained.
Sometimes it is useful to see a digital set as a new domain for further computation. This is possible with the facade class DigitalSetDomain, which wraps around some given digital set all necessary methods and types so that it satisfies the concept concepts::CDomain.