当前位置: 首页>>代码示例>>C++>>正文


C++ QPolygonF::containsPoint方法代码示例

本文整理汇总了C++中QPolygonF::containsPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ QPolygonF::containsPoint方法的具体用法?C++ QPolygonF::containsPoint怎么用?C++ QPolygonF::containsPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPolygonF的用法示例。


在下文中一共展示了QPolygonF::containsPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: collides

bool Simulation::collides(const QPolygonF& p1, const QPolygonF& p2) {
    // Check each point of each polygon for being inside the other polygon
    for(const QPointF& point : p1) {
        if(p2.containsPoint(point, Qt::OddEvenFill)) {
            return true;
        }
    }
    for(const QPointF& point : p2) {
        if(p1.containsPoint(point, Qt::OddEvenFill)) {
            return true;
        }
    }
    return false;
}
开发者ID:samcrow,项目名称:GripperSimulator,代码行数:14,代码来源:simulation.cpp

示例2: checkVisiblePoints

/**
 * @brief A point of the road is visible if it is between the robot and the laser beam running through it, and if the previous point was visible
 * All points in the road are updated
 * @param road ...
 * @param laserData ...
 * @return bool
 */
bool ElasticBand::checkVisiblePoints(InnerModel *innermodel, WayPoints &road, const RoboCompLaser::TLaserData &laserData)
{
	//Simplify laser polyline using Ramer-Douglas-Peucker algorithm
	std::vector<Point> points, res;
	QVec wd;
	for (auto &ld : laserData)
	{
		//wd = innermodel->laserTo("world", "laser", ld.dist, ld.angle); //OPTIMIZE THIS FOR ALL CLASS METHODS
		wd = innermodel->getNode<InnerModelLaser>("laser")->laserTo("world", ld.dist, ld.angle);
		points.push_back(Point(wd.x(), wd.z()));
	}
	res = simPath.simplifyWithRDP(points, 70); 
	//qDebug() << __FUNCTION__ << "laser polygon after simp" << res.size();

	// Create a QPolygon so we can check if robot outline falls inside
	QPolygonF polygon;
	for (auto &p: res)
		polygon << QPointF(p.x, p.y);

	// Move the robot along the road
	int robot = road.getIndexOfNextPoint();
	QVec memo = innermodel->transform6D("world", "robot");
	for(int it = robot; it<road.size(); ++it)
	{
		road[it].isVisible = true;
		innermodel->updateTransformValues("robot", road[it].pos.x(), road[it].pos.y(), road[it].pos.z(), 0, road[it].rot.y(), 0);
		//get Robot transformation matrix
		QMat m = innermodel->getTransformationMatrix("world", "robot");
		// Transform all points at one to world RS
		//m.print("m");
		//pointsMat.print("pointsMat");
		QMat newPoints = m * pointsMat;

		//Check if they are inside the laser polygon
		for (int i = 0; i < newPoints.nCols(); i++)
		{
// 			qDebug() << __FUNCTION__ << "----------------------------------";
// 			qDebug() << __FUNCTION__ << QPointF(newPoints(0, i), newPoints(2, i));
// 			qDebug() << __FUNCTION__ << polygon;
			if (polygon.containsPoint(QPointF(newPoints(0, i), newPoints(2, i)),Qt::OddEvenFill) == false)
			{
				road[it].isVisible = false;
				//qFatal("fary");
				break;
			}
		}
//		if( road[it].isVisible == false)
//		{
//			for (int k = it; k < road.size(); ++k)
//				road[k].isVisible = false;
//			break;
//		}
	}

	// Set the robot back to its original state
	innermodel->updateTransformValues("robot", memo.x(), memo.y(), memo.z(), 0, memo.ry(), 0);

	//road.print();
	return true;
}
开发者ID:robocomp,项目名称:robocomp-ursus-rockin,代码行数:67,代码来源:elasticband.cpp

示例3: run

