50 #include <boost/geometry/algorithms/intersects.hpp> 51 #include <boost/geometry/algorithms/within.hpp> 52 #include <boost/geometry/geometries/box.hpp> 74 template<
typename T,
int D,
typename Derived>
80 typedef boost::geometry::model::box<PointType>
BoxType;
89 for(
int d=0; d<D; ++d) {
96 RectBase(T x, T y, T z, T width, T height, T depth) :
130 for(
int d=0; d<D; ++d)
132 if(makeValid && (p1[d]>p2[d])) {
146 template<
typename Reflector>
149 reflector.property(
"MinCorner",
minCorner,
"The minimum corner");
150 reflector.property(
"MaxCorner",
maxCorner,
"The maximum corner");
174 template <
typename OtherDerived>
179 template <
typename OtherDerived>
191 template <
typename OtherGeometry>
192 bool contains(
const OtherGeometry& otherGeometry)
const {
193 return boost::geometry::within(otherGeometry, *
this);
197 template <
typename OtherGeometry>
199 return boost::geometry::intersects(otherGeometry, *
this);
203 template <
typename OtherGeometry>
204 bool disjoint(
const OtherGeometry& otherGeometry)
const {
205 return boost::geometry::disjoint(otherGeometry, *
this);
220 for(
int d=0; d<D; ++d)
242 for(
int d=0; d<D; ++d)
260 for(
int d=0; d<D; ++d)
303 return *((Derived*)
this);
306 for(
int d=0; d<D; ++d) {
308 r.maxCorner[d] = std::max(
maxCorner[d], other.maxCorner[d]);
325 }
else if(other.isValid()) {
326 for(
int d=0; d<D; ++d) {
333 return *((Derived*)
this);
362 for(
int d=0; d<D; ++d) {
369 return *((Derived*)
this);
391 for(
int d=0; d<D; ++d) {
392 r.minCorner[d] = std::max(
minCorner[d], other.minCorner[d]);
393 r.maxCorner[d] = std::min(
maxCorner[d], other.maxCorner[d]);
405 return *((Derived*)
this);
407 if(!other.isValid()) {
410 for(
int d=0; d<D; ++d) {
415 return *((Derived*)
this);
420 template<
typename U,
typename OtherDerived>
433 return *((Derived*)
this);
456 template<
typename T,
int D>
471 bool makeValid =
true) :
472 Base(p1, p2, makeValid) {}
505 Rect(T x, T y, T width, T height) :
506 Base(x, y, width, height) {}
515 Base(pos, width, height) {}
530 explicit Rect(
const cv::Rect_<T>& rect) :
531 Base(rect.x, rect.y, rect.width, rect.height) {}
539 bool makeValid =
true) :
540 Base(p1, p2, makeValid) {}
549 operator cv::Rect_<T>()
const 597 return std::list<Rect<T,2>>();
607 return std::list<Rect<T,2>>( {*
this} );
612 std::list<Rect<T,2>> result;
619 PointType otl(other.
x0(), other.
y1());
629 if ((rtl.
width() > 0) && (rtl.
height() > 0)) result.push_back(rtl);
630 if ((rbl.width() > 0) && (rbl.height() > 0)) result.push_back(rbl);
631 if ((rbr.width() > 0) && (rbr.height() > 0)) result.push_back(rbr);
632 if ((rtr.width() > 0) && (rtr.height() > 0)) result.push_back(rtr);
668 Rect(T x, T y, T z, T width, T height, T depth) :
669 Base(x, y, z, width, height, depth) {}
678 Base(pos, width, height, depth) {}
695 bool makeValid =
true) :
696 Base(p1, p2, makeValid) {}
789 namespace boost {
namespace geometry {
namespace traits {
793 template <
typename T,
int D,
typename Derived>
794 struct tag<
mira::RectBase<T,D, Derived> > {
typedef box_tag
type; };
796 template <
typename T,
int D,
typename Derived>
799 template <
typename T,
int D, std::
size_t Dimension,
typename Derived>
800 struct indexed_access<
mira::RectBase<T,D, Derived>, min_corner, Dimension>
802 typedef typename geometry::coordinate_type<mira::Point<T,D> >
::type coordinate_type;
804 return geometry::get<Dimension>(b.minCorner);
807 geometry::set<Dimension>(b.minCorner, value);
811 template <
typename T,
int D, std::
size_t Dimension,
typename Derived>
812 struct indexed_access<
mira::RectBase<T,D, Derived>, max_corner, Dimension>
814 typedef typename geometry::coordinate_type<mira::Point<T,D>>
::type coordinate_type;
816 return geometry::get<Dimension>(b.maxCorner);
819 geometry::set<Dimension>(b.maxCorner, value);
823 template <
typename T,
int D>
824 struct tag<
mira::Rect<T,D> > :
public tag<mira::RectBase<T,D, mira::Rect<T,D>>> {};
826 template <
typename T,
int D>
827 struct point_type<
mira::Rect<T,D> > :
public point_type<mira::RectBase<T,D,mira::Rect<T,D>>> {};
829 template <
typename T,
int D, std::
size_t Dimension>
830 struct indexed_access<
mira::Rect<T,D>, min_corner, Dimension> :
831 public indexed_access<mira::RectBase<T,D,mira::Rect<T,D>>, min_corner, Dimension> {};
833 template <
typename T,
int D, std::
size_t Dimension>
834 struct indexed_access<
mira::Rect<T,D>, max_corner, Dimension> :
835 public indexed_access<mira::RectBase<T,D,mira::Rect<T,D>>, max_corner, Dimension> {};
Rect class for defining rectangles.
Definition: Rect.h:457
Rect< int, 3 > Box3i
A 3D box with integer precision.
Definition: Rect.h:755
Derived operator|(const Derived &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: Rect.h:298
T & y0()
Returns the y-coordinate of the lower corner.
Definition: Rect.h:710
T y0() const
Returns the y-coordinate of the lower corner.
Definition: Rect.h:712
A class for a n-dimensional line.
Rect< int, 2 > Rect2i
A 2D rect with integer precision.
Definition: Rect.h:746
Definition: SyncTimedRead.h:62
static Derived zero()
Same as null().
Definition: Rect.h:280
RectBase(const BoxType &box)
Creating an n-dimensional object from boost::model::box.
Definition: Rect.h:117
Derived operator &(const Derived &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: Rect.h:383
RectBase< T, D, Rect< T, D > > Base
Definition: Rect.h:460
const Derived & operator &=(const Derived &other)
Intersects the rectangle with the given rectangle.
Definition: Rect.h:402
T depth() const
Returns the depth.
Definition: Rect.h:739
General point class template.
Definition: Point.h:140
RectBase< T, 3, Rect< T, 3 > > Base
Definition: Rect.h:649
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Base::PointType PointType
Definition: Rect.h:461
RectBase(const PointType &pos, T width, T height)
A constructor for the 2D case.
Definition: Rect.h:104
T & y1()
Returns the y-coordinate of the upper corner.
Definition: Rect.h:725
Rect(const PointType &pos, T width, T height, T depth)
a constructor to create a 3D rect
Definition: Rect.h:677
Rect< float, 3 > Box3f
A 3D box with floating point precision.
Definition: Rect.h:758
bool isValid() const
Returns true if this is a valid Rect where the maxCorner's components are not smaller than the minCor...
Definition: Rect.h:219
T & y0()
Returns the y-coordinate of the lower corner.
Definition: Rect.h:566
Derived normalized() const
Returns the normalized Rect, where the maxCorner and minCorner components are swapped if necessary to...
Definition: Rect.h:239
RectBase(const PointType &p1, const PointType &p2, bool makeValid)
Create an n-dimensional object from specifying two corners.
Definition: Rect.h:127
T & z0()
Returns the z-coordinate of the lower corner.
Definition: Rect.h:715
Rect< float, 2 > Rect2f
A 2D rect with floating point precision.
Definition: Rect.h:749
PointType minCorner
Definition: Rect.h:445
T width() const
Returns the width.
Definition: Rect.h:735
boost::geometry::model::box< PointType > BoxType
Definition: Rect.h:80
Rect(const PointType &pos, T width, T height)
A constructor to create a 2D rect.
Definition: Rect.h:514
Point< T, D > PointType
Definition: Rect.h:78
Rect(const PointType &pos, const SizeType &s)
A constructor to create a 2D rect.
Definition: Rect.h:522
Base::PointType PointType
Definition: Rect.h:487
T & y1()
Returns the y-coordinate of the upper corner.
Definition: Rect.h:576
Rect(const cv::Rect_< T > &rect)
copy constructor from OpenCV rect
Definition: Rect.h:530
T & x1()
Returns the x-coordinate of the upper corner.
Definition: Rect.h:571
RectBase< T, 2, Rect< T, 2 > > Base
Definition: Rect.h:486
Rect()
the default constructor
Definition: Rect.h:658
By default, IsCheapToCopy<T>::value evaluates to true for fundamental types T, false for all other ty...
Definition: IsCheapToCopy.h:63
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
const Derived & operator+=(const PointType &displacement)
Moves the rect (the minCorner and the maxCorner) by the specified displacement.
Definition: Rect.h:429
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
a constructor to create a 3D rect
Definition: Rect.h:694
RectBase(T x, T y, T width, T height)
A constructor for the 2D case.
Definition: Rect.h:100
T x0() const
Returns the x-coordinate of the lower corner.
Definition: Rect.h:563
T width() const
Returns the width.
Definition: Rect.h:581
bool isNull() const
Returns true, if all extends (i.e.
Definition: Rect.h:259
Rect(const BoxType &box)
copy constructor from boost::BoxType
Definition: Rect.h:688
Type trait to define if a class is cheap to copy.
T x1() const
Returns the x-coordinate of the upper corner.
Definition: Rect.h:722
T z1() const
Returns the z-coordinate of the upper corner.
Definition: Rect.h:732
static Derived invalid()
Returns an invalid rect with negative extends.
Definition: Rect.h:230
Rect< double, 2 > Rect2d
A 2D rect with 64 bit floating point precision.
Definition: Rect.h:752
Base::SizeType SizeType
Definition: Rect.h:651
Size< T, D > SizeType
Definition: Rect.h:79
T y1() const
Returns the y-coordinate of the upper corner.
Definition: Rect.h:578
RectBase(const PointType &pos, T width, T height, T depth)
A constructor for the 3D case.
Definition: Rect.h:108
Base::PointType PointType
Definition: Rect.h:650
PointType maxCorner
Definition: Rect.h:446
Rect(const PointType &pos, const SizeType &s)
a constructor to create a 3D rect
Definition: Rect.h:684
Base::BoxType BoxType
Definition: Rect.h:489
Base::BoxType BoxType
Definition: Rect.h:463
This class provides templatized multidimensional sizes for multidimensional geometric objects...
T & x1()
Returns the x-coordinate of the upper corner.
Definition: Rect.h:720
Rect()
The default constructor.
Definition: Rect.h:496
T height() const
Returns the height.
Definition: Rect.h:737
T & x0()
Returns the x-coordinate of the lower corner.
Definition: Rect.h:561
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
A constructor to create a 2D rect.
Definition: Rect.h:538
Rect(const PointType &p1, const PointType &p2, bool makeValid=true)
A constructor to initialize from 2 points.
Definition: Rect.h:470
static Derived null()
Returns a null-Rect which extends are null (minCorner and maxCorner) are set to 0.
Definition: Rect.h:270
RectBase(const PointType &pos, const SizeType &s)
a constructor to construct the rect, cube or whatever by defining the lower corner and specifying an ...
Definition: Rect.h:113
T & z1()
Returns the z-coordinate of the upper corner.
Definition: Rect.h:730
T x0() const
Returns the x-coordinate of the lower corner.
Definition: Rect.h:707
Base::SizeType SizeType
Definition: Rect.h:488
bool operator==(const RectBase< T, D, OtherDerived > &other) const
Definition: Rect.h:175
void reflect(Reflector &reflector)
the method to serialize this object
Definition: Rect.h:147
Rect(const BoxType &box)
copy constructor from boost::BoxType
Definition: Rect.h:526
RectBase()
The default constructor, creates an invalid rect with negative extends.
Definition: Rect.h:87
T y1() const
Returns the y-coordinate of the upper corner.
Definition: Rect.h:727
T x1() const
Returns the x-coordinate of the upper corner.
Definition: Rect.h:573
Base::BoxType BoxType
Definition: Rect.h:652
T y0() const
Returns the y-coordinate of the lower corner.
Definition: Rect.h:568
bool disjoint(const OtherGeometry &otherGeometry) const
this method checks for non-intersections with other geometry
Definition: Rect.h:204
Rect(T x, T y, T width, T height)
A constructor to create a 2D rect.
Definition: Rect.h:505
Size class for defining sizes with different data types.
Definition: Size.h:69
Rect< double, 3 > Box3d
A 3D box with 64 bit floating point precision.
Definition: Rect.h:761
Base::SizeType SizeType
Definition: Rect.h:462
static Derived convertFrom(const RectBase< U, D, OtherDerived > &other)
Converts from a Rect of a different type.
Definition: Rect.h:421
T height() const
Returns the height.
Definition: Rect.h:583
Rect(T x, T y, T z, T width, T height, T depth)
a constructor to create a 3D rect
Definition: Rect.h:668
SizeType size() const
return the size of the multidimensional rect
Definition: Rect.h:166
bool contains(const OtherGeometry &otherGeometry) const
this method checks if a given geometry is enclosed by this box
Definition: Rect.h:192
RectBase(T x, T y, T z, T width, T height, T depth)
A constructor for the 3D case.
Definition: Rect.h:96
The base class for rectangles.
Definition: Rect.h:75
T z0() const
Returns the z-coordinate of the lower corner.
Definition: Rect.h:717
bool intersects(const OtherGeometry &otherGeometry) const
this method checks for intersections with other geometry
Definition: Rect.h:198
bool operator!=(const RectBase< T, D, OtherDerived > &other) const
Definition: Rect.h:180
T & x0()
Returns the x-coordinate of the lower corner.
Definition: Rect.h:705
const Derived & operator|=(const PointType &p)
Unites this rectangle with the given point.
Definition: Rect.h:356
std::list< Rect< T, 2 > > operator-(const Rect< T, 2 > &other) const
Intersects the rectangle with the inverse of the given rectangle, i.e.
Definition: Rect.h:594
Rect()
The default constructor.
Definition: Rect.h:467
const Derived & operator|=(const Derived &other)
Unites this rectangle with the given rectangle.
Definition: Rect.h:321
Specialization for 2D.
Definition: Rect.h:483
Derived operator+(const PointType &displacement) const
Returns a rect that is moved by the specified displacement.
Definition: Rect.h:439