34#include <visp3/core/vpImageConvert.h>
35#include <visp3/core/vpMatrixException.h>
36#include <visp3/core/vpMeterPixelConversion.h>
37#include <visp3/core/vpPixelMeterConversion.h>
38#include <visp3/core/vpPolygon3D.h>
39#include <visp3/core/vpRotationMatrix.h>
40#include <visp3/robot/vpImageSimulator.h>
42#ifdef VISP_HAVE_MODULE_IO
43#include <visp3/io/vpImageIo.h>
58 : cMt(), pt(), ptClipped(), interp(
SIMPLE), normal_obj(), normal_Cam(), normal_Cam_optim(), distance(1.),
59 visible_result(1.), visible(false), X0_2_optim(nullptr), frobeniusNorm_u(0.), fronbniusNorm_v(0.), vbase_u(),
60 vbase_v(), vbase_u_optim(nullptr), vbase_v_optim(nullptr), Xinter_optim(nullptr), listTriangle(), colorI(col), Ig(), Ic(),
61 rect(), cleanPrevImage(false), setBackgroundTexture(false), bgColor(
vpColor::white), focal(), needClipping(false)
63 for (
int i = 0; i < 4; i++)
66 for (
int i = 0; i < 4; i++)
82 normal_Cam_optim =
new double[3];
83 X0_2_optim =
new double[3];
84 vbase_u_optim =
new double[3];
85 vbase_v_optim =
new double[3];
86 Xinter_optim =
new double[3];
95 : cMt(), pt(), ptClipped(), interp(
SIMPLE), normal_obj(), normal_Cam(), normal_Cam_optim(), distance(1.),
96 visible_result(1.), visible(false), X0_2_optim(nullptr), frobeniusNorm_u(0.), fronbniusNorm_v(0.), vbase_u(),
97 vbase_v(), vbase_u_optim(nullptr), vbase_v_optim(nullptr), Xinter_optim(nullptr), listTriangle(), colorI(
GRAY_SCALED), Ig(),
98 Ic(), rect(), cleanPrevImage(false), setBackgroundTexture(false), bgColor(
vpColor::white), focal(),
102 for (
unsigned int i = 0; i < 4; i++) {
107 for (
int i = 0; i < 4; i++)
117 normal_obj = text.normal_obj;
118 frobeniusNorm_u = text.frobeniusNorm_u;
119 fronbniusNorm_v = text.fronbniusNorm_v;
121 normal_Cam.resize(3);
125 normal_Cam_optim =
new double[3];
126 X0_2_optim =
new double[3];
127 vbase_u_optim =
new double[3];
128 vbase_v_optim =
new double[3];
129 Xinter_optim =
new double[3];
131 colorI = text.colorI;
132 interp = text.interp;
133 bgColor = text.bgColor;
134 cleanPrevImage = text.cleanPrevImage;
135 setBackgroundTexture =
false;
145 delete[] normal_Cam_optim;
147 delete[] vbase_u_optim;
148 delete[] vbase_v_optim;
149 delete[] Xinter_optim;
154 for (
unsigned int i = 0; i < 4; i++) {
162 bgColor = sim.bgColor;
163 cleanPrevImage = sim.cleanPrevImage;
167 normal_obj = sim.normal_obj;
168 frobeniusNorm_u = sim.frobeniusNorm_u;
169 fronbniusNorm_v = sim.fronbniusNorm_v;
186 if (setBackgroundTexture)
190 if (cleanPrevImage) {
191 unsigned char col =
static_cast<unsigned char>(0.2126 * bgColor.R + 0.7152 * bgColor.G + 0.0722 * bgColor.B);
192 for (
unsigned int i = 0; i < I.getHeight(); i++) {
193 for (
unsigned int j = 0; j < I.getWidth(); j++) {
202 getRoi(I.getWidth(), I.getHeight(), cam, pt, rect);
204 getRoi(I.getWidth(), I.getHeight(), cam, ptClipped, rect);
206 double top = rect.getTop();
207 double bottom = rect.getBottom();
208 double left = rect.getLeft();
209 double right = rect.getRight();
211 unsigned char *bitmap = I.bitmap;
212 unsigned int width = I.getWidth();
215 for (
unsigned int i =
static_cast<unsigned int>(top); i < static_cast<unsigned int>(bottom); i++) {
216 for (
unsigned int j =
static_cast<unsigned int>(left); j < static_cast<unsigned int>(right); j++) {
222 unsigned char Ipixelplan = 0;
223 if (getPixel(ip, Ipixelplan)) {
224 *(bitmap + i * width + j) = Ipixelplan;
229 if (getPixel(ip, Ipixelplan)) {
230 unsigned char pixelgrey =
231 static_cast<unsigned char>(0.2126 * Ipixelplan.
R + 0.7152 * Ipixelplan.
G + 0.0722 * Ipixelplan.
B);
232 *(bitmap + i * width + j) = pixelgrey;
251 if (cleanPrevImage) {
252 unsigned char col =
static_cast<unsigned char>(0.2126 * bgColor.R + 0.7152 * bgColor.G + 0.0722 * bgColor.B);
253 for (
unsigned int i = 0; i < I.getHeight(); i++) {
254 for (
unsigned int j = 0; j < I.getWidth(); j++) {
261 getRoi(I.getWidth(), I.getHeight(), cam, pt, rect);
263 getRoi(I.getWidth(), I.getHeight(), cam, ptClipped, rect);
265 double top = rect.getTop();
266 double bottom = rect.getBottom();
267 double left = rect.getLeft();
268 double right = rect.getRight();
270 unsigned char *bitmap = I.bitmap;
271 unsigned int width = I.getWidth();
274 for (
unsigned int i =
static_cast<unsigned int>(top); i < static_cast<unsigned int>(bottom); i++) {
275 for (
unsigned int j =
static_cast<unsigned int>(left); j < static_cast<unsigned int>(right); j++) {
280 unsigned char Ipixelplan = 0;
281 if (getPixel(Isrc, ip, Ipixelplan)) {
282 *(bitmap + i * width + j) = Ipixelplan;
306 if (I.getWidth() !=
static_cast<unsigned int>(zBuffer.
getCols()) || I.getHeight() !=
static_cast<unsigned int>(zBuffer.
getRows()))
308 " zBuffer must have the same size as the image I ! "));
310 if (cleanPrevImage) {
311 unsigned char col =
static_cast<unsigned char>(0.2126 * bgColor.R + 0.7152 * bgColor.G + 0.0722 * bgColor.B);
312 for (
unsigned int i = 0; i < I.getHeight(); i++) {
313 for (
unsigned int j = 0; j < I.getWidth(); j++) {
320 getRoi(I.getWidth(), I.getHeight(), cam, pt, rect);
322 getRoi(I.getWidth(), I.getHeight(), cam, ptClipped, rect);
324 double top = rect.getTop();
325 double bottom = rect.getBottom();
326 double left = rect.getLeft();
327 double right = rect.getRight();
329 unsigned char *bitmap = I.bitmap;
330 unsigned int width = I.getWidth();
333 for (
unsigned int i =
static_cast<unsigned int>(top); i < static_cast<unsigned int>(bottom); i++) {
334 for (
unsigned int j =
static_cast<unsigned int>(left); j < static_cast<unsigned int>(right); j++) {
340 unsigned char Ipixelplan;
341 if (getPixel(ip, Ipixelplan)) {
342 if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0) {
343 *(bitmap + i * width + j) = Ipixelplan;
344 zBuffer[i][j] = Xinter_optim[2];
350 if (getPixel(ip, Ipixelplan)) {
351 if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0) {
352 unsigned char pixelgrey =
353 static_cast<unsigned char>(0.2126 * Ipixelplan.
R + 0.7152 * Ipixelplan.
G + 0.0722 * Ipixelplan.
B);
354 *(bitmap + i * width + j) = pixelgrey;
355 zBuffer[i][j] = Xinter_optim[2];
373 if (cleanPrevImage) {
374 for (
unsigned int i = 0; i < I.getHeight(); i++) {
375 for (
unsigned int j = 0; j < I.getWidth(); j++) {
383 getRoi(I.getWidth(), I.getHeight(), cam, pt, rect);
385 getRoi(I.getWidth(), I.getHeight(), cam, ptClipped, rect);
387 double top = rect.getTop();
388 double bottom = rect.getBottom();
389 double left = rect.getLeft();
390 double right = rect.getRight();
392 vpRGBa *bitmap = I.bitmap;
393 unsigned int width = I.getWidth();
396 for (
unsigned int i =
static_cast<unsigned int>(top); i < static_cast<unsigned int>(bottom); i++) {
397 for (
unsigned int j =
static_cast<unsigned int>(left); j < static_cast<unsigned int>(right); j++) {
403 unsigned char Ipixelplan;
404 if (getPixel(ip, Ipixelplan)) {
406 pixelcolor.
R = Ipixelplan;
407 pixelcolor.
G = Ipixelplan;
408 pixelcolor.
B = Ipixelplan;
409 *(bitmap + i * width + j) = pixelcolor;
414 if (getPixel(ip, Ipixelplan)) {
415 *(bitmap + i * width + j) = Ipixelplan;
434 if (cleanPrevImage) {
435 for (
unsigned int i = 0; i < I.getHeight(); i++) {
436 for (
unsigned int j = 0; j < I.getWidth(); j++) {
444 getRoi(I.getWidth(), I.getHeight(), cam, pt, rect);
446 getRoi(I.getWidth(), I.getHeight(), cam, ptClipped, rect);
448 double top = rect.getTop();
449 double bottom = rect.getBottom();
450 double left = rect.getLeft();
451 double right = rect.getRight();
453 vpRGBa *bitmap = I.bitmap;
454 unsigned int width = I.getWidth();
457 for (
unsigned int i =
static_cast<unsigned int>(top); i < static_cast<unsigned int>(bottom); i++) {
458 for (
unsigned int j =
static_cast<unsigned int>(left); j < static_cast<unsigned int>(right); j++) {
464 if (getPixel(Isrc, ip, Ipixelplan)) {
465 *(bitmap + i * width + j) = Ipixelplan;
489 if (I.getWidth() !=
static_cast<unsigned int>(zBuffer.
getCols()) || I.getHeight() !=
static_cast<unsigned int>(zBuffer.
getRows()))
491 " zBuffer must have the same size as the image I ! "));
493 if (cleanPrevImage) {
494 for (
unsigned int i = 0; i < I.getHeight(); i++) {
495 for (
unsigned int j = 0; j < I.getWidth(); j++) {
502 getRoi(I.getWidth(), I.getHeight(), cam, pt, rect);
504 getRoi(I.getWidth(), I.getHeight(), cam, ptClipped, rect);
506 double top = rect.getTop();
507 double bottom = rect.getBottom();
508 double left = rect.getLeft();
509 double right = rect.getRight();
511 vpRGBa *bitmap = I.bitmap;
512 unsigned int width = I.getWidth();
515 for (
unsigned int i =
static_cast<unsigned int>(top); i < static_cast<unsigned int>(bottom); i++) {
516 for (
unsigned int j =
static_cast<unsigned int>(left); j < static_cast<unsigned int>(right); j++) {
522 unsigned char Ipixelplan;
523 if (getPixel(ip, Ipixelplan)) {
524 if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0) {
526 pixelcolor.
R = Ipixelplan;
527 pixelcolor.
G = Ipixelplan;
528 pixelcolor.
B = Ipixelplan;
529 *(bitmap + i * width + j) = pixelcolor;
530 zBuffer[i][j] = Xinter_optim[2];
536 if (getPixel(ip, Ipixelplan)) {
537 if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0) {
538 *(bitmap + i * width + j) = Ipixelplan;
539 zBuffer[i][j] = Xinter_optim[2];
659 unsigned int width = I.getWidth();
660 unsigned int height = I.getHeight();
662 unsigned int nbsimList =
static_cast<unsigned int>(list.size());
669 double topFinal = height + 1;
670 double bottomFinal = -1;
671 double leftFinal = width + 1;
672 double rightFinal = -1;
674 unsigned int unvisible = 0;
675 unsigned int indexSimu = 0;
676 for (std::list<vpImageSimulator>::iterator it = list.begin(); it != list.end(); ++it, ++indexSimu) {
679 simList[indexSimu] = sim;
683 nbsimList = nbsimList - unvisible;
690 for (
unsigned int i = 0; i < nbsimList; i++) {
691 if (!simList[i]->needClipping)
692 simList[i]->getRoi(width, height, cam, simList[i]->pt, simList[i]->rect);
694 simList[i]->getRoi(width, height, cam, simList[i]->ptClipped, simList[i]->rect);
696 if (topFinal > simList[i]->rect.getTop())
697 topFinal = simList[i]->rect.
getTop();
698 if (bottomFinal < simList[i]->rect.getBottom())
699 bottomFinal = simList[i]->rect.
getBottom();
700 if (leftFinal > simList[i]->rect.getLeft())
701 leftFinal = simList[i]->rect.
getLeft();
702 if (rightFinal < simList[i]->rect.getRight())
703 rightFinal = simList[i]->rect.
getRight();
708 unsigned char *bitmap = I.bitmap;
711 for (
unsigned int i =
static_cast<unsigned int>(topFinal); i < static_cast<unsigned int>(bottomFinal); i++) {
712 for (
unsigned int j =
static_cast<unsigned int>(leftFinal); j < static_cast<unsigned int>(rightFinal); j++) {
718 for (
int k = 0; k < static_cast<int>(nbsimList); k++) {
720 if (simList[k]->getPixelDepth(ip, z)) {
721 if (z < zmin || zmin < 0) {
729 unsigned char Ipixelplan = 255;
730 simList[indice]->getPixel(ip, Ipixelplan);
731 *(bitmap + i * width + j) = Ipixelplan;
733 else if (simList[indice]->colorI ==
COLORED) {
734 vpRGBa Ipixelplan(255, 255, 255);
735 simList[indice]->getPixel(ip, Ipixelplan);
736 unsigned char pixelgrey =
737 static_cast<unsigned char>(0.2126 * Ipixelplan.
R + 0.7152 * Ipixelplan.
G + 0.0722 * Ipixelplan.
B);
738 *(bitmap + i * width + j) = pixelgrey;
859 unsigned int width = I.getWidth();
860 unsigned int height = I.getHeight();
862 unsigned int nbsimList =
static_cast<unsigned int>(list.size());
869 double topFinal = height + 1;
870 double bottomFinal = -1;
871 double leftFinal = width + 1;
872 double rightFinal = -1;
874 unsigned int unvisible = 0;
875 unsigned int indexSimu = 0;
876 for (std::list<vpImageSimulator>::iterator it = list.begin(); it != list.end(); ++it, ++indexSimu) {
879 simList[indexSimu] = sim;
884 nbsimList = nbsimList - unvisible;
891 for (
unsigned int i = 0; i < nbsimList; i++) {
892 if (!simList[i]->needClipping)
893 simList[i]->getRoi(width, height, cam, simList[i]->pt, simList[i]->rect);
895 simList[i]->getRoi(width, height, cam, simList[i]->ptClipped, simList[i]->rect);
897 if (topFinal > simList[i]->rect.getTop())
898 topFinal = simList[i]->rect.
getTop();
899 if (bottomFinal < simList[i]->rect.getBottom())
900 bottomFinal = simList[i]->rect.
getBottom();
901 if (leftFinal > simList[i]->rect.getLeft())
902 leftFinal = simList[i]->rect.
getLeft();
903 if (rightFinal < simList[i]->rect.getRight())
904 rightFinal = simList[i]->rect.
getRight();
909 vpRGBa *bitmap = I.bitmap;
912 for (
unsigned int i =
static_cast<unsigned int>(topFinal); i < static_cast<unsigned int>(bottomFinal); i++) {
913 for (
unsigned int j =
static_cast<unsigned int>(leftFinal); j < static_cast<unsigned int>(rightFinal); j++) {
919 for (
int k = 0; k < static_cast<int>(nbsimList); k++) {
921 if (simList[k]->getPixelDepth(ip, z)) {
922 if (z < zmin || zmin < 0) {
930 unsigned char Ipixelplan = 255;
931 simList[indice]->getPixel(ip, Ipixelplan);
933 pixelcolor.
R = Ipixelplan;
934 pixelcolor.
G = Ipixelplan;
935 pixelcolor.
B = Ipixelplan;
936 *(bitmap + i * width + j) = pixelcolor;
938 else if (simList[indice]->colorI ==
COLORED) {
939 vpRGBa Ipixelplan(255, 255, 255);
940 simList[indice]->getPixel(ip, Ipixelplan);
943 *(bitmap + i * width + j) = Ipixelplan;
962 needClipping =
false;
964 normal_Cam = R * normal_obj;
968 for (
unsigned int i = 0; i < 4; i++)
975 e1[0] = pt[1].get_X() - pt[0].get_X();
976 e1[1] = pt[1].get_Y() - pt[0].get_Y();
977 e1[2] = pt[1].get_Z() - pt[0].get_Z();
979 e2[0] = pt[2].get_X() - pt[1].get_X();
980 e2[1] = pt[2].get_Y() - pt[1].get_Y();
981 e2[2] = pt[2].get_Z() - pt[1].get_Z();
985 double angle = pt[0].get_X() * facenormal[0] + pt[0].get_Y() * facenormal[1] + pt[0].get_Z() * facenormal[2];
995 for (
unsigned int i = 0; i < 4; i++) {
996 project(X[i], cMt, X2[i]);
998 if (pt[i].get_Z() < 0)
1002 vbase_u = X2[1] - X2[0];
1003 vbase_v = X2[3] - X2[0];
1012 for (
unsigned int i = 0; i < 3; i++) {
1013 normal_Cam_optim[i] = normal_Cam[i];
1014 X0_2_optim[i] = X2[0][i];
1015 vbase_u_optim[i] = vbase_u[i];
1016 vbase_v_optim[i] = vbase_v[i];
1019 std::vector<vpPoint> *ptPtr = &pt;
1025 listTriangle.clear();
1026 for (
unsigned int i = 1; i < (*ptPtr).size() - 1; i++) {
1028 ip1.
set_j((*ptPtr)[0].get_x());
1029 ip1.
set_i((*ptPtr)[0].get_y());
1031 ip2.
set_j((*ptPtr)[i].get_x());
1032 ip2.
set_i((*ptPtr)[i].get_y());
1034 ip3.
set_j((*ptPtr)[i + 1].get_x());
1035 ip3.
set_i((*ptPtr)[i + 1].get_y());
1038 listTriangle.push_back(tri);
1045 for (
unsigned int i = 0; i < 4; i++) {
1047 pt[i].setWorldCoordinates(X_[i][0], X_[i][1], X_[i][2]);
1051 normal_obj = normal_obj / normal_obj.frobeniusNorm();
1053 frobeniusNorm_u = (X[1] - X[0]).frobeniusNorm();
1054 fronbniusNorm_v = (X[3] - X[0]).frobeniusNorm();
1099#ifdef VISP_HAVE_MODULE_IO
1140 if (X_.size() != 4) {
1144 for (
unsigned int i = 0; i < 4; ++i) {
1146 Xvec[i][0] = X_[i].get_oX();
1147 Xvec[i][1] = X_[i].get_oY();
1148 Xvec[i][2] = X_[i].get_oZ();
1172 if (X_.size() != 4) {
1176 for (
unsigned int i = 0; i < 4; ++i) {
1178 Xvec[i][0] = X_[i].get_oX();
1179 Xvec[i][1] = X_[i].get_oY();
1180 Xvec[i][2] = X_[i].get_oZ();
1188#ifdef VISP_HAVE_MODULE_IO
1207 if (X_.size() != 4) {
1211 for (
unsigned int i = 0; i < 4; ++i) {
1213 Xvec[i][0] = X_[i].get_oX();
1214 Xvec[i][1] = X_[i].get_oY();
1215 Xvec[i][2] = X_[i].get_oZ();
1224bool vpImageSimulator::getPixel(
const vpImagePoint &iP,
unsigned char &Ipixelplan)
1228 bool inside =
false;
1229 for (
unsigned int i = 0; i < listTriangle.size(); i++)
1230 if (listTriangle[i].inTriangle(iP)) {
1246 z = distance / (normal_Cam_optim[0] * iP.
get_u() + normal_Cam_optim[1] * iP.
get_v() + normal_Cam_optim[2]);
1248 Xinter_optim[0] = iP.
get_u() *
z;
1249 Xinter_optim[1] = iP.
get_v() *
z;
1250 Xinter_optim[2] =
z;
1258 double u = 0,
v = 0;
1259 for (
unsigned int i = 0;
i < 3;
i++) {
1260 double diff = (Xinter_optim[
i] - X0_2_optim[
i]);
1261 u += diff * vbase_u_optim[
i];
1262 v += diff * vbase_v_optim[
i];
1264 u =
u / (frobeniusNorm_u * frobeniusNorm_u);
1265 v =
v / (fronbniusNorm_v * fronbniusNorm_v);
1267 if (u > 0 && v > 0 && u < 1. && v < 1.) {
1269 i2 =
v * (Ig.getHeight() - 1);
1270 j2 =
u * (Ig.getWidth() - 1);
1272 Ipixelplan = Ig.getValue(i2, j2);
1273 else if (interp ==
SIMPLE)
1274 Ipixelplan = Ig[
static_cast<unsigned int>(i2)][
static_cast<unsigned int>(j2)];
1284 bool inside =
false;
1285 for (
unsigned int i = 0;
i < listTriangle.size();
i++)
1286 if (listTriangle[i].inTriangle(iP)) {
1300 z = distance / (normal_Cam_optim[0] * iP.
get_u() + normal_Cam_optim[1] * iP.
get_v() + normal_Cam_optim[2]);
1302 Xinter_optim[0] = iP.
get_u() *
z;
1303 Xinter_optim[1] = iP.
get_v() *
z;
1304 Xinter_optim[2] =
z;
1312 double u = 0,
v = 0;
1313 for (
unsigned int i = 0;
i < 3;
i++) {
1314 double diff = (Xinter_optim[
i] - X0_2_optim[
i]);
1315 u += diff * vbase_u_optim[
i];
1316 v += diff * vbase_v_optim[
i];
1318 u =
u / (frobeniusNorm_u * frobeniusNorm_u);
1319 v =
v / (fronbniusNorm_v * fronbniusNorm_v);
1321 if (u > 0 && v > 0 && u < 1. && v < 1.) {
1326 Ipixelplan = Isrc.
getValue(i2, j2);
1327 else if (interp ==
SIMPLE)
1328 Ipixelplan = Isrc[
static_cast<unsigned int>(i2)][
static_cast<unsigned int>(j2)];
1338 bool inside =
false;
1339 for (
unsigned int i = 0;
i < listTriangle.size();
i++)
1340 if (listTriangle[i].inTriangle(iP)) {
1353 z = distance / (normal_Cam_optim[0] * iP.
get_u() + normal_Cam_optim[1] * iP.
get_v() + normal_Cam_optim[2]);
1355 Xinter_optim[0] = iP.
get_u() *
z;
1356 Xinter_optim[1] = iP.
get_v() *
z;
1357 Xinter_optim[2] =
z;
1365 double u = 0,
v = 0;
1366 for (
unsigned int i = 0;
i < 3;
i++) {
1367 double diff = (Xinter_optim[
i] - X0_2_optim[
i]);
1368 u += diff * vbase_u_optim[
i];
1369 v += diff * vbase_v_optim[
i];
1371 u =
u / (frobeniusNorm_u * frobeniusNorm_u);
1372 v =
v / (fronbniusNorm_v * fronbniusNorm_v);
1374 if (u > 0 && v > 0 && u < 1. && v < 1.) {
1376 i2 =
v * (Ic.getHeight() - 1);
1377 j2 =
u * (Ic.getWidth() - 1);
1379 Ipixelplan = Ic.getValue(i2, j2);
1380 else if (interp ==
SIMPLE)
1381 Ipixelplan = Ic[
static_cast<unsigned int>(i2)][
static_cast<unsigned int>(j2)];
1393 bool inside =
false;
1394 for (
unsigned int i = 0;
i < listTriangle.size();
i++)
1395 if (listTriangle[i].inTriangle(iP)) {
1406 z = distance / (normal_Cam_optim[0] * iP.
get_u() + normal_Cam_optim[1] * iP.
get_v() + normal_Cam_optim[2]);
1408 Xinter_optim[0] = iP.
get_u() *
z;
1409 Xinter_optim[1] = iP.
get_v() *
z;
1410 Xinter_optim[2] =
z;
1418 double u = 0,
v = 0;
1419 for (
unsigned int i = 0;
i < 3;
i++) {
1420 double diff = (Xinter_optim[
i] - X0_2_optim[
i]);
1421 u += diff * vbase_u_optim[
i];
1422 v += diff * vbase_v_optim[
i];
1424 u =
u / (frobeniusNorm_u * frobeniusNorm_u);
1425 v =
v / (fronbniusNorm_v * fronbniusNorm_v);
1427 if (u > 0 && v > 0 && u < 1. && v < 1.) {
1432 Ipixelplan = Isrc.
getValue(i2, j2);
1433 else if (interp ==
SIMPLE)
1434 Ipixelplan = Isrc[
static_cast<unsigned int>(i2)][
static_cast<unsigned int>(j2)];
1441bool vpImageSimulator::getPixelDepth(
const vpImagePoint &iP,
double &Zpixelplan)
1444 bool inside =
false;
1445 for (
unsigned int i = 0;
i < listTriangle.size();
i++)
1446 if (listTriangle[i].inTriangle(iP)) {
1455 Zpixelplan = distance / (normal_Cam_optim[0] * iP.
get_u() + normal_Cam_optim[1] * iP.
get_v() + normal_Cam_optim[2]);
1459bool vpImageSimulator::getPixelVisibility(
const vpImagePoint &iP,
double &Visipixelplan)
1462 bool inside =
false;
1463 for (
unsigned int i = 0;
i < listTriangle.size();
i++)
1464 if (listTriangle[i].inTriangle(iP)) {
1473 Visipixelplan = visible_result;
1480 getHomogCoord(_vin, XH);
1481 getCoordFromHomog(_cMt * XH, _vout);
1486 for (
unsigned int i = 0;
i < 3;
i++)
1493 for (
unsigned int i = 0;
i < 3;
i++)
1494 _v[i] = _vH[i] / _vH[3];
1497void vpImageSimulator::getRoi(
const unsigned int &Iwidth,
const unsigned int &Iheight,
const vpCameraParameters &cam,
1498 const std::vector<vpPoint> &point,
vpRect &rectangle)
1500 double top = Iheight + 1;
1503 double left = Iwidth + 1;
1505 for (
unsigned int i = 0;
i < point.size();
i++) {
1506 double u = 0,
v = 0;
1523 if (bottom >= Iheight)
1524 bottom = Iheight - 1;
1531 if (right >= Iwidth)
1542 std::vector<vpColVector> X_;
1543 for (
int i = 0; i < 4; i++)
unsigned int getCols() const
unsigned int getRows() const
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
static double dotProd(const vpColVector &a, const vpColVector &b)
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
void resize(unsigned int i, bool flagNullify=true)
Class to define RGB colors available for display functionalities.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_ij(double ii, double jj)
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
VP_EXPLICIT vpImageSimulator(const vpColorPlan &col=COLORED)
std::vector< vpColVector > get3DcornersTextureRectangle()
void init(const vpImage< unsigned char > &I, vpColVector *X)
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpImageSimulator &)
void setCameraPosition(const vpHomogeneousMatrix &cMt)
vpImageSimulator & operator=(const vpImageSimulator &sim)
virtual ~vpImageSimulator()
Definition of the vpImage class member functions.
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Type getValue(unsigned int i, unsigned int j) const
unsigned int getHeight() const
error that can be emitted by the vpMatrix class and its derivatives
@ incorrectMatrixSizeError
Incorrect matrix size.
Implementation of a matrix and operations on matrices.
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
static void getClippedPolygon(const std::vector< vpPoint > &ptIn, std::vector< vpPoint > &ptOut, const vpHomogeneousMatrix &cMo, const unsigned int &clippingFlags, const vpCameraParameters &cam=vpCameraParameters(), const double &znear=0.001, const double &zfar=100)
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
Defines a rectangle in the plane.
void setRight(double pos)
void setBottom(double pos)
Implementation of a rotation matrix and operations on such kind of matrices.