60 #include <visp3/core/vpImageDraw.h> 61 #include <visp3/core/vpPoint.h> 62 #include <visp3/core/vpMeterPixelConversion.h> 66 template<
class Type>
void DrawLine(
vpImage<Type> & canvas,
int x1,
int y1,
int x2,
int y2,
const Type & color,
unsigned int width = 1)
68 const int w =
static_cast<int>(canvas.
getWidth()) - 1;
69 const int h =
static_cast<int>(canvas.
getHeight()) - 1;
71 if (x1 < 0 || y1 < 0 || (x1 - w) > 0 || (y1 - h) > 0 || x2 < 0 || y2 < 0 || (x2 - w) > 0 || (y2 - h) > 0) {
72 if ((x1 < 0 && x2 < 0) || (y1 < 0 && y2 < 0) || ((x1 - w) > 0 && (x2 - w) > 0) || ((y1 - h) > 0 && (y2 -h) > 0)) {
77 x1 = std::min<int>(std::max<int>(x1, 0), w);
78 x2 = std::min<int>(std::max<int>(x2, 0), w);
79 }
else if (x1 == x2) {
80 y1 = std::min<int>(std::max<int>(y1, 0), h);
81 y2 = std::min<int>(std::max<int>(y2, 0), h);
83 int x0 = (x1*y2 - y1*x2) / (y2 - y1);
84 int y0 = (y1*x2 - x1*y2) / (x2 - x1);
85 int xh = (x1*y2 - y1*x2 + h*(x2 - x1)) / (y2 - y1);
86 int yw = (y1*x2 - x1*y2 + w*(y2 - y1)) / (x2 - x1);
104 if ((y1 < 0 && y2 < 0) || (y1 > h && y2 > h)) {
128 const bool inverse = ((std::abs(y2 - y1) - std::abs(x2 - x1)) > 0);
139 const double dx = x2 - x1;
140 const double dy =
static_cast<double>(std::abs(y2 - y1));
142 double error = dx / 2.0f;
143 const int ystep = (y1 < y2) ? 1 : -1;
144 int y0 = y1 -
static_cast<int>(width) / 2;
146 for (
int x = x1; x <= x2; x++) {
147 for (
int i = 0; i < static_cast<int>(width); i++) {
152 canvas[x][y] = color;
156 canvas[y][x] = color;
171 template<
class Type>
void DrawCircle(
vpImage<Type> & canvas,
const vpImagePoint & center,
int radius,
const Type & color,
unsigned int width = 1)
173 const size_t n = 8 * std::max(static_cast<size_t>(1), static_cast<size_t>(::pow(radius, 0.5)));
174 double px = 0, py = 0, da = 2 * M_PI / n;
175 for (
size_t i = 0; i <= n; i++) {
177 double cx = radius*::cos(a) + center.
get_u();
178 double cy = radius*::sin(a) + center.
get_v();
180 DrawLine(canvas, static_cast<int>(cx), static_cast<int>(cy), static_cast<int>(px), static_cast<int>(py), color, width);
187 template<
class Type>
void DrawFilledRectangle(
vpImage<Type> & canvas,
vpRect rect,
const Type & color)
190 for (
int row = static_cast<int>(rect.
getTop()); row < static_cast<int>(rect.
getBottom()); row++) {
191 Type * dst = canvas[row];
192 for (
int col = static_cast<int>(rect.
getLeft()); col < static_cast<int>(rect.
getRight()); col++) {
198 template<
class Type>
void DrawPolygon(
vpImage<Type> & canvas,
const std::vector<vpImagePoint> & polygon,
199 const Type & color,
unsigned int width = 1,
bool closed =
true)
202 for (
size_t i = 0; i < polygon.size(); i++) {
203 const vpImagePoint & p1 = (i ? polygon[i - 1] : polygon.back()), p2 = polygon[i];
204 DrawLine(canvas, static_cast<int>(p1.
get_u()), static_cast<int>(p1.
get_v()),
205 static_cast<int>(p2.get_u()), static_cast<int>(p2.get_v()), color, width);
209 for (
size_t i = 1; i < polygon.size(); i++) {
210 DrawLine(canvas, static_cast<int>(polygon[i-1].get_u()), static_cast<int>(polygon[i-1].get_v()),
211 static_cast<int>(polygon[i].get_u()), static_cast<int>(polygon[i].get_v()), color, width);
216 template<
class Type>
void DrawRectangle(
vpImage<Type> & canvas,
const vpRect & rect,
const Type & color,
unsigned int width = 1)
218 DrawLine(canvas, static_cast<int>(rect.
getLeft()), static_cast<int>(rect.
getTop()),
219 static_cast<int>(rect.
getRight()), static_cast<int>(rect.
getTop()), color, width);
220 DrawLine(canvas, static_cast<int>(rect.
getRight()), static_cast<int>(rect.
getTop()),
221 static_cast<int>(rect.
getRight()), static_cast<int>(rect.
getBottom()), color, width);
222 DrawLine(canvas, static_cast<int>(rect.
getRight()), static_cast<int>(rect.
getBottom()),
223 static_cast<int>(rect.
getLeft()), static_cast<int>(rect.
getBottom()), color, width);
224 DrawLine(canvas, static_cast<int>(rect.
getLeft()), static_cast<int>(rect.
getBottom()),
225 static_cast<int>(rect.
getLeft()), static_cast<int>(rect.
getTop()), color, width);
238 unsigned char color,
unsigned int w,
unsigned int h,
unsigned int thickness)
244 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
245 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
260 drawLine(I, ip2, ip4, color, thickness);
267 drawLine(I, ip2, ip4, color, thickness);
270 drawLine(I, ip1, ip2, color, thickness);
283 const vpColor &color,
unsigned int w,
unsigned int h,
unsigned int thickness)
289 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
290 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
305 drawLine(I, ip2, ip4, color, thickness);
312 drawLine(I, ip2, ip4, color, thickness);
315 drawLine(I, ip1, ip2, color, thickness);
328 unsigned int radius,
unsigned char color,
unsigned int thickness)
330 DrawCircle(I, center, static_cast<int>(radius), color, thickness);
342 unsigned int radius,
const vpColor &color,
unsigned int thickness)
344 DrawCircle(I, center, static_cast<int>(radius),
vpRGBa(color.
R, color.
G, color.
B), thickness);
356 unsigned char color,
unsigned int thickness)
367 drawLine(I, top, bottom, color, thickness);
368 drawLine(I, left, right, color, thickness);
380 const vpColor &color,
unsigned int thickness)
391 drawLine(I, top, bottom, color, thickness);
392 drawLine(I, left, right, color, thickness);
403 unsigned char color,
unsigned int thickness)
410 bool vertical_line =
static_cast<int>(ip2_.
get_j()) == static_cast<int>(ip1_.
get_j());
413 std::swap(ip1_, ip2_);
416 std::swap(ip1_, ip2_);
419 double diff_j = vertical_line ? 1 : ip2_.
get_j() - ip1_.
get_j();
420 double deltaj = size / length * diff_j;
421 double deltai = size / length * (ip2_.
get_i() - ip1_.
get_i());
422 double slope = (ip2_.
get_i() - ip1_.
get_i()) / diff_j;
423 double orig = ip1_.
get_i() - slope * ip1_.
get_j();
426 for (
unsigned int i = static_cast<unsigned int>(ip1_.
get_i()); i < ip2_.
get_i(); i +=
static_cast<unsigned int>(2 * deltai)) {
427 double j = ip1_.
get_j();
431 for (
unsigned int j = static_cast<unsigned int>(ip1_.
get_j()); j < ip2_.
get_j(); j +=
static_cast<unsigned int>(2 * deltaj)) {
432 double i = slope * j + orig;
452 bool vertical_line =
static_cast<int>(ip2_.
get_j()) == static_cast<int>(ip1_.
get_j());
455 std::swap(ip1_, ip2_);
458 std::swap(ip1_, ip2_);
461 double diff_j = vertical_line ? 1 : ip2_.
get_j() - ip1_.
get_j();
462 double deltaj = size / length * diff_j;
463 double deltai = size / length * (ip2_.
get_i() - ip1_.
get_i());
464 double slope = (ip2_.
get_i() - ip1_.
get_i()) / diff_j;
465 double orig = ip1_.
get_i() - slope * ip1_.
get_j();
468 for (
unsigned int i = static_cast<unsigned int>(ip1_.
get_i()); i < ip2_.
get_i(); i +=
static_cast<unsigned int>(2 * deltai)) {
469 double j = ip1_.
get_j();
473 for (
unsigned int j = static_cast<unsigned int>(ip1_.
get_j()); j < ip2_.
get_j(); j +=
static_cast<unsigned int>(2 * deltaj)) {
474 double i = slope * j + orig;
536 double coef2,
double coef3,
bool use_centered_moments,
unsigned char color,
537 double theta1,
double theta2,
unsigned int thickness)
539 double a = 0., b = 0., e = 0.;
541 double mu20_p = coef1;
542 double mu11_p = coef2;
543 double mu02_p = coef3;
545 if (use_centered_moments) {
546 if (std::fabs(mu11_p) > std::numeric_limits<double>::epsilon()) {
549 a = sqrt((mu20_p + mu02_p + val_p) / 2);
550 b = sqrt((mu20_p + mu02_p - val_p) / 2);
552 e = (mu02_p - mu20_p + val_p) / (2 * mu11_p);
568 double t = (a - b) / (a + b);
571 int nbpoints =
static_cast<int>(floor(circumference / 5));
575 double incr = 2 * M_PI / nbpoints;
582 double k = smallalpha;
583 double j1 = a * cos(k);
584 double i1 = b * sin(k);
590 iP11.
set_j(center.
get_j() + ce * j1 - se * i1);
591 iP11.
set_i(center.
get_i() + se * j1 + ce * i1);
593 while (k + incr < highalpha + incr) {
594 double j2 = a * cos(k + incr);
595 double i2 = b * sin(k + incr);
598 iP22.
set_j(center.
get_j() + ce * j2 - se * i2);
599 iP22.
set_i(center.
get_i() + se * j2 + ce * i2);
601 drawLine(I, iP11, iP22, color, thickness);
665 double coef2,
double coef3,
bool use_centered_moments,
const vpColor &color,
666 double theta1,
double theta2,
unsigned int thickness)
668 double a = 0., b = 0., e = 0.;
670 double mu20_p = coef1;
671 double mu11_p = coef2;
672 double mu02_p = coef3;
674 if (use_centered_moments) {
675 if (std::fabs(mu11_p) > std::numeric_limits<double>::epsilon()) {
677 a = sqrt((mu20_p + mu02_p + val_p) / 2);
678 b = sqrt((mu20_p + mu02_p - val_p) / 2);
680 e = (mu02_p - mu20_p + val_p) / (2 * mu11_p);
696 double t = (a - b) / (a + b);
699 int nbpoints =
static_cast<int>(floor(circumference / 5));
703 double incr = 2 * M_PI / nbpoints;
710 double k = smallalpha;
711 double j1 = a * cos(k);
712 double i1 = b * sin(k);
718 iP11.
set_j(center.
get_j() + ce * j1 - se * i1);
719 iP11.
set_i(center.
get_i() + se * j1 + ce * i1);
721 while (k + incr < highalpha + incr) {
722 double j2 = a * cos(k + incr);
723 double i2 = b * sin(k + incr);
726 iP22.
set_j(center.
get_j() + ce * j2 - se * i2);
727 iP22.
set_i(center.
get_i() + se * j2 + ce * i2);
729 drawLine(I, iP11, iP22, color, thickness);
753 double size,
unsigned char color,
unsigned int thickness,
const vpImagePoint &offset)
770 drawArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
773 drawArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
776 drawArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
824 drawArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
827 drawArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
830 drawArrow(I, ipo + offset, ip1 + offset, color, 4 * thickness, 2 * thickness, thickness);
842 unsigned char color,
unsigned int thickness)
844 DrawLine(I, static_cast<int>(ip1.
get_u()), static_cast<int>(ip1.
get_v()),
845 static_cast<int>(ip2.
get_u()), static_cast<int>(ip2.
get_v()), color,
858 DrawLine(I, static_cast<int>(ip1.
get_u()), static_cast<int>(ip1.
get_v()),
859 static_cast<int>(ip2.
get_u()), static_cast<int>(ip2.
get_v()),
vpRGBa(color.
R, color.
G, color.
B),
896 unsigned char color,
unsigned int thickness,
bool closed)
898 DrawPolygon(I, vip, color, thickness, closed);
910 const vpColor &color,
unsigned int thickness,
bool closed)
912 DrawPolygon(I, vip,
vpRGBa(color.
R, color.
G, color.
B), thickness, closed);
930 DrawFilledRectangle(I, rectangle, color);
932 DrawRectangle(I, rectangle, color, thickness);
951 DrawFilledRectangle(I, rectangle,
vpRGBa(color.
R, color.
G, color.
B));
953 DrawRectangle(I, rectangle,
vpRGBa(color.
R, color.
G, color.
B), thickness);
static void drawEllipse(vpImage< unsigned char > &I, const vpImagePoint ¢er, double coef1, double coef2, double coef3, bool use_centered_moments, unsigned char color, double theta1=0, double theta2=360, unsigned int thickness=1)
static void drawRectangle(vpImage< unsigned char > &I, const vpRect &rectangle, unsigned char color, bool fill=false, unsigned int thickness=1)
Implementation of an homogeneous matrix and operations on such kind of matrices.
unsigned char B
Blue component.
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
static void drawCircle(vpImage< unsigned char > &I, const vpImagePoint ¢er, unsigned int radius, unsigned char color, unsigned int thickness=1)
static void drawFrame(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, unsigned char color, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
Class to define colors available for display functionnalities.
static void drawArrow(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static const vpColor none
void track(const vpHomogeneousMatrix &cMo)
static void drawDottedLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
unsigned char G
Green component.
static const vpColor green
Class that defines what is a point.
static double sqr(double x)
static void drawPoint(vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned char color, unsigned int thickness=1)
Generic class defining intrinsic camera parameters.
static double rad(double deg)
unsigned int getHeight() const
static void drawCross(vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, unsigned char color, unsigned int thickness=1)
unsigned char R
Red component.
static void drawPolygon(vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, unsigned char color, unsigned int thickness=1, bool closed=true)
Defines a rectangle in the plane.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
static void drawLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
Definition of the vpImage class member functions.
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
static const vpColor blue