41#include <visp3/core/vpConfig.h>
43#include <visp3/core/vpPolygon.h>
44#include <visp3/core/vpPolygon3D.h>
62 for (
unsigned int i = 0; i <
nbpt; i++)
78 for (
unsigned int i = 0; i <
nbpt; i++)
104 if (_index >=
nbpt) {
143 for (
unsigned int i = 0; i <
nbpt; i++) {
144 p[i].changeFrame(cMo);
159 std::vector<vpColVector> fovNormals;
160 std::vector<std::pair<vpPoint, unsigned int> > polyClippedTemp;
161 std::vector<std::pair<vpPoint, unsigned int> > polyClippedTemp2;
164 fovNormals = cam.getFovNormals();
166 for (
unsigned int i = 0; i <
nbpt; i++) {
167 p[i %
nbpt].projection();
172 for (
unsigned int i = 1; i < 64; i = i * 2) {
179 for (
unsigned int j = 0; j < polyClippedTemp.size(); j++) {
180 vpPoint p1Clipped = polyClippedTemp[j].first;
181 vpPoint p2Clipped = polyClippedTemp[(j + 1) % polyClippedTemp.size()].first;
183 unsigned int p2ClippedInfoBefore = polyClippedTemp[(j + 1) % polyClippedTemp.size()].second;
184 unsigned int p1ClippedInfo = polyClippedTemp[j].second;
185 unsigned int p2ClippedInfo = polyClippedTemp[(j + 1) % polyClippedTemp.size()].second;
191 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
195 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
200 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
205 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
210 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
215 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
222 polyClippedTemp2.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
224 if (p2ClippedInfo != p2ClippedInfoBefore) {
226 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
230 if (p2ClippedInfo == p2ClippedInfoBefore) {
232 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
239 polyClippedTemp = polyClippedTemp2;
240 polyClippedTemp2.clear();
262bool vpPolygon3D::getClippedPointsFovGeneric(
const vpPoint &p1,
const vpPoint &p2,
vpPoint &p1Clipped,
263 vpPoint &p2Clipped,
unsigned int &p1ClippedInfo,
264 unsigned int &p2ClippedInfo,
const vpColVector &normal,
265 const unsigned int &flag)
268 p1Vec[0] = p1.
get_X();
269 p1Vec[1] = p1.
get_Y();
270 p1Vec[2] = p1.
get_Z();
274 p2Vec[0] = p2.
get_X();
275 p2Vec[1] = p2.
get_Y();
276 p2Vec[2] = p2.
get_Z();
280 double beta1 = acos(p1Vec * normal);
281 double beta2 = acos(p2Vec * normal);
286 if (beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
288 else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0) {
290 double t = -(normal[0] * p1.
get_X() + normal[1] * p1.
get_Y() + normal[2] * p1.
get_Z());
298 if (beta1 < M_PI / 2.0) {
299 p1ClippedInfo = p1ClippedInfo | flag;
300 p1Clipped = pClipped;
303 p2ClippedInfo = p2ClippedInfo | flag;
304 p2Clipped = pClipped;
313 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
314 const unsigned int &flag,
const double &distance)
319 vpPoint p1Clipped_, p2Clipped_;
323 p1Clipped = p1Clipped_;
324 p2Clipped = p2Clipped_;
326 bool test1 = (p1Clipped.
get_Z() < distance && p2Clipped.
get_Z() < distance);
328 test1 = (p1Clipped.
get_Z() > distance && p2Clipped.
get_Z() > distance);
330 bool test2 = (p1Clipped.
get_Z() < distance || p2Clipped.
get_Z() < distance);
332 test2 = (p1Clipped.
get_Z() > distance || p2Clipped.
get_Z() > distance);
334 bool test3 = (p1Clipped.
get_Z() < distance);
336 test3 = (p1Clipped.
get_Z() > distance);
342 vpPoint pClippedNear;
345 t = (distance - p1Clipped.
get_Z()) /
t;
349 pClippedNear.
set_Z(distance);
352 p1Clipped = pClippedNear;
359 p2Clipped = pClippedNear;
381 std::vector<vpImagePoint> roi;
382 for (
unsigned int i = 0; i <
nbpt; i++) {
405#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
416 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
442 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
458 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
495 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
499 roi.push_back(std::make_pair(ip,
polyClipped[i].second));
528 unsigned int nbPolyIn = 0;
529 for (
unsigned int i = 0; i <
nbpt; i++) {
530 if (
p[i].get_Z() > 0) {
533 if ((ip.
get_i() >= 0) && (ip.
get_j() >= 0) && (ip.
get_i() < I.getHeight()) && (ip.
get_j() < I.getWidth()))
567 poly.
setNbPoint(
static_cast<unsigned int>(ptIn.size()));
576 for (
unsigned int i = 0; i < ptIn.size(); i++)
588 double i_min_d =
static_cast<double>(INT_MAX);
590 double j_min_d =
static_cast<double>(INT_MAX);
593 for (
unsigned int i = 0; i < iroi.size(); i += 1) {
594 if (i_min_d > iroi[i].get_i())
595 i_min_d = iroi[i].get_i();
597 if (iroi[i].get_i() < 0)
600 if ((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
601 i_max_d = iroi[i].get_i();
603 if (j_min_d > iroi[i].get_j())
604 j_min_d = iroi[i].get_j();
606 if (iroi[i].get_j() < 0)
609 if ((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
610 j_max_d = iroi[i].get_j();
612 i_min =
static_cast<int>(i_min_d);
613 i_max =
static_cast<int>(i_max_d);
614 j_min =
static_cast<int>(j_min_d);
615 j_max =
static_cast<int>(j_max_d);
628 for (
unsigned int i = 0; i < corners.size(); ++i) {
629 if ((corners[i].get_i() >= 0) && (corners[i].get_j() >= 0) && (corners[i].get_i() < I.getHeight()) &&
630 (corners[i].get_j() < I.getWidth())) {
635 if (nbPolyIn < 3 && nbPolyIn < 0.7 * corners.size())
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void projection(const vpColVector &_cP, vpColVector &_p) const VP_OVERRIDE
double get_Y() const
Get the point cY coordinate in the camera frame.
void set_X(double cX)
Set the point cX coordinate in the camera frame.
void set_Y(double cY)
Set the point cY coordinate in the camera frame.
double get_Z() const
Get the point cZ coordinate in the camera frame.
void set_Z(double cZ)
Set the point cZ coordinate in the camera frame.
double get_X() const
Get the point cX coordinate in the camera frame.
void changeFrame(const vpHomogeneousMatrix &cMo)
void setFarClippingDistance(const double &dist)
unsigned int nbpt
Number of points used to define the polygon.
void setNearClippingDistance(const double &dist)
double distNearClip
Distance for near clipping.
vpPoint & getPoint(const unsigned int _index)
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)
vpPoint * p
corners in the object frame
void computePolygonClipped(const vpCameraParameters &cam=vpCameraParameters())
static bool roiInsideImage(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &corners)
std::vector< vpImagePoint > getRoi(const vpCameraParameters &cam)
virtual void setNbPoint(unsigned int nb)
unsigned int clippingFlag
Clipping flag.
void setClipping(const unsigned int &flags)
void getRoiClipped(const vpCameraParameters &cam, std::vector< vpImagePoint > &roi)
unsigned int getNbCornerInsideImage(const vpImage< unsigned char > &I, const vpCameraParameters &cam)
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
void addPoint(unsigned int n, const vpPoint &P)
double distFarClip
Distance for near clipping.
void getPolygonClipped(std::vector< std::pair< vpPoint, unsigned int > > &poly)
vpPolygon3D & operator=(const vpPolygon3D &mbtp)
unsigned int nbCornersInsidePrev
static void getMinMaxRoi(const std::vector< vpImagePoint > &roi, int &i_min, int &i_max, int &j_min, int &j_max)
Implementation of row vector and the associated operations.