QT-C++ Nesting排料优化,广告,服装,木工排料(支持矩形、异形排版,提高优化效率)

25 篇文章 6 订阅

QT-C++Nesting排料优化(支持异形排版,提高优化效率)


一、工具效果

在这里插入图片描述

支持多段线工件排版优化。

二、关键代码

代码如下:


    const double & stripWid = LB_NestConfig::STRIP_WIDTH;
    const double & stripHei = LB_NestConfig::STRIP_HEIGHT;
    const double & itemGap = LB_NestConfig::ITEM_GAP;
    const bool & enRotation = LB_NestConfig::ENABLE_ROTATION;

    if(enRotation)
        RotateToMinBounds();
    if(itemGap != 0) {
        for(int ctr = 0; ctr < polygons.size(); ++ctr) {
            polygons[ctr] = polygons[ctr].Shrinking(-itemGap);
        }
    }

    SortByAreaDecreasing();

    int stripNb = 0;
    QVector<LB_Polygon2D> unPlaced = polygons;
    QVector<LB_Polygon2D> operate;

    while(!unPlaced.isEmpty())
    {
        stripNb++;
        emit AddStrip();

      
        unPlaced[0].SetLocation(0,0);
        unPlaced[0].SetID(stripNb-1);
        emit AddItem(unPlaced[0]);

        LB_Polygon2D last = unPlaced[0];
        operate.clear();

      
        for(int i=1;i<unPlaced.size();++i) {

            if(doNestWait)
            {
                aMutex.lock();
                waitCondition.wait(&aMutex);
                aMutex.unlock();
            }

            LB_Polygon2D &orb = unPlaced[i];
            QVector<LB_Polygon2D> NFPS = NoFitPolygon(last,orb,false,false);
            LB_Polygon2D nfp;
            if(!NFPS.isEmpty()) {
                nfp = NFPS.takeFirst();
            }
            else {
                operate.append(orb);
                continue;
            }

            // iterate the nfp, to find the most left position to place the polygon
            int leftIndex = -1;
            int left = stripWid;
            for(int i=0;i<nfp.size();++i) {
                orb.SetPosition(nfp[i],0);
                if(orb.X()<0 || orb.X()+orb.Width()>stripWid)
                    continue;

                if(orb.Y()<0 || orb.Y()+orb.Height()>stripHei)
                    continue;

                if(orb.X()<left)
                {
                    left = orb.X();
                    leftIndex = i;
                }
            }

            if(leftIndex != -1) {
                orb.SetPosition(nfp[leftIndex],0);
                orb.SetID(stripNb-1);
                emit AddItem(orb);

                // get the hull of the polygons which have been placed
                bool ret1 = orb.IsAntiClockWise();
                bool ret2 = last.IsAntiClockWise();
                if(ret1 != ret2) {
                    std::reverse(orb.begin(),orb.end());
                }

                last = last.United(orb);
            }
            else {
                operate.append(orb);
            }
        }
        unPlaced = operate;
    }

    emit NestEnd();

三、代码链接

https://download.csdn.net/download/u013083044/49176476

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的大海贼

联系博主,为您提供有价值的资源

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值