47 #include <visp/vpConfig.h>
53 #include <visp/vpMbtPolygon.h>
54 #include <visp/vpPolygon.h>
60 : index(-1), nbpt(0), nbCornersInsidePrev(0), isvisible(false), isappearing(false),
61 p(NULL), roiPointsClip(), clippingFlag(
vpMbtPolygon::NO_CLIPPING),
62 distNearClip(0.001), distFarClip(100.),
63 useLod(false), minLineLengthThresh(50.0), minPolygonAreaThresh(2500.0), name(
"")
68 : index(-1), nbpt(0), nbCornersInsidePrev(0), isvisible(false), isappearing(false),
69 p(NULL), roiPointsClip(), clippingFlag(
vpMbtPolygon::NO_CLIPPING),
70 distNearClip(0.001), distFarClip(100.),
71 useLod(false), minLineLengthThresh(50.0), minPolygonAreaThresh(2500.0), name(
"")
94 for(
unsigned int i = 0; i <
nbpt; i++)
163 for (
unsigned int i = 0 ; i <
nbpt ; i++)
201 std::vector<vpImagePoint> roiImagePoints;
204 if (roiImagePoints.size() == 2) {
205 double x1 = roiImagePoints[0].get_u();
206 double y1 = roiImagePoints[0].get_v();
207 double x2 = roiImagePoints[1].get_u();
208 double y2 = roiImagePoints[1].get_v();
209 double length = std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
232 for(
unsigned int i = 0; i<
nbpt; i++) {
233 currentVertex =
p[i].
cP;
234 nextVertex =
p[(i+1) % nbpt].cP;
236 faceNormal[0] += (currentVertex[1] - nextVertex[1]) * (currentVertex[2] + nextVertex[2]);
237 faceNormal[1] += (currentVertex[2] - nextVertex[2]) * (currentVertex[0] + nextVertex[0]);
238 faceNormal[2] += (currentVertex[0] - nextVertex[0]) * (currentVertex[1] + nextVertex[1]);
244 for (
unsigned int i = 0; i <
nbpt; i += 1){
249 e4[0] = -pt.
get_X() / (double)nbpt;
250 e4[1] = -pt.
get_Y() / (double)nbpt;
251 e4[2] = -pt.
get_Z() / (double)nbpt;
258 if( angle < alpha || (modulo && (M_PI - angle) < alpha)) {
268 std::vector<vpImagePoint> roiImagePoints;
272 double area = roiPolygon.
getArea();
288 else if (modulo && (M_PI - angle) < alpha+
vpMath::rad(1) ){
310 std::vector<vpColVector> fovNormals;
311 std::vector<std::pair<vpPoint,unsigned int> > roiPointsClipTemp;
312 std::vector<std::pair<vpPoint,unsigned int> > roiPointsClipTemp2;
317 for(
unsigned int i = 0 ; i <
nbpt ; i++){
323 for(
unsigned int i = 1 ; i < 64 ; i=i*2)
327 for(
unsigned int j = 0 ; j < roiPointsClipTemp.size() ; j++)
329 vpPoint p1Clipped = roiPointsClipTemp[j].first;
330 vpPoint p2Clipped = roiPointsClipTemp[(j+1)%roiPointsClipTemp.size()].first;
332 unsigned int p2ClippedInfoBefore = roiPointsClipTemp[(j+1)%roiPointsClipTemp.size()].second;
333 unsigned int p1ClippedInfo = roiPointsClipTemp[j].second;
334 unsigned int p2ClippedInfo = roiPointsClipTemp[(j+1)%roiPointsClipTemp.size()].second;
340 problem = !(vpMbtPolygon::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
344 problem = !(vpMbtPolygon::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
348 problem = !(vpMbtPolygon::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
352 problem = !(vpMbtPolygon::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
356 problem = !(vpMbtPolygon::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
360 problem = !(vpMbtPolygon::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
368 roiPointsClipTemp2.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
370 if(p2ClippedInfo != p2ClippedInfoBefore)
373 roiPointsClipTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
377 if(p2ClippedInfo == p2ClippedInfoBefore)
380 roiPointsClipTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
387 roiPointsClipTemp = roiPointsClipTemp2;
388 roiPointsClipTemp2.clear();
414 vpMbtPolygon::getClippedPointsFovGeneric(
const vpPoint &p1,
const vpPoint &p2,
416 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
417 const vpColVector &normal,
const unsigned int &flag)
421 p1Vec = p1Vec.normalize();
425 p2Vec = p2Vec.normalize();
428 double beta1 = acos( p1Vec * normal );
429 double beta2 = acos( p2Vec * normal );
434 if(beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
436 else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0){
438 double t = -(normal[0] * p1.
get_X() + normal[1] * p1.
get_Y() + normal[2] * p1.
get_Z());
445 if(beta1 < M_PI / 2.0){
446 p1ClippedInfo = p1ClippedInfo | flag;
447 p1Clipped = pClipped;
450 p2ClippedInfo = p2ClippedInfo | flag;
451 p2Clipped = pClipped;
460 vpMbtPolygon::getClippedPointsDistance(
const vpPoint &p1,
const vpPoint &p2,
462 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
463 const unsigned int &flag,
const double &distance)
468 vpPoint p1Clipped_, p2Clipped_;
472 p1Clipped = p1Clipped_;
473 p2Clipped = p2Clipped_;
476 bool test1 = (p1Clipped.
get_Z() < distance && p2Clipped.
get_Z() < distance);
478 test1 = (p1Clipped.
get_Z() > distance && p2Clipped.
get_Z() > distance);
480 bool test2 = (p1Clipped.
get_Z() < distance || p2Clipped.
get_Z() < distance);
482 test2 = (p1Clipped.
get_Z() > distance || p2Clipped.
get_Z() > distance);
484 bool test3 = (p1Clipped.
get_Z() < distance);
486 test3 = (p1Clipped.
get_Z() > distance);
495 t = (distance - p1Clipped.
get_Z()) / t;
499 pClippedNear.
set_Z(distance);
502 p1Clipped = pClippedNear;
509 p2Clipped = pClippedNear;
529 std::vector<vpImagePoint>
532 std::vector<vpImagePoint> roi;
533 for (
unsigned int i = 0; i <
nbpt; i ++){
550 std::vector<vpImagePoint>
651 unsigned int nbPolyIn = 0;
652 for (
unsigned int i = 0; i <
nbpt; i ++){
653 if(
p[i].get_Z() > 0){
698 for(
unsigned int i = 0; i < ptIn.size(); i++)
710 double i_min_d = (double) INT_MAX;
712 double j_min_d = (double) INT_MAX;
715 for (
unsigned int i = 0; i < iroi.size(); i += 1){
716 if(i_min_d > iroi[i].get_i())
717 i_min_d = iroi[i].get_i();
719 if(iroi[i].get_i() < 0)
722 if((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
723 i_max_d = iroi[i].get_i();
725 if(j_min_d > iroi[i].get_j())
726 j_min_d = iroi[i].get_j();
728 if(iroi[i].get_j() < 0)
731 if((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
732 j_max_d = iroi[i].get_j();
734 i_min =
static_cast<int> (i_min_d);
735 i_max =
static_cast<int> (i_max_d);
736 j_min =
static_cast<int> (j_min_d);
737 j_max =
static_cast<int> (j_max_d);
751 for(
unsigned int i=0; i<corners.size(); ++i){
752 if((corners[i].get_i() >= 0) && (corners[i].get_j() >= 0) &&
758 if(nbPolyIn < 3 && nbPolyIn < 0.7 * corners.size())
815 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
832 for (
unsigned int i = 0 ; i <
nbpt ; i++){
833 if(
p[i].get_Z() < 0){
void setFarClippingDistance(const double &dist)
void setClipping(const unsigned int &flags)
void projection(const vpColVector &_cP, vpColVector &_p)
Projection onto the image plane of a point. Input: the 3D coordinates in the camera frame _cP...
void changeFrame(const vpHomogeneousMatrix &cMo)
unsigned int getNbCornerInsideImage(const vpImage< unsigned char > &I, const vpCameraParameters &cam)
std::string name
Name of the polygon.
unsigned int getWidth() const
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
unsigned int clippingFlag
Clipping flag.
Definition of the row vector class.
bool isFovComputed() const
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
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)
void getRoiClipped(std::vector< vpPoint > &points)
vpPoint & getPoint(const unsigned int _index)
int index
Index of the polygon. Cannot be unsigned int because default value is -1.
error that can be emited by ViSP classes.
unsigned int nbpt
Number of points used to define the polygon.
vpMbtPolygon & operator=(const vpMbtPolygon &mbtp)
void set_X(const double X)
Set the point X coordinate in the camera frame.
void setNearClippingDistance(const double &dist)
unsigned int nbCornersInsidePrev
Number of corners inside the image during the last call to getNbCornerInsideImage.
Class that defines what is a point.
std::vector< std::pair< vpPoint, unsigned int > > roiPointsClip
Region of interest clipped.
double distFarClip
Distance for near clipping.
void addPoint(const unsigned int n, const vpPoint &P)
Defines a generic 2D polygon.
void set_Z(const double Z)
Set the point Z coordinate in the camera frame.
double minLineLengthThresh
Threshold for minimum line length in pixel to consider if the line is visible or not in LOD case...
Implementation of a polygon of the model used by the model-based tracker.
Generic class defining intrinsic camera parameters.
void set_Y(const double Y)
Set the point Y coordinate in the camera frame.
double minPolygonAreaThresh
Threshold for minimum polygon area in pixel to consider if the polygon is visible or not in LOD case...
void computeRoiClipped(const vpCameraParameters &cam=vpCameraParameters())
double get_Y() const
Get the point Y coordinate in the camera frame.
static double rad(double deg)
double get_Z() const
Get the point Z coordinate in the camera frame.
std::vector< vpImagePoint > getRoi(const vpCameraParameters &cam)
bool isappearing
flag to specify whether the face is appearing or not
bool useLod
Flag to specify if the visibility of the polygon depends also of the current level of detail (LOD) ...
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void setLod(const bool use_lod)
std::vector< vpColVector > getFovNormals() const
static double dotProd(const vpColVector &a, const vpColVector &b)
Dot Product.
static void getMinMaxRoi(const std::vector< vpImagePoint > &roi, int &i_min, int &i_max, int &j_min, int &j_max)
unsigned int getHeight() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static bool roiInsideImage(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &corners)
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &_cP)
virtual void setNbPoint(const unsigned int nb)
bool isvisible
flag to specify whether the face is visible or not
vpColVector & normalize()
Normalise the vector.
double get_X() const
Get the point X coordinate in the camera frame.
double distNearClip
Distance for near clipping.
void computeFov(const unsigned int &w, const unsigned int &h)
vpPoint * p
corners in the object frame