Public Types | Public Member Functions | Protected Types | Protected Attributes | Private Types | List of all members
lar::example::SpacePartition< PointIter > Class Template Reference

A container of points sorted in cells. More...

#include <SpacePartition.h>

Public Types

using Coord_t = details::ExtractCoordType_t< Point_t >
 type of point coordinate More...
 
using Range_t = CoordRangeCells< Coord_t >
 type of coordinate range More...
 
using Indexer_t = typename Grid_t::Indexer_t
 type of index manager of the grid More...
 
using CellIndexOffset_t = typename Indexer_t::CellIndexOffset_t
 type of difference between cell indices More...
 
using CellIndex_t = typename Indexer_t::CellIndex_t
 
using CellID_t = typename Indexer_t::CellID_t
 type of cell index More...
 
using Cell_t = typename Grid_t::Cell_t
 type of cell More...
 

Public Member Functions

 SpacePartition (Range_t rangeX, Range_t rangeY, Range_t rangeZ)
 Constructs the partition in a given volume with the given cell size. More...
 
void fill (PointIter begin, PointIter end)
 
CellIndexOffset_t pointIndex (Point_t const &point) const
 
Indexer_t const & indexManager () const
 Returns the index manager of the grid. More...
 
bool has (CellIndexOffset_t ofs) const
 Returns whether there is a cell with the specified index (signed!) More...
 
Cell_t const & operator[] (CellIndex_t index) const
 Returns the cell with the specified index. More...
 
Grid_t::const_iterator begin () const
 Returns a constant iterator pointing to the first cell. More...
 
Grid_t::const_iterator end () const
 Returns a constant iterator pointing after the last cell. More...
 

Protected Types

using CellDimIndex_t = typename Grid_t::CellDimIndex_t
 

Protected Attributes

Coord_t cellSize
 length of the side of each cubic cell More...
 
Range_t xRange
 coordinates of the contained volume on x axis More...
 
Range_t yRange
 coordinates of the contained volume on z axis More...
 
Range_t zRange
 coordinates of the contained volume on z axis More...
 
Grid_t data
 container of points More...
 

Private Types

using Point_t = decltype(*(PointIter()))
 type of the point More...
 
using Grid_t = ::util::GridContainer3D< PointIter >
 data container More...
 

Detailed Description

template<typename PointIter>
class lar::example::SpacePartition< PointIter >

A container of points sorted in cells.

Template Parameters
PointItertype of iterator to the point

This container arranges its elements into a 3D grid according to their position in space. The "position" is defined by the PositionExtractor class.

The container stores a bit on information for each cell (it is not sparse), therefore its size can become large very quickly. Currently each (empty) cell in the grid uses sizeof(std::vector<...>), that is 24, bytes.

Currently, no facility is provided to find an element, although from a copy of the element, its position in the container can be computed with pointIndex().

For example, suppose you need to arrange points in a box of 6 x 8 x 4 (arbitrary units) symmetric around the origin, each with 20 cells. This already makes a quite large container of 8000 elements.

std::vector<std::array<double, 3U>> data;
// fill the data points
lar::examples::SpacePartition<double const*> partition(
{ -3.0, 3.0, 0.3 },
{ -4.0, 4.0, 0.4 },
{ -2.0, 2.0, 0.2 }
);
// populate the partition
for (auto const& point: data) partition.fill(point.data());
// find the cell for a reference point
const double refPoint[] = { 0.5, 0.5, 0.5 };
auto cellIndex = partition.pointIndex(refPoint);
// do something with all the points in the same cell as the reference one
for (double const* point: partition[cellIndex]) {
// ...
}
// do something with all cells
for (auto const& cell: partition) {
// and process all points in each cell
for (double const* point: cell) {
// ...
}
}

Note that in the example the stored data is direct pointers to the data in order to save space (the data is 3 doubles big, that is 24 bytes, while a pointer is usually only 8 bytes). The class PositionExtractor is specialized for double const* in this same library.

Definition at line 222 of file SpacePartition.h.

Member Typedef Documentation

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::Cell_t = typename Grid_t::Cell_t

type of cell

Definition at line 243 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::CellDimIndex_t = typename Grid_t::CellDimIndex_t
protected

Definition at line 276 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::CellID_t = typename Indexer_t::CellID_t

type of cell index

type of cell identifier

Definition at line 240 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::CellIndex_t = typename Indexer_t::CellIndex_t

Definition at line 237 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::CellIndexOffset_t = typename Indexer_t::CellIndexOffset_t

type of difference between cell indices

Definition at line 235 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::Coord_t = details::ExtractCoordType_t<Point_t>

type of point coordinate

Definition at line 228 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::Grid_t = ::util::GridContainer3D<PointIter>
private

data container

Definition at line 224 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::Indexer_t = typename Grid_t::Indexer_t

type of index manager of the grid

Definition at line 232 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::Point_t = decltype(*(PointIter()))
private

type of the point

Definition at line 223 of file SpacePartition.h.

template<typename PointIter>
using lar::example::SpacePartition< PointIter >::Range_t = CoordRangeCells<Coord_t>

type of coordinate range

Definition at line 229 of file SpacePartition.h.

Constructor & Destructor Documentation

template<typename PointIter >
lar::example::SpacePartition< PointIter >::SpacePartition ( Range_t  rangeX,
Range_t  rangeY,
Range_t  rangeZ 
)

Constructs the partition in a given volume with the given cell size.

Definition at line 431 of file SpacePartition.h.

432  : xRange(rangeX)
433  , yRange(rangeY)
434  , zRange(rangeZ)
436 {
437  /*
438  std::cout << "Grid: "
439  << indexManager().sizeX() << " x "
440  << indexManager().sizeY() << " x " << indexManager().sizeZ()
441  << " (" << indexManager().size() << " cells)"
442  << "\n range X: " << xRange.lower << " -- " << xRange.upper << " [/" << xRange.cellSize << "]"
443  << "\n range Y: " << yRange.lower << " -- " << yRange.upper << " [/" << yRange.cellSize << "]"
444  << "\n range Z: " << zRange.lower << " -- " << zRange.upper << " [/" << zRange.cellSize << "]"
445  << std::endl;
446  */
447 } // lar::example::SpacePartition<>::SpacePartition
Range_t zRange
coordinates of the contained volume on z axis
Range_t yRange
coordinates of the contained volume on z axis
Range_t xRange
coordinates of the contained volume on x axis
std::array< size_t, 3 > diceVolume(CoordRangeCells< Coord > const &rangeX, CoordRangeCells< Coord > const &rangeY, CoordRangeCells< Coord > const &rangeZ)
Returns the dimensions of a grid diced with the specified size.
Grid_t data
container of points

Member Function Documentation

template<typename PointIter>
Grid_t::const_iterator lar::example::SpacePartition< PointIter >::begin ( ) const

Returns a constant iterator pointing to the first cell.

template<typename PointIter>
Grid_t::const_iterator lar::example::SpacePartition< PointIter >::end ( ) const

Returns a constant iterator pointing after the last cell.

template<typename PointIter >
void lar::example::SpacePartition< PointIter >::fill ( PointIter  begin,
PointIter  end 
)

Fills the partition with the points in the specified range

Exceptions
std::runtime_errora point is outside the covered volume

Definition at line 453 of file SpacePartition.h.

454 {
455 
456  PointIter it = begin;
457  while (it != end) {
458  // if the point is outside the volume, pointIndex will throw an exception
459  data.insert(pointIndex(*it), it);
460  ++it;
461  } // while
462 
463 } // lar::example::SpacePartition<>::fill()
Grid_t::const_iterator end() const
Returns a constant iterator pointing after the last cell.
CellIndexOffset_t pointIndex(Point_t const &point) const
Grid_t::const_iterator begin() const
Returns a constant iterator pointing to the first cell.
void insert(CellID_t const &cellID, Datum_t const &elem)
Copies an element into the specified cell.
Grid_t data
container of points
template<typename PointIter>
bool lar::example::SpacePartition< PointIter >::has ( CellIndexOffset_t  ofs) const
inline

Returns whether there is a cell with the specified index (signed!)

Definition at line 262 of file SpacePartition.h.

263  { return data.has(ofs); }
bool has(CellIndexOffset_t index) const
Returns whether the specified index is valid.
Grid_t data
container of points
template<typename PointIter>
Indexer_t const& lar::example::SpacePartition< PointIter >::indexManager ( ) const
inline

Returns the index manager of the grid.

Definition at line 258 of file SpacePartition.h.

259  { return data.indexManager(); }
Indexer_t const & indexManager() const
Returns the index manager of the grid.
Grid_t data
container of points
template<typename PointIter>
Cell_t const& lar::example::SpacePartition< PointIter >::operator[] ( CellIndex_t  index) const
inline

Returns the cell with the specified index.

Definition at line 266 of file SpacePartition.h.

267  { return data[index]; }
Grid_t data
container of points
template<typename PointIter >
lar::example::SpacePartition< PointIter >::CellIndexOffset_t lar::example::SpacePartition< PointIter >::pointIndex ( Point_t const &  point) const

Returns the index pertaining the point (might be invalid!)

Exceptions
std::runtime_errorpoint is outside the covered volume

Definition at line 469 of file SpacePartition.h.

470 {
471  // compute the cell ID coordinates
472  Coord_t const x = details::extractPositionX(point);
473  CellDimIndex_t const xc = xRange.findCell(x);
474  if (!data.hasX(xc)) {
475  throw std::runtime_error
476  ("Point out of the volume (x = " + std::to_string(x) + ")");
477  }
478 
479  Coord_t const y = details::extractPositionY(point);
480  CellDimIndex_t const yc = yRange.findCell(y);
481  if (!data.hasY(yc)) {
482  throw std::runtime_error
483  ("Point out of the volume (y = " + std::to_string(y) + ")");
484  }
485 
486  Coord_t const z = details::extractPositionZ(point);
487  CellDimIndex_t const zc = zRange.findCell(z);
488  if (!data.hasZ(zc)) {
489  throw std::runtime_error
490  ("Point out of the volume (z = " + std::to_string(z) + ")");
491  }
492 
493  // return its index
494  return data.index(CellID_t{{ xc, yc, zc }});
495 
496 } // lar::example::SpacePartition<>::pointIndex()
Range_t zRange
coordinates of the contained volume on z axis
Range_t yRange
coordinates of the contained volume on z axis
bool hasX(typename Base_t::CellDimIndex_t index) const
Returns whether the specified x index is valid.
bool hasZ(typename Base_t::CellDimIndex_t index) const
Returns whether the specified x index is valid.
Range_t xRange
coordinates of the contained volume on x axis
details::ExtractCoordType_t< Point_t > Coord_t
type of point coordinate
auto extractPositionY(Point const &point)
Grid_t data
container of points
auto extractPositionX(Point const &point)
typename Grid_t::CellDimIndex_t CellDimIndex_t
typename Indexer_t::CellID_t CellID_t
type of cell index
std::ptrdiff_t findCell(Coord_t c) const
Returns the index of the cell for coordinate c.
list x
Definition: train.py:276
CellIndex_t index(CellID_t const &id) const
Return the index of the element from its cell coordinates (no check!)
bool hasY(typename Base_t::CellDimIndex_t index) const
Returns whether the specified x index is valid.
auto extractPositionZ(Point const &point)
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34

Member Data Documentation

template<typename PointIter>
Coord_t lar::example::SpacePartition< PointIter >::cellSize
protected

length of the side of each cubic cell

Definition at line 278 of file SpacePartition.h.

template<typename PointIter>
Grid_t lar::example::SpacePartition< PointIter >::data
protected

container of points

Definition at line 284 of file SpacePartition.h.

template<typename PointIter>
Range_t lar::example::SpacePartition< PointIter >::xRange
protected

coordinates of the contained volume on x axis

Definition at line 280 of file SpacePartition.h.

template<typename PointIter>
Range_t lar::example::SpacePartition< PointIter >::yRange
protected

coordinates of the contained volume on z axis

Definition at line 281 of file SpacePartition.h.

template<typename PointIter>
Range_t lar::example::SpacePartition< PointIter >::zRange
protected

coordinates of the contained volume on z axis

Definition at line 282 of file SpacePartition.h.


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