homog2d library
Functions
Free functions handling variant type

Functions

template<typename T >
HOMOG2D_INUMTYPE h2d::area (const T &elem)
 Returns area of element or variant (free function) More...
 
template<typename U , typename T , typename std::enable_if< trait::IsContainer< T >::value, T >::type * = nullptr>
void h2d::draw (img::Image< U > &img, const T &cont, const img::DrawParams &dp=img::DrawParams())
 Free function, draws a set of primitives. More...
 
template<typename T >
Dtype h2d::dtype (const T &elem)
 Returns the underlying data type of object or variant. More...
 
template<typename T >
FRect_< HOMOG2D_INUMTYPEh2d::getBB (const T &t)
 Return Bounding Box of primitive or container holding primitives (free function) More...
 
template<typename T >
HOMOG2D_INUMTYPE h2d::length (const T &elem)
 Returns length of element or variant (free function) More...
 
template<typename T >
HOMOG2D_INUMTYPE h2d::size (const T &elem)
 Returns size of element or variant (free function) More...
 
template<typename T , typename FPT >
CommonType_< FPT > h2d::transform (const Homogr_< FPT > &h, const T &elem)
 Apply homography to primitive. More...
 
template<typename T >
Type h2d::type (const T &elem)
 Free function. Returns the type of object or variant. More...
 

Detailed Description

defgroup

These function can be used on a "regular" geometric object or on a CommonType object, holding a std::variant and allowing run-time polymorphism,

See md_docs_homog2d_manual.html::section_rtp

Function Documentation

◆ area()

template<typename T >
HOMOG2D_INUMTYPE h2d::area ( const T &  elem)

Returns area of element or variant (free function)

10243 {
10244 #ifdef HOMOG2D_ENABLE_VRTP
10245  if constexpr( trait::IsVariant<T>::value )
10246  return std::visit( fct::AreaFunct{}, elem );
10247  else
10248 #endif
10249  return elem.area();
10250 }
Here is the caller graph for this function:

◆ draw()

template<typename U , typename T , typename std::enable_if< trait::IsContainer< T >::value, T >::type * = nullptr>
void h2d::draw ( img::Image< U > &  img,
const T &  cont,
const img::DrawParams dp = img::DrawParams() 
)

Free function, draws a set of primitives.

  • Type T can be std::array<type> or std::vector<type>, with type being anything drawable.
  • The types inside the container can be either plain h2d types (FRect, Segment, ...) of variant types, using the CommonType class (requires HOMOG2D_ENABLE_VRTP symbol).
11315 {
11316 #ifdef HOMOG2D_ENABLE_VRTP
11317  if constexpr( trait::IsVariant<typename T::value_type>::value )
11318  {
11319  fct::DrawFunct vde( img, dp ); // functor
11320  for( auto& e: cont )
11321  std::visit( vde, e );
11322  }
11323  else
11324 #endif
11325  {
11326  size_t c=0;
11327  for( const auto& elem: cont )
11328  {
11329  elem.draw( img, dp );
11330  priv::impl_drawIndexes( img, c++, dp, elem );
11331  }
11332  }
11333 }
void impl_drawIndexes(img::Image< IMG > &, size_t, const img::DrawParams &, const DUMMY &)
Default signature, will be instanciated if no other fits (and does nothing)
Definition: homog2d.hpp:11292
Here is the call graph for this function:

◆ dtype()

template<typename T >
Dtype h2d::dtype ( const T &  elem)

Returns the underlying data type of object or variant.

Can be printed with getString()

10213 {
10214 #ifdef HOMOG2D_ENABLE_VRTP
10215  if constexpr( trait::IsVariant<T>::value )
10216  return std::visit( fct::DTypeFunct{}, elem );
10217  else
10218 #endif
10219  return elem.dtype();
10220 }
Here is the caller graph for this function:

◆ getBB()

template<typename T >
FRect_<HOMOG2D_INUMTYPE> h2d::getBB ( const T &  t)

Return Bounding Box of primitive or container holding primitives (free function)

tests: [BB-cont]

10317 {
10318  HOMOG2D_START;
10319 
10320  if constexpr( !trait::IsContainer<T>::value ) // if not a container,
10321  return t.getBB(); // then call the member function
10322  else
10323  {
10324  if( t.empty() )
10325  HOMOG2D_THROW_ERROR_1( "unable, can't compute BB of empty container" );
10326 
10327  if constexpr( trait::IsPoint<typename T::value_type>::value )
10328  {
10329  if( t.size() < 2 )
10330  HOMOG2D_THROW_ERROR_1( "unable, need at least two points" );
10331  return FRect_<typename T::value_type::FType>( priv::getBB_Points( t ) );
10332  }
10333  else
10334  {
10335  if constexpr( trait::HasBB<typename T::value_type>::value )
10336  {
10337  using FPT = typename T::value_type::FType;
10338  std::vector<FRect_<FPT>> v_bb( t.size() );
10339 
10340  auto it = v_bb.begin();
10341  for( const auto& elem: t ) // compute bounding box of each element
10342  *it++ = elem.getBB();
10343 
10344  return priv::getBB_FRect( v_bb ); // compute BB of all the BB
10345  }
10346  else
10347  {
10348  if constexpr( trait::IsSegment<typename T::value_type>::value )
10349  {
10350  if( t.empty() )
10351  HOMOG2D_THROW_ERROR_1( "unable, need at least one segment" );
10352  return priv::getBB_Segments( t );
10353  }
10354  else
10355  {
10356 #ifdef HOMOG2D_ENABLE_VRTP
10357  if constexpr( !trait::IsVariant<typename T::value_type>::value )
10358  {
10359  HOMOG2D_THROW_ERROR_1( "Unable, cannot compute BoundingBox of a container holding Line2d objects" );
10360  }
10361  else
10362  return priv::getBB_CommonType( t );
10363 #else
10364  HOMOG2D_THROW_ERROR_1( "Unable, cannot compute BoundingBox of a container holding Line2d objects" );
10365 #endif
10366  }
10367  }
10368  }
10369  }
10370 }
PointPair_< typename T::value_type::FType > getBB_Points(const T &vpts)
Returns the bounding box of points in vector/list/array of points vpts (free function) ...
Definition: homog2d.hpp:5907
#define HOMOG2D_START
Definition: homog2d.hpp:106
auto getBB_FRect(const std::vector< FRect_< FPT >> &v_rects)
get BB for a set of FRect_ objects
Definition: homog2d.hpp:5981
auto getBB_CommonType(const std::vector< CommonType_< FPT >> &v_var)
Get Bounding Box for a container holding variant objects.
Definition: homog2d.hpp:10280
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
FRect_< typename T::value_type::FType > getBB_Segments(const T &vsegs)
Returns the bounding box of segments in vector/list/array of points vsegs.
Definition: homog2d.hpp:5960
Here is the call graph for this function:
Here is the caller graph for this function:

◆ length()

template<typename T >
HOMOG2D_INUMTYPE h2d::length ( const T &  elem)

Returns length of element or variant (free function)

10228 {
10229 #ifdef HOMOG2D_ENABLE_VRTP
10230  if constexpr( trait::IsVariant<T>::value )
10231  return std::visit( fct::LengthFunct{}, elem );
10232  else
10233 #endif
10234  return elem.length();
10235 }
Here is the caller graph for this function:

◆ size()

template<typename T >
HOMOG2D_INUMTYPE h2d::size ( const T &  elem)

Returns size of element or variant (free function)

10258 {
10259 #ifdef HOMOG2D_ENABLE_VRTP
10260  if constexpr( trait::IsVariant<T>::value )
10261  return std::visit( fct::SizeFunct{}, elem );
10262  else
10263 #endif
10264  return elem.size();
10265 }
Here is the caller graph for this function:

◆ transform()

template<typename T , typename FPT >
CommonType_<FPT> h2d::transform ( const Homogr_< FPT > &  h,
const T &  elem 
)

Apply homography to primitive.

Warning
The floating-point type of the returned object (variant) will be the one of the homography h, NOT the one of the input element.
10383 {
10384  if constexpr( trait::IsVariant<T>::value )
10385  return std::visit( fct::TransformFunct<FPT>(h), elem );
10386  else
10387  return h * elem;
10388 }
Here is the caller graph for this function:

◆ type()

template<typename T >
Type h2d::type ( const T &  elem)

Free function. Returns the type of object or variant.

Can be printed with getString()

See also
CommonType_
10195 {
10196 #ifdef HOMOG2D_ENABLE_VRTP
10197  if constexpr( trait::IsVariant<T>::value )
10198  return std::visit( fct::TypeFunct{}, elem );
10199  else
10200 #endif
10201  return elem.type();
10202 }
Here is the caller graph for this function: