46 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpPolygon.h>
49 #include <visp3/core/vpPolygon3D.h>
56 : nbpt(0), nbCornersInsidePrev(0), p(nullptr), polyClipped(), clippingFlag(
vpPolygon3D::NO_CLIPPING),
57 distNearClip(0.001), distFarClip(100.)
61 : nbpt(mbtp.nbpt), nbCornersInsidePrev(mbtp.nbCornersInsidePrev), p(nullptr), polyClipped(mbtp.polyClipped),
62 clippingFlag(mbtp.clippingFlag), distNearClip(mbtp.distNearClip), distFarClip(mbtp.distFarClip)
67 for (
unsigned int i = 0; i <
nbpt; i++)
83 for (
unsigned int i = 0; i <
nbpt; i++)
109 if (_index >=
nbpt) {
148 for (
unsigned int i = 0; i <
nbpt; i++) {
164 std::vector<vpColVector> fovNormals;
165 std::vector<std::pair<vpPoint, unsigned int> > polyClippedTemp;
166 std::vector<std::pair<vpPoint, unsigned int> > polyClippedTemp2;
171 for (
unsigned int i = 0; i <
nbpt; i++) {
177 for (
unsigned int i = 1; i < 64; i = i * 2) {
184 for (
unsigned int j = 0; j < polyClippedTemp.size(); j++) {
185 vpPoint p1Clipped = polyClippedTemp[j].first;
186 vpPoint p2Clipped = polyClippedTemp[(j + 1) % polyClippedTemp.size()].first;
188 unsigned int p2ClippedInfoBefore = polyClippedTemp[(j + 1) % polyClippedTemp.size()].second;
189 unsigned int p1ClippedInfo = polyClippedTemp[j].second;
190 unsigned int p2ClippedInfo = polyClippedTemp[(j + 1) % polyClippedTemp.size()].second;
196 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
200 problem = !(vpPolygon3D::getClippedPointsDistance(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,
220 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
227 polyClippedTemp2.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
229 if (p2ClippedInfo != p2ClippedInfoBefore) {
231 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
235 if (p2ClippedInfo == p2ClippedInfoBefore) {
237 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
244 polyClippedTemp = polyClippedTemp2;
245 polyClippedTemp2.clear();
271 bool vpPolygon3D::getClippedPointsFovGeneric(
const vpPoint &p1,
const vpPoint &p2,
vpPoint &p1Clipped,
272 vpPoint &p2Clipped,
unsigned int &p1ClippedInfo,
273 unsigned int &p2ClippedInfo,
const vpColVector &normal,
274 const unsigned int &flag)
277 p1Vec[0] = p1.
get_X();
278 p1Vec[1] = p1.
get_Y();
279 p1Vec[2] = p1.
get_Z();
283 p2Vec[0] = p2.
get_X();
284 p2Vec[1] = p2.
get_Y();
285 p2Vec[2] = p2.
get_Z();
289 double beta1 = acos(p1Vec * normal);
290 double beta2 = acos(p2Vec * normal);
295 if (beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
297 else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0) {
299 double t = -(normal[0] * p1.
get_X() + normal[1] * p1.
get_Y() + normal[2] * p1.
get_Z());
307 if (beta1 < M_PI / 2.0) {
308 p1ClippedInfo = p1ClippedInfo | flag;
309 p1Clipped = pClipped;
312 p2ClippedInfo = p2ClippedInfo | flag;
313 p2Clipped = pClipped;
322 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
323 const unsigned int &flag,
const double &distance)
328 vpPoint p1Clipped_, p2Clipped_;
332 p1Clipped = p1Clipped_;
333 p2Clipped = p2Clipped_;
335 bool test1 = (p1Clipped.
get_Z() < distance && p2Clipped.
get_Z() < distance);
337 test1 = (p1Clipped.
get_Z() > distance && p2Clipped.
get_Z() > distance);
339 bool test2 = (p1Clipped.
get_Z() < distance || p2Clipped.
get_Z() < distance);
341 test2 = (p1Clipped.
get_Z() > distance || p2Clipped.
get_Z() > distance);
343 bool test3 = (p1Clipped.
get_Z() < distance);
345 test3 = (p1Clipped.
get_Z() > distance);
354 t = (distance - p1Clipped.
get_Z()) / t;
358 pClippedNear.
set_Z(distance);
361 p1Clipped = pClippedNear;
368 p2Clipped = pClippedNear;
390 std::vector<vpImagePoint> roi;
391 for (
unsigned int i = 0; i <
nbpt; i++) {
414 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
425 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
451 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
467 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
504 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
508 roi.push_back(std::make_pair(ip,
polyClipped[i].second));
537 unsigned int nbPolyIn = 0;
538 for (
unsigned int i = 0; i <
nbpt; i++) {
539 if (
p[i].get_Z() > 0) {
587 for (
unsigned int i = 0; i < ptIn.size(); i++)
599 double i_min_d = (double)INT_MAX;
601 double j_min_d = (double)INT_MAX;
604 for (
unsigned int i = 0; i < iroi.size(); i += 1) {
605 if (i_min_d > iroi[i].get_i())
606 i_min_d = iroi[i].get_i();
608 if (iroi[i].get_i() < 0)
611 if ((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
612 i_max_d = iroi[i].get_i();
614 if (j_min_d > iroi[i].get_j())
615 j_min_d = iroi[i].get_j();
617 if (iroi[i].get_j() < 0)
620 if ((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
621 j_max_d = iroi[i].get_j();
623 i_min =
static_cast<int>(i_min_d);
624 i_max =
static_cast<int>(i_max_d);
625 j_min =
static_cast<int>(j_min_d);
626 j_max =
static_cast<int>(j_max_d);
639 for (
unsigned int i = 0; i < corners.size(); ++i) {
640 if ((corners[i].get_i() >= 0) && (corners[i].get_j() >= 0) && (corners[i].get_i() < I.
getHeight()) &&
641 (corners[i].get_j() < I.
getWidth())) {
646 if (nbPolyIn < 3 && nbPolyIn < 0.7 * corners.size())
Generic class defining intrinsic camera parameters.
bool isFovComputed() const
std::vector< vpColVector > getFovNormals() const
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 ...
unsigned int getWidth() const
unsigned int getHeight() const
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.
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE
double get_X() const
Get the point cX coordinate in the camera frame.
Implements a 3D polygon with render functionalities like clipping.
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.