40 #include <visp3/core/vpConfig.h>
46 #include <visp3/core/vpPolygon3D.h>
47 #include <visp3/core/vpPolygon.h>
53 : nbpt(0), nbCornersInsidePrev(0),
54 p(NULL), polyClipped(), clippingFlag(
vpPolygon3D::NO_CLIPPING),
55 distNearClip(0.001), distFarClip(100.)
60 : nbpt(mbtp.nbpt), nbCornersInsidePrev(mbtp.nbCornersInsidePrev),
61 p(NULL), polyClipped(mbtp.polyClipped), clippingFlag(mbtp.clippingFlag),
62 distNearClip(mbtp.distNearClip), distFarClip(mbtp.distFarClip)
66 for(
unsigned int i = 0; i <
nbpt; i++)
81 for(
unsigned int i = 0; i <
nbpt; i++)
150 for (
unsigned int i = 0 ; i <
nbpt ; i++)
168 std::vector<vpColVector> fovNormals;
169 std::vector<std::pair<vpPoint,unsigned int> > polyClippedTemp;
170 std::vector<std::pair<vpPoint,unsigned int> > polyClippedTemp2;
175 for(
unsigned int i = 0 ; i <
nbpt ; i++){
181 for(
unsigned int i = 1 ; i < 64 ; i=i*2)
185 for(
unsigned int j = 0 ; j < polyClippedTemp.size() ; j++)
187 vpPoint p1Clipped = polyClippedTemp[j].first;
188 vpPoint p2Clipped = polyClippedTemp[(j+1)%polyClippedTemp.size()].first;
190 unsigned int p2ClippedInfoBefore = polyClippedTemp[(j+1)%polyClippedTemp.size()].second;
191 unsigned int p1ClippedInfo = polyClippedTemp[j].second;
192 unsigned int p2ClippedInfo = polyClippedTemp[(j+1)%polyClippedTemp.size()].second;
198 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
202 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
206 problem = !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
210 problem = !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
214 problem = !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
218 problem = !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
226 polyClippedTemp2.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
228 if(p2ClippedInfo != p2ClippedInfoBefore)
231 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
235 if(p2ClippedInfo == p2ClippedInfoBefore)
238 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
245 polyClippedTemp = polyClippedTemp2;
246 polyClippedTemp2.clear();
272 vpPolygon3D::getClippedPointsFovGeneric(
const vpPoint &p1,
const vpPoint &p2,
274 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
275 const vpColVector &normal,
const unsigned int &flag)
279 p1Vec = p1Vec.normalize();
283 p2Vec = p2Vec.normalize();
286 double beta1 = acos( p1Vec * normal );
287 double beta2 = acos( p2Vec * normal );
292 if(beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
294 else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0){
296 double t = -(normal[0] * p1.
get_X() + normal[1] * p1.
get_Y() + normal[2] * p1.
get_Z());
303 if(beta1 < M_PI / 2.0){
304 p1ClippedInfo = p1ClippedInfo | flag;
305 p1Clipped = pClipped;
308 p2ClippedInfo = p2ClippedInfo | flag;
309 p2Clipped = pClipped;
318 vpPolygon3D::getClippedPointsDistance(
const vpPoint &p1,
const vpPoint &p2,
320 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
321 const unsigned int &flag,
const double &distance)
326 vpPoint p1Clipped_, p2Clipped_;
330 p1Clipped = p1Clipped_;
331 p2Clipped = p2Clipped_;
334 bool test1 = (p1Clipped.
get_Z() < distance && p2Clipped.
get_Z() < distance);
336 test1 = (p1Clipped.
get_Z() > distance && p2Clipped.
get_Z() > distance);
338 bool test2 = (p1Clipped.
get_Z() < distance || p2Clipped.
get_Z() < distance);
340 test2 = (p1Clipped.
get_Z() > distance || p2Clipped.
get_Z() > distance);
342 bool test3 = (p1Clipped.
get_Z() < distance);
344 test3 = (p1Clipped.
get_Z() > distance);
353 t = (distance - p1Clipped.
get_Z()) / t;
357 pClippedNear.
set_Z(distance);
360 p1Clipped = pClippedNear;
367 p2Clipped = pClippedNear;
387 std::vector<vpImagePoint>
390 std::vector<vpImagePoint> roi;
391 for (
unsigned int i = 0; i <
nbpt; i ++){
408 std::vector<vpImagePoint>
415 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
426 for(
unsigned int i = 0 ; i <
polyClipped.size() ; i++){
455 for(
unsigned int i = 0 ; i <
polyClipped.size() ; i++){
471 for(
unsigned int i = 0 ; i <
polyClipped.size() ; i++){
505 for(
unsigned int i = 0 ; i <
polyClipped.size() ; i++){
509 roi.push_back(std::make_pair(ip,
polyClipped[i].second));
539 unsigned int nbPolyIn = 0;
540 for (
unsigned int i = 0; i <
nbpt; i ++){
541 if(
p[i].get_Z() > 0){
586 for(
unsigned int i = 0; i < ptIn.size(); i++)
598 double i_min_d = (double) INT_MAX;
600 double j_min_d = (double) INT_MAX;
603 for (
unsigned int i = 0; i < iroi.size(); i += 1){
604 if(i_min_d > iroi[i].get_i())
605 i_min_d = iroi[i].get_i();
607 if(iroi[i].get_i() < 0)
610 if((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
611 i_max_d = iroi[i].get_i();
613 if(j_min_d > iroi[i].get_j())
614 j_min_d = iroi[i].get_j();
616 if(iroi[i].get_j() < 0)
619 if((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
620 j_max_d = iroi[i].get_j();
622 i_min =
static_cast<int> (i_min_d);
623 i_max =
static_cast<int> (i_max_d);
624 j_min =
static_cast<int> (j_min_d);
625 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) &&
646 if(nbPolyIn < 3 && nbPolyIn < 0.7 * corners.size())
void getRoiClipped(const vpCameraParameters &cam, std::vector< vpImagePoint > &roi)
void projection(const vpColVector &_cP, vpColVector &_p)
Projection onto the image plane of a point. Input: the 3D coordinates in the camera frame _cP...
Implements a 3D polygon with render functionnalities like clipping.
virtual void setNbPoint(const unsigned int nb)
unsigned int nbCornersInsidePrev
Number of corners inside the image during the last call to getNbCornerInsideImage.
static bool roiInsideImage(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &corners)
unsigned int getWidth() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of row vector and the associated operations.
bool isFovComputed() const
void setFarClippingDistance(const double &dist)
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 ...
error that can be emited by ViSP classes.
vpPoint * p
corners in the object frame
void set_X(const double X)
Set the point X coordinate in the camera frame.
static void getMinMaxRoi(const std::vector< vpImagePoint > &roi, int &i_min, int &i_max, int &j_min, int &j_max)
Class that defines what is a point.
void changeFrame(const vpHomogeneousMatrix &cMo)
void set_Z(const double Z)
Set the point Z coordinate in the camera frame.
vpPoint & getPoint(const unsigned int _index)
void computePolygonClipped(const vpCameraParameters &cam=vpCameraParameters())
double distFarClip
Distance for near clipping.
double distNearClip
Distance for near clipping.
void addPoint(const unsigned int n, const vpPoint &P)
void getPolygonClipped(std::vector< std::pair< vpPoint, unsigned int > > &poly)
Generic class defining intrinsic camera parameters.
unsigned int getNbCornerInsideImage(const vpImage< unsigned char > &I, const vpCameraParameters &cam)
void set_Y(const double Y)
Set the point Y coordinate in the camera frame.
vpPolygon3D & operator=(const vpPolygon3D &mbtp)
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
double get_Y() const
Get the point Y coordinate in the camera frame.
void setClipping(const unsigned int &flags)
double get_Z() const
Get the point Z coordinate in the camera frame.
unsigned int nbpt
Number of points used to define the polygon.
std::vector< vpImagePoint > getRoi(const vpCameraParameters &cam)
Implementation of column vector and the associated operations.
std::vector< vpColVector > getFovNormals() const
void setNearClippingDistance(const double &dist)
unsigned int getHeight() const
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)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int clippingFlag
Clipping flag.
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &_cP)
double get_X() const
Get the point X coordinate in the camera frame.