47 #include <visp/vpConfig.h>
53 #include <visp/vpMbtPolygon.h>
59 : index(-1), nbpt(0), nbCornersInsidePrev(0), isvisible(false), isappearing(false),
60 p(NULL), roiPointsClip(), clippingFlag(
vpMbtPolygon::NO_CLIPPING),
61 distNearClip(0.001), distFarClip(100.)
66 : index(-1), nbpt(0), nbCornersInsidePrev(0), isvisible(false), isappearing(false),
67 p(NULL), roiPointsClip(), clippingFlag(
vpMbtPolygon::NO_CLIPPING),
68 distNearClip(0.001), distFarClip(100.)
86 for(
unsigned int i = 0; i <
nbpt; i++)
155 for (
unsigned int i = 0 ; i <
nbpt ; i++)
208 for (
unsigned int i = 0; i <
nbpt; i += 1){
213 e4[0] = -pt.
get_X()/(double)nbpt; e4[1] = -pt.
get_Y()/(double)nbpt; e4[2] = -pt.
get_Z()/(double)nbpt;
217 double angle = acos(cos_angle);
227 if(modulo && (M_PI - angle) < alpha){
236 else if (modulo && (M_PI - angle) < alpha+
vpMath::rad(1) ){
254 roiPointsClip = std::vector<std::pair<vpPoint,unsigned int> >();
255 std::vector<vpColVector> fovNormals;
260 for (
unsigned int i = 0; i <
nbpt; i ++){
262 unsigned int p1ClippedInfo, p2ClippedInfo;
264 if(vpMbtPolygon::getClippedPoints(
p[i],
p[(i+1)%nbpt], p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo, cam, fovNormals)){
266 roiPointsClip.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
270 roiPointsClip.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
276 roiPointsClip.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
303 vpMbtPolygon::getClippedPointsFov(
const vpPoint &p1,
const vpPoint &p2,
305 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
306 const vpColVector &normal,
const unsigned int &flag)
310 p1Vec = p1Vec.normalize();
314 p2Vec = p2Vec.normalize();
317 double beta1 = acos( p1Vec * normal );
318 double beta2 = acos( p2Vec * normal );
320 if(beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
322 else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0){
324 double t = -(normal[0] * p1.
get_X() + normal[1] * p1.
get_Y() + normal[2] * p1.
get_Z());
331 if(beta1 < M_PI / 2.0){
332 p1ClippedInfo = p1ClippedInfo | flag;
333 p1Clipped = pClipped;
336 p2ClippedInfo = p2ClippedInfo | flag;
337 p2Clipped = pClipped;
359 vpMbtPolygon::getClippedPoints(
const vpPoint &p1,
const vpPoint &p2,
361 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
378 double t = (p2Clipped.
get_Z() - p1Clipped.
get_Z());
386 p1Clipped = pClippedNear;
390 p2Clipped = pClippedNear;
399 vpTRACE(
"Field of view not computed, left clipping skipped.");
400 else if(!getClippedPointsFov(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
401 fovNormals[0], vpMbtPolygon::LEFT_CLIPPING))
408 vpTRACE(
"Field of view not computed, right clipping skipped.");
409 else if(!getClippedPointsFov(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
410 fovNormals[1], vpMbtPolygon::RIGHT_CLIPPING))
417 vpTRACE(
"Field of view not computed, up clipping skipped.");
418 else if(!getClippedPointsFov(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
419 fovNormals[2], vpMbtPolygon::UP_CLIPPING))
426 vpTRACE(
"Field of view not computed, down clipping skipped.");
427 else if(!getClippedPointsFov(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
428 fovNormals[3], vpMbtPolygon::DOWN_CLIPPING))
438 double t = (p2Clipped.
get_Z() - p1Clipped.
get_Z());
446 p1Clipped = pClippedFar;
450 p2Clipped = pClippedFar;
469 std::vector<vpImagePoint>
472 std::vector<vpImagePoint> roi;
473 for (
unsigned int i = 0; i <
nbpt; i ++){
490 std::vector<vpImagePoint>
574 unsigned int nbPolyIn = 0;
575 for (
unsigned int i = 0; i <
nbpt; i ++){
576 if(
p[i].get_Z() > 0){
597 double i_min_d = (double) INT_MAX;
599 double j_min_d = (double) INT_MAX;
602 for (
unsigned int i = 0; i < iroi.size(); i += 1){
603 if(i_min_d > iroi[i].get_i())
604 i_min_d = iroi[i].get_i();
606 if(iroi[i].get_i() < 0)
609 if((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
610 i_max_d = iroi[i].get_i();
612 if(j_min_d > iroi[i].get_j())
613 j_min_d = iroi[i].get_j();
615 if(iroi[i].get_j() < 0)
618 if((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
619 j_max_d = iroi[i].get_j();
621 i_min =
static_cast<int> (i_min_d);
622 i_max =
static_cast<int> (i_max_d);
623 j_min =
static_cast<int> (j_min_d);
624 j_max =
static_cast<int> (j_max_d);
638 for(
unsigned int i=0; i<corners.size(); ++i){
639 if((corners[i].get_i() >= 0) && (corners[i].get_j() >= 0) &&
645 if(nbPolyIn < 3 && nbPolyIn < 0.7 * corners.size())
651 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
668 for (
unsigned int i = 0 ; i <
nbpt ; i++){
669 if(
p[i].get_Z() < 0){
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)
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 ...
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.
void getRoiClipped(const vpCameraParameters &cam, std::vector< vpImagePoint > &roi)
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.
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)
void set_Z(const double Z)
Set the point Z coordinate in the camera frame.
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.
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
Class that provides a data structure for the column vectors as well as a set of operations on these v...
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)
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
normalise the vector
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.
vpPoint * p
corners in the object frame