41 #include <visp3/core/vpConfig.h> 47 #include <visp3/core/vpPolygon.h> 48 #include <visp3/core/vpPolygon3D.h> 54 : nbpt(0), nbCornersInsidePrev(0), p(NULL), polyClipped(), clippingFlag(
vpPolygon3D::NO_CLIPPING),
55 distNearClip(0.001), distFarClip(100.)
66 for (
unsigned int i = 0; i <
nbpt; i++)
82 for (
unsigned int i = 0; i <
nbpt; i++)
108 if (_index >=
nbpt) {
147 for (
unsigned int i = 0; i <
nbpt; i++) {
163 std::vector<vpColVector> fovNormals;
164 std::vector<std::pair<vpPoint, unsigned int> > polyClippedTemp;
165 std::vector<std::pair<vpPoint, unsigned int> > polyClippedTemp2;
170 for (
unsigned int i = 0; i <
nbpt; i++) {
176 for (
unsigned int i = 1; i < 64; i = i * 2) {
183 for (
unsigned int j = 0; j < polyClippedTemp.size(); j++) {
184 vpPoint p1Clipped = polyClippedTemp[j].first;
185 vpPoint p2Clipped = polyClippedTemp[(j + 1) % polyClippedTemp.size()].first;
187 unsigned int p2ClippedInfoBefore = polyClippedTemp[(j + 1) % polyClippedTemp.size()].second;
188 unsigned int p1ClippedInfo = polyClippedTemp[j].second;
189 unsigned int p2ClippedInfo = polyClippedTemp[(j + 1) % polyClippedTemp.size()].second;
195 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
199 problem = !(vpPolygon3D::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
204 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
209 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
214 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
219 !(vpPolygon3D::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo,
226 polyClippedTemp2.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
228 if (p2ClippedInfo != p2ClippedInfoBefore) {
230 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
234 if (p2ClippedInfo == p2ClippedInfoBefore) {
236 polyClippedTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
243 polyClippedTemp = polyClippedTemp2;
244 polyClippedTemp2.clear();
270 bool vpPolygon3D::getClippedPointsFovGeneric(
const vpPoint &p1,
const vpPoint &p2,
vpPoint &p1Clipped,
271 vpPoint &p2Clipped,
unsigned int &p1ClippedInfo,
272 unsigned int &p2ClippedInfo,
const vpColVector &normal,
273 const unsigned int &flag)
276 p1Vec[0] = p1.
get_X();
277 p1Vec[1] = p1.
get_Y();
278 p1Vec[2] = p1.
get_Z();
282 p2Vec[0] = p2.
get_X();
283 p2Vec[1] = p2.
get_Y();
284 p2Vec[2] = p2.
get_Z();
288 double beta1 = acos(p1Vec * normal);
289 double beta2 = acos(p2Vec * normal);
294 if (beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
296 else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0) {
298 double t = -(normal[0] * p1.
get_X() + normal[1] * p1.
get_Y() + normal[2] * p1.
get_Z());
306 if (beta1 < M_PI / 2.0) {
307 p1ClippedInfo = p1ClippedInfo | flag;
308 p1Clipped = pClipped;
310 p2ClippedInfo = p2ClippedInfo | flag;
311 p2Clipped = pClipped;
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_;
333 bool test1 = (p1Clipped.
get_Z() < distance && p2Clipped.
get_Z() < distance);
335 test1 = (p1Clipped.
get_Z() > distance && p2Clipped.
get_Z() > distance);
337 bool test2 = (p1Clipped.
get_Z() < distance || p2Clipped.
get_Z() < distance);
339 test2 = (p1Clipped.
get_Z() > distance || p2Clipped.
get_Z() > distance);
341 bool test3 = (p1Clipped.
get_Z() < distance);
343 test3 = (p1Clipped.
get_Z() > distance);
352 t = (distance - p1Clipped.
get_Z()) / t;
356 pClippedNear.
set_Z(distance);
359 p1Clipped = pClippedNear;
365 p2Clipped = pClippedNear;
387 std::vector<vpImagePoint> roi;
388 for (
unsigned int i = 0; i <
nbpt; i++) {
411 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS 422 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
448 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
464 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
501 for (
unsigned int i = 0; i <
polyClipped.size(); i++) {
505 roi.push_back(std::make_pair(ip,
polyClipped[i].second));
534 unsigned int nbPolyIn = 0;
535 for (
unsigned int i = 0; i <
nbpt; i++) {
536 if (
p[i].get_Z() > 0) {
584 for (
unsigned int i = 0; i < ptIn.size(); i++)
596 double i_min_d = (double)INT_MAX;
598 double j_min_d = (double)INT_MAX;
601 for (
unsigned int i = 0; i < iroi.size(); i += 1) {
602 if (i_min_d > iroi[i].get_i())
603 i_min_d = iroi[i].get_i();
605 if (iroi[i].get_i() < 0)
608 if ((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
609 i_max_d = iroi[i].get_i();
611 if (j_min_d > iroi[i].get_j())
612 j_min_d = iroi[i].get_j();
614 if (iroi[i].get_j() < 0)
617 if ((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
618 j_max_d = iroi[i].get_j();
620 i_min =
static_cast<int>(i_min_d);
621 i_max =
static_cast<int>(i_max_d);
622 j_min =
static_cast<int>(j_min_d);
623 j_max =
static_cast<int>(j_max_d);
636 for (
unsigned int i = 0; i < corners.size(); ++i) {
637 if ((corners[i].get_i() >= 0) && (corners[i].get_j() >= 0) && (corners[i].get_i() < I.
getHeight()) &&
638 (corners[i].get_j() < I.
getWidth())) {
643 if (nbPolyIn < 3 && nbPolyIn < 0.7 * corners.size())
void getRoiClipped(const vpCameraParameters &cam, std::vector< vpImagePoint > &roi)
void projection(const vpColVector &_cP, vpColVector &_p)
Implements a 3D polygon with render functionnalities like clipping.
vpRowVector & normalize()
virtual void setNbPoint(const unsigned int nb)
unsigned int nbCornersInsidePrev
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)
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.
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
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)
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.