LArSoft
v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
|
Utilities to extend the interface of geometry vectors. More...
#include "larcoreobj/SimpleTypesAndConstants/geo_vectors.h"
#include <array>
#include <vector>
#include <iterator>
#include <type_traits>
#include <functional>
#include <cassert>
Go to the source code of this file.
Namespaces | |
geo | |
Namespace collecting geometry-related classes utilities. | |
geo::vect | |
Utilities to manipulate geometry vectors.The utilities include generic vector interface facilities allowing to use different vector types via templates. | |
geo::vect::details | |
geo::vect::extra | |
Convenience utilities not directly related to vectors. | |
Typedefs | |
template<typename Vector > | |
using | geo::vect::details::VectorScalar_t = typename VectorScalar< Vector >::type |
template<typename Vector > | |
using | geo::vect::details::CoordinateArray_t = std::array< VectorScalar_t< Vector >, dimension< Vector >()> |
A STL array suitable to contain all coordinate values of a Vector . More... | |
template<typename T > | |
using | geo::vect::details::MemberFuncReturn_t = typename MemberFuncReturnType< T >::type |
template<typename T > | |
using | geo::vect::details::MemberFuncClass_t = typename MemberFuncClassType< T >::type |
template<typename Vector > | |
using | geo::vect::coordinate_t = details::VectorScalar_t< Vector > |
Type of coordinate of the specified vector type. More... | |
template<typename Vector > | |
using | geo::vect::CoordReader_t = decltype(details::makeCoordReader(&Vector::X)) |
Type of a coordinate reader for a vector type. More... | |
template<typename Vector > | |
using | geo::vect::CoordManager_t = decltype(details::makeCoordManager(&Vector::X,&Vector::SetX)) |
Type of a coordinate manager for a vector type. More... | |
using | geo::vect::MiddlePointAccumulator = MiddlePointAccumulatorDim< 3U > |
Middle-point accumulator for vectors of dimension 3. More... | |
template<typename Vector > | |
using | geo::vect::details::VectorIndices_t = std::make_index_sequence< dimension< Vector >()> |
Type of sequence of indices up to Vector size. More... | |
Functions | |
template<typename Op , typename... T> | |
auto | geo::vect::details::extended_accumulate (Op op, T &&...args) |
template<typename... T> | |
auto | geo::vect::details::extended_and (T...args) -> decltype(auto) |
template<typename Vector > | |
constexpr bool | geo::vect::details::HasX () |
template<typename Vector > | |
constexpr bool | geo::vect::details::HasY () |
template<typename Vector > | |
constexpr bool | geo::vect::details::HasZ () |
template<typename Vector > | |
constexpr bool | geo::vect::details::HasT () |
template<typename Vector > | |
constexpr unsigned int | geo::vect::details::dimension () |
template<typename Getter > | |
constexpr auto | geo::vect::details::makeCoordReader (Getter getter) |
template<typename Getter , typename Setter > | |
constexpr auto | geo::vect::details::makeCoordManager (Getter getter, Setter setter) |
template<typename T > | |
T | geo::vect::extra::roundValue01 (T value, T tol) |
Returns value , rounded to 0, -1 or +1 if closer than tol . More... | |
template<typename Vector , typename Coords > | |
constexpr Vector | geo::vect::makeFromCoords (Coords &&coords) |
Creates a Vector object with coordinates from coords . More... | |
template<typename Vector > | |
constexpr auto | geo::vect::coordManager (unsigned int n) |
Returns an object that can be bound to a vector to manage one of its coordinates. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::coordManager (unsigned int n, Vector &v) |
Returns an object that can be bound to a vector to manage one of its coordinates. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::bindCoord (Vector const &v, CoordReader_t< Vector > helper) |
Binds the specified constant vector to the coordinate reader. More... | |
template<typename Vector > | |
auto | geo::vect::bindCoord (Vector &v, CoordManager_t< Vector > helper) -> details::BoundCoordManager< CoordManager_t< Vector >, Vector > |
Binds the specified vector to the coordinate manager. More... | |
template<typename Vector > | |
auto | geo::vect::Xcoord (Vector &v) |
Returns an object to manage the coordinate X of the vector v . More... | |
template<typename Vector > | |
auto | geo::vect::Ycoord (Vector &v) |
Returns an object to manage the coordinate Y of the vector v . More... | |
template<typename Vector > | |
auto | geo::vect::Zcoord (Vector &v) |
Returns an object to manage the coordinate Z of the vector v . More... | |
template<typename Vector > | |
auto | geo::vect::Tcoord (Vector &v) |
Returns an object to manage the coordinate T of the vector v . More... | |
template<typename Vector > | |
auto | geo::vect::coord (Vector &v, unsigned int n) noexcept |
Returns an object to manage the coordinate n of a vector. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::bindCoordManagers (Vector &v) |
template<typename Vector > | |
constexpr auto | geo::vect::bindCoordReaders (Vector const &v) |
template<typename Dest , typename Source > | |
Dest | geo::vect::convertTo (Source const &v) |
Returns a vector of type Dest with the same content as a Src . More... | |
template<typename Dest , typename Source > | |
std::vector< Dest > | geo::vect::convertCollTo (std::vector< Source > const &coll) |
Returns a vector of type Dest with the same content as a Src . More... | |
template<typename Vector , typename Pred > | |
Vector | geo::vect::transformCoords (Vector const &v, Pred &&pred) |
Returns a new vector applying a predicate to each component. More... | |
template<> | |
auto | geo::vect::norm (geo::Vector_t const &v) |
template<typename T > | |
constexpr T && | geo::vect::details::constexpr_forward (std::remove_reference_t< T > &t) |
template<typename T > | |
constexpr T && | geo::vect::details::constexpr_forward (std::remove_reference_t< T > &&t) |
template<typename Vector > | |
constexpr auto | geo::vect::details::makeVectorIndices () |
template<typename Vector > | |
constexpr auto | geo::vect::details::makeVectorIndices (Vector &&) |
template<typename T , T... Indices> | |
constexpr auto | geo::vect::details::makeIndexSeqImpl (std::integer_sequence< T, Indices... >) |
template<typename T , T N> | |
constexpr auto | geo::vect::details::makeIndexSeq () |
template<std::size_t I, typename Data > | |
constexpr auto | geo::vect::details::accessElement (Data &&data) |
template<typename Vector , typename Coords , std::size_t... Indices> | |
constexpr Vector | geo::vect::details::makeFromCoordsImpl (Coords &&coords, std::index_sequence< Indices... >) |
template<typename Point , std::size_t... I> | |
bool | geo::vect::details::isfiniteImpl (Point const &point, std::index_sequence< I... >) |
Vector coordinate access abstraction | |
This group of utilities provides a common interface for tasks involving geometry vectors, which may have different interface. An example of that is the access of coordinates by an index: it is supported (and "slow") in Coordinate managersA "coordinate manager" is an object handling a specific coordinate out of a specific vector type; i.e., a coordinate manager object will manage for its entire lifetime the same coordinate, e.g. x or z. A coordinate manager can be:
Two types of managers are available:
Note that a coordinate is never returned as a reference, either mutable or constant. Handling a coordinate of a vector object: bound managersA bound coordinate manager can be created directly: geo::Point_t p { 1.0, 2.0, 3.0 }; auto px = geo::vect::Xcoord(p); std::cout << p << " has x=" << px() << std::endl; px += 5.0; std::cout << p << " has now x=" << px() << std::endl; will return something along the line of Functions If access by numeric index is necessary, geo::Vector_t const v { 1.0, 2.0, 3.0 }; for (unsigned c = 0; c < 3; ++c) { auto vc = geo::vect::coord(v, c); std::cout << v << "[" << c << "]=" << vc() << std::endl; } (note that for this example we have implicitly obtained a coordinate reader instead of a full coordinate manager because v[0]=1 v[1]=2 v[2]=3 If there are more vectors to access the same coordinate of, it's better to use unbound managers (see below). Handling a coordinate for any vector objectUnbound coordinate managers (and readers) can't operate directly on vectors but they need to be bound to one. Binding produces a new bound manager, leaving the unbound manager untouched. Binding is done with geo::Point_t A { 1.0, 2.0, 3.0 }; auto Ax = geo::vect::bindCoord(A, YcoordManager<geo::Point_t>); std::cout << A << " has y=" << Ax << std::endl; should produce an output like (1,2,3) has y=2 In the example, for (unsigned c = 0; c < 3; ++c) { auto coordMan = geo::vect::coordManager(c); auto Ac = geo::vect::bindCoord(A, coordMan); std::cout << (Bc() - Ac() * 2.0) << std::endl; } // for which will emit 3 3 3 This is marginally faster than the same code with for (auto coordMan: geo::vect::coordManagers<geo::Point_t const>()) { auto Ac = geo::vect::bindCoord(A, coordMan); std::cout << (Bc() - Ac() * 2.0) << std::endl; } // for Conversion between vector typesA convenience function Vector requirementsSo far, the requirements for this set of utilities are the following. The vector type must support:
| |
template<typename Vector > | |
constexpr unsigned int | geo::vect::dimension () |
Returns the dimension of the specified vector type. More... | |
template<typename Vector > | |
constexpr unsigned int | geo::vect::dimension (Vector &&) |
Returns the dimension of the specified vector type. More... | |
template<typename Vector > | |
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> | geo::vect::indices () |
Returns a sequence of indices valid for a vector of the specified type. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::indices (Vector const &) -> decltype(indices< Vector >()) |
Returns a sequence of indices valid for a vector of the specified type. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::coordManagers () |
Returns an array with all coordinate managers for a type of vector. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::coordManagers (Vector &&) |
Returns an array with all coordinate managers for a type of vector. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::coordReaders () |
Returns an array with all coordinate readers for a type of vector. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::coordReaders (Vector &&) |
Returns an array with all coordinate readers for a type of vector. More... | |
Functions for common vector operations. | |
This group of template functions are meant to be used with vectors in a generic way. The default implementation is for In addition, two "standard" representations for vectors and points are provided.
| |
template<typename Vector , typename Scalar > | |
Vector | geo::vect::rounded01 (Vector const &v, Scalar tol) |
Returns a vector with all components rounded if close to 0, -1 or +1. More... | |
template<typename Vector , typename Scalar > | |
void | geo::vect::round01 (Vector &v, Scalar tol) |
Returns a vector with all components rounded if close to 0, -1 or +1. More... | |
template<typename Vector > | |
bool | geo::vect::isfinite (Vector const &v) |
Returns whether all components of the vector are finite. More... | |
template<typename Vector > | |
Vector | geo::vect::normalize (Vector const &v) |
Returns a vector parallel to v and with norm 1. More... | |
template<typename Vector > | |
Vector | geo::vect::cross (Vector const &a, Vector const &b) |
Return cross product of two vectors. More... | |
template<typename Vector > | |
constexpr auto | geo::vect::dot (Vector const &a, Vector const &b) |
Return cross product of two vectors. More... | |
template<typename Vector > | |
auto | geo::vect::mag2 (Vector const &v) |
Return norm of the specified vector. More... | |
template<typename Vector > | |
auto | geo::vect::norm (Vector const &v) |
Return norm of the specified vector. More... | |
template<typename Vector > | |
auto | geo::vect::mixedProduct (Vector const &a, Vector const &b, Vector const &c) |
Middle point functions | |
template<typename Point , typename BeginIter , typename EndIter > | |
Point | geo::vect::middlePointAs (BeginIter begin, EndIter end) |
Returns the middle of the specified points. More... | |
template<typename BeginIter , typename EndIter > | |
geo::Point_t | geo::vect::middlePoint (BeginIter begin, EndIter end) |
Returns the middle of the specified points. More... | |
template<typename Point > | |
Point | geo::vect::middlePoint (std::initializer_list< Point > points) |
Returns the middle of the specified points. More... | |
Support for LArSoft geometry vectors | |
template<typename Point > | |
::geo::Point_t | geo::vect::toPoint (Point const &p) |
Convert the specified point into a geo::Point_t . More... | |
template<typename Vector > | |
::geo::Vector_t | geo::vect::toVector (Vector const &v) |
Convert the specified vector into a geo::Vector_t . More... | |
template<typename Point > | |
std::vector< geo::Point_t > | geo::vect::convertCollToPoint (std::vector< Point > const &coll) |
template<typename Vector > | |
std::vector< geo::Vector_t > | geo::vect::convertCollToVector (std::vector< Vector > const &coll) |
template<typename Coords > | |
GENVECTOR_CONSTEXPR::geo::Point_t | geo::vect::makePointFromCoords (Coords &&coords) |
Creates a geo::Point_t from its coordinates (see makeFromCoords() ). More... | |
template<typename Coords > | |
GENVECTOR_CONSTEXPR::geo::Vector_t | geo::vect::makeVectorFromCoords (Coords &&coords) |
Creates a geo::Vector_t from its coordinates (see makeFromCoords() ). More... | |
Variables | |
template<typename Vector > | |
static constexpr auto | geo::vect::XcoordManager = details::makeCoordManager(&Vector::X, &Vector::SetX) |
Object that can be bound to a vector to manage its X coordinate. More... | |
template<typename Vector > | |
static constexpr auto | geo::vect::XcoordManager< Vector const > = details::makeCoordReader(&Vector::X) |
Object that can be bound to a vector to access its X coordinate. More... | |
template<typename Vector > | |
static constexpr auto const | geo::vect::YcoordManager = details::makeCoordManager(&Vector::Y, &Vector::SetY) |
template<typename Vector > | |
static constexpr auto | geo::vect::YcoordManager< Vector const > = details::makeCoordReader(&Vector::Y) |
template<typename Vector > | |
static constexpr auto | geo::vect::ZcoordManager = details::makeCoordManager(&Vector::Z, &Vector::SetZ) |
template<typename Vector > | |
static constexpr auto | geo::vect::ZcoordManager< Vector const > = details::makeCoordReader(&Vector::Z) |
template<typename Vector > | |
static constexpr auto | geo::vect::TcoordManager = details::makeCoordManager(&Vector::T, &Vector::SetT) |
template<typename Vector > | |
static constexpr auto | geo::vect::TcoordManager< Vector const > = details::makeCoordReader(&Vector::T) |
template<typename Vector > | |
constexpr CoordManager_t< Vector > | geo::vect::details::NoCoordManager { nullptr, nullptr } |
Utilities to extend the interface of geometry vectors.
This library provides facilities that can be used for both LArSoft geometry vectors (geo_vectors.h
) and ROOT TVector3
and related, with the same interface.
This library depends on ROOT GenVector. In the CET link list in CMakeLists.txt
, link to ${ROOT_GENVECTOR}
.
Definition in file geo_vectors_utils.h.