void AppendFaceIDToFace::run() {

    *(Output) = *(Faces);

    std::vector<std::string> faceids = VectorDataHelper::findElementsWithIdentifier(this->IdentifierFaceIDs, this->FaceIDs->getFaceNames());

    foreach (std::string faceid, faceids){
        Logger(Debug) << faceid;
        std::vector<Face> fs = this->FaceIDs->getFaces(faceid);
        std::vector<Point> pointlist = this->FaceIDs->getPoints(faceid);

        foreach (Face f, fs) {
            QPolygonF poly;

            for (int i = 0; i < f.getIDs().size(); i++) {
                poly.append(QPointF(pointlist[f.getIDs()[i]].x, pointlist[f.getIDs()[i]].y));
            }

            std::vector<std::string> faces = VectorDataHelper::findElementsWithIdentifier(this->IdentifierFaces, this->Faces->getAttributeNames());

            foreach (std::string f, faces) {
                Attribute attr = this->Faces->getAttributes(f);
                QPointF p(attr.getAttribute("centroid_x"),attr.getAttribute("centroid_y") );
                if ( poly.containsPoint(p, Qt::WindingFill) ) {
                    std::stringstream ss;
                    ss << this->IdentifierFaceIDs << "ID";
                    attr.setAttribute(ss.str(), faceid);
                    this->Output->setAttributes(f, attr);
                }

            }
开发者ID:christianurich,项目名称:VIBe2Modules,代码行数:31,代码来源:appendfaceidtoface.cpp

示例4: containsPoint

/**
  * whether a given point is within image region
  *@ coord, a point
  *@ returns true, if the point is within borders of image
  */
bool RS_Image::containsPoint(const RS_Vector& coord) const{
    QPolygonF paf;
    RS_VectorSolutions corners =getCorners();
	for(const RS_Vector& vp: corners){
		paf.push_back(QPointF(vp.x, vp.y));
    }
    paf.push_back(paf.at(0));
    return paf.containsPoint(QPointF(coord.x,coord.y),Qt::OddEvenFill);
}
开发者ID:PlastecProfiles,项目名称:LibreCAD,代码行数:14,代码来源:rs_image.cpp

示例5: main

int main(int argc, char *argv[])
{
    // This usage QApplication and QLabel is adapted from
    // http://en.wikipedia.org/wiki/Qt_(toolkit)#Qt_hello_world
    QApplication app(argc, argv);

    // Declare a polygon. This is just Qt. The Qt Polygon can be used
    // in GGL as well, just by its oneline registration above.
    QPolygonF polygon;

    // Qt methods can be used, in this case to add points
    polygon
        << QPointF(10, 20) << QPointF(20, 30)
        << QPointF(30, 20) << QPointF(20, 10)
        << QPointF(10, 20);

    // GGL methods can be used, e.g. to calculate area
    std::ostringstream out;
    out << "GGL area: " << boost::geometry::area(polygon) << std::endl;

    // Some functionality is defined in both Qt and GGL
    QPointF p(20,20);
    out << "Qt contains: "
        << (polygon.containsPoint(p, Qt::WindingFill) ? "yes" : "no")
        << std::endl
        << "GGL within: "
        << (boost::geometry::within(p, polygon) ? "yes" : "no")
        << std::endl;
    // Detail: if point is ON boundary, Qt says yes, GGL says no.


    // Qt defines an iterator
    // (which is actually required for GGL, it's part of the ring-concept)
    // such that GGL can use the points of this polygon
    QPolygonF::const_iterator it;
    for (it = polygon.begin(); it != polygon.end(); ++it)
    {
        // Stream Delimiter-Separated, just to show something GGL can do
        out << boost::geometry::dsv(*it) << std::endl;
    }

    // Stream the polygon as well
    out << boost::geometry::dsv(polygon) << std::endl;

    // Just show what we did in a label
    QLabel label(out.str().c_str());
    label.show();
    return app.exec();

    // What else could be useful, functionality that GGL has and Qt not (yet)?
    // - simplify a polygon (to get less points and preserve shape)
    // - clip a polygon with a box
    // - calculate the centroid
    // - calculate the perimeter
    // - calculate the convex hull
    // - transform it using matrix transformations
}
开发者ID:lihe757,项目名称:mylinuxproject,代码行数:57,代码来源:main.cpp

示例6: setTransformFunction

void KisFreeTransformStrategy::setTransformFunction(const QPointF &mousePos, bool perspectiveModifierActive)
{
    if (perspectiveModifierActive) {
        m_d->function = PERSPECTIVE;
        return;
    }

    QPolygonF transformedPolygon = m_d->transform.map(QPolygonF(m_d->transaction.originalRect()));
    qreal handleRadius = KisTransformUtils::effectiveHandleGrabRadius(m_d->converter);
    qreal rotationHandleRadius = KisTransformUtils::effectiveHandleGrabRadius(m_d->converter);


    StrokeFunction defaultFunction =
        transformedPolygon.containsPoint(mousePos, Qt::OddEvenFill) ? MOVE : ROTATE;
    KisTransformUtils::HandleChooser<StrokeFunction>
        handleChooser(mousePos, defaultFunction);

    handleChooser.addFunction(m_d->transformedHandles.topMiddle,
                              handleRadius, TOPSCALE);
    handleChooser.addFunction(m_d->transformedHandles.topRight,
                              handleRadius, TOPRIGHTSCALE);
    handleChooser.addFunction(m_d->transformedHandles.middleRight,
                              handleRadius, RIGHTSCALE);

    handleChooser.addFunction(m_d->transformedHandles.bottomRight,
                              handleRadius, BOTTOMRIGHTSCALE);
    handleChooser.addFunction(m_d->transformedHandles.bottomMiddle,
                              handleRadius, BOTTOMSCALE);
    handleChooser.addFunction(m_d->transformedHandles.bottomLeft,
                              handleRadius, BOTTOMLEFTSCALE);
    handleChooser.addFunction(m_d->transformedHandles.middleLeft,
                              handleRadius, LEFTSCALE);
    handleChooser.addFunction(m_d->transformedHandles.topLeft,
                              handleRadius, TOPLEFTSCALE);
    handleChooser.addFunction(m_d->transformedHandles.rotationCenter,
                              rotationHandleRadius, MOVECENTER);

    m_d->function = handleChooser.function();

    if (m_d->function == ROTATE || m_d->function == MOVE) {
        QRectF originalRect = m_d->transaction.originalRect();
        QPointF t = m_d->transform.inverted().map(mousePos);

        if (t.x() >= originalRect.left() && t.x() <= originalRect.right()) {
            if (fabs(t.y() - originalRect.top()) <= handleRadius)
                m_d->function = TOPSHEAR;
            if (fabs(t.y() - originalRect.bottom()) <= handleRadius)
                m_d->function = BOTTOMSHEAR;
        }
        if (t.y() >= originalRect.top() && t.y() <= originalRect.bottom()) {
            if (fabs(t.x() - originalRect.left()) <= handleRadius)
                m_d->function = LEFTSHEAR;
            if (fabs(t.x() - originalRect.right()) <= handleRadius)
                m_d->function = RIGHTSHEAR;
        }
    }
}
开发者ID:IGLOU-EU,项目名称:krita,代码行数:57,代码来源:kis_free_transform_strategy.cpp

示例7: drawMesh

void Renderer::drawMesh()
{
  // render mesh as a wireframe

  QPainter p(&mImage);
  p.setRenderHint(QPainter::Antialiasing);
  p.setPen(QPen(QBrush(mCfg.mesh.mMeshColor),0.5));
  p.setFont(QFont(""));
  const Mesh::Elements& elems = mMesh->elements();
  for (int i=0; i < elems.count(); ++i)
  {
    const Element& elem = elems[i];
    if( elem.isDummy() )
        continue;

    // If the element is outside the view of the canvas, skip it
    if( elemOutsideView(i) )
        continue;

    QPolygonF pts = elementPolygonPixel(elem);
    p.drawPolyline(pts.constData(), pts.size());

    if (mCfg.mesh.mRenderMeshLabels)
    {
        double cx, cy;
        mMesh->elementCentroid(i, cx, cy);
        QString txt = QString::number(elem.id());
        QRect bb = p.fontMetrics().boundingRect(txt);
        QPointF xy = mtp.realToPixel(cx, cy);
        bb.moveTo(xy.x() - bb.width()/2.0, xy.y() - bb.height()/2.0);

        if (pts.containsPoint(bb.bottomLeft(), Qt::WindingFill) &&
            pts.containsPoint(bb.bottomRight(), Qt::WindingFill) &&
            pts.containsPoint(bb.topLeft(), Qt::WindingFill) &&
            pts.containsPoint(bb.topRight(), Qt::WindingFill))
        {
            p.drawText(bb, Qt::AlignCenter, txt);
        }
    }
  }
}
开发者ID:erpas,项目名称:qgis-crayfish-plugin,代码行数:41,代码来源:crayfish_renderer.cpp

示例8: filtrate

bool FShapePolygon::filtrate(const Tag &mark)
{
  if (m_points.size() == 0) return false;

  QPolygonF polygon;
  for (int i = 0; i < m_points.size(); i++)
  {
    polygon << m_points.at(i);
  }
  polygon << m_points.at(0);
  return polygon.containsPoint(QPointF(mark.getLatitude(), mark.getLongitude()), Qt::OddEvenFill);
}
开发者ID:4ukuta,项目名称:core,代码行数:12,代码来源:FShapePolygon.cpp

示例9: checkCollisionAlongRoad

/**
 * @brief Moves a virtual copy of the robot along the road checking for enough free space around it
 * 
 * @param innermodel ...
 * @param road ...
 * @param laserData ...
 * @param robotRadius ...
 * @return bool
 */
 bool ElasticBand::checkCollisionAlongRoad(InnerModel *innermodel, const RoboCompLaser::TLaserData& laserData, WayPoints &road,  WayPoints::const_iterator robot,
                                            WayPoints::const_iterator target, float robotRadius)
 {
	//Simplify laser polyline using Ramer-Douglas-Peucker algorithm
	std::vector<Point> points, res;
	QVec wd;
	for( auto &ld : laserData)
	{
		wd = innermodel->laserTo("world", "laser", ld.dist, ld.angle);      //OPTIMIZE THIS FOR ALL CLASS METHODS
		points.push_back(Point(wd.x(), wd.z()));
	}
	res = simPath.simplifyWithRDP(points, 70);
	qDebug() << __FUNCTION__ << "laser polygon after simp" << res.size();

	// Create a QPolygon so we can check if robot outline falls inside
	QPolygonF polygon;
	for (auto &p: res)
		polygon << QPointF(p.x, p.y);

	// Move the robot along the road
	QVec memo = innermodel->transform6D("world","robot");
	bool free = false;
	for( WayPoints::const_iterator it = robot; it != target; ++it)
	{
		if( it->isVisible == false)
			break;
		// compute orientation of the robot at the point

		innermodel->updateTransformValues("robot", it->pos.x(), it->pos.y(), it->pos.z(), 0, it->rot.y(), 0);
		//get Robot transformation matrix
		QMat m = innermodel->getTransformationMatrix("world", "robot");
		// Transform all points at one
		qDebug() << __FUNCTION__ << "hello2";
		m.print("m");
		pointsMat.print("pointsMat");
		QMat newPoints = m * pointsMat;
		qDebug() << __FUNCTION__ << "hello3";

		//Check if they are inside the laser polygon
		for( int i=0; i<newPoints.nRows(); i++)
			if( polygon.containsPoint(QPointF(pointsMat(i,0)/pointsMat(i,3), pointsMat(i,2)/pointsMat(i,3)), Qt::OddEvenFill ) == false)
			{
				free = false;
				break;
			}
		free = true;
	}
	 qDebug() << __FUNCTION__ << "hello";

	 // Set the robot back to its original state
	innermodel->updateTransformValues("robot", memo.x(), memo.y(), memo.z(), 0, memo.ry(), 0);
	return free ? true : false;
 }
开发者ID:robocomp,项目名称:robocomp-ursus-rockin,代码行数:62,代码来源:elasticband.cpp

示例10:

QList<mapItem *> gameMap::getPlayerTokensOnArea(Area *a,player *p)
{
    QPolygonF areaPoly = viewer->sceneCoordinatesPolygon(a->polygon(),a->position());
    QList<mapItem *> findTokens = QList<mapItem *>();
    for(int i = 0; i < tokens->length(); i++)
    {

        if(areaPoly.containsPoint(getTokens()[i]->pos(),Qt::OddEvenFill) && getTokens()[i]->getOwnerPlayer()->getName() == p->getName())
            findTokens.append(getTokens()[i]);
    }
    return findTokens;
}
开发者ID:jcambray,项目名称:ProjetWarCPP,代码行数:12,代码来源:gamemap.cpp

示例11: paintEvent

void MainWindow::paintEvent(QPaintEvent *)
{
	QPainter p(this);

	QPolygonF frame;

	frame.append(QPointF(0.0, 0.0));
	frame.append(QPointF(0.0, 50.0));
	frame.append(QPointF(50.0, 50.0));
	frame.append(QPointF(50.0, 0.0));
	frame.append(QPointF(30.0, 0.0));
	frame.append(QPointF(30.0, 10.0));
	frame.append(QPointF(20.0, 10.0));
	frame.append(QPointF(20.0, 0.0));
	frame.append(QPointF(10.0, 0.0));

	qDebug("contains 30.0 30.0 = %d", frame.containsPoint(QPointF(30.0, 30.0), Qt::WindingFill));

	qDebug("contains 25.0 0.0 = %d", frame.containsPoint(QPointF(25.0, 0.0), Qt::WindingFill));






	frame.translate(QPointF(100, 100.0));
	p.setPen(QPen(Qt::red, 1.0));
	p.setBrush(Qt::NoBrush);

	p.drawPolygon(frame, Qt::WindingFill);

	p.setPen(QPen(Qt::blue, 2.0));
	p.setBrush(QBrush(Qt::blue));
	p.drawPoint(QPointF(130.0, 130.0));

	p.setPen(QPen(Qt::green, 2.0));
	p.setBrush(QBrush(Qt::green));
	p.drawPoint(QPointF(125.0, 100.0));

}
开发者ID:cero2k6,项目名称:qt,代码行数:40,代码来源:mainwindow.cpp

示例12: atRegion

  bool Region::atRegion(const Tag& point)
  {
    if (m_points.size() == 0) return false;

    QPolygonF polygon;
    for (int i=0;i<m_points.size();i++)
    {
      polygon << QPointF(m_points.at(i).getLatitude(),m_points.at(i).getLongitude());
    }
    polygon << QPointF(m_points.at(0).getLatitude(),m_points.at(0).getLongitude());
    return polygon.containsPoint(QPointF(point.getLatitude(),point.getLongitude()), Qt::OddEvenFill);

  }
开发者ID:h0st,项目名称:core,代码行数:13,代码来源:Region.cpp

示例13: itself

/**
  \brief This creates a database of points that are in the polygon.

  This useful for quering which points are in the polygon which ones aren't.  This should be
  much faster than quering the polygon itself (which is probably much slower).

    This returns a set of indices that are within the polygon.
*/
QSet<int> cwTriangulateTask::pointsInPolygon(const cwTriangulateTask::PointGrid &grid, const QPolygonF &polygon) const {
    QSet<int> inPolygon;

    //Go through all the grid points
    for(int i = 0; i < grid.Points.size(); i++) {
        const QPointF& point = grid.Points[i];

        //See if the grid point containts point
        if(polygon.containsPoint(point, Qt::OddEvenFill)) {
            inPolygon.insert(i);
        }
    }

    return inPolygon;
}
开发者ID:jlillest,项目名称:cavewhere,代码行数:23,代码来源:cwTriangulateTask.cpp

示例14: removePlayerTokensArea

void gameMap::removePlayerTokensArea(Area *a, player *p,int nbIteration)
{
    QPolygonF areaPoly = viewer->sceneCoordinatesPolygon(a->polygon(),a->position());

    for(int j = 0; j < nbIteration; j++)
    {
    for(int i = 0; i < tokens->length(); i++)
    {

        if(areaPoly.containsPoint(getTokens()[i]->pos(),Qt::OddEvenFill) && getTokens()[i]->getOwnerPlayer()->getName() == p->getName())
        {
           viewer->scene()->removeItem(tokens->at(i));
            tokens->removeAt(i);
        }
    }
    }
}
开发者ID:jcambray,项目名称:ProjetWarCPP,代码行数:17,代码来源:gamemap.cpp

示例15: layout

void RandomLayout::layout()
{
	int margin = 2*vertexdraws[0]->radius();
	QRect viewRect = graphdraw->rect().adjusted(margin, margin, -margin, -margin);
	// TODO: adjust for scroll bars also...

	QPolygonF polygon = graphdraw->mapToScene(viewRect);
	QRectF rect = polygon.boundingRect();
	QPointF point;

	foreach(VertexDraw* vertexdraw, vertexdraws)
	{
		do
		{
			point = QPointF(qrand() / (RAND_MAX + 1.0) * (rect.right() + 1 - rect.left()) + rect.left(),
							qrand() / (RAND_MAX + 1.0) * (rect.bottom() + 1 - rect.top()) + rect.top());

		} while(!polygon.containsPoint(point, Qt::OddEvenFill));

		vertexdraw->setPos(point);
	}
}
开发者ID:stringoftheseus,项目名称:graphshop,代码行数:22,代码来源:randomlayout.cpp


注:本文中的QPolygonF::containsPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。