DGtal 2.1.0
Loading...
Searching...
No Matches
DGtal::DigitalSetByOctree< Space > Class Template Reference

A DigitalSet that stores voxels as an octree, or a DAG. More...

#include <DGtal/kernel/sets/DigitalSetByOctree.h>

Data Structures

struct  ComputationCacheKey
 Helper struct for computing local estimators. More...
 
struct  Node
 Node for octree. More...
 
struct  OctreeIterator
 Iterator over the octree. More...
 
struct  TraversalMemory
 Helper struct to store traversal and go to next leaf. More...
 

Public Types

using DimIndex = std::uint8_t
 
using CellIndex = typename Space::UnsignedInteger
 
using Size = size_t
 
using Domain = HyperRectDomain< Space >
 
using Point = typename Domain::Point
 
using Value = void
 
using Iterator = OctreeIterator
 
using ConstIterator = OctreeIterator
 

Public Member Functions

 DigitalSetByOctree (const Domain &d)
 Constructor from a domain.
 
const Domaindomain () const
 Returns the domain of the digital set.
 
CowPtr< DomaindomainPointer () const
 Returns the domain of the voxels.
 
void insert (const Point &p)
 Inserts a new point in the octree.
 
void insertNew (const Point &p)
 Inserts a new point in the octree.
 
bool operator() (const Point &p) const
 Check if a voxel is set or not.
 
Iterator find (const Point &p) const
 Finds a point within the Octree.
 
size_t size () const
 Returns the number of voxel in the set.
 
bool empty () const
 Check if the octree is empty or not.
 
size_t memoryFootprint () const
 Returns the memory occupied by node storage in bytes.
 
void clear ()
 Removes all nodes from the octree.
 
size_t erase (const Iterator &it)
 Remove a voxel from the octree.
 
size_t erase (Iterator begin, Iterator end)
 Removes a range of voxels.
 
size_t erase (const Point &p)
 Removes a voxel from the octree.
 
void shrinkToFit ()
 Shrinks storage to reduce memory usage.
 
DigitalSetByOctreeoperator+= (const DigitalSetByOctree &other)
 Appends an octree to another.
 
template<typename It >
void computeComplement (It out) const
 Computes the complement of the octree.
 
template<class DSet >
void assignFromComplement (const DSet &other)
 Assigns the octree as the complement of another set.
 
void computeBoundingBox (Point &lb, Point &ub) const
 Computes the bounding box of stored points.
 
Iterator begin () const
 Returns an iterator to the begining of the octree.
 
Iterator begin ()
 Returns an iterator to the begining of the octree.
 
Iterator end ()
 Returns an iterator to the end of the octree.
 
Iterator end () const
 Returns an iterator to the end of the octree.
 
void convertToDAG ()
 Converts the octree to DAG.
 
template<class Func >
auto computeFunction (OctreeIterator start, OctreeIterator end, CellIndex range, const Func &f)
 
void dumpOctree () const
 Dumps the octree to std out.
 

Static Public Attributes

static constexpr DGtal::Dimension D = Space::dimension
 
static constexpr DGtal::Dimension dimension = Space::dimension
 
static constexpr CellIndex CELL_COUNT = (1 << D)
 
static constexpr CellIndex INVALID_IDX = std::numeric_limits<CellIndex>::max()
 
static constexpr std::array< std::array< DimIndex, D >, CELL_COUNTSIDES_FROM_INDEX
 

Private Types

enum class  State { OCTREE = 1 , DAG = 2 }
 The state the container is in. More...
 

Static Private Member Functions

static Domain splitDomain (const Domain &domain, const DimIndex *sides)
 Helper function to split and select among 2^D subdomains.
 

Private Attributes

CowPtr< DomainmyAdmissibleDomain
 
CowPtr< DomainmyDomain
 
State myState = State::OCTREE
 
size_t mySize
 
std::vector< std::vector< Node > > myNodes
 

Friends

template<class >
class SVOWriter
 
template<class >
class SVOReader
 

Detailed Description

template<class Space>
class DGtal::DigitalSetByOctree< Space >

A DigitalSet that stores voxels as an octree, or a DAG.

This class allows for a compact representation of voxel as a sparse voxel octree (SVO). Optionally, this can be further compressed as a Sparse Voxel Directed Acyclic Graph where nodes are shared when they share a common structure.

Leaves are never explicitly stored to further reduce memory usage.

