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)

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

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

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

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

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