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.)
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)
188 for(
unsigned int j = 0 ; j < polyClippedTemp.size() ; j++)
190 vpPoint p1Clipped = polyClippedTemp[j].first;
191 vpPoint p2Clipped = polyClippedTemp[(j+1)%polyClippedTemp.size()].first;
193 unsigned int p2ClippedInfoBefore = polyClippedTemp[(j+1)%polyClippedTemp.size()].second;
194 unsigned int p1ClippedInfo = polyClippedTemp[j].second;
195 unsigned int p2ClippedInfo = polyClippedTemp[(j+1)%polyClippedTemp.size()].second;
201 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
205 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
209 problem = !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
213 problem = !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
217 problem = !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
221 problem = !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
229 polyClippedTemp2.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
231 if(p2ClippedInfo != p2ClippedInfoBefore)
234 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
238 if(p2ClippedInfo == p2ClippedInfoBefore)
241 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
248 polyClippedTemp = polyClippedTemp2;
249 polyClippedTemp2.clear();
276 vpPolygon3D::getClippedPointsFovGeneric(
const vpPoint &p1,
const vpPoint &p2,
278 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
279 const vpColVector &normal,
const unsigned int &flag)
290 double beta1 = acos( p1Vec * normal );
291 double beta2 = acos( p2Vec * normal );
296 if(beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
298 else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0){
300 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 vpPolygon3D::getClippedPointsDistance(
const vpPoint &p1,
const vpPoint &p2,
324 unsigned int &p1ClippedInfo,
unsigned int &p2ClippedInfo,
325 const unsigned int &flag,
const double &distance)
330 vpPoint p1Clipped_, p2Clipped_;
334 p1Clipped = p1Clipped_;
335 p2Clipped = p2Clipped_;
338 bool test1 = (p1Clipped.
get_Z() < distance && p2Clipped.
get_Z() < distance);
340 test1 = (p1Clipped.
get_Z() > distance && p2Clipped.
get_Z() > distance);
342 bool test2 = (p1Clipped.
get_Z() < distance || p2Clipped.
get_Z() < distance);
344 test2 = (p1Clipped.
get_Z() > distance || p2Clipped.
get_Z() > distance);
346 bool test3 = (p1Clipped.
get_Z() < distance);
348 test3 = (p1Clipped.
get_Z() > distance);
357 t = (distance - p1Clipped.
get_Z()) / t;
361 pClippedNear.
set_Z(distance);
364 p1Clipped = pClippedNear;
371 p2Clipped = pClippedNear;
391 std::vector<vpImagePoint>
394 std::vector<vpImagePoint> roi;
395 for (
unsigned int i = 0; i <
nbpt; i ++){
412 std::vector<vpImagePoint>
419 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS 430 for(
unsigned int i = 0 ; i <
polyClipped.size() ; i++){
459 for(
unsigned int i = 0 ; i <
polyClipped.size() ; i++){
475 for(
unsigned int i = 0 ; i <
polyClipped.size() ; i++){
509 for(
unsigned int i = 0 ; i <
polyClipped.size() ; i++){
513 roi.push_back(std::make_pair(ip,
polyClipped[i].second));
543 unsigned int nbPolyIn = 0;
544 for (
unsigned int i = 0; i <
nbpt; i ++){
545 if(
p[i].get_Z() > 0){
590 for(
unsigned int i = 0; i < ptIn.size(); i++)
602 double i_min_d = (double) INT_MAX;
604 double j_min_d = (double) INT_MAX;
607 for (
unsigned int i = 0; i < iroi.size(); i += 1){
608 if(i_min_d > iroi[i].get_i())
609 i_min_d = iroi[i].get_i();
611 if(iroi[i].get_i() < 0)
614 if((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
615 i_max_d = iroi[i].get_i();
617 if(j_min_d > iroi[i].get_j())
618 j_min_d = iroi[i].get_j();
620 if(iroi[i].get_j() < 0)
623 if((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
624 j_max_d = iroi[i].get_j();
626 i_min =
static_cast<int> (i_min_d);
627 i_max =
static_cast<int> (i_max_d);
628 j_min =
static_cast<int> (j_min_d);
629 j_max =
static_cast<int> (j_max_d);
643 for(
unsigned int i=0; i<corners.size(); ++i){
644 if((corners[i].get_i() >= 0) && (corners[i].get_j() >= 0) &&
650 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.
vpRowVector & normalize()
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)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of row vector and the associated operations.
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)
bool isFovComputed() const
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.
std::vector< vpColVector > getFovNormals() const
vpPolygon3D & operator=(const vpPolygon3D &mbtp)
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
void setClipping(const unsigned int &flags)
double get_X() const
Get the point X coordinate in the camera frame.
unsigned int nbpt
Number of points used to define the polygon.
unsigned int getHeight() const
std::vector< vpImagePoint > getRoi(const vpCameraParameters &cam)
Implementation of column vector and the associated operations.
void setNearClippingDistance(const double &dist)
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.
double get_Z() const
Get the point Z coordinate in the camera frame.
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &_cP)
double get_Y() const
Get the point Y coordinate in the camera frame.
unsigned int getWidth() const