Common operation complexity: (L = depth of the tree computed with domain size, N = number of voxels)

  • Insertion: O(log(L))
  • Erase: O(N * log(L))
  • find: O(log(L))
  • Iterator next: O(log(L))
  • Listing all voxels: O(N * log(L))
  • Memory usage (octree): O(N * log(L))

When converted to a DAG, the digital set can not be modified anymore (neither insertion, or erase).

References: [82] [66]

Definition at line 69 of file DigitalSetByOctree.h.

Member Typedef Documentation

◆ CellIndex

template<class Space >
using DGtal::DigitalSetByOctree< Space >::CellIndex = typename Space::UnsignedInteger

Definition at line 78 of file DigitalSetByOctree.h.

◆ ConstIterator

Definition at line 282 of file DigitalSetByOctree.h.

◆ DimIndex

template<class Space >
using DGtal::DigitalSetByOctree< Space >::DimIndex = std::uint8_t

Definition at line 77 of file DigitalSetByOctree.h.

◆ Domain

Definition at line 82 of file DigitalSetByOctree.h.

◆ Iterator

template<class Space >
using DGtal::DigitalSetByOctree< Space >::Iterator = OctreeIterator

Definition at line 281 of file DigitalSetByOctree.h.

◆ Point

template<class Space >
using DGtal::DigitalSetByOctree< Space >::Point = typename Domain::Point

Definition at line 83 of file DigitalSetByOctree.h.

◆ Size

template<class Space >
using DGtal::DigitalSetByOctree< Space >::Size = size_t

Definition at line 79 of file DigitalSetByOctree.h.

◆ Value

template<class Space >
using DGtal::DigitalSetByOctree< Space >::Value = void

Definition at line 87 of file DigitalSetByOctree.h.

Member Enumeration Documentation

◆ State

template<class Space >
enum class DGtal::DigitalSetByOctree::State
strongprivate

The state the container is in.

After the octree is converted to a DAG, it is not possible to insert or remove nodes.

Enumerator
OCTREE 
DAG 

Definition at line 581 of file DigitalSetByOctree.h.

Constructor & Destructor Documentation

◆ DigitalSetByOctree()

template<class Space >
DGtal::DigitalSetByOctree< Space >::DigitalSetByOctree ( const Domain d)

Constructor from a domain.

Only HyperRectDomains are supported for octrees.

The given domain will be extended to ensure it is an hyper cube with sides that is a power of 2

Parameters
dThe domain

Member Function Documentation

◆ assignFromComplement()

template<class Space >
template<class DSet >
void DGtal::DigitalSetByOctree< Space >::assignFromComplement ( const DSet &  other)
inline

Assigns the octree as the complement of another set.

This is equivalent to looping through a set and inserting every node

Parameters
otherThe digital set to compute complement of

Definition at line 484 of file DigitalSetByOctree.h.

