Esempio n. 1
0
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;
}
/**
 * @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;
}
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);
                }

            }
Esempio n. 4
0
/**
  * 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);
}
Esempio n. 5
0
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
}
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;
        }
    }
}
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);
        }
    }
  }
}
Esempio n. 8
0
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);
}
/**
 * @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;
 }
Esempio n. 10
0
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;
}
Esempio n. 11
0
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));

}
Esempio n. 12
0
File: Region.cpp Progetto: h0st/core
  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);

  }
Esempio n. 13
0
/**
  \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;
}
Esempio n. 14
0
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 Qt polygon. The Qt Polygon can be used
    // in Boost.Geometry, just by its oneline registration above.
    QPolygonF polygon;

    // Use Qt to add points to polygon
    polygon
        << QPointF(10, 20) << QPointF(20, 30)
        << QPointF(30, 20) << QPointF(20, 10)
        << QPointF(10, 20);

    // Use Boost.Geometry e.g. to calculate area
    std::ostringstream out;
    out << "Boost.Geometry area: " << boost::geometry::area(polygon) << std::endl;

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

    // Qt defines an iterator
    // (which is required for of the Boost.Geometry ring-concept)
    // such that Boost.Geometry 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 Boost.Geometry 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();
}
Esempio n. 15
0
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);
        }
    }
    }
}
Esempio n. 16
0
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);
	}
}
Esempio n. 17
0
QVector<QPair<Stroke, int>> Page::getStrokes(QPolygonF selectionPolygon)
{
  QVector<QPair<Stroke, int>> strokesAndPositions;

  for (int i = m_strokes.size() - 1; i >= 0; --i)
  {
    const MrDoc::Stroke &stroke = m_strokes.at(i);
    bool containsStroke = true;
    for (int j = 0; j < stroke.points.size(); ++j)
    {
      if (!selectionPolygon.containsPoint(stroke.points.at(j), Qt::OddEvenFill))
      {
        containsStroke = false;
      }
    }
    if (containsStroke)
    {
      // add selected strokes and positions to return vector
      strokesAndPositions.append(QPair<Stroke, int>(stroke, i));
    }
  }

  return strokesAndPositions;
}
Esempio n. 18
0
qreal FlyThroughTask::calculateFlightPerformance(const QList<Position> &positions,
                                                 const QPolygonF &geoPoly,
                                                 const UAVParameters &)
{
    //First, see if one of the points is within the polygon
    foreach(const Position& pos, positions)
    {
        if (geoPoly.containsPoint(pos.lonLat(), Qt::OddEvenFill))
            return this->maxTaskPerformance();
    }

    //if that fails, take the distance to the last point
    Position goalPos(geoPoly.boundingRect().center(),
                     positions.first().altitude());

    const Position& last = positions.last();
    QVector3D enuPos = Conversions::lla2enu(last, goalPos);
    qreal dist = enuPos.length();

    const qreal stdDev = 90.0;
    qreal toRet = 100*FlightTask::normal(dist,stdDev,2000);

    return qMin<qreal>(toRet,this->maxTaskPerformance());
}
Esempio n. 19
0
void Meshing::splitDiag()
{
    for(int id=0;id<mesh_.size();id++){
        QPolygonF poly = mesh_.at(id);
        if(poly.isEmpty())
            continue;

        if(!poly.isClosed())
            poly << poly.at(0);

        if(poly.size()<=4)
            continue;

        QStringList polyID;
        for(int k=0;k<poly.size();k++)
            polyID << findID(poly.at(k));

        /*for(int i=0;i<poly.size()-2;i++){
            QPointF p = (poly.at(i) + poly.at(i+2))/2.0;
            if(poly.containsPoint(p,Qt::WindingFill)){
                QPolygonF p1,p2;
                for(int k=i;k<i+3;k++){
                    p1 << poly.at(k);
                }
                p1 << poly.at(i);
                for(int k=i+3;k<=poly.size()-1;k++){
                    p2 << poly.at(k);
                }
                for(int k=0;k<i;k++){
                    p2 << poly.at(k);
                }
                p2 << poly.at(i);
                mesh_.push_back(p1);
                mesh_.push_back(p2);
                mesh_.removeAt(id);
                splitDiag();
                return;
            }
        }*/

        //qDebug() << "Split poly" << polyID;
        for(int i=0;i<poly.size()-1;i++){
            for(int j=i+2;j<poly.size()-(i==0?2:1);j++){
                //qDebug() << "Try to split along" << findID(poly.at(i)) << findID(poly.at(j));
                QLineF line(poly.at(i),poly.at(j));
                QPointF middle = (poly.at(i)+poly.at(j))/2.0;
                if(!poly.containsPoint(middle,Qt::WindingFill))
                    continue;
                if(!intersects(poly,line)){
                    QPolygonF p1,p2;
                    //QStringList poly1id,poly2id;

                    for(int k=i;k<=j;k++){
                        p1 << poly.at(k);
                        //poly1id << findID(poly.at(k));
                    }
                    p1 << poly.at(i);
                    //poly1id << findID(poly.at(i));
                    for(int k=j;k<poly.size()-1;k++){
                        p2 << poly.at(k);
                        //poly2id << findID(poly.at(k));
                    }
                    for(int k=0;k<=i;k++){
                        p2 << poly.at(k);
                        //poly2id << findID(poly.at(k));
                    }
                    p2 << poly.at(j);
                    //poly2id << findID(poly.at(j));
                    //qDebug() << poly.size() << QPair<int,QString>(i,findID(poly.at(i))) << QPair<int,QString>(j,findID(poly.at(j))) << p1.size() << p2.size();
                    //qDebug() << "Poly1" << poly1id;
                    //qDebug() << "Poly2" << poly2id;
                    mesh_.push_back(p1);
                    mesh_.push_back(p2);
                    mesh_.removeAt(id);
                    splitDiag();
                    return;
                }
            }
        }
        //qDebug() << "Can't split poly " << polyID;
    }
}
Esempio n. 20
0
bool NodeBackDrop::isNearbyResizeHandle(const QPointF& scenePos)
{
    QPointF p = mapFromScene(scenePos);
    QPolygonF resizePoly = _imp->resizeHandle->polygon();
    return resizePoly.containsPoint(p,Qt::OddEvenFill);
}
Esempio n. 21
0
// Find next boundary pixel starting from position (x,y) which is guaranteed to be
// on the boundary, while previous direction was dir
QPoint SourceWidget::findStartingFromDir(QPolygonF & selectionPoly, int x, int y, int & dir){
    
    bool N,W,S,E;
    N = selectionPoly.containsPoint(QPointF(x,y+1),Qt::WindingFill);
    W = selectionPoly.containsPoint(QPointF(x-1,y),Qt::WindingFill);
    S = selectionPoly.containsPoint(QPointF(x,y-1),Qt::WindingFill);
    E = selectionPoly.containsPoint(QPointF(x+1,y),Qt::WindingFill);
    
    dir = (dir+3)%4;
    if (dir==0){
        if (E) {
            dir = 0;
            return QPoint(x+1,y);
        }
        if (N){
            dir = 1;
            return QPoint(x,y+1);
        }
        if (W){
            dir = 2;
            return QPoint(x-1,y);
        }
        if (S){
            dir = 3;
            return QPoint(x,y-1);
        }
    }
    
    if (dir==1){
        if (N){
            dir = 1;
            return QPoint(x,y+1);
        }
        if (W){
            dir = 2;
            return QPoint(x-1,y);
        }
        if (S){
            dir = 3;
            return QPoint(x,y-1);
        }
        if (E){
            dir = 0;
            return QPoint(x+1,y);
        }
    }
    
    if (dir==2){
        if (W){
            dir = 2;
            return QPoint(x-1,y);
        }
        if (S){
            dir = 3;
            return QPoint(x,y-1);
        }
        if (E){
            dir = 0;
            return QPoint(x+1,y);
        }
        if (N){
            dir = 1;
            return QPoint(x,y+1);
        }
    }
    if (dir==3){
        if (S){
            dir = 3;
            return QPoint(x,y-1);
        }
        if (E){
            dir = 0;
            return QPoint(x+1,y);
        }
        if (N){
            dir = 1;
            return QPoint(x,y+1);
        }
        if (W){
            dir = 2;
            return QPoint(x-1,y);
        }
    }
    
    //throw std::exception();
	assert("Wrong path in findStartingFromDir");
    return QPoint(-1,-1);
}
Esempio n. 22
0
void SourceWidget::mouseReleaseEvent(QMouseEvent *event)
{
    // Once the user releases the mouse, the selection process is finished. We need to
    // extract the selection and update the glWidget
    if (event->button() == Qt::LeftButton) {
        
        // Draw the last line
        path.lineTo(event->pos());
        path.connectPath(path);
        update();
		
		// TODO: safety due to CGAL fail
//		if (path.length()<20)
//			return;

        QPolygonF selectionPoly = path.toFillPolygon();
        QRectF boundingRect = selectionPoly.boundingRect();
		
		// Don't pass bad selections on
		if (boundingRect.width()>20 && boundingRect.height()>20)
			;
		else
			return;
		
		// adjusted - boundary value will be cut without it
        QImage sourcePatch = image.copy(boundingRect.toRect().adjusted(-1,-1,1,1)); 
        
        // Pass source patch pixels to glWidet
        glWidget->setSourcePatch(sourcePatch);
        
        qreal x0,x1,y0,y1;
        boundingRect.getCoords(&x0,&y0,&x1,&y1);
		
		
		
        // Find a point on the boundary of the selection
        QPoint cPoint(-1,-1);
        for (int x=x0; x<=x1; x++) {
            for (int y=y0; y<=y1; y++) {
                if (selectionPoly.containsPoint(QPointF(x,y),Qt::WindingFill))
                    cPoint = QPoint(x,y);
            }
        }

        //assert(cPoint != QPoint(-1,-1));
		//TODO: No violence please...
		if (cPoint == QPoint(-1,-1)){
			qDebug() << "assert(cPoint != QPoint(-1,-1)) fails";
			return;
		}
		
        // Track the boundary of the selection
        std::vector<Point> boundaryVector;
        
        // TODO: Why does it fail with dir=0 ???
        int dir = 1;
        int x,y;
        int c=0;
        bool cont = true;
        do {
            x = cPoint.x();
            y = cPoint.y();
            cPoint = findStartingFromDir(selectionPoly ,x, y, dir);
            boundaryVector.push_back(Point((cPoint.x()-x0),((y1-y0) - (cPoint.y()-y0))));

            if (boundaryVector.size()>3){
                if(boundaryVector[0]==boundaryVector[c-1] && boundaryVector[1]==boundaryVector[c]){
                    boundaryVector.pop_back();
                    boundaryVector.pop_back();
                    cont = false;
                }
            }
            c++;
        } while (cont);
		
		if (boundaryVector.size()>8192) {
			path = QPainterPath();
			update();
			QMessageBox::warning(this, tr("Boundary Size"),
							   tr("Largest supported boundary size is 8192"));
			return;
		}
		
//		// Subsample
//		std::vector<Point> boundaryVectorNew;
//		bool subs = false;
//		for(std::vector<Point>::const_iterator it = boundaryVector.begin(); it != boundaryVector.end(); ++it){
//			if(subs)
//				boundaryVectorNew.push_back(Point((*it).x(),(*it).y()));
//			subs = 1-subs;
//		}
//		boundaryVector = boundaryVectorNew;
		
//		// Subsample
//		QPolygon selectionPolyNew; 
//		int i = 0;
//		for(std::vector<Point>::const_iterator it = boundaryVector.begin(); it != boundaryVector.end(); ++it){
//			selectionPolyNew.setPoint(i, (*it).x(), (*it).y());
//			i++;
//		}	

        // TODO: Since we didn't figure out the way yet to get from CGAL the information
        // about the whenever triangle inside the boundary, glWidget will do it with
        // the help of selectionPoly
		
//		QPolygon temp(boundaryVector);
//		selectionPoly = QPolygonF(temp);
		
        selectionPoly.translate(-x0,-y0);
//        boundingRect = selectionPoly.boundingRect();
//        boundingRect.getCoords(&x0,&y0,&x1,&y1);
        glWidget->updateSelection(boundaryVector, selectionPoly);
        glWidget->update();
    }
}
Esempio n. 23
0
//-----------------------------------------------------------------------------
// Function: StickyNote::clickedAssociationButton()
//-----------------------------------------------------------------------------
bool StickyNote::hitsAssociationButton(QPointF const& clickPosition) const
{
    QPolygonF buttonArea = mapFromItem(associationButton_, associationButton_->boundingRect());
    return buttonArea.containsPoint(clickPosition, Qt::OddEvenFill);
}