47 #include <visp/vpConfig.h>
53 #include <visp/vpMbtPolygon.h>
135 for (
unsigned int i = 0 ; i <
nbpt ; i++)
188 for (
unsigned int i = 0; i <
nbpt; i += 1){
193 e4[0] = -pt.
get_X()/(double)nbpt; e4[1] = -pt.
get_Y()/(double)nbpt; e4[2] = -pt.
get_Z()/(double)nbpt;
197 double angle = acos(cos_angle);
207 if(modulo && (M_PI - angle) < alpha){
216 else if (modulo && (M_PI - angle) < alpha+
vpMath::rad(1) ){
234 roiPointsClip = std::vector<std::pair<vpPoint,unsigned int> >();
235 std::vector<vpColVector> fovNormals;
240 for (
unsigned int i = 0; i <
nbpt; i ++){
242 unsigned int p1ClippedInfo, p2ClippedInfo;
244 if(vpMbtPolygon::getClippedPoints(
p[i],
p[(i+1)%nbpt], p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo, cam, fovNormals)){
246 roiPointsClip.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
250 roiPointsClip.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
256 roiPointsClip.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
283 vpMbtPolygon::getClippedPointsFov(
const vpPoint &p1,
const vpPoint &p2,
285 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
286 const vpColVector &normal,
const unsigned int &flag)
290 p1Vec = p1Vec.normalize();
294 p2Vec = p2Vec.normalize();
297 double beta1 = acos( p1Vec * normal );
298 double beta2 = acos( p2Vec * normal );
300 if(beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
302 else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0){
304 double t = -(normal[0] * p1.
get_X() + normal[1] * p1.
get_Y() + normal[2] * p1.
get_Z());
311 if(beta1 < M_PI / 2.0){
312 p1ClippedInfo = p1ClippedInfo | flag;
313 p1Clipped = pClipped;
316 p2ClippedInfo = p2ClippedInfo | flag;
317 p2Clipped = pClipped;
339 vpMbtPolygon::getClippedPoints(
const vpPoint &p1,
const vpPoint &p2,
341 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
358 double t = (p2Clipped.
get_Z() - p1Clipped.
get_Z());
366 p1Clipped = pClippedNear;
370 p2Clipped = pClippedNear;
379 vpTRACE(
"Field of view not computed, left clipping skipped.");
380 else if(!getClippedPointsFov(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
381 fovNormals[0], vpMbtPolygon::LEFT_CLIPPING))
388 vpTRACE(
"Field of view not computed, right clipping skipped.");
389 else if(!getClippedPointsFov(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
390 fovNormals[1], vpMbtPolygon::RIGHT_CLIPPING))
397 vpTRACE(
"Field of view not computed, up clipping skipped.");
398 else if(!getClippedPointsFov(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
399 fovNormals[2], vpMbtPolygon::UP_CLIPPING))
406 vpTRACE(
"Field of view not computed, down clipping skipped.");
407 else if(!getClippedPointsFov(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
408 fovNormals[3], vpMbtPolygon::DOWN_CLIPPING))
418 double t = (p2Clipped.
get_Z() - p1Clipped.
get_Z());
426 p1Clipped = pClippedFar;
430 p2Clipped = pClippedFar;
449 std::vector<vpImagePoint>
452 std::vector<vpImagePoint> roi;
453 for (
unsigned int i = 0; i <
nbpt; i ++){
470 std::vector<vpImagePoint>
554 unsigned int nbPolyIn = 0;
555 for (
unsigned int i = 0; i <
nbpt; i ++){
556 if(
p[i].get_Z() > 0){
577 double i_min_d = (double) INT_MAX;
579 double j_min_d = (double) INT_MAX;
582 for (
unsigned int i = 0; i < iroi.size(); i += 1){
583 if(i_min_d > iroi[i].get_i())
584 i_min_d = iroi[i].get_i();
586 if(iroi[i].get_i() < 0)
589 if((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
590 i_max_d = iroi[i].get_i();
592 if(j_min_d > iroi[i].get_j())
593 j_min_d = iroi[i].get_j();
595 if(iroi[i].get_j() < 0)
598 if((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
599 j_max_d = iroi[i].get_j();
601 i_min =
static_cast<int> (i_min_d);
602 i_max =
static_cast<int> (i_max_d);
603 j_min =
static_cast<int> (j_min_d);
604 j_max =
static_cast<int> (j_max_d);
618 for(
unsigned int i=0; i<corners.size(); ++i){
619 if((corners[i].get_i() >= 0) && (corners[i].get_j() >= 0) &&
625 if(nbPolyIn < 3 && nbPolyIn < 0.7 * corners.size())
631 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
648 for (
unsigned int i = 0 ; i <
nbpt ; i++){
649 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)
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.
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.
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