485 {
486 if (myState == State::OCTREE)
487 {
488 clear();
489 for (auto it = myDomain->begin(); it != myDomain->end(); ++it)
490 {
491 if (!other(*it))
492 insert(*it);
493 }
494 }
495 }
void insert(const Point &p)
Inserts a new point in the octree.
void clear()
Removes all nodes from the octree.
const ConstIterator & begin() const
const ConstIterator & end() const

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::DigitalSetByOctree< Space >::clear(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::DigitalSetByOctree< Space >::insert(), DGtal::DigitalSetByOctree< Space >::myDomain, DGtal::DigitalSetByOctree< Space >::myState, and DGtal::DigitalSetByOctree< Space >::OCTREE.

◆ begin() [1/2]

template<class Space >
Iterator DGtal::DigitalSetByOctree< Space >::begin ( )
inline

Returns an iterator to the begining of the octree.

Definition at line 538 of file DigitalSetByOctree.h.

538{ return static_cast<const DigitalSetByOctree&>(*this).begin(); }
DigitalSetByOctree(const Domain &d)
Constructor from a domain.

References DGtal::DigitalSetByOctree< Space >::begin().

◆ begin() [2/2]

◆ clear()

template<class Space >
void DGtal::DigitalSetByOctree< Space >::clear ( )
inline

Removes all nodes from the octree.

Note: if the octree has been converted to a dag, this function reset the flag and insertion is available afterwards.

Definition at line 379 of file DigitalSetByOctree.h.

380 {
381 myNodes.clear();
383 }
std::vector< std::vector< Node > > myNodes

References DGtal::DigitalSetByOctree< Space >::myNodes, DGtal::DigitalSetByOctree< Space >::myState, and DGtal::DigitalSetByOctree< Space >::OCTREE.

Referenced by DGtal::DigitalSetByOctree< Space >::assignFromComplement().

◆ computeBoundingBox()

template<class Space >
void DGtal::DigitalSetByOctree< Space >::computeBoundingBox ( Point lb,
Point ub 
) const
inline

Computes the bounding box of stored points.

This functions runs in O(N log(L)).

Parameters
lbOutput lower bound
ubOutput upper bound

Definition at line 505 of file DigitalSetByOctree.h.

506 {
507 lb = myDomain->upperBound();
508 ub = myDomain->lowerBound();
509
510 for (auto it = begin(); it != end(); ++it)
511 {
512 const auto p = *it;
513 for (DimIndex d = 0; d < D; d++)
514 {
515 lb[d] = std::min(lb[d], p[d]);
516 ub[d] = std::max(ub[d], p[d]);
517 }
518 }
519 }
static constexpr DGtal::Dimension D
Iterator end()
Returns an iterator to the end of the octree.
Iterator begin() const
Returns an iterator to the begining of the octree.
const Point & lowerBound() const
const Point & upperBound() const

References DGtal::DigitalSetByOctree< Space >::begin(), DGtal::DigitalSetByOctree< Space >::D, DGtal::DigitalSetByOctree< Space >::end(), DGtal::HyperRectDomain< TSpace >::lowerBound(), DGtal::DigitalSetByOctree< Space >::myDomain, and DGtal::HyperRectDomain< TSpace >::upperBound().

◆ computeComplement()

template<class Space >
template<typename It >
void DGtal::DigitalSetByOctree< Space >::computeComplement ( It  out) const
inline

Computes the complement of the octree.

This is equivalent to looping through an octree and inserting

Parameters
outThe output iterator

Definition at line 462 of file DigitalSetByOctree.h.

463 {
464 DigitalSetByOctree complement(*myDomain);
465 for (auto it = myDomain->begin(); it != myDomain->end(); ++it)
466 {
467 if (!this->operator()(*it))
468 {
469 *out = *it;
470 ++out;
471 }
472 }
473 }

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::HyperRectDomain< TSpace >::end(), and DGtal::DigitalSetByOctree< Space >::myDomain.

◆ computeFunction()

template<class Space >
template<class Func >
auto DGtal::DigitalSetByOctree< Space >::computeFunction ( OctreeIterator  start,
OctreeIterator  end,
CellIndex  range,
const Func &  f 
)

◆ convertToDAG()

template<class Space >
void DGtal::DigitalSetByOctree< Space >::convertToDAG ( )

Converts the octree to DAG.

Referenced by TEST_CASE_METHOD().

◆ domain()

template<class Space >
const Domain & DGtal::DigitalSetByOctree< Space >::domain ( ) const
inline

Returns the domain of the digital set.

Definition at line 299 of file DigitalSetByOctree.h.

299{ return *myAdmissibleDomain; }
CowPtr< Domain > myAdmissibleDomain

References DGtal::DigitalSetByOctree< Space >::myAdmissibleDomain.

Referenced by TEST_CASE_METHOD().

◆ domainPointer()

template<class Space >
CowPtr< Domain > DGtal::DigitalSetByOctree< Space >::domainPointer ( ) const
inline

Returns the domain of the voxels.

Definition at line 304 of file DigitalSetByOctree.h.

304{ return myAdmissibleDomain; }

References DGtal::DigitalSetByOctree< Space >::myAdmissibleDomain.

◆ dumpOctree()

template<class Space >
void DGtal::DigitalSetByOctree< Space >::dumpOctree ( ) const

Dumps the octree to std out.

Note: This function is meant for debug purposes only

◆ empty()

template<class Space >
bool DGtal::DigitalSetByOctree< Space >::empty ( ) const
inline

Check if the octree is empty or not.

Definition at line 357 of file DigitalSetByOctree.h.

357{ return size() == 0; }
size_t size() const
Returns the number of voxel in the set.

References DGtal::DigitalSetByOctree< Space >::size().

◆ end() [1/2]

◆ end() [2/2]

template<class Space >
Iterator DGtal::DigitalSetByOctree< Space >::end ( ) const
inline

Returns an iterator to the end of the octree.

Definition at line 548 of file DigitalSetByOctree.h.

548{ return Iterator(this); }

◆ erase() [1/3]

template<class Space >
size_t DGtal::DigitalSetByOctree< Space >::erase ( const Iterator it)

Remove a voxel from the octree.

This functions is undefined behavior if the Iterator is invalid.

Parameters
itThe iterator pointing to the voxel to remove

Referenced by DGtal::DigitalSetByOctree< Space >::erase(), DGtal::DigitalSetByOctree< Space >::erase(), and TEST_CASE_METHOD().

◆ erase() [2/3]

template<class Space >
size_t DGtal::DigitalSetByOctree< Space >::erase ( const Point p)
inline

Removes a voxel from the octree.

Parameters
pThe point to remove

Definition at line 414 of file DigitalSetByOctree.h.

415 {
416 return erase(find(p));
417 }
size_t erase(const Iterator &it)
Remove a voxel from the octree.
Iterator find(const Point &p) const
Finds a point within the Octree.

References DGtal::DigitalSetByOctree< Space >::erase(), and DGtal::DigitalSetByOctree< Space >::find().

◆ erase() [3/3]

template<class Space >
size_t DGtal::DigitalSetByOctree< Space >::erase ( Iterator  begin,
Iterator  end 
)
inline

Removes a range of voxels.

Parameters
beginThe begining of the range
endThe end of the range

Definition at line 401 of file DigitalSetByOctree.h.

402 {
403 size_t count = 0;
404 for (; begin != end; ++begin)
405 count += erase(begin);
406 return count;
407 }

References DGtal::DigitalSetByOctree< Space >::begin(), DGtal::DigitalSetByOctree< Space >::end(), and DGtal::DigitalSetByOctree< Space >::erase().

◆ find()

template<class Space >
Iterator DGtal::DigitalSetByOctree< Space >::find ( const Point p) const

Finds a point within the Octree.

Parameters
pThe point to find
Returns
An iterator to the point if possible otherwise end()

Referenced by DGtal::DigitalSetByOctree< Space >::erase(), and DGtal::DigitalSetByOctree< Space >::operator()().

◆ insert()

template<class Space >
void DGtal::DigitalSetByOctree< Space >::insert ( const Point p)

Inserts a new point in the octree.

This function can be called multiple times with the same point without any risk.

If the point is not in bounds or the octree has been converted to a DAG, this function does nothing.

Parameters
pThe point to insert

Referenced by DGtal::DigitalSetByOctree< Space >::assignFromComplement(), DGtal::DigitalSetByOctree< Space >::insertNew(), DGtal::DigitalSetByOctree< Space >::operator+=(), and TEST_CASE_METHOD().

◆ insertNew()

template<class Space >
void DGtal::DigitalSetByOctree< Space >::insertNew ( const Point p)
inline

Inserts a new point in the octree.

This function can be called multiple times with the same point without any risk.

If the point is not in bounds or the octree has been converted to a DAG, this function does nothing.

Parameters
pThe point to insert
See also
insert

Definition at line 331 of file DigitalSetByOctree.h.

331{ insert(p); }

References DGtal::DigitalSetByOctree< Space >::insert().

◆ memoryFootprint()

template<class Space >
size_t DGtal::DigitalSetByOctree< Space >::memoryFootprint ( ) const
inline

Returns the memory occupied by node storage in bytes.

See also
shrink

Definition at line 364 of file DigitalSetByOctree.h.

365 {
366 size_t count = 0;
367 for (CellIndex i = 0; i < myNodes.size(); ++i)
368 count += myNodes[i].capacity() * sizeof(Node);
369 return count;
370 }
typename Space::UnsignedInteger CellIndex

References DGtal::DigitalSetByOctree< Space >::myNodes.

◆ operator()()

template<class Space >
bool DGtal::DigitalSetByOctree< Space >::operator() ( const Point p) const
inline

Check if a voxel is set or not.

Parameters
pThe point to check for
See also
find

Definition at line 339 of file DigitalSetByOctree.h.

339{ return find(p) != end(); }

References DGtal::DigitalSetByOctree< Space >::end(), and DGtal::DigitalSetByOctree< Space >::find().

◆ operator+=()

template<class Space >
DigitalSetByOctree & DGtal::DigitalSetByOctree< Space >::operator+= ( const DigitalSetByOctree< Space > &  other)
inline

Appends an octree to another.

This is equivalent to looping through an octree and inserting every node into another

Parameters
otherThe octree to append

Definition at line 444 of file DigitalSetByOctree.h.

445 {
446 if (myState == State::OCTREE)
447 {
448 for (auto it = other.begin(); it != other.end(); ++it)
449 insert(*it);
450 }
451 return *this;
452 }

References DGtal::DigitalSetByOctree< Space >::begin(), DGtal::DigitalSetByOctree< Space >::end(), DGtal::DigitalSetByOctree< Space >::insert(), DGtal::DigitalSetByOctree< Space >::myState, and DGtal::DigitalSetByOctree< Space >::OCTREE.

◆ shrinkToFit()

template<class Space >
void DGtal::DigitalSetByOctree< Space >::shrinkToFit ( )
inline

Shrinks storage to reduce memory usage.

This function removes extra capacity added for faster insertion with vector and can free some memory once insertion phase is over.

This function is called automatically by convertToDAG.

See also
memoryFootprint

Definition at line 430 of file DigitalSetByOctree.h.

431 {
432 for (CellIndex i = 0; i < myNodes.size(); ++i)
433 myNodes[i].shrink_to_fit();
434 }

References DGtal::DigitalSetByOctree< Space >::myNodes.

◆ size()

template<class Space >
size_t DGtal::DigitalSetByOctree< Space >::size ( ) const
inline

Returns the number of voxel in the set.

Definition at line 352 of file DigitalSetByOctree.h.

352{ return mySize; }

References DGtal::DigitalSetByOctree< Space >::mySize.

Referenced by DGtal::DigitalSetByOctree< Space >::empty(), and TEST_CASE_METHOD().

◆ splitDomain()

template<class Space >
static Domain DGtal::DigitalSetByOctree< Space >::splitDomain ( const Domain domain,
const DimIndex sides 
)
staticprivate

Helper function to split and select among 2^D subdomains.

Parameters
domainThe domain to split
sidesSelection between left or right subdomain for each dimension

Referenced by DGtal::DigitalSetByOctree< Space >::OctreeIterator::operator*().

Friends And Related Symbol Documentation

◆ SVOReader

template<class Space >
template<class >
friend class SVOReader
friend

Definition at line 75 of file DigitalSetByOctree.h.

◆ SVOWriter

template<class Space >
template<class >
friend class SVOWriter
friend

Definition at line 73 of file DigitalSetByOctree.h.

Field Documentation

◆ CELL_COUNT

template<class Space >
constexpr CellIndex DGtal::DigitalSetByOctree< Space >::CELL_COUNT = (1 << D)
staticconstexpr

Definition at line 92 of file DigitalSetByOctree.h.

Referenced by DGtal::DigitalSetByOctree< Space >::Node::Node().

◆ D

template<class Space >
constexpr DGtal::Dimension DGtal::DigitalSetByOctree< Space >::D = Space::dimension
staticconstexpr

◆ dimension

template<class Space >
constexpr DGtal::Dimension DGtal::DigitalSetByOctree< Space >::dimension = Space::dimension
staticconstexpr

Definition at line 90 of file DigitalSetByOctree.h.

◆ INVALID_IDX

template<class Space >
constexpr CellIndex DGtal::DigitalSetByOctree< Space >::INVALID_IDX = std::numeric_limits<CellIndex>::max()
staticconstexpr

◆ myAdmissibleDomain

◆ myDomain

◆ myNodes

◆ mySize

template<class Space >
size_t DGtal::DigitalSetByOctree< Space >::mySize
private

Definition at line 600 of file DigitalSetByOctree.h.

Referenced by DGtal::DigitalSetByOctree< Space >::size().

◆ myState

◆ SIDES_FROM_INDEX

template<class Space >
constexpr std::array<std::array<DimIndex, D>, CELL_COUNT> DGtal::DigitalSetByOctree< Space >::SIDES_FROM_INDEX
staticconstexpr
Initial value:
= []()
{
std::array<std::array<DimIndex, D>, CELL_COUNT> sides_from_index{};
for (CellIndex i = 0; i < CELL_COUNT; ++i)
{
CellIndex coord = i;
for (DimIndex d = 0; d < D; ++d)
{
sides_from_index[i][d] = coord % 2;
coord /= 2;
}
}
return sides_from_index;
}()
static constexpr CellIndex CELL_COUNT

Definition at line 96 of file DigitalSetByOctree.h.

97 {
98 std::array<std::array<DimIndex, D>, CELL_COUNT> sides_from_index{};
99 for (CellIndex i = 0; i < CELL_COUNT; ++i)
100 {
101 CellIndex coord = i;
102 for (DimIndex d = 0; d < D; ++d)
103 {
104 sides_from_index[i][d] = coord % 2;
105 coord /= 2;
106 }
107 }
108
109 return sides_from_index;
110 }();

Referenced by DGtal::DigitalSetByOctree< Space >::OctreeIterator::operator*().


The documentation for this class was generated from the following file: