iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::Dims< T > Class Template Reference

#include <nrt/Core/Geometry/Dims.H>

template<class T>
class nrt::Dims< T >

A generic dimensions class.

The Dims class is used to represent the size of a 2-dimensional object, for example an Image.

Template Parameters
TThe internal datatype with which to store the width and height. The majority of nrt uses int32.
Note
The operators of Dims do not use type promotions (see Automatic type promotion for operations). This is to minimize template burden and also possible programmer confusion. For example, while in principle one could define Dims<int> + float and return a Dims<float>, here we do not define such an operator. The same result can be achieved by first converting the range and then adding the constant:
nrt::Dims<int> r1(100, 100);
// NOT ALLOWED: nrt::Dims<float> r2 = r1 + 1.23F;
nrt::Dims<float> r2 = nrt::Dims<float>(r1) + 1.23F; // OK, no hidden conversions, easy to read, explicit, nice
Operators on Dims use range checking and clamping internally. Thus, be careful if using Dims<byte>. For example:
nrt::Dims<nrt::byte> d(nrt::byte(3), nrt::byte(250));
d += nrt::byte(250); // new dims is 253x255
Todo:
The multiplication operators seem to not work properly.
Examples:
tests/test-Module.C, tests/test-rgb2hsv-Image_vs_Blitz_vs_OpenCV.C, and tests/test-UKF.C.

Definition at line 139 of file Dims.H.

Public Member Functions

 Dims ()
 Default constructor - creates a Dims with width and height = 0.
 
 Dims (T const width, T const height)
 Construct with from a given width and height.
 
 Dims (Dims< T > const &other)=default
 Copy constructor.
 
 Dims (Dims< T > &&other)=default
 Move constructor.
 
template<class U >
 Dims (Dims< U > const &other)
 Copy-conversion constructor, uses nrt::clamped_convert<T,U> internally.
 
Dims< T > & operator= (Dims< T > const &other)=default
 Assignment.
 
Dims< T > & operator= (Dims< T > &&other)=default
 Move assignment.
 
width () const
 Return the width.
 
height () const
 Return the height.
 
size () const
 Return the size (width * height)
 
bool empty () const
 Return whether the Dims encloses 0 area.
 
template<class U >
bool contains (Point2D< U > const &p) const
 Return whether the given point is contained in this Dims. More...
 
template<class Archive >
void serialize (Archive &ar)
 Serialize Dims into an Archive.
 

Friends

class cereal::access
 

Related Functions

(Note that these are not member functions.)

template<class T >
std::ostream & operator<< (std::ostream &out, Dims< T > const &d)
 Human-readable output to a stream: outputs width x height (with no space, e.g., 640x480) More...
 
template<class T >
std::istream & operator>> (std::istream &in, Dims< T > &d)
 Human-readable input from a stream: reads width x height (with no space, e.g., 640x480) More...
 
template<class T >
void paramValToString (Dims< T > const &val, std::string &result)
 Machine-readable output to a string, for use in nrt::Parameter: outputs width x height (e.g., 640x480) More...
 
template<class T >
void paramStringToVal (std::string const &valstring, Dims< T > &result)
 Machine-readable input from a string, for use in nrt::Parameter: reads width x height (e.g., 640x480) More...
 
template<class T >
bool operator== (Dims< T > const &dims1, Dims< T > const &dims2)
 Operator overload for Dims<T> == Dims<T> More...
 
template<class T >
bool operator!= (Dims< T > const &dims1, Dims< T > const &dims2)
 Operator overload for Dims<T> != Dims<T> More...
 
template<class T >
Dims< T > operator+ (Dims< T > const &dims1, Dims< T > const &dims2)
 Operator overload for Dims<T> + Dims<T> More...
 
template<class T >
Dims< T > operator+ (Dims< T > const &dims, T const scalar)
 Operator overload for Dims<T> + T. More...
 
template<class T >
Dims< T > operator+ (T const scalar, Dims< T > const &dims)
 Operator overload for T + Dims<T> More...
 
template<class T >
Dims< T > operator- (Dims< T > const &dims1, Dims< T > const &dims2)
 Operator overload for Dims<T> - Dims<T> More...
 
template<class T >
Dims< T > operator- (Dims< T > const &dims, T const scalar)
 Operator overload for Dims<T> - T. More...
 
template<class T >
Dims< T > operator- (T const scalar, Dims< T > const &dims)
 Operator overload for T - Dims<T> More...
 
template<class T >
Dims< T > operator/ (Dims< T > const &dims1, Dims< T > const &dims2)
 Operator overload for Dims<T> / Dims<T> More...
 
template<class T >
Dims< T > operator/ (Dims< T > const &dims, double const scalar)
 Operator overload for Dims<T> / double. More...
 
template<class T >
Dims< T > operator* (Dims< T > const &dims, double const scalar)
 Operator overload for Dims<T> * double. More...
 
template<class T >
Dims< T > operator* (double const scalar, Dims< T > const &dims)
 Operator overload for double * Dims<T> More...
 
template<class T >
Dims< T > & operator+= (Dims< T > &dims, T const scalar)
 Operator overload for Dims<T> += T. More...
 
template<class T >
Dims< T > & operator-= (Dims< T > &dims, T const scalar)
 Operator overload for Dims<T> -= T. More...
 
template<class T >
Dims< T > & operator*= (Dims< T > &dims, double const scalar)
 Operator overload for Dims<T> *= double. More...
 
template<class T >
Dims< T > & operator/= (Dims< T > &dims, double const scalar)
 Operator overload for Dims<T> /= double. More...
 
template<class T >
Dims< T > & operator+= (Dims< T > &dims1, Dims< T > const &dims2)
 Operator overload for Dims<T> += Dims<T> More...
 
template<class T >
Dims< T > & operator-= (Dims< T > &dims1, Dims< T > const &dims2)
 Operator overload for Dims<T> -= Dims<T> More...
 

Member Function Documentation

template<class T >
template<class U >
bool nrt::Dims< T >::contains ( Point2D< U > const &  p) const
inline

Return whether the given point is contained in this Dims.

This is equivalent to asking whether a Rectangle with its top-left corner at (0,0) and dimensions equal to this class contains the point.

Definition at line 90 of file DimsImpl.H.

References nrt::Point2D< T >::x(), and nrt::Point2D< T >::y().

Friends And Related Function Documentation

template<class T >
std::ostream & operator<< ( std::ostream &  out,
Dims< T > const &  d 
)
related

Human-readable output to a stream: outputs width x height (with no space, e.g., 640x480)

template<class T >
std::istream & operator>> ( std::istream &  in,
Dims< T > &  d 
)
related

Human-readable input from a stream: reads width x height (with no space, e.g., 640x480)

Exceptions
nrt::exception::Exceptionif input is malformed
template<class T >
void paramValToString ( Dims< T > const &  val,
std::string &  result 
)
related

Machine-readable output to a string, for use in nrt::Parameter: outputs width x height (e.g., 640x480)

This is an overload for Dims<T> of the function template in nrt/Core/Model/ParameterStringConversion.H.

template<class T >
void paramStringToVal ( std::string const &  valstring,
Dims< T > &  result 
)
related

Machine-readable input from a string, for use in nrt::Parameter: reads width x height (e.g., 640x480)

Exceptions
nrt::exception::Exceptionif input is malformed. This is an overload for Dims<T> of the function template in nrt/Core/Model/ParameterStringConversion.H.
template<class T >
bool operator== ( Dims< T > const &  dims1,
Dims< T > const &  dims2 
)
related

Operator overload for Dims<T> == Dims<T>

template<class T >
bool operator!= ( Dims< T > const &  dims1,
Dims< T > const &  dims2 
)
related

Operator overload for Dims<T> != Dims<T>

template<class T >
Dims< T > operator+ ( Dims< T > const &  dims1,
Dims< T > const &  dims2 
)
related

Operator overload for Dims<T> + Dims<T>

template<class T >
Dims< T > operator+ ( Dims< T > const &  dims,
T const  scalar 
)
related

Operator overload for Dims<T> + T.

template<class T >
Dims< T > operator+ ( T const  scalar,
Dims< T > const &  dims 
)
related

Operator overload for T + Dims<T>

template<class T >
Dims< T > operator- ( Dims< T > const &  dims1,
Dims< T > const &  dims2 
)
related

Operator overload for Dims<T> - Dims<T>

template<class T >
Dims< T > operator- ( Dims< T > const &  dims,
T const  scalar 
)
related

Operator overload for Dims<T> - T.

template<class T >
Dims< T > operator- ( T const  scalar,
Dims< T > const &  dims 
)
related

Operator overload for T - Dims<T>

template<class T >
Dims< T > operator/ ( Dims< T > const &  dims1,
Dims< T > const &  dims2 
)
related

Operator overload for Dims<T> / Dims<T>

template<class T >
Dims< T > operator/ ( Dims< T > const &  dims,
double const  scalar 
)
related

Operator overload for Dims<T> / double.

template<class T >
Dims< T > operator* ( Dims< T > const &  dims,
double const  scalar 
)
related

Operator overload for Dims<T> * double.

template<class T >
Dims< T > operator* ( double const  scalar,
Dims< T > const &  dims 
)
related

Operator overload for double * Dims<T>

template<class T >
Dims< T > & operator+= ( Dims< T > &  dims,
T const  scalar 
)
related

Operator overload for Dims<T> += T.

template<class T >
Dims< T > & operator-= ( Dims< T > &  dims,
T const  scalar 
)
related

Operator overload for Dims<T> -= T.

template<class T >
Dims< T > & operator*= ( Dims< T > &  dims,
double const  scalar 
)
related

Operator overload for Dims<T> *= double.

template<class T >
Dims< T > & operator/= ( Dims< T > &  dims,
double const  scalar 
)
related

Operator overload for Dims<T> /= double.

template<class T >
Dims< T > & operator+= ( Dims< T > &  dims1,
Dims< T > const &  dims2 
)
related

Operator overload for Dims<T> += Dims<T>

template<class T >
Dims< T > & operator-= ( Dims< T > &  dims1,
Dims< T > const &  dims2 
)
related

Operator overload for Dims<T> -= Dims<T>


The documentation for this class was generated from the following files: