12 #ifndef LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_POINTISOLATIONALG_H 13 #define LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_POINTISOLATIONALG_H 126 template <
typename Coord =
double>
190 template <
typename Po
intIter>
192 (PointIter
begin, PointIter
end)
const;
201 template <
typename Cont>
219 template <
typename Po
intIter>
221 (PointIter begin, PointIter end)
const;
236 {
return radius / std::sqrt(3.); }
246 template <
typename Po
intIter>
249 template <
typename Po
intIter>
257 template <
typename Po
intIter = std::array<
double, 3> const*>
263 (
Indexer_t const& indexer,
unsigned int neighExtent)
const;
266 template <
typename Po
intIter>
273 template <
typename Po
intIter>
282 template <
typename Po
int>
308 template <
typename Coord>
309 template <
typename Po
intIter>
314 std::vector<size_t> nonIsolated;
327 Coord_t cellSize = computeCellSize<PointIter>();
328 assert(cellSize > 0);
336 bool const cellContainedInIsolationSphere
346 unsigned int const neighExtent = (
int) std::ceil(R / cellSize);
353 if (!cellContainedInIsolationSphere)
354 neighList.insert(neighList.begin(), { 0, 0, 0 });
364 size_t const nCells =
partition.indexManager().size();
366 auto const& cellPoints =
partition[cellIndex];
372 if (cellContainedInIsolationSphere && (cellPoints.size() > 1)) {
373 for (
auto const& pointPtr: cellPoints)
382 for (
auto const pointPtr: cellPoints) {
391 (
partition, cellIndex, *pointPtr, neighList)
405 template <
typename Coord>
409 std::vector<std::string> errors;
424 if (errors.empty())
return;
430 for (
auto const&
error: errors) message +=
"\n * " +
error;
431 throw std::runtime_error(message);
437 template <
typename Coord>
438 template <
typename PointIter >
454 if (config.
maxMemory == 0)
return cellSize;
463 size_t const nCells = partition[0] * partition[1] * partition[2];
464 if (nCells <= 1)
break;
479 template <
typename Coord>
482 (
Indexer_t const& indexer,
unsigned int neighExtent)
const 484 unsigned int const neighSize = 1 + 2 * neighExtent;
486 neighList.reserve(neighSize * neighSize * neighSize - 1);
498 CellDimIndex_t
const ext = neighExtent;
501 for (CellDimIndex_t ixOfs = -ext; ixOfs <= ext; ++ixOfs) {
503 for (CellDimIndex_t iyOfs = -ext; iyOfs <= ext; ++iyOfs) {
505 for (CellDimIndex_t izOfs = -ext; izOfs <= ext; ++izOfs) {
506 if ((ixOfs == 0) && (iyOfs == 0) && (izOfs == 0))
continue;
520 template <
typename Coord>
521 template <
typename Po
intIter>
528 for (
auto const& otherPointPtr: otherPoints) {
530 if (
closeEnough(point, *otherPointPtr) && (&point != &*otherPointPtr))
540 template <
typename Coord>
541 template <
typename Po
intIter>
558 if (!partition.
has(cellIndex + neighOfs))
continue;
559 auto const& neighCellPoints = partition[cellIndex + neighOfs];
561 if (!isPointIsolatedFrom<PointIter>(point, neighCellPoints))
return false;
571 template <
typename Coord>
572 template <
typename Po
intIter>
575 (PointIter begin, PointIter end)
const 581 std::vector<size_t> nonIsolated;
584 for (
auto it = begin; it !=
end; ++it, ++i) {
586 for (
auto ioth = begin; ioth !=
end; ++ioth) {
587 if (it == ioth)
continue;
590 nonIsolated.push_back(i);
603 template <
typename Coord>
604 template <
typename Po
int>
617 template <
typename Coord>
625 #endif // LAREXAMPLES_ALGORITHMS_REMOVEISOLATEDSPACEPOINTS_POINTISOLATIONALG_H Algorithm to detect isolated space points.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
A container of points sorted in cells.
std::ptrdiff_t CellIndexOffset_t
type of difference between indices
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
CellIndexOffset_t CellDimIndex_t
type of difference between indices along a dimension
static std::string rangeString(Range_t range)
Helper function. Returns a string "(<from> to <to>)"
constexpr T sum_of_squares(T x, T y)
Coord_t radius2
square of isolation radius [cm^2]
size_t maxMemory
grid smaller than this number of bytes (100 MiB)
typename IndexManager_t::LinIndex_t CellIndex_t
type of index for direct access to the cell
Range_t rangeY
range in Y of the covered volume
static std::string rangeString(Coord_t from, Coord_t to)
Helper function. Returns a string "(<from> to <to>)"
bool closeEnough(Point const &A, Point const &B) const
Returns whether A and B are close enough to be considered non-isolated.
NeighAddresses_t buildNeighborhood(Indexer_t const &indexer, unsigned int neighExtent) const
Returns a list of cell offsets for the neighbourhood of given radius.
Class to organise data into a 3D grid.
Range_t rangeX
range in X of the covered volume
bool has(CellIndexOffset_t ofs) const
Returns whether there is a cell with the specified index (signed!)
Coord_t upper
upper boundary
std::array< CellDimIndex_t, dims()> CellID_t
type of cell coordinate (x, y, z)
GridContainerIndicesBase3D<> GridContainer3DIndices
Index manager for a container of data arranged on a 3D grid.
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.
Coord_t lower
lower boundary
auto extractPositionY(Point const &point)
std::vector< Indexer_t::CellIndexOffset_t > NeighAddresses_t
type of neighbourhood cell offsets
bool valid() const
Returns whether the range is valid (empty is also valid)
std::vector< size_t > bruteRemoveIsolatedPoints(PointIter begin, PointIter end) const
Brute-force reference algorithm.
decltype(*PointIter()) Point_t
PointIsolationAlg(Configuration_t const &first_config)
Constructor with configuration validation.
Type containing all configuration parameters of the algorithm.
Configuration_t & configuration() const
typename Grid_t::Cell_t Cell_t
type of cell
Index manager for a container of data arranged on a >=3-dim grid.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
CellIndexOffset_t offset(CellID_t const &origin, CellID_t const &cellID) const
Returns the difference in index of cellID respect to origin.
static void validateConfiguration(Configuration_t const &config)
std::vector< size_t > removeIsolatedPoints(Cont const &points) const
Returns the set of points that are not isolated.
LArSoft-specific namespace.
Range_t rangeZ
range in Z of the covered volume
auto extractPositionX(Point const &point)
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
bool isPointIsolatedFrom(Point_t< PointIter > const &point, typename Partition_t< PointIter >::Cell_t const &otherPoints) const
Returns whether a point is isolated with respect to all the others.
Configuration_t config
all configuration data
std::vector< size_t > removeIsolatedPoints(PointIter begin, PointIter end) const
Returns the set of points that are not isolated.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
bool isPointIsolatedWithinNeighborhood(Partition_t< PointIter > const &partition, Indexer_t::CellIndex_t cellIndex, Point_t< PointIter > const &point, NeighAddresses_t const &neighList) const
Returns whether a point is isolated in the specified neighbourhood.
void reconfigure(Configuration_t const &new_config)
static Coord_t maximumOptimalCellSize(Coord_t radius)
Returns the maximum optimal cell size when using a isolation radius.
Coord_t computeCellSize() const
Computes the cell size to be used.
auto extractPositionZ(Point const &point)
std::string to_string(ModuleType const mt)