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)

10239 {
10240 #ifdef HOMOG2D_ENABLE_VRTP
10241  if constexpr( trait::IsVariant<T>::value )
10242  return std::visit( fct::AreaFunct{}, elem );
10243  else
10244 #endif
10245  return elem.area();
10246 }
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).
11311 {
11312 #ifdef HOMOG2D_ENABLE_VRTP
11313  if constexpr( trait::IsVariant<typename T::value_type>::value )
11314  {
11315  fct::DrawFunct vde( img, dp ); // functor
11316  for( auto& e: cont )
11317  std::visit( vde, e );
11318  }
11319  else
11320 #endif
11321  {
11322  size_t c=0;
11323  for( const auto& elem: cont )
11324  {
11325  elem.draw( img, dp );
11326  priv::impl_drawIndexes( img, c++, dp, elem );
11327  }
11328  }
11329 }
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:11288
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()

10209 {
10210 #ifdef HOMOG2D_ENABLE_VRTP
10211  if constexpr( trait::IsVariant<T>::value )
10212  return std::visit( fct::DTypeFunct{}, elem );
10213  else
10214 #endif
10215  return elem.dtype();
10216 }
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]

10313 {
10314  HOMOG2D_START;
10315 
10316  if constexpr( !trait::IsContainer<T>::value ) // if not a container,
10317  return t.getBB(); // then call the member function
10318  else
10319  {
10320  if( t.empty() )
10321  HOMOG2D_THROW_ERROR_1( "unable, can't compute BB of empty container" );
10322 
10323  if constexpr( trait::IsPoint<typename T::value_type>::value )
10324  {
10325  if( t.size() < 2 )
10326  HOMOG2D_THROW_ERROR_1( "unable, need at least two points" );
10327  return FRect_<typename T::value_type::FType>( priv::getBB_Points( t ) );
10328  }
10329  else
10330  {
10331  if constexpr( trait::HasBB<typename T::value_type>::value )
10332  {
10333  using FPT = typename T::value_type::FType;
10334  std::vector<FRect_<FPT>> v_bb( t.size() );
10335 
10336  auto it = v_bb.begin();
10337  for( const auto& elem: t ) // compute bounding box of each element
10338  *it++ = elem.getBB();
10339 
10340  return priv::getBB_FRect( v_bb ); // compute BB of all the BB
10341  }
10342  else
10343  {
10344  if constexpr( trait::IsSegment<typename T::value_type>::value )
10345  {
10346  if( t.empty() )
10347  HOMOG2D_THROW_ERROR_1( "unable, need at least one segment" );
10348  return priv::getBB_Segments( t );
10349  }
10350  else
10351  {
10352 #ifdef HOMOG2D_ENABLE_VRTP
10353  if constexpr( !trait::IsVariant<typename T::value_type>::value )
10354  {
10355  HOMOG2D_THROW_ERROR_1( "Unable, cannot compute BoundingBox of a container holding Line2d objects" );
10356  }
10357  else
10358  return priv::getBB_CommonType( t );
10359 #else
10360  HOMOG2D_THROW_ERROR_1( "Unable, cannot compute BoundingBox of a container holding Line2d objects" );
10361 #endif
10362  }
10363  }
10364  }
10365  }
10366 }
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:5903
#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:5977
auto getBB_CommonType(const std::vector< CommonType_< FPT >> &v_var)
Get Bounding Box for a container holding variant objects.
Definition: homog2d.hpp:10276
#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:5956
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)

10224 {
10225 #ifdef HOMOG2D_ENABLE_VRTP
10226  if constexpr( trait::IsVariant<T>::value )
10227  return std::visit( fct::LengthFunct{}, elem );
10228  else
10229 #endif
10230  return elem.length();
10231 }
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)

10254 {
10255 #ifdef HOMOG2D_ENABLE_VRTP
10256  if constexpr( trait::IsVariant<T>::value )
10257  return std::visit( fct::SizeFunct{}, elem );
10258  else
10259 #endif
10260  return elem.size();
10261 }
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.
10379 {
10380  if constexpr( trait::IsVariant<T>::value )
10381  return std::visit( fct::TransformFunct<FPT>(h), elem );
10382  else
10383  return h * elem;
10384 }
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_
10191 {
10192 #ifdef HOMOG2D_ENABLE_VRTP
10193  if constexpr( trait::IsVariant<T>::value )
10194  return std::visit( fct::TypeFunct{}, elem );
10195  else
10196 #endif
10197  return elem.type();
10198 }
Here is the caller graph for